/* ─────────────────────────────────────────────────────────────
   SNAKE — a pocket LCD handheld, and the leaflet in its box.
   Tokens: mint desk · tangerine shell · cream keys · one green LCD.
   ───────────────────────────────────────────────────────────── */

@font-face {
  font-family: 'Silkscreen';
  src: url('fonts/silkscreen-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Silkscreen';
  src: url('fonts/silkscreen-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --mint: #CBE0DA;
  --mint-hi: #DFEEE9;
  --mint-lo: #AFCAC3;

  --shell-hi: #FF7C46;
  --shell: #EF5A2A;
  --shell-lo: #C6400F;
  --shell-dark: #8E2C0C;
  --shell-deep: #7A2408;

  --cream: #FFF3E0;
  --cream-lo: #EBD9BE;
  --ink: #3B1606;
  --print: #33120A;          /* the ink the shell is printed with */
  --key: #2C2C34;
  --key-hi: #43434F;

  --lcd: #A9BE86;
  --lcd-lo: #97AC74;
  --seg: #23300D;

  --paper: #FFFCF5;
  --paper-ink: #2B2823;
  --paper-faint: #6F675A;
  --rule: rgba(43, 40, 35, .14);
  --desk-ink: #4A463E;
  --accent: #A8400F;
  --on-accent: #FFF3E0;

  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --pixel: 'Silkscreen', -apple-system, BlinkMacSystemFont, 'PingFang SC',
    'Microsoft YaHei', sans-serif;

  --key-size: clamp(42px, 12.5vw, 56px);
  --radius: 30px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mint: #16211F;
    --mint-hi: #1E2C29;
    --mint-lo: #0F1716;
    --paper: #1D1C1A;
    --paper-ink: #EDE7DC;
    --paper-faint: #9E9587;
    --rule: rgba(237, 231, 220, .16);
    --desk-ink: #C6BFB1;
    --accent: #FF8A54;
    --on-accent: #2A1401;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--ui);
  color: var(--paper-ink);
  background: var(--mint);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.room {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3.5vw, 44px);
  background:
    radial-gradient(120% 90% at 50% -10%, var(--mint-hi) 0%, var(--mint) 42%, var(--mint-lo) 100%);
}

.stage {
  width: 100%;
  max-width: 1000px;
  display: grid;
  gap: clamp(20px, 3.5vw, 36px);
  align-items: start;
}

@media (min-width: 900px) {
  .stage {
    grid-template-columns: minmax(320px, 1fr) minmax(300px, 360px);
    align-items: center;
  }
}

/* ── the toy ─────────────────────────────────────────────────── */

.device {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin-inline: auto;
  padding: 16px 18px 14px;
  border-radius: var(--radius) var(--radius) calc(var(--radius) + 6px) calc(var(--radius) + 6px);
  background-color: var(--shell);
  background-image:
    linear-gradient(178deg, var(--shell-hi) 0%, var(--shell) 16%, var(--shell) 66%, var(--shell-lo) 100%);
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, .5),
    inset 0 -2px 2px rgba(0, 0, 0, .22),
    0 3px 0 var(--shell-dark),
    0 26px 34px -20px rgba(18, 40, 34, .65),
    0 44px 60px -40px rgba(18, 40, 34, .5);
  user-select: none;
  -webkit-user-select: none;
}

/* a soft plastic sheen across the moulding */
.device::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(90% 55% at 22% 0%, rgba(255, 255, 255, .34), rgba(255, 255, 255, 0) 62%);
  pointer-events: none;
}

.device__cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 4px 12px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 15px;
  font-weight: 400;
}

.brand__mark {
  font-family: var(--pixel);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .14em;
  color: var(--print);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .3);
}

.brand__sub {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .2em;
  color: var(--print);
}

.led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #FFE07A;
  box-shadow:
    0 0 0 2px rgba(122, 36, 8, .55),
    0 0 8px 2px rgba(255, 224, 122, .75);
}

/* ── the LCD ─────────────────────────────────────────────────── */

.bezel {
  position: relative;
  padding: 22px 14px 24px;
  border-radius: 14px;
  background-color: var(--shell-dark);
  background-image: linear-gradient(180deg, #A63710 0%, var(--shell-dark) 100%);
  box-shadow:
    inset 0 3px 7px rgba(0, 0, 0, .5),
    inset 0 -1px 0 rgba(255, 255, 255, .16);
}

.bezel__print {
  position: absolute;
  top: 8px;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: .16em;
  color: #FFD9B8;
}
.bezel__print--l { left: 16px; }
.bezel__print--r { right: 16px; }

.bezel__model {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: .22em;
  color: rgba(255, 217, 184, .95);
}

.screen {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: var(--lcd);
  animation: lcd-on .34s steps(1, end) both;
  box-shadow:
    inset 0 0 0 1px rgba(35, 48, 13, .45),
    inset 0 2px 10px rgba(35, 48, 13, .4),
    inset 0 -1px 0 rgba(255, 255, 255, .18);
  touch-action: pan-y;
}
.screen--playing { touch-action: none; }

#lcd { display: block; width: 100%; height: auto; }

.glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(114deg,
    rgba(255, 255, 255, .3) 0%,
    rgba(255, 255, 255, .07) 32%,
    rgba(255, 255, 255, 0) 44%);
}

/* ── the overlays on the glass ───────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
  color: var(--seg);
  background: rgba(169, 190, 134, .84);
  font-family: var(--pixel);
}
.overlay[hidden] { display: none; }

.overlay__title {
  font-size: clamp(14px, 4.4vw, 19px);
  font-weight: 700;
  letter-spacing: .06em;
}
.overlay__title:empty { display: none; }

.overlay__hint {
  font-family: var(--ui);
  font-size: 12px;
  line-height: 1.5;
  max-width: 22em;
  color: rgba(35, 48, 13, .85);
}
.overlay__hint:empty { display: none; }

.overlay__big {
  font-size: clamp(13px, 4vw, 16px);
  letter-spacing: .04em;
  white-space: pre-line;
}
.overlay__big:empty { display: none; }

.overlay__btn {
  margin-top: 4px;
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--seg);
  background: rgba(255, 255, 255, .55);
  border: 2px solid var(--seg);
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
}
.overlay__btn[hidden] { display: none; }
.overlay__btn:active { transform: translateY(2px); }

/* ── controls ────────────────────────────────────────────────── */

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 6px 10px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, var(--key-size));
  grid-template-rows: repeat(3, var(--key-size));
  place-items: center;
  touch-action: none;
}

.dpad__key {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-lo) 100%);
  box-shadow:
    inset 0 1px 0 #fff,
    0 3px 0 rgba(122, 36, 8, .8),
    0 5px 8px -4px rgba(0, 0, 0, .5);
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease;
}
.dpad__key:active,
.dpad__key.is-down {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 #fff,
    0 0 0 rgba(122, 36, 8, .8),
    0 2px 4px -2px rgba(0, 0, 0, .5);
}

.dpad__key--up { grid-area: 1 / 2; border-radius: 12px 12px 4px 4px; }
.dpad__key--left { grid-area: 2 / 1; border-radius: 12px 4px 4px 12px; }
.dpad__key--right { grid-area: 2 / 3; border-radius: 4px 12px 12px 4px; }
.dpad__key--down { grid-area: 3 / 2; border-radius: 4px 4px 12px 12px; }

.dpad__key span {
  width: 11px;
  height: 11px;
  border-top: 3px solid var(--shell-lo);
  border-left: 3px solid var(--shell-lo);
  border-radius: 1px;
}
.dpad__key--up span { transform: rotate(45deg) translate(2px, 2px); }
.dpad__key--down span { transform: rotate(225deg) translate(2px, 2px); }
.dpad__key--left span { transform: rotate(-45deg) translate(2px, 2px); }
.dpad__key--right span { transform: rotate(135deg) translate(2px, 2px); }

.dpad__hub {
  grid-area: 2 / 2;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--shell-hi), var(--shell-lo));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .4);
}

.actions {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2.5vw, 16px);
}

.action {
  display: grid;
  justify-items: center;
  gap: 7px;
}

.rbtn {
  width: clamp(52px, 15vw, 68px);
  height: clamp(52px, 15vw, 68px);
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: linear-gradient(180deg, #A9370E 0%, var(--shell-deep) 100%);
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, .55), inset 0 -1px 0 rgba(255, 255, 255, .14);
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: none;
}

.rbtn__face {
  width: 84%;
  height: 84%;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--key-hi) 0%, var(--key) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .28),
    0 2px 0 rgba(0, 0, 0, .35);
  transition: transform .05s ease, box-shadow .05s ease;
}
.rbtn:active .rbtn__face,
.rbtn.is-down .rbtn__face {
  transform: translateY(2px) scale(.97);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .6), 0 0 0 rgba(0, 0, 0, .35);
}

.rbtn__print {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: .12em;
  color: var(--print);
}
.rbtn--pause .rbtn__face {
  background: linear-gradient(180deg, #D9481B 0%, #A9370E 100%);
}

.device__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 2px 6px 0;
}

.grille {
  width: 38px;
  height: 14px;
  flex: none;
  margin-right: auto;
  background-image: radial-gradient(rgba(90, 26, 4, .62) 1.4px, transparent 1.5px);
  background-size: 7px 7px;
  background-position: 3px 3px;
}

.switch {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: none;
}
.switch__track {
  display: block;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--shell-deep);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .55);
  position: relative;
}
.switch__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-lo) 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .45);
  transition: transform .12s ease;
}
.switch[aria-checked="false"] .switch__knob { transform: translateX(0); }
.switch[aria-checked="true"] .switch__knob { transform: translateX(20px); }

.device__note {
  padding: 8px 6px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--print);
}

/* ── the leaflet ─────────────────────────────────────────────── */

.leaflet {
  display: grid;
  gap: 14px;
  align-content: start;
}

.card {
  background: var(--paper);
  border-radius: 14px;
  padding: 18px 20px 20px;
  box-shadow:
    0 18px 30px -24px rgba(18, 40, 34, .8),
    0 0 0 1px rgba(18, 40, 34, .07);
}

.card__title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--paper-ink);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.card__note,
.card__keys {
  font-size: 12px;
  line-height: 1.6;
  color: var(--paper-faint);
}
.card__note { padding-top: 10px; }
.card__keys { padding-top: 12px; }

.board {
  list-style: none;
  padding-top: 6px;
}

.board__row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--rule);
}
.board__row:last-child { border-bottom: 0; }
.board__row--wait {
  font-size: 13px;
  color: var(--paper-faint);
  border-bottom: 0;
}
.board__row--you .board__name { font-weight: 700; color: var(--accent); }

.board__rank {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--paper-faint);
  width: 20px;
  flex: none;
}
.board__name {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board__you {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: .06em;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 1px 5px;
  flex: none;
}
.board__score {
  font-family: var(--pixel);
  font-size: 12px;
  flex: none;
}

.namer {
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  margin-top: 6px;
}
.namer__label {
  display: block;
  font-size: 12px;
  color: var(--paper-faint);
  padding-bottom: 6px;
}
.namer__row { display: flex; gap: 8px; }
.namer__input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--paper-ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 10px;
}
.namer__input:focus-visible { outline: none; border-color: var(--accent); }
.namer__btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.namer__btn:active { transform: translateY(1px); }
.namer__ok {
  font-size: 12px;
  color: var(--accent);
  padding-top: 6px;
}
.namer__ok[hidden] { display: none; }

.howto {
  list-style: none;
  display: grid;
  gap: 10px;
  padding-top: 12px;
}
.howto li {
  font-size: 13.5px;
  line-height: 1.65;
  padding-left: 18px;
  position: relative;
}
.howto li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: .62em;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 1px;
}

.leaflet__lang {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--desk-ink);
}
.langbtn {
  font: inherit;
  font-size: 12px;
  min-height: 28px;
  color: var(--desk-ink);
  background: none;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}
.langbtn[aria-current="true"] {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* ── focus, motion, and the small screens ────────────────────── */

:focus-visible {
  outline: 3px solid #123C7A;
  outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
  :focus-visible { outline-color: #9CC6FF; }
}

@keyframes lcd-on {
  0%   { opacity: 0; }
  14%  { opacity: .9; }
  22%  { opacity: .12; }
  40%  { opacity: .95; }
  52%  { opacity: .45; }
  62%  { opacity: 1; }
  74%  { opacity: .8; }
  100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .001ms !important; animation-duration: .001ms !important; }
  .led { box-shadow: 0 0 0 2px rgba(122, 36, 8, .55); }
}

@media (max-width: 420px) {
  .device { padding: 12px 12px 10px; }
  .bezel { padding: 20px 10px 22px; }
  .controls { padding: 16px 0 8px; }
}
