@font-face { font-family:Chivo; src:url(assets/fonts/Chivo-Regular.otf) format("opentype"); font-weight:400; font-display:swap }
@font-face { font-family:Chivo; src:url(assets/fonts/Chivo-SemiBold.otf) format("opentype"); font-weight:600; font-display:swap }
:root { --ink:#16222a; --sky:#eaf3f8; --yellow:#ffd23f; --muted:#53636d; color:var(--ink); font:400 16px/1.45 Chivo,Arial,sans-serif; color-scheme:light }
* { box-sizing:border-box }
body,h1,h2,p,dd,dl { margin:0 }
body { background-color:#f8fbfd; background-image:radial-gradient(#bdced9 .8px,transparent 1px); background-size:17px 17px }
button { font:inherit; font-weight:600; color:inherit; cursor:pointer; touch-action:manipulation }
:focus-visible { outline:3px solid #1268a0; outline-offset:3px }
dt,.boardbar { text-transform:uppercase; font-size:12px; letter-spacing:.09em; font-weight:600 }
main { max-width:1032px; margin:clamp(30px,8vh,88px) auto; padding:0 28px; display:grid; grid-template-columns:minmax(240px,.75fr) minmax(320px,1fr); align-items:center; gap:clamp(36px,7vw,100px) }
.intro { min-width:0 }
h1 { font-size:clamp(92px,10.8vw,154px); line-height:.9; letter-spacing:-.08em; font-weight:600; margin-left:-.055em }
.heading p { margin:20px 0 30px; font-size:clamp(16px,1.45vw,20px); line-height:1.5 }
.scores { display:grid; grid-template-columns:1fr 1fr; border:2px solid var(--ink); max-width:350px; background:white }
.scores > div { padding:13px 18px; min-width:0 }
.best { background:var(--yellow); border-left:2px solid var(--ink) }
dt { display:flex; align-items:center; gap:6px }
svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round }
dt svg { width:15px; height:15px }
dd { margin-top:4px; font-size:clamp(22px,2.7vw,38px); line-height:1.1; font-weight:600; letter-spacing:-.05em; overflow-wrap:anywhere; font-variant-numeric:tabular-nums }
.restart,dialog button { display:inline-flex; align-items:center; justify-content:center; gap:9px; border:1.5px solid var(--ink); background:white; border-radius:2px; min-height:44px; padding:8px 15px; font-size:14px }
.restart { margin-top:20px }
.restart:hover,dialog button:hover,.directions button:hover { background:var(--sky) }
.play { min-width:0; border:2px solid var(--ink); background:white; box-shadow:5px 5px 0 var(--ink) }
.boardbar { background:var(--ink); color:white; padding:11px 16px; display:flex; justify-content:space-between; align-items:center }
.boardbar h2 { display:flex; align-items:center; gap:10px; font:inherit }
.boardbar > span { font-size:11px; color:#d3e0e8; font-variant-numeric:tabular-nums }
.mini-grid { width:12px; height:12px; background:conic-gradient(var(--yellow) 25%,transparent 0 50%,var(--yellow) 0 75%,transparent 0) 0 0 / 8px 8px }
.board { --gap:clamp(5px,1vw,10px); position:relative; aspect-ratio:1; padding:var(--gap); background:#bdd0dd; touch-action:none; user-select:none; -webkit-user-select:none; container-type:inline-size; outline-offset:-3px }
#cells { position:relative; width:100%; height:100%; display:grid; grid-template-columns:repeat(4,1fr); grid-template-rows:repeat(4,1fr); gap:var(--gap) }
.cell,.tile { border-radius:4px }
.cell { background:#dfebf2; border:1px solid #9fb6c5 }
.tile { position:absolute; left:0; top:0; width:calc((100% - 3 * var(--gap)) / 4); aspect-ratio:1; transform:translate(calc(var(--x) * (100% + var(--gap))),calc(var(--y) * (100% + var(--gap)))); transition:transform 110ms ease-out; pointer-events:none }
.tile span { height:100%; display:grid; place-items:center; border:1.5px solid var(--ink); border-radius:inherit; background:var(--color,#234861); color:var(--text,white); font-size:var(--size); font-weight:600; line-height:1; letter-spacing:-.055em; box-shadow:inset 0 -3px 0 #16222a15 }
.tile[data-level="1"] { --color:#fff9e9; --text:var(--ink) }
.tile[data-level="2"] { --color:#ffd966; --text:var(--ink) }
.tile[data-level="3"] { --color:#ffad66; --text:var(--ink) }
.tile[data-level="4"] { --color:#f98568; --text:var(--ink) }
.tile[data-level="5"] { --color:#ba4851 } .tile[data-level="6"] { --color:#89405e }
.tile[data-level="7"] { --color:#a4dcba; --text:var(--ink) } .tile[data-level="8"] { --color:#478477; --text:#fff }
.tile[data-level="9"] { --color:#456a95 } .tile[data-level="10"] { --color:#525181 }
.tile[data-level="11"] { --color:var(--yellow); --text:var(--ink) }
.spawn span { animation:appear 140ms ease-out both } .merge span { animation:pop 160ms ease-out }
@keyframes appear { from { transform:scale(.65); opacity:.1 } }
@keyframes pop { 45% { transform:scale(1.09) } }
.controls { display:flex; justify-content:space-between; align-items:center; gap:8px; padding:6px 12px; border-top:1.5px solid var(--ink) }
.hint { font-size:13px; color:var(--muted) }
.touch-hint { display:none }
.directions { display:flex }
.directions button { padding:0; border:0; width:32px; min-height:38px; background:white; font-size:19px }
dialog { width:min(350px,calc(100% - 28px)); border:2px solid var(--ink); padding:22px; color:inherit; box-shadow:4px 4px 0 var(--ink) }
dialog::backdrop { background:#14273688 }
dialog h2 { font-size:28px; letter-spacing:-.045em }
dialog p { margin:10px 0 20px }
dialog form { display:flex; gap:8px; flex-wrap:wrap } dialog .primary { background:var(--yellow) }
.sr { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap }
@media (pointer:coarse) { .desktop-hint { display:none } .touch-hint { display:inline } .directions button { width:44px; min-height:44px } }
@media (max-width:700px) and (orientation:portrait), (max-width:560px) {
  main { width:min(100%,480px,calc(100svh - 194px)); min-width:min(100%,280px); margin:16px auto 22px; padding:0 12px; display:block }
  .intro { display:grid; grid-template-columns:minmax(0,1fr) minmax(134px,.87fr); gap:9px 8px; align-items:center }
  .heading { display:contents }
  h1 { grid-row:1; font-size:clamp(49px,13vw,70px) }
  .heading p { grid-row:2; margin:0; font-size:12px; line-height:1.35 }
  .scores { width:100%; justify-self:end; grid-row:1; grid-column:2 }
  .scores > div { padding:5px 6px }
  dt { font-size:9px; gap:3px; letter-spacing:.025em } dt svg { width:12px; height:12px } dd { font-size:22px; margin-top:1px }
  .restart { margin:0; justify-self:end; grid-row:2; grid-column:2; font-size:12px; padding:5px 9px }
  .play { margin-top:12px; box-shadow:3px 3px 0 var(--ink) }
  .boardbar { padding:6px 10px }
  .controls { padding:0 5px 0 9px } .hint { font-size:11px }
  .directions button { width:clamp(34px,11vw,44px) }
}
@media (orientation:landscape) and (max-height:650px) and (min-width:561px) {
  main { max-width:840px; grid-template-columns:1fr min(49vw,calc(100svh - 95px)); margin:12px auto; gap:30px }
  h1 { font-size:clamp(52px,15vh,88px) } .heading p { margin:9px 0 14px; font-size:14px }
  .scores > div { padding:6px 10px } dd { font-size:24px } .restart { margin-top:10px }
  .boardbar { padding:4px 10px } .controls { padding:0 4px; justify-content:center } .controls .hint { display:none }
}
@media (prefers-reduced-motion:reduce) { *,*::before,*::after { transition:none !important; animation:none !important } }
@media (orientation:portrait) and (max-height:610px) {
  main { margin-block:6px }
  .goal-copy { display:none }
  .intro { row-gap:3px }
  .play { margin-top:5px }
}
