:root {
  --bg: #f7f0e7;
  --bg-deep: #eee1d1;
  --panel: #fffaf3;
  --panel-2: #f5eadc;
  --line: #bca487;
  --line-soft: #d8c7b1;
  --ink: #5c432d;
  --ink-soft: #8a6d50;
  --gold: #f4bd34;
  --gold-hi: #ffd86a;
  --gold-deep: #c98508;
  --green: #89ad4d;
  --green-deep: #56782d;
  --shadow: 0 14px 32px rgba(83, 57, 34, 0.16);
  --shadow-small: 0 7px 14px rgba(83, 57, 34, 0.14);
  --radius-xl: 32px;
  --radius-lg: 22px;
  --radius-md: 16px;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background: radial-gradient(circle at 50% 18%, #fffaf4 0%, var(--bg) 48%, var(--bg-deep) 100%);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button { color: inherit; }
.icon-sprite { position:absolute; width:0; height:0; overflow:hidden; pointer-events:none; }
.ti {
  display:block; width:1em; height:1em;
  fill:none; stroke:currentColor; stroke-width:2;
  stroke-linecap:round; stroke-linejoin:round;
}
.button-icon .ti { width:26px; height:26px; }

.app-shell { position: relative; width: 100%; height: 100%; min-height: 100%; }
.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(1.015);
  transition: opacity .28s ease, transform .28s ease, visibility .28s;
}
.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

/* Loading */
.loading-screen {
  display:grid;
  place-items:center;
  overflow:hidden;
  background:
    radial-gradient(circle at 50% 18%, #fffdf8 0%, #f4eadf 62%, #e7d7c3 100%);
}
.loading-screen::before {
  content:"";
  position:absolute; inset:-10%;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.42), transparent 24%),
    radial-gradient(circle at 80% 18%, rgba(255,255,255,.26), transparent 22%),
    radial-gradient(circle at 52% 82%, rgba(255,255,255,.18), transparent 26%);
  pointer-events:none;
}
.brand-splash,
.loading-content {
  position:absolute; inset:0;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  padding:24px;
  transition:opacity .45s ease, transform .45s ease, visibility .45s ease;
}
.brand-splash {
  gap:18px;
  opacity:1; visibility:visible;
  transform:scale(1);
}
.brand-splash__logo {
  display:block;
  width:min(620px, 72vw);
  height:auto;
  filter:drop-shadow(0 18px 30px rgba(38, 24, 78, .22));
  pointer-events:none;
  animation:brandSplashIn 1.15s cubic-bezier(.18,.8,.18,1);
}
@keyframes brandSplashIn {
  0% { opacity:0; transform:translateY(20px) scale(.84); }
  55% { opacity:1; transform:translateY(0) scale(1.03); }
  100% { opacity:1; transform:translateY(0) scale(1); }
}
.loading-content {
  gap:20px;
  opacity:0; visibility:hidden;
  transform:translateY(14px) scale(.98);
}
.loading-game-logo-img {
  display:block;
  width:min(430px, 54vw);
  height:auto;
  filter:drop-shadow(0 10px 22px rgba(74, 47, 18, .16));
  pointer-events:none;
}
.loading-screen.stage-loading .brand-splash {
  opacity:0; visibility:hidden;
  transform:translateY(-16px) scale(.96);
}
.loading-screen.stage-loading .loading-content {
  opacity:1; visibility:visible;
  transform:translateY(0) scale(1);
}
.loading-track {
  width:min(360px, 50vw);
  height:14px;
  padding:3px;
  border-radius:999px;
  background:rgba(255,255,255,.72);
  overflow:hidden;
  box-shadow:inset 0 2px 8px rgba(80,52,27,.12), 0 7px 18px rgba(83,57,34,.08);
}
.loading-bar {
  height:100%; width:0%; border-radius:inherit;
  background:linear-gradient(90deg, var(--gold-deep), var(--gold-hi));
  transition:width .2s ease;
}
.loading-text {
  margin:0; font-size:12px; letter-spacing:.18em; color:var(--ink-soft);
}

/* Shared brand */
.brand-mark {
  position: relative;
  width: min(860px, 66vw);
  padding: clamp(8px, 1.4vw, 18px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 72px;
  height: 2px;
  background: var(--line);
}
.brand-mark::before { left: -48px; }
.brand-mark::after { right: -48px; }
.brand-crown {
  position: absolute;
  left: 50%; top: -30px;
  transform: translateX(-50%);
  font-size: clamp(38px, 4vw, 62px);
  color: var(--gold);
  line-height: 1;
  text-shadow: 0 3px 0 var(--gold-deep), 0 7px 12px rgba(95,64,20,.22);
}
.brand-title {
  font-weight: 1000;
  font-size: clamp(42px, 7vw, 100px);
  line-height: .95;
  letter-spacing: .035em;
  color: #67472f;
  -webkit-text-stroke: clamp(1px, .12vw, 2px) #d49a2d;
  text-shadow: 0 4px 0 #fff3d6, 0 8px 0 rgba(104,70,35,.14);
  white-space: nowrap;
}
.brand-rule {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 58%;
  margin: 18px auto 0;
  color: var(--line);
}
.brand-rule::before, .brand-rule::after { content:""; flex:1; height:2px; background: var(--line-soft); }
.brand-rule span {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 50%; border: 2px solid var(--line);
  background: #fff8ed;
  font-weight: 900;
}
.brand-mark--compact { width: min(720px, 72vw); padding-block: 26px 18px; }
.brand-mark--compact .brand-title { font-size: clamp(36px, 5.4vw, 72px); }

.brand-mark--logo {
  display:flex; align-items:center; justify-content:center;
  padding: clamp(14px, 2.4vw, 28px);
}
.brand-mark--logo::before,
.brand-mark--logo::after,
.brand-mark--logo .brand-crown,
.brand-mark--logo .brand-title,
.brand-mark--logo .brand-rule { display:none; }
.brand-logo {
  display:block;
  width:min(100%, 820px);
  height:auto;
  filter: drop-shadow(0 10px 20px rgba(74, 47, 18, .16));
  image-rendering:auto;
  pointer-events:none;
}
.brand-mark--compact.brand-mark--logo { width:min(760px, 78vw); padding: 14px 18px; }
.brand-mark--compact.brand-mark--logo .brand-logo { width:min(100%, 660px); }

/* Buttons */
.button {
  border: 0;
  border-radius: 18px;
  padding: 17px 26px;
  font-weight: 1000;
  letter-spacing: .055em;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  touch-action: manipulation;
}
.button:hover { filter: brightness(1.025); }
.button:active { transform: translateY(3px) scale(.99); }
.button--gold {
  color: #68400b;
  border: 2px solid #bc7708;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  box-shadow: inset 0 0 0 4px rgba(255,245,186,.54), 0 7px 0 #b76f05, var(--shadow-small);
}
.button--green {
  color: #fff;
  border: 2px solid #55752e;
  background: linear-gradient(180deg, #9fbe63, #7ea446);
  text-shadow: 0 2px rgba(40,64,20,.3);
  box-shadow: inset 0 0 0 3px rgba(233,255,207,.3), 0 6px 0 #4f6d2d, var(--shadow-small);
}
.button--soft {
  background: linear-gradient(180deg, #fffaf2, #eee2d2);
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.55), 0 5px 0 #b9a187;
}

/* Menu */
.menu-screen { padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
.menu-frame {
  position: relative;
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(20px, 3.2vh, 34px);
  border: 3px solid var(--line);
  border-radius: 34px;
  background:
    linear-gradient(90deg, transparent 49.75%, rgba(163,131,94,.04) 49.75%, rgba(163,131,94,.04) 50.25%, transparent 50.25%),
    linear-gradient(180deg, rgba(255,255,255,.72), rgba(246,236,223,.84));
  box-shadow: inset 0 0 0 8px rgba(255,255,255,.48), var(--shadow);
  overflow: hidden;
}
.menu-frame::before {
  content:""; position:absolute; inset:16px; pointer-events:none;
  border: 2px solid rgba(188,164,135,.58); border-radius:24px;
}
.corner-emblem {
  position: absolute;
  display: grid; place-items: center;
  width: 54px; height: 54px;
  border: 2px solid var(--line-soft);
  border-radius: 50%;
  background: rgba(255,250,242,.72);
  color: var(--ink-soft); font-size: 28px; font-weight: 1000;
}
.corner-emblem--tl { left: 30px; top: 28px; }
.corner-emblem--tr { right: 30px; top: 28px; }
.corner-emblem--bl { left: 30px; bottom: 28px; }
.corner-emblem--br { right: 30px; bottom: 28px; }
.button--play { min-width: min(520px, 54vw); font-size: clamp(28px, 3.6vw, 52px); padding-block: clamp(17px, 2.3vh, 26px); }
.menu-actions { display: grid; grid-template-columns: repeat(3, minmax(180px, 280px)); gap: 18px; }
.button--panel {
  min-height: 88px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(180deg, rgba(255,252,247,.96), rgba(238,225,209,.94));
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.54), 0 5px 0 #b9a187, var(--shadow-small);
}
.button--panel span:last-child { display:flex; flex-direction:column; align-items:flex-start; }
.button--panel b { font-size: 17px; }
.button--panel small { margin-top: 3px; font-size: 12px; color: var(--ink-soft); letter-spacing: .08em; }
.button-icon {
  display:grid; place-items:center; flex:0 0 auto;
  width:50px; height:50px; border-radius:50%;
  border:2px solid var(--line-soft); background:#fff9f0; font-size:25px;
}
.menu-footer { margin: 0; font-size: 12px; letter-spacing: .22em; color: var(--ink-soft); }

/* Game */
.game-screen {
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}
.game-header {
  display:grid;
  grid-template-columns:minmax(86px, 1fr) minmax(150px, 270px) minmax(150px, 270px) minmax(170px, 1fr);
  gap:12px;
  align-items:center;
}
.header-left { display:flex; justify-content:flex-start; align-items:center; }
.score-card, .icon-button {
  min-height:74px;
  border:2px solid var(--line);
  border-radius:18px;
  background:linear-gradient(180deg, rgba(255,252,247,.96), rgba(238,225,209,.94));
  box-shadow:inset 0 0 0 3px rgba(255,255,255,.54), var(--shadow-small);
}
.score-card { display:flex; flex-direction:column; justify-content:center; align-items:center; }
.score-card span { font-size:12px; color:var(--ink-soft); letter-spacing:.14em; font-weight:900; }
.score-card strong { font-size:clamp(25px, 2.7vw, 42px); line-height:1.04; }
.header-actions { display:flex; justify-content:flex-end; gap:12px; }
.icon-button {
  display:grid; place-items:center; width:74px; padding:0;
  font-size:32px; font-weight:1000; cursor:pointer; color:var(--ink);
  transition:transform .14s ease, filter .14s ease, background .14s ease;
}
.icon-button .ti { width:32px; height:32px; }
.icon-button--home { background:linear-gradient(180deg, #fff9ed, #ecdcc7); }
.icon-button:hover { filter:brightness(1.035); }
.icon-button:active { transform:translateY(2px) scale(.98); }

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns:minmax(145px, .62fr) minmax(520px, 3.2fr) minmax(190px, .86fr);
  gap: 12px;
  align-items: stretch;
}
.side-card {
  min-height: 0;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,252,247,.92), rgba(238,225,209,.92));
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.5), var(--shadow-small);
  padding: 16px 12px;
}
.next-card { display:flex; flex-direction:column; align-items:center; justify-content:flex-start; }
.side-label { font-weight:1000; letter-spacing:.16em; color:var(--ink-soft); font-size:13px; }
.next-preview {
  width: min(150px, 100%); aspect-ratio: 1;
  margin: 12px 0;
  display:grid; place-items:center;
  border:2px solid var(--line-soft); border-radius:20px;
  background:rgba(255,255,255,.48);
}
.next-preview img { width:76%; height:76%; object-fit:contain; filter:drop-shadow(0 5px 4px rgba(80,50,20,.17)); }
.next-card p { margin:auto 0 4px; text-align:center; color:var(--ink-soft); font-size:11px; line-height:1.35; }
.board-column { min-width:0; min-height:0; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.board-frame {
  position:relative; min-height:0; flex:0 1 auto;
  width:min(100%, calc((100vh - 125px) * 1.384615));
  aspect-ratio:900 / 650;
  border: 3px solid var(--line);
  border-radius: 30px;
  overflow:hidden;
  background: linear-gradient(180deg, rgba(252,247,240,.97), rgba(232,219,203,.97));
  box-shadow: inset 0 0 0 6px rgba(255,255,255,.42), var(--shadow-small);
}
.board-frame::after {
  content:""; position:absolute; inset:8px; border:1px solid rgba(149,117,83,.2); border-radius:22px; pointer-events:none;
}
#gameCanvas { display:block; width:100%; height:100%; touch-action:none; cursor:crosshair; }
.danger-label {
  position:absolute; right:12px; top:calc(18.46% - 9px);
  padding:2px 7px; border-radius:999px;
  background:#e7d8c5; color:#a07858; font-size:9px; letter-spacing:.1em; font-weight:1000;
  pointer-events:none;
}
.control-hint { text-align:center; padding:7px 0 0; font-size:10px; letter-spacing:.14em; color:var(--ink-soft); font-weight:900; }
.touch-hint { display:none; }
.ladder-card { overflow:hidden; display:flex; flex-direction:column; }
.ladder-card .side-label { text-align:center; white-space:nowrap; }
.merge-ladder {
  position:relative; flex:1; min-height:0; margin-top:8px;
  display:grid; grid-template-rows:repeat(12, minmax(0, 1fr)); gap:2px;
  align-items:stretch;
}
.merge-ladder::before {
  content:""; position:absolute; left:13px; top:12px; bottom:12px; width:2px;
  border-radius:99px; background:linear-gradient(180deg, var(--gold), var(--line), var(--gold-deep));
  opacity:.65;
}
.ladder-step {
  position:relative; z-index:1; min-height:0; width:100%;
  display:grid; grid-template-columns:26px minmax(0, 1fr) 44px; align-items:center; gap:7px;
  padding:2px 4px 2px 0; border-radius:10px;
}
.ladder-step:nth-child(even) { background:rgba(255,255,255,.2); }
.ladder-node {
  display:grid; place-items:center; width:24px; height:24px; margin-left:2px;
  border:1.5px solid var(--line); border-radius:50%;
  background:#fff9ef; color:var(--ink-soft);
  font-size:9px; line-height:1; font-weight:1000;
  box-shadow:0 2px 4px rgba(80,50,20,.1);
}
.ladder-image { min-width:0; min-height:0; height:100%; display:flex; align-items:center; justify-content:center; }
.ladder-image img {
  display:block; max-width:100%; max-height:clamp(22px, 5.2vh, 50px); width:auto; height:auto;
  object-fit:contain; filter:drop-shadow(0 2px 1px rgba(80,50,20,.15));
}
.ladder-step--circle .ladder-image img { max-width:clamp(24px, 4.1vh, 46px); }
.ladder-value {
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:right;
  color:var(--ink); font-size:12px; font-weight:1000; letter-spacing:.01em;
}
.ladder-step:last-child .ladder-value { color:var(--gold-deep); }

/* Modals */
.modal-layer {
  position:absolute; inset:0; z-index:20;
  display:grid; place-items:center;
  padding:24px;
  background:rgba(64,45,28,.46);
  backdrop-filter:blur(6px);
  opacity:0; visibility:hidden; pointer-events:none;
  transition:opacity .2s ease, visibility .2s;
}
.modal-layer.is-open { opacity:1; visibility:visible; pointer-events:auto; }
.modal-card {
  display:none;
  position:relative;
  width:min(560px, 92vw);
  padding:42px 42px 34px;
  border:3px solid var(--line);
  border-radius:30px;
  background:linear-gradient(180deg, #fffdf9, #f1e6d8);
  box-shadow:inset 0 0 0 6px rgba(255,255,255,.6), 0 25px 60px rgba(42,27,14,.3);
  text-align:center;
  animation:popIn .24s ease both;
}
.modal-card.is-active { display:block; }
@keyframes popIn { from { opacity:0; transform:translateY(16px) scale(.94); } to { opacity:1; transform:none; } }
.modal-crown {
  position:absolute; left:50%; top:-31px; transform:translateX(-50%);
  font-size:52px; line-height:1; color:var(--gold); text-shadow:0 3px var(--gold-deep), 0 8px 12px rgba(80,50,10,.2);
}
.modal-card h2 { margin:5px 0 8px; font-size:clamp(34px, 5vw, 58px); letter-spacing:.05em; }
.modal-card p { color:var(--ink-soft); }
.modal-card > .button { width:100%; margin-top:20px; font-size:20px; }
.modal-row { display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-top:18px; }
.result-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin:22px 0 6px; }
.result-grid div { padding:18px; border:2px solid var(--line-soft); border-radius:17px; background:rgba(255,255,255,.46); }
.result-grid span { display:block; color:var(--ink-soft); font-size:12px; letter-spacing:.12em; font-weight:1000; }
.result-grid strong { display:block; font-size:36px; margin-top:4px; }
.new-best-badge { display:none; margin:10px auto -5px; width:max-content; padding:7px 15px; border-radius:999px; background:#f4c94f; color:#6f480d; font-weight:1000; letter-spacing:.08em; transform:rotate(-2deg); }
.new-best-badge.is-visible { display:block; }
.settings-card { width:min(500px, 92vw); }
.volume-control {
  padding:15px 18px 17px; margin-top:12px;
  border:2px solid var(--line-soft); border-radius:17px;
  background:rgba(255,255,255,.52);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.8);
}
.volume-control__head {
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  margin-bottom:13px; font-weight:1000;
}
.volume-control__label, .toggle-label { display:flex; align-items:center; gap:10px; }
.volume-control__label .ti, .toggle-label .ti { width:24px; height:24px; stroke-width:2.1; }
.volume-control output {
  min-width:54px; padding:5px 9px; border:1px solid var(--line-soft); border-radius:999px;
  background:#f3e7d8; color:var(--ink); font-size:12px; font-weight:1000; letter-spacing:.05em;
  text-align:center; font-variant-numeric:tabular-nums;
}
.volume-range {
  --range-progress:70%;
  --range-accent:var(--gold);
  width:100%; height:14px; margin:0; border:0; border-radius:999px; outline:0;
  appearance:none; -webkit-appearance:none; cursor:pointer; touch-action:none;
  background:linear-gradient(90deg, var(--range-accent) 0 var(--range-progress), #d7c5ae var(--range-progress) 100%);
  box-shadow:inset 0 2px 4px rgba(68,42,20,.18), 0 1px 0 rgba(255,255,255,.9);
}
.volume-range--green { --range-accent:var(--green); }
.volume-range::-webkit-slider-runnable-track { height:14px; border-radius:999px; background:transparent; }
.volume-range::-webkit-slider-thumb {
  width:29px; height:29px; margin-top:-7.5px; border:3px solid #fff9ef; border-radius:50%;
  appearance:none; -webkit-appearance:none; background:var(--range-accent);
  box-shadow:0 2px 0 rgba(93,61,26,.25), 0 5px 12px rgba(79,50,22,.22);
  transition:transform .12s ease, box-shadow .12s ease;
}
.volume-range::-moz-range-track { height:14px; border-radius:999px; background:#d7c5ae; box-shadow:inset 0 2px 4px rgba(68,42,20,.18); }
.volume-range::-moz-range-progress { height:14px; border-radius:999px; background:var(--range-accent); }
.volume-range::-moz-range-thumb {
  width:24px; height:24px; border:3px solid #fff9ef; border-radius:50%; background:var(--range-accent);
  box-shadow:0 2px 0 rgba(93,61,26,.25), 0 5px 12px rgba(79,50,22,.22);
}
.volume-range:hover::-webkit-slider-thumb, .volume-range:focus-visible::-webkit-slider-thumb { transform:scale(1.08); box-shadow:0 2px 0 rgba(93,61,26,.25), 0 6px 16px rgba(79,50,22,.3); }
.volume-range:focus-visible { box-shadow:0 0 0 4px rgba(244,189,52,.22), inset 0 2px 4px rgba(68,42,20,.18); }
.toggle-row {
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 18px; margin-top:12px;
  border:2px solid var(--line-soft); border-radius:16px; background:rgba(255,255,255,.48);
  font-weight:1000;
}
.toggle-row input { position:absolute; opacity:0; pointer-events:none; }
.toggle-row i {
  position:relative; flex:0 0 auto; width:58px; height:32px; border-radius:999px; background:#cbb9a4; box-shadow:inset 0 2px 4px rgba(60,35,15,.16); transition:.2s;
}
.toggle-row i::after {
  content:""; position:absolute; left:4px; top:4px; width:24px; height:24px; border-radius:50%; background:#fff; box-shadow:0 2px 5px rgba(50,30,15,.22); transition:.2s;
}
.toggle-row input:checked + i { background:var(--green); }
.toggle-row input:checked + i::after { transform:translateX(26px); }
.toggle-row input:focus-visible + i { box-shadow:0 0 0 4px rgba(137,173,77,.24), inset 0 2px 4px rgba(60,35,15,.16); }
.how-steps { text-align:left; margin:22px 0 0; }
.how-steps p { margin:10px 0; padding:12px 14px; border-radius:13px; background:rgba(255,255,255,.45); }
.how-steps b { display:inline-grid; place-items:center; width:27px; height:27px; margin-right:8px; border-radius:50%; background:var(--gold); color:#6b430b; }

.toast {
  position:absolute; z-index:40; left:50%; bottom:28px; transform:translate(-50%, 18px);
  padding:11px 18px; border-radius:999px; background:rgba(75,52,33,.9); color:white;
  font-weight:900; font-size:13px; letter-spacing:.04em; opacity:0; pointer-events:none; transition:.2s;
}
.toast.is-visible { opacity:1; transform:translate(-50%, 0); }
.rotate-notice { display:none; }

@media (pointer:coarse) {
  .mouse-hint { display:none; }
  .touch-hint { display:inline; }
}

@media (max-width: 1100px) {
  .game-header { grid-template-columns:minmax(72px,1fr) 180px 180px 160px; }
  .game-layout { grid-template-columns:132px minmax(460px,1fr) 174px; }
  .menu-actions { grid-template-columns:repeat(3, minmax(150px, 220px)); }
  .brand-mark { width:min(900px,78vw); }
}

@media (max-height: 700px) {
  .menu-frame { gap:16px; }
  .brand-mark { padding-top:25px; padding-bottom:12px; }
  .brand-title { font-size:clamp(38px, 6vw, 74px); }
  .button--play { padding-block:14px; }
  .button--panel { min-height:70px; }
  .menu-footer { display:none; }
  .game-header { gap:8px; }
  .score-card, .icon-button { min-height:58px; }
  .icon-button { width:58px; }
  .icon-button .ti { width:26px; height:26px; }
  .game-layout { gap:8px; }
  .side-card { padding:11px 8px; }
  .next-preview { margin:8px 0; }
  .control-hint { padding-top:4px; }
}

@media (orientation: portrait) and (max-width: 760px) {
  .rotate-notice {
    position:absolute; inset:0; z-index:100;
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px;
    padding:30px; text-align:center; background:linear-gradient(180deg,#fffaf4,#eadbc8);
  }
  .rotate-notice::before { content:"↻"; font-size:66px; color:var(--gold-deep); }
  .rotate-notice strong { font-size:24px; }
  .rotate-notice span { color:var(--ink-soft); }
}

@media (max-width: 900px) and (orientation: landscape) {
  .game-screen { padding:6px; gap:6px; }
  .game-header { grid-template-columns:48px 130px 130px auto; gap:6px; }
  .score-card, .icon-button { min-height:48px; border-radius:12px; }
  .score-card strong { font-size:22px; }
  .header-actions { gap:6px; justify-content:flex-end; }
  .icon-button { width:48px; font-size:24px; }
  .icon-button .ti { width:23px; height:23px; }
  .game-layout { grid-template-columns:98px minmax(0,1fr) 132px; gap:6px; }
  .side-card { border-radius:16px; padding:8px 5px; }
  .side-label { font-size:11px; }
  .next-card p { display:none; }
  .board-frame { border-radius:19px; width:min(100%, calc((100vh - 72px) * 1.384615)); }
  .control-hint { display:none; }
  .merge-ladder { margin-top:4px; gap:0; }
  .merge-ladder::before { left:9px; top:8px; bottom:8px; }
  .ladder-step { grid-template-columns:18px minmax(0,1fr) 36px; gap:4px; padding:1px 2px 1px 0; border-radius:6px; }
  .ladder-node { width:18px; height:18px; margin-left:1px; font-size:7px; border-width:1px; }
  .ladder-image img { max-height:22px; }
  .ladder-step--circle .ladder-image img { max-width:22px; }
  .ladder-value { font-size:9px; }
  .brand-mark::before, .brand-mark::after { display:none; }
  .menu-actions { grid-template-columns:repeat(3, minmax(120px, 160px)); gap:10px; }
  .button--panel { min-height:62px; padding:8px; gap:8px; }
  .button-icon { width:36px; height:36px; font-size:18px; }
  .button--panel b { font-size:12px; }
  .button--panel small { display:none; }
}

/* Responsive mobile pass */
html, body, .app-shell { width:100%; height:100%; height:100dvh; }
img, canvas { -webkit-user-drag:none; user-drag:none; }
.rotate-notice { display:none !important; }

/* Keep every modal inside the real phone viewport. */
.modal-layer {
  padding:max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.modal-card {
  max-height:calc(100dvh - 20px);
  overflow-y:auto;
  overscroll-behavior:contain;
}

@media (max-width: 760px) {
  .loading-content, .brand-splash { padding:16px; }
  .brand-splash__logo { width:min(500px, 86vw); }
  .loading-game-logo-img { width:min(390px, 78vw); }
  .loading-track { width:min(330px, 76vw); }

  .menu-screen {
    padding:max(7px, env(safe-area-inset-top)) max(7px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left));
  }
  .menu-frame {
    min-height:0;
    justify-content:center;
    gap:clamp(8px, 2.2dvh, 16px);
    padding:clamp(12px, 3dvh, 24px) 10px;
    border-width:2px;
    border-radius:22px;
    overflow:hidden;
  }
  .menu-frame::before { inset:7px; border-width:1px; border-radius:16px; }
  .corner-emblem { width:32px; height:32px; font-size:16px; border-width:1px; opacity:.62; }
  .corner-emblem--tl { left:13px; top:12px; }
  .corner-emblem--tr { right:13px; top:12px; }
  .corner-emblem--bl { left:13px; bottom:12px; }
  .corner-emblem--br { right:13px; bottom:12px; }
  .brand-mark, .brand-mark--logo {
    width:min(430px, 88vw);
    padding:0;
    flex:0 1 auto;
  }
  .brand-logo { width:100%; max-height:clamp(100px, 25dvh, 190px); object-fit:contain; filter:drop-shadow(0 6px 12px rgba(74,47,18,.13)); }
  .button--play {
    width:min(330px, 78vw);
    min-width:0;
    padding:clamp(10px, 2dvh, 15px) 20px;
    border-radius:14px;
    font-size:clamp(23px, 7vw, 32px);
  }
  .menu-actions {
    width:min(430px, 90vw);
    grid-template-columns:1fr;
    gap:8px;
  }
  .button--panel {
    width:100%;
    min-height:54px;
    justify-content:flex-start;
    padding:7px 14px;
    border-radius:13px;
    gap:11px;
  }
  .button-icon { width:36px; height:36px; font-size:18px; border-width:1px; }
  .button-icon .ti { width:20px; height:20px; }
  .button--panel b { font-size:13px; }
  .button--panel small { margin-top:1px; font-size:9px; }
  .menu-footer { display:none; }

  .modal-card {
    width:min(440px, calc(100vw - 18px));
    padding:30px 16px 16px;
    border-width:2px;
    border-radius:20px;
  }
  .modal-crown { top:-21px; font-size:38px; }
  .modal-card h2 { margin:2px 0 5px; font-size:clamp(27px, 9vw, 40px); }
  .modal-card p { margin:6px 0; font-size:13px; }
  .modal-card > .button { margin-top:12px; padding:12px 16px; font-size:15px; }
  .modal-row { gap:8px; margin-top:10px; }
  .result-grid { gap:8px; margin:12px 0 4px; }
  .result-grid div { padding:10px 8px; border-radius:12px; }
  .result-grid span { font-size:9px; }
  .result-grid strong { font-size:27px; }
  .volume-control { padding:10px 11px 12px; margin-top:8px; border-radius:13px; }
  .volume-control__head { margin-bottom:9px; }
  .volume-control__label .ti, .toggle-label .ti { width:19px; height:19px; }
  .toggle-row { padding:11px 12px; margin-top:8px; border-radius:13px; }
  .toggle-row i { width:50px; height:28px; }
  .toggle-row i::after { width:20px; height:20px; }
  .toggle-row input:checked + i::after { transform:translateX(22px); }
  .how-steps { margin-top:10px; }
  .how-steps p { margin:6px 0; padding:8px 10px; font-size:12px; }
  .how-steps b { width:23px; height:23px; }
}

/* Phone portrait: actual playable stacked layout, no rotate wall. */
@media (max-width: 760px) and (orientation: portrait) {
  .game-screen {
    padding:max(5px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    grid-template-rows:auto minmax(0, 1fr);
    gap:5px;
  }
  .game-header {
    grid-template-columns:38px minmax(72px,1fr) minmax(72px,1fr) 82px;
    gap:4px;
  }
  .score-card, .icon-button {
    min-height:42px;
    border-width:1.5px;
    border-radius:11px;
    box-shadow:inset 0 0 0 2px rgba(255,255,255,.46), 0 3px 7px rgba(83,57,34,.1);
  }
  .icon-button { width:38px; }
  .icon-button .ti { width:20px; height:20px; }
  .score-card span { font-size:8px; letter-spacing:.1em; }
  .score-card strong { font-size:clamp(17px, 5.6vw, 23px); }
  .header-actions { gap:4px; }

  .game-layout {
    min-height:0;
    display:grid;
    grid-template-columns:1fr;
    grid-template-rows:46px minmax(0, 1fr) 88px;
    gap:5px;
    align-items:stretch;
  }
  .side-card {
    border-width:1.5px;
    border-radius:13px;
    padding:5px 7px;
    box-shadow:inset 0 0 0 2px rgba(255,255,255,.42), 0 3px 7px rgba(83,57,34,.1);
  }
  .next-card {
    order:1;
    display:grid;
    grid-template-columns:auto 42px 1fr;
    align-items:center;
    justify-items:start;
    gap:8px;
  }
  .next-card .side-label { font-size:10px; white-space:nowrap; }
  .next-preview {
    width:40px;
    height:40px;
    aspect-ratio:auto;
    margin:0;
    border-width:1px;
    border-radius:10px;
  }
  .next-preview img { width:82%; height:82%; }
  .next-card p { margin:0; font-size:10px; text-align:left; }
  .board-column { order:2; min-height:0; justify-content:center; }
  .board-frame {
    width:min(100%, calc((100dvh - 194px) * 1.384615));
    max-height:calc(100dvh - 194px);
    border-width:2px;
    border-radius:17px;
    box-shadow:inset 0 0 0 3px rgba(255,255,255,.36), 0 4px 9px rgba(83,57,34,.11);
  }
  .board-frame::after { inset:4px; border-radius:12px; }
  .danger-label { right:7px; padding:1px 5px; font-size:7px; }
  .control-hint { display:none; }

  .ladder-card { order:3; padding:5px 6px 6px; overflow:hidden; }
  .ladder-card .side-label { font-size:9px; line-height:11px; }
  .merge-ladder {
    margin-top:3px;
    display:grid;
    grid-template-columns:repeat(6, minmax(0, 1fr));
    grid-template-rows:repeat(2, minmax(0, 1fr));
    gap:2px;
  }
  .merge-ladder::before { display:none; }
  .ladder-step {
    min-width:0;
    display:grid;
    grid-template-columns:1fr;
    grid-template-rows:minmax(0,1fr) auto;
    place-items:center;
    gap:0;
    padding:1px;
    border-radius:6px;
  }
  .ladder-node { display:none; }
  .ladder-image { width:100%; }
  .ladder-image img { max-height:24px; max-width:45px; }
  .ladder-step--circle .ladder-image img { max-width:25px; }
  .ladder-value { width:100%; font-size:8px; line-height:10px; text-align:center; }
}

/* Very short portrait phones such as 360x480. */
@media (max-width: 430px) and (orientation: portrait) and (max-height: 560px) {
  .menu-frame { gap:7px; padding:10px 8px; }
  .brand-mark, .brand-mark--logo { width:min(340px, 82vw); }
  .brand-logo { max-height:112px; }
  .button--play { padding:9px 18px; font-size:23px; }
  .menu-actions { gap:5px; width:min(340px, 88vw); }
  .button--panel { min-height:48px; padding:5px 11px; }
  .button-icon { width:32px; height:32px; }
  .button--panel small { display:none; }

  .game-layout { grid-template-rows:42px minmax(0,1fr) 76px; gap:4px; }
  .game-header { grid-template-columns:34px minmax(64px,1fr) minmax(64px,1fr) 74px; }
  .score-card, .icon-button { min-height:38px; }
  .icon-button { width:34px; }
  .board-frame {
    width:min(100%, calc((100dvh - 170px) * 1.384615));
    max-height:calc(100dvh - 170px);
  }
  .next-card { grid-template-columns:auto 35px 1fr; }
  .next-preview { width:34px; height:34px; }
  .ladder-image img { max-height:20px; }
  .ladder-step--circle .ladder-image img { max-width:21px; }
  .ladder-value { font-size:7px; }
}

/* Phone landscape: compact but complete, fitting 360px-high screens. */
@media (max-width: 960px) and (orientation: landscape) {
  .menu-screen { padding:5px; }
  .menu-frame {
    display:grid;
    grid-template-columns:minmax(210px, .95fr) minmax(230px, 1.05fr);
    grid-template-rows:auto auto;
    align-content:center;
    justify-items:center;
    column-gap:14px;
    row-gap:9px;
    padding:10px 16px;
    border-radius:20px;
  }
  .menu-frame::before { inset:6px; border-radius:14px; }
  .brand-mark, .brand-mark--logo {
    grid-column:1;
    grid-row:1 / span 2;
    width:min(430px, 43vw);
    padding:0;
  }
  .brand-logo { width:100%; max-height:72dvh; object-fit:contain; }
  .button--play {
    grid-column:2;
    grid-row:1;
    width:min(310px, 42vw);
    min-width:0;
    padding:10px 18px;
    font-size:clamp(22px, 5vw, 32px);
  }
  .menu-actions {
    grid-column:2;
    grid-row:2;
    width:min(360px, 47vw);
    grid-template-columns:repeat(3, minmax(0,1fr));
    gap:6px;
  }
  .button--panel {
    min-width:0;
    min-height:54px;
    padding:5px;
    justify-content:center;
    gap:4px;
  }
  .button-icon { width:31px; height:31px; }
  .button--panel span:last-child { align-items:center; }
  .button--panel b { font-size:9px; }
  .button--panel small { display:none; }
  .corner-emblem { display:none; }

  .game-screen { padding:5px; gap:5px; }
  .game-header { grid-template-columns:40px minmax(85px, 128px) minmax(85px, 128px) auto; gap:5px; }
  .score-card, .icon-button { min-height:42px; border-radius:11px; border-width:1.5px; }
  .score-card span { font-size:8px; }
  .score-card strong { font-size:19px; }
  .icon-button { width:40px; }
  .icon-button .ti { width:20px; height:20px; }
  .header-actions { gap:5px; }
  .game-layout { grid-template-columns:82px minmax(0,1fr) 118px; gap:5px; }
  .side-card { border-radius:13px; padding:6px 4px; border-width:1.5px; }
  .side-label { font-size:9px; }
  .next-preview { width:min(70px,100%); margin:5px 0; border-radius:11px; }
  .next-card p { display:none; }
  .board-frame {
    width:min(100%, calc((100dvh - 57px) * 1.384615));
    border-width:2px;
    border-radius:17px;
  }
  .board-frame::after { inset:4px; border-radius:12px; }
  .control-hint { display:none; }
  .merge-ladder { margin-top:3px; gap:0; }
  .merge-ladder::before { left:8px; top:7px; bottom:7px; }
  .ladder-step { grid-template-columns:17px minmax(0,1fr) 31px; gap:2px; padding:0; }
  .ladder-node { width:16px; height:16px; margin-left:0; font-size:6px; }
  .ladder-image img { max-height:18px; }
  .ladder-step--circle .ladder-image img { max-width:18px; }
  .ladder-value { font-size:7px; }
}

@media (max-width: 700px) and (orientation: landscape) and (max-height: 420px) {
  .menu-frame { grid-template-columns:.9fr 1.1fr; padding:7px 12px; }
  .brand-mark, .brand-mark--logo { width:min(350px, 40vw); }
  .button--play { width:min(260px, 40vw); padding:8px 14px; font-size:22px; }
  .menu-actions { width:min(315px, 48vw); }
  .button--panel { min-height:46px; }
  .button-icon { width:27px; height:27px; }

  .game-header { grid-template-columns:36px 105px 105px auto; }
  .score-card, .icon-button { min-height:36px; }
  .icon-button { width:36px; }
  .game-layout { grid-template-columns:72px minmax(0,1fr) 105px; gap:4px; }
  .board-frame { width:min(100%, calc((100dvh - 47px) * 1.384615)); }
  .ladder-image img { max-height:15px; }
  .ladder-step--circle .ladder-image img { max-width:15px; }
  .ladder-value { font-size:6px; }
}
