/*
 * drifty Snake (/game/). A minimal game mode on a light stage: one way home
 * and one game frame (status row and board) centred with room around it. The
 * page heading is kept for screen readers only; the start screen carries the
 * rule and the two reward steps.
 * assets/shared.css supplies the fonts and tokens; board colours reach game.js
 * through --g-* custom properties on the game root.
 */
:root {
  background: #f4f3ef;
}

body[data-page="game"] {
  --stage: #f4f3ef;
  --stage-text: #1c1c19;
  --stage-muted: rgba(0, 0, 0, .56);
  --stage-soft: rgba(0, 0, 0, .38);
  --accent: #465126;
  --frame: #fff;
  --frame-line: rgba(40, 40, 20, .08);
  /* Drawn after the frame hairline: a soft lift off the paper. */
  --frame-shadow: 0 1px 2px rgba(40, 40, 20, .04), 0 24px 48px -32px rgba(40, 40, 20, .22);
  --plot: #fbfbf9;
  --ink-strong: #1c1c19;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Mono", Consolas, "Malgun Gothic", monospace;
  /*
   * One spacing rhythm. The frame pads the board by --s-frame
   * on three sides; the status row takes the fourth as a band of --s-band.
   */
  --s-title-sub: 8px;
  --s-head-game: 36px;
  --s-frame: 12px;
  --s-band: 52px;
  --frame-radius: 22px;
  --board-radius: 10px;
  min-height: 100svh;
  color: var(--stage-text);
  background: var(--stage);
}

[hidden] {
  display: none !important;
}

.game-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.game-skip {
  position: fixed;
  inset-block-start: 10px;
  inset-inline-start: 12px;
  z-index: 100;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--ink-strong);
  background: #fff;
  font-size: 13px;
  font-weight: 620;
  transform: translateY(-200%);
  transition: transform .16s ease;
}

.game-skip:focus {
  transform: translateY(0);
}

/* The only way out: back to drifty. */
.arena-home {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 5;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px 0 9px;
  border-radius: 10px;
  color: var(--stage-muted);
  background: var(--frame);
  box-shadow: inset 0 0 0 1px var(--frame-line);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.005em;
  white-space: nowrap;
  text-decoration: none;
  transition: color .16s ease, background-color .16s ease;
}

.arena-home:hover {
  color: var(--stage-text);
}

.arena-home svg {
  width: 16px;
  height: 16px;
}

/*
 * The heading and the game frame sit in the middle of the window with equal
 * space above and below; the folded terms keep to the bottom edge.
 */
.arena {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr auto auto 1fr auto;
  justify-items: center;
  padding: 48px 24px 20px;
  outline: none;
}

/* The game is the page: the heading stays for screen readers and search. */
.arena-head {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.arena-title {
  margin: 0;
  color: var(--stage-text);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.02em;
  word-break: keep-all;
  text-wrap: balance;
}

.arena-sub {
  margin: var(--s-title-sub) 0 0;
  color: var(--stage-muted);
  font-size: 15px;
  line-height: 1.4;
}

.arena-sub b {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Game frame: status band on top, board below ---------- */
.game {
  --g-fluid: 1;
  --g-gutter: 0;
  /* The board takes at most a little over half the window height. */
  --g-fill: .56;
  --g-reserve: 260;
  --g-reserve-touch: 220;
  --g-cell-max: 40;
  /* The drifty flow chart (light theme): one tint for empty slots and a
     bright hairline between hour columns; square, touching cells. */
  --g-plot: #fafaf8;
  --g-empty: #f3f2ef;
  --g-alpha: 1;
  --g-radius: 0;
  --g-gap: 0;
  grid-row: 3;
  position: relative;
  width: max-content;
  max-width: 100%;
  padding: 0 var(--s-frame) var(--s-frame);
  border-radius: var(--frame-radius);
  background: var(--frame);
  box-shadow: inset 0 0 0 1px var(--frame-line), var(--frame-shadow);
}

.game-hud {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 auto;
  width: var(--board-w, 100%);
  max-width: 100%;
  height: var(--s-band);
  padding: 0 4px;
}

.game-score {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.game-score b {
  color: var(--stage-text);
  font: 650 15px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  transition: color .2s ease;
}

/* The first reward step: the count turns to the accent for a moment. */
.game.is-tier .game-score b {
  animation: game-tier 1.6s ease;
}

.game-score span {
  color: var(--stage-soft);
  font: 600 12px/1 var(--font-mono);
}

.game-timebar {
  position: relative;
  flex: 1 1 auto;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, .08);
}

.game-timebar i {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--olive);
  transform: scaleX(var(--left, 1));
  transform-origin: 0 50%;
  transition: transform .12s linear;
}

.game-timebar i.is-urgent {
  background: #e0705c;
}

.game-clock {
  min-width: 38px;
  margin: 0;
  color: var(--stage-text);
  font: 600 15px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.game-clock.is-urgent {
  color: #b8493a;
}

.game-hud__button {
  width: 28px;
  height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: var(--stage-muted);
  background: rgba(0, 0, 0, .05);
  cursor: pointer;
}

.game-hud__button:hover {
  color: var(--stage-text);
  background: rgba(0, 0, 0, .09);
}

.game-hud__button svg {
  width: 13px;
  height: 13px;
}

.game-hud__button .game-icon-play,
.game-hud__button[data-paused="true"] .game-icon-pause {
  display: none;
}

.game-hud__button[data-paused="true"] .game-icon-play {
  display: block;
}

/* ---------- Board ---------- */
.game-plot {
  --cell: 32px;
  --cols: 16;
  --rows: 12;
  position: relative;
  display: grid;
  grid-template-columns: calc(var(--cols) * var(--cell));
  grid-template-rows: calc(var(--rows) * var(--cell));
  justify-content: center;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/*
 * First paint uses the size game.js will pick (sizeBoard: the share of the
 * window height, the column width and the 40px cap), so the board does not
 * jump when the script runs or while a page transition shows the new page.
 */
@supports (width: round(down, 10.5px, 1px)) {
  .game-plot {
    --cell: max(14px, min(40px,
      round(down, (100vw - 72px) / 16, 1px),
      max(18px, round(down, min(100dvh - 260px, 56dvh) / 12, 1px))));
  }

  @media (pointer: coarse) {
    .game-plot {
      --cell: max(14px, min(40px,
        round(down, (100vw - 72px) / 16, 1px),
        max(18px, round(down, min(100dvh - 220px, 56dvh) / 12, 1px))));
    }
  }

  @media (max-width: 640px) {
    .game-plot {
      --cell: max(14px, min(40px,
        round(down, (100vw - 44px) / 16, 1px),
        max(18px, round(down, (100dvh - 220px) / 12, 1px))));
    }
  }

  @media (max-width: 640px) and (orientation: portrait) {
    .game-plot {
      --cols: 12;
      --rows: 16;
      --cell: max(14px, min(40px,
        round(down, (100vw - 44px) / 12, 1px),
        max(18px, round(down, (100dvh - 220px) / 16, 1px))));
    }
  }
}

.game-canvas,
.game-overlay,
.game-countdown {
  grid-column: 1;
  grid-row: 1;
}

.game-canvas {
  display: block;
  width: calc(var(--cols) * var(--cell));
  height: calc(var(--rows) * var(--cell));
  border-radius: var(--board-radius);
  /* The empty board game.js draws, shown until its first frame. */
  background:
    linear-gradient(to right, transparent calc(var(--cell) - .5px), var(--g-plot) calc(var(--cell) - .5px)) 0 0 / var(--cell) 100%,
    var(--g-empty);
}

@media (max-width: 640px) and (orientation: portrait) {
  /* A portrait board runs the hours down, so the hairlines run across. */
  .game-canvas {
    background:
      linear-gradient(to bottom, transparent calc(var(--cell) - .5px), var(--g-plot) calc(var(--cell) - .5px)) 0 0 / 100% var(--cell),
      var(--g-empty);
  }
}

.game-overlay {
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: var(--board-radius);
  pointer-events: none;
  transition: background-color .2s ease;
}

.game[data-state="ready"] .game-overlay {
  background: rgba(251, 251, 249, .86);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.game[data-state="paused"] .game-overlay {
  background: rgba(246, 245, 241, .7);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.game[data-state="over"] .game-overlay {
  background: rgba(251, 251, 249, .72);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.game-countdown {
  z-index: 3;
  place-self: center;
  margin: 0;
  color: var(--ink-strong);
  font: 700 64px/1 var(--font-mono);
  pointer-events: none;
}

.game-countdown.is-tick {
  animation: game-count .42s cubic-bezier(.25, 1, .5, 1);
}

/* ---------- Panels ---------- */
.game-panel {
  width: min(100%, 320px);
  max-height: 100%;
  overflow: auto;
  padding: 24px 22px 18px;
  border-radius: 18px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .05);
  text-align: center;
  pointer-events: auto;
  animation: game-rise .24s cubic-bezier(.25, 1, .5, 1);
}

.game-panel--bare {
  width: auto;
  padding: 0;
  background: none;
  box-shadow: none;
}

/* Start screen: the rule, the two reward steps, then the start button. */
.game-panel--rules {
  width: min(100%, 320px);
  padding: 0;
  background: none;
  box-shadow: none;
}

.game-rules__title {
  margin: 0;
  color: var(--ink-strong);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.015em;
  word-break: keep-all;
}

.game-rules {
  margin: 16px 0 20px;
  padding: 0;
  list-style: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(40, 40, 20, .08), 0 12px 28px -20px rgba(40, 40, 20, .35);
  text-align: left;
}

.game-rules li {
  display: grid;
  /* The count column fits its text ("15개", "15 blocks"); both rows match. */
  grid-template-columns: max-content max-content 1fr;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
}

.game-rules li + li {
  border-top: 1px solid rgba(40, 40, 20, .07);
}

.game-rules__count {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.game-rules__count b {
  color: var(--ink-strong);
  font: 650 15px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.game-rules__name {
  color: var(--ink-strong);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.game-rules__detail {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}

.game-panel__title {
  margin: 0;
  color: var(--ink-strong);
  font-size: 20px;
  font-weight: 720;
  line-height: 1.3;
  letter-spacing: -.015em;
  word-break: keep-all;
}

.game-panel__copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  word-break: keep-all;
  text-wrap: balance;
}

.game-panel__hint {
  margin: 12px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  color: rgba(0, 0, 0, .5);
  background: rgba(251, 251, 249, .9);
  font-size: 13px;
}

.game-panel__actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* With a coupon to claim, trying again becomes the quieter choice. */
.game-panel[data-has-claim] .game-button--primary {
  color: var(--ink-strong);
  background: rgba(0, 0, 0, .06);
  box-shadow: none;
}

.game-panel[data-has-claim] .game-button--primary:hover {
  background: rgba(0, 0, 0, .1);
}

.game-panel[data-has-claim] .game-button--primary kbd {
  background: rgba(0, 0, 0, .08);
}

.game-panel__links {
  margin: 12px 0 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  color: var(--soft);
  font-size: 13px;
}

.game-panel__links b {
  color: var(--ink);
  font: 650 13px/1 var(--font-mono);
}

.game-panel__note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 11px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: left;
  word-break: keep-all;
}

.game-button {
  min-height: 44px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .16s ease, transform .16s ease;
}

.game-button:active {
  transform: translateY(1px);
}

.game-button--primary {
  color: #fff;
  background: var(--ink-strong);
  box-shadow: 0 12px 28px -14px rgba(0, 0, 0, .7);
}

.game-button--primary:hover {
  background: #33332e;
}

.game-button--claim {
  color: #fff;
  background: var(--olive-cta);
  box-shadow: 0 12px 26px -14px rgba(70, 81, 38, .9);
}

.game-button--claim:hover {
  background: var(--olive-dark);
}

.game-button kbd {
  padding: 3px 6px;
  border-radius: 999px;
  color: inherit;
  background: rgba(255, 255, 255, .16);
  font: 600 10.5px/1.2 var(--font-mono);
}

.game-button:focus-visible,
.game-link:focus-visible,
.game-pad__key:focus-visible,
.game-hud__button:focus-visible,
.arena-home:focus-visible,
.arena-terms summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.game-link {
  padding: 2px 0;
  border: 0;
  color: var(--muted);
  background: none;
  font-size: 13px;
  font-weight: 560;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}

.game-link:hover {
  color: var(--ink);
}

.game-toast {
  position: absolute;
  inset-inline: 0;
  bottom: 18px;
  z-index: 4;
  width: max-content;
  margin: 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--ink-strong);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .6);
  font-size: 13px;
  font-weight: 560;
  animation: game-rise .24s cubic-bezier(.25, 1, .5, 1);
}

/* Touch controls, shown where the main pointer is coarse. */
.game-pad {
  display: none;
  margin: var(--s-frame) auto 0;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: 50px 50px;
  gap: 8px;
  justify-content: center;
  touch-action: none;
}

.game-pad__key {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: var(--stage-text);
  background: rgba(0, 0, 0, .05);
  cursor: pointer;
  touch-action: none;
}

.game-pad__key:active {
  background: rgba(0, 0, 0, .09);
  transform: translateY(1px);
}

.game-pad__key svg {
  width: 20px;
  height: 20px;
}

.game-pad__key--up { grid-column: 2; grid-row: 1; }
.game-pad__key--left { grid-column: 1; grid-row: 2; }
.game-pad__key--down { grid-column: 2; grid-row: 2; }
.game-pad__key--right { grid-column: 3; grid-row: 2; }

@media (pointer: coarse) {
  .game-pad {
    display: grid;
  }

  .game-button kbd {
    display: none;
  }
}

.game.is-crashed .game-canvas {
  animation: game-shake .3s cubic-bezier(.36, .07, .19, .97);
}

/* ---------- Terms, folded away ---------- */
.arena-terms {
  grid-row: 5;
  width: min(100%, 520px);
  margin-top: 24px;
  color: var(--stage-soft);
  font-size: 12.5px;
  text-align: center;
}

.arena-terms summary {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  list-style: none;
  cursor: pointer;
}

.arena-terms summary::-webkit-details-marker {
  display: none;
}

.arena-terms summary:hover {
  color: var(--stage-muted);
}

.arena-terms ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  line-height: 1.8;
  word-break: keep-all;
}

.arena-terms p {
  margin: 10px 0 0;
}

.arena-terms a {
  color: var(--stage-muted);
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, .2);
  text-underline-offset: 3px;
}

.game-noscript {
  margin: 24px auto;
  color: var(--stage-muted);
  text-align: center;
}

@keyframes game-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes game-shake {
  20%, 80% { transform: translateX(-2px); }
  40%, 60% { transform: translateX(3px); }
}

@keyframes game-count {
  from { opacity: .2; transform: scale(1.4); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes game-tier {
  0%, 70% { color: var(--accent); }
  100% { color: var(--stage-text); }
}

@media (max-width: 640px) {
  body[data-page="game"] {
    --s-title-sub: 6px;
    --s-head-game: 20px;
    --s-frame: 10px;
    --s-band: 48px;
    --frame-radius: 20px;
  }

  .arena-home {
    top: 12px;
    left: 12px;
  }

  /* Phones read top to bottom: heading, frame, then the terms. */
  .arena {
    grid-template-rows: 0 auto auto 1fr auto;
    padding: 76px 12px 16px;
  }

  .arena-title {
    font-size: 22px;
  }

  .arena-sub {
    font-size: 14px;
  }

  .game {
    --g-fill: 0;
  }

  .game-panel {
    padding: 20px 16px 16px;
  }

  .game-panel__title {
    font-size: 18px;
  }

  .game-rules__title {
    font-size: 19px;
  }

  .game-rules {
    margin: 14px 0 16px;
  }

  .game-rules li {
    gap: 10px;
    padding: 11px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-panel,
  .game-countdown.is-tick,
  .game.is-crashed .game-canvas,
  .game-panel__carry,
  .game-card,
  .game-card__sheet {
    animation: none;
  }

  .game-timebar i {
    transition: none;
  }
}

/* ---------- Carrying on past the free coupon ---------- */
/* The arrow-key hint arrives a moment after the win panel, as quiet text. */
.game-panel__carry {
  padding: 0;
  color: var(--soft);
  background: none;
  animation: game-rise .3s cubic-bezier(.25, 1, .5, 1);
}

/* Pause during a full day: end here and keep the coupon. */
.game-panel__stop {
  display: block;
  margin: 12px auto 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(251, 251, 249, .92);
}

/* A full day: a gold edge on the frame, the bar fills with the day, and the
   hidden reward's claim turns gold. The free coupon's claim stays olive. */
.game.is-day {
  box-shadow: inset 0 0 0 1px rgba(181, 138, 46, .5), var(--frame-shadow);
}

.game.is-day .game-timebar i,
.game.is-day [data-panel="win"] [data-control="claim"] {
  background: #b58a2e;
}

.game.is-day [data-panel="win"] [data-control="claim"] {
  box-shadow: 0 12px 26px -14px rgba(154, 116, 37, .9);
}

.game.is-day [data-panel="win"] [data-control="claim"]:hover {
  background: #9a7425;
}

/* The full-day win: who it is for, the reward as a row like the start card,
   then the claim. */
.game-panel__eyebrow {
  display: inline-block;
  margin: 0 0 8px;
  padding: 3px 10px;
  border-radius: 999px;
  color: #8a6514;
  background: rgba(181, 138, 46, .14);
  font-size: 12px;
  font-weight: 650;
}

.game-reward {
  margin: 14px 0 0;
}

.game-reward .game-rules__count b {
  color: #9a7425;
}

/* The server check of a finished round: a quiet line under the claim, red
   when it could not confirm or connect. The claim waits, dimmed. */
.game-panel__status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  word-break: keep-all;
}

.game-panel__status.is-error {
  color: #9e4238;
}

/* The discount step's shared Polar code, shown in the claim note. */
.game-code {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.game-code b {
  color: var(--ink-strong);
  font: 650 15px/1.2 var(--font-mono);
  letter-spacing: .04em;
  user-select: all;
}

.game-code__how {
  margin-top: 6px;
  display: block;
}

.game-code__link {
  margin-top: 6px;
  display: inline-block;
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
}

.game-code__link:hover {
  text-decoration: underline;
}

.game-button:disabled {
  cursor: default;
  opacity: .55;
  transform: none;
}

/* ---------- Share card ---------- */
.game-card {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(28, 28, 25, .5);
  animation: game-card-in .2s ease;
}

.game-card__sheet {
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  padding: 14px 14px 16px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .55);
  text-align: center;
  animation: game-rise .24s cubic-bezier(.25, 1, .5, 1);
}

.game-card__image {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 170px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(40, 40, 20, .08);
}

.game-card__actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 12px;
}

.game-card .game-button {
  text-decoration: none;
}

.game-button--quiet {
  color: var(--ink-strong);
  background: rgba(0, 0, 0, .06);
}

.game-button--quiet:hover {
  background: rgba(0, 0, 0, .1);
}

@keyframes game-card-in {
  from {
    opacity: 0;
  }
}
