/* Santa Claw shell UI. Fonts: /fonts/fonts.css (Vietnamese subsets). */
:root {
  --pine: #0e2a22;
  --pine-deep: #081a15;
  --pine-hi: #17402f;
  --velvet: #7a1020;
  --velvet-hi: #a3182c;
  --gold: #d9b878;
  --gold-deep: #b8924a;
  --gold-dark: #7d6130;
  --ivory: #f6efe2;
  --ink: #241a10;
  --ink-soft: #5b4630;
  --f-display: 'Playfair Display', Georgia, serif;
  --f-ui: 'Be Vietnam Pro', system-ui, sans-serif;
  --f-block: 'Anton', 'Be Vietnam Pro', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.22, .8, .24, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, #173a2e 0%, #0a1d17 55%, #050e0b 100%);
  color: var(--ivory);
  font-family: var(--f-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.world {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh; height: 100dvh;
  display: block;
  touch-action: none;
  outline: none;
}

/* Overlay: pass pointer events through to the canvas except on real controls. */
.ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.ui button, .ui .panel, .ui .title-block, .ui .chips { pointer-events: auto; }
.reveal-root { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.reveal-root > * { pointer-events: auto; }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  z-index: 3;
}
.topbar__actions { display: flex; gap: 10px; margin-left: auto; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(8, 26, 21, .82);
  border: 1px solid rgba(217, 184, 120, .55);
  color: var(--gold);
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--gold); background: rgba(14, 42, 34, .95); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:focus-visible, .btn:focus-visible, .chip:focus-visible, .grab-btn:focus-visible {
  outline: 2px solid var(--ivory); outline-offset: 3px;
}

/* Turn tokens: two gold coins, one is used up per try. */
.tokens {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px 7px 12px;
  border-radius: 999px;
  background: rgba(8, 26, 21, .82);
  border: 1px solid rgba(217, 184, 120, .45);
}
.tokens__label { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); margin-right: 2px; }
.token {
  width: 26px; height: 26px; border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 5px, rgba(122, 90, 40, .55) 5px 6px, transparent 6px),
    radial-gradient(circle at 35% 30%, #f3dfae 0%, #d9b878 38%, #a98340 75%, #7d6130 100%);
  box-shadow: inset 0 0 0 1.5px rgba(122, 90, 40, .65), 0 1px 2px rgba(0, 0, 0, .45);
  position: relative;
  transition: opacity .5s var(--ease), transform .5s var(--ease), filter .5s;
}
.token::after { /* small deco star cut */
  content: ''; position: absolute; inset: 9px;
  background: #8a6a33;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.token.is-used {
  background: #2a2417;
  box-shadow: inset 0 0 0 2px var(--gold-deep), 0 1px 2px rgba(0, 0, 0, .45);
  transform: scale(.9);
}
.token.is-used::after { background: rgba(217, 184, 120, .4); } /* spent: dark coin, faint star */

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: 48px; padding: 0 28px;
  border-radius: 2px;
  font-family: var(--f-ui); font-weight: 700; font-size: 15px; letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap;
  transition: transform .15s, background .2s, color .2s, box-shadow .2s;
}
.btn--gold {
  color: var(--pine-deep);
  background: linear-gradient(180deg, #ecd6a2 0%, #d9b878 45%, #c09a55 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 220, .55), 0 0 0 1px var(--gold-dark), 0 6px 18px rgba(0, 0, 0, .35);
}
.btn--gold:hover { background: linear-gradient(180deg, #f2e0b4 0%, #e0c285 45%, #c8a35e 100%); }
.btn--gold:active { transform: translateY(1px); }
.btn--ghost { color: var(--gold); background: transparent; box-shadow: inset 0 0 0 1px rgba(217, 184, 120, .6); }
.btn--lg { min-height: 56px; padding: 0 44px; font-size: 16px; }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; display: flex; justify-content: center; }

.screen--title {
  align-items: flex-end;
  padding: 0 20px calc(7vh + var(--safe-b));
  background: linear-gradient(180deg, rgba(5, 14, 11, 0) 38%, rgba(5, 14, 11, .72) 72%, rgba(5, 14, 11, .9) 100%);
}
.title-block { text-align: center; max-width: 640px; color: var(--ivory); }
.deco-fan { width: 96px; height: 32px; color: var(--gold); display: block; margin: 0 auto 10px; opacity: .9; }
.title {
  margin: 0;
  font-family: var(--f-display); font-weight: 700;
  font-size: clamp(34px, 5.2vw, 64px); line-height: 1.12; letter-spacing: .005em;
  color: var(--ivory);
  white-space: nowrap;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .55);
}
.rule { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px auto 14px; width: min(320px, 70vw); }
.rule span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--gold)); }
.rule span:last-child { background: linear-gradient(90deg, var(--gold), transparent); }
.rule i { width: 7px; height: 7px; background: var(--gold); transform: rotate(45deg); }
.lede { margin: 0 0 26px; font-size: 17px; line-height: 1.6; color: rgba(246, 239, 226, .9); }

.screen--who {
  align-items: center;
  padding: calc(72px + var(--safe-t)) 16px calc(20px + var(--safe-b));
  background: rgba(4, 12, 9, .62);
}
.panel {
  position: relative;
  width: min(760px, 100%);
  max-height: 100%;
  display: flex; flex-direction: column;
  padding: 34px 36px 32px;
  background:
    linear-gradient(180deg, rgba(23, 64, 47, .25), rgba(0, 0, 0, 0) 40%),
    var(--pine);
  border: 1px solid var(--gold-deep);
  box-shadow: inset 0 0 0 5px var(--pine), inset 0 0 0 6px rgba(217, 184, 120, .45), 0 24px 60px rgba(0, 0, 0, .55);
}
.panel::before, .panel::after { /* stepped deco corners */
  content: ''; position: absolute; width: 22px; height: 22px; border: 1px solid var(--gold);
  top: -1px; left: -1px; border-right: 0; border-bottom: 0;
}
.panel::after { top: auto; left: auto; right: -1px; bottom: -1px; border: 1px solid var(--gold); border-left: 0; border-top: 0; }
.panel__title {
  margin: 0; text-align: center;
  font-family: var(--f-display); font-weight: 700; font-size: clamp(30px, 4vw, 42px); line-height: 1.15;
  color: var(--ivory);
}
.panel__sub { margin: 8px 0 24px; text-align: center; font-size: 15px; color: rgba(246, 239, 226, .78); }

.chips {
  list-style: none; margin: 0;
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 18px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 6px; /* room for the photo rings' outer shadow */
  touch-action: pan-y;
}
.chips > li { width: 124px; display: flex; justify-content: center; }
.chip {
  width: 100%;
  appearance: none; background: transparent; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 10px 4px 12px; border-radius: 6px;
  transition: background .2s;
}
.chip__photo {
  width: 92px; height: 92px; border-radius: 50%;
  background-size: cover; background-repeat: no-repeat;
  box-shadow: 0 0 0 2px var(--gold-deep), 0 0 0 5px var(--pine), 0 0 0 6px rgba(217, 184, 120, .5), 0 8px 18px rgba(0, 0, 0, .45);
  transition: transform .25s var(--ease), box-shadow .25s;
}
.chip__name {
  font-weight: 600; font-size: 15px; line-height: 1.3; color: var(--ivory);
  white-space: nowrap;
}
.chip:hover .chip__photo, .chip:focus-visible .chip__photo { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--gold), 0 0 0 5px var(--pine), 0 0 0 6px var(--gold), 0 10px 22px rgba(0, 0, 0, .5); }
.chip:hover { background: rgba(217, 184, 120, .07); }
.chip.is-picked .chip__photo { box-shadow: 0 0 0 3px var(--ivory), 0 0 0 6px var(--pine), 0 0 0 7px var(--gold); }

/* ---------- Hint card ----------
   Phone / portrait: paper card in the band under the pit, just above the GẮP button.
   Desktop / landscape: hint in the empty left column, styled like the title (see "side" below).
   It never sits over the 3D name plate. */
:root { --dock: calc(22px + 84px + 12px + 34px + 14px); }          /* fine pointer: button + key hints */
@media (pointer: coarse) { :root { --dock: calc(22px + 92px + 18px); } } /* 18px = 7px gold ring + clear gap */
.hint {
  position: absolute; left: 0; right: 0; margin: 0 auto;
  bottom: calc(var(--dock) + var(--safe-b));
  width: min(440px, calc(100vw - 24px));
  z-index: 2;
}
.hint__card {
  position: relative;
  padding: 15px 20px 14px;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 60%),
    repeating-linear-gradient(0deg, rgba(120, 90, 50, .025) 0 1px, transparent 1px 3px),
    #f4ecdc;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(184, 146, 74, .55), inset 0 0 0 5px #f4ecdc, inset 0 0 0 6px rgba(184, 146, 74, .35), 0 12px 28px rgba(0, 0, 0, .45);
  text-align: center;
}
.hint__rail {
  position: absolute; left: 12%; right: 12%; top: -6px; height: 10px;
  border-radius: 2px;
  background: linear-gradient(180deg, #f0dba6, #c9a45c 55%, #8f6d34);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.hint__rail b {
  position: absolute; top: 2px; width: 6px; height: 6px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3cf, #7d6130);
}
.hint__rail b:first-child { left: 14%; } .hint__rail b:last-child { right: 14%; }
.hint__label {
  margin: 0 0 4px;
  font-family: var(--f-ui); font-weight: 700; font-size: 11px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--velvet);
}
.hint__text {
  margin: 0;
  font-family: var(--f-display); font-style: italic; font-weight: 500;
  font-size: 19px; line-height: 1.32;
  color: var(--ink);
}
.hint__text .seg { display: inline-block; max-width: 100%; } /* wrap between phrases, not inside them */
.side-scrim {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .7s var(--ease);
  background: linear-gradient(90deg, rgba(5, 14, 11, .84) 0%, rgba(5, 14, 11, .55) 22%, rgba(5, 14, 11, 0) 40%);
}

/* Side layout: desktop, and landscape phones. */
@media (min-width: 900px) and (min-aspect-ratio: 4/3), (min-width: 640px) and (max-height: 520px) and (orientation: landscape) {
  body.has-hint .side-scrim { opacity: 1; }
  .hint {
    left: max(4.5vw, 32px); right: auto; top: 0; bottom: 0; margin: auto 0; height: fit-content;
    width: min(400px, 29vw);
  }
  .hint__card { background: none; box-shadow: none; padding: 0; text-align: left; color: var(--ivory); }
  .hint__rail { position: static; width: 64px; height: 2px; margin: 0 0 16px; border-radius: 0; background: var(--gold); box-shadow: none; }
  .hint__rail b { display: none; }
  .hint__label { margin: 0 0 12px; font-size: 13px; color: var(--gold); }
  .hint__text {
    font-size: clamp(26px, 2.4vw, 40px); line-height: 1.28; color: var(--ivory);
    text-shadow: 0 2px 16px rgba(0, 0, 0, .55);
  }
}
@media (min-width: 640px) and (max-height: 520px) and (orientation: landscape) {
  .hint__text { font-size: 22px; }
  .hint__rail { margin-bottom: 10px; }
}

body[data-state="reveal"] .topbar { visibility: hidden; }

/* ---------- Message (miss beat, auto-reveal line) ---------- */
.message {
  position: absolute; left: 0; right: 0; margin: 0 auto; bottom: calc(9% + var(--safe-b));
  width: min(520px, calc(100vw - 32px));
  padding: 24px 28px 22px;
  text-align: center;
  background: linear-gradient(180deg, #8a1324, var(--velvet) 60%, #650c1a);
  border: 1px solid var(--gold-deep);
  box-shadow: inset 0 0 0 4px var(--velvet), inset 0 0 0 5px rgba(217, 184, 120, .55), 0 18px 44px rgba(0, 0, 0, .5);
  z-index: 4;
}
.message__title {
  margin: 0;
  font-family: var(--f-display); font-weight: 700; font-size: clamp(26px, 3.2vw, 34px); line-height: 1.2;
  color: var(--ivory);
  text-wrap: balance;
}
.message__line { margin: 10px 0 0; font-size: 16px; line-height: 1.5; color: #f6e7c8; }
.message__line:empty { display: none; }

/* ---------- Controls ---------- */
.controls {
  position: absolute; left: 0; right: 0; margin: 0 auto; width: max-content; bottom: calc(22px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  z-index: 2;
}
.grab-btn {
  appearance: none; cursor: pointer; border: 0;
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 50% 38%, #c42a3d 0%, var(--velvet-hi) 40%, var(--velvet) 75%, #55091a 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 220, 200, .25),
    inset 0 -4px 8px rgba(0, 0, 0, .35),
    0 0 0 3px #3d0710,
    0 0 0 6px var(--gold-deep),
    0 0 0 7px #f0dba6,
    0 10px 22px rgba(0, 0, 0, .55);
  touch-action: manipulation;
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.grab-btn span {
  font-family: var(--f-block); font-size: 24px; letter-spacing: .06em; color: var(--ivory);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
  transform: translateY(1px);
}
.grab-btn:hover { filter: brightness(1.06); }
.grab-btn:active, .grab-btn.is-pressed { transform: translateY(3px) scale(.97); box-shadow: inset 0 2px 6px rgba(0, 0, 0, .45), 0 0 0 3px #3d0710, 0 0 0 6px var(--gold-deep), 0 0 0 7px #f0dba6, 0 4px 10px rgba(0, 0, 0, .5); }
.grab-btn:disabled { cursor: default; filter: saturate(.4) brightness(.7); }

.keyhints {
  margin: 0; display: flex; gap: 18px; align-items: center;
  padding: 7px 14px; border-radius: 999px;
  background: rgba(8, 26, 21, .82); border: 1px solid rgba(217, 184, 120, .35);
  font-size: 13px; color: rgba(246, 239, 226, .9); white-space: nowrap;
}
.keys { display: inline-flex; align-items: center; gap: 4px; }
.keys em { font-style: normal; margin-left: 5px; }
kbd {
  min-width: 22px; height: 22px; padding: 0 5px;
  display: inline-grid; place-items: center;
  font-family: var(--f-ui); font-size: 12px; font-weight: 600; color: var(--ivory);
  border-radius: 4px; border: 1px solid rgba(217, 184, 120, .55);
  background: rgba(217, 184, 120, .08);
}
.drag-hint {
  margin: 0; padding: 6px 14px; border-radius: 999px;
  font-size: 13px; color: rgba(246, 239, 226, .92);
  background: rgba(8, 26, 21, .78); border: 1px solid rgba(217, 184, 120, .3);
  white-space: nowrap;
  transition: opacity .6s;
}
.drag-hint.is-done { opacity: 0; }

@media (min-width: 1600px) {
  .lede { font-size: 19px; }
  .keyhints { font-size: 16px; }
  .tokens__label { font-size: 15px; }
}
@media (min-width: 1280px) {
  .keyhints { font-size: 14px; }
  .tokens__label { font-size: 13px; }
}

/* Desktop title: beside the machine, not on top of it. */
.title__br { display: none; }
@media (min-width: 1024px) and (min-aspect-ratio: 4/3) {
  .screen--title {
    justify-content: flex-start; align-items: center;
    padding: 0 0 0 max(4.5vw, 48px);
    background: linear-gradient(90deg, rgba(5, 14, 11, .86) 0%, rgba(5, 14, 11, .6) 24%, rgba(5, 14, 11, 0) 40%);
  }
  .title-block { text-align: left; max-width: none; }
  .deco-fan { margin: 0 0 12px; }
  .title { font-size: clamp(46px, 3.4vw, 66px); }
  .title__br { display: inline; }
  .rule { margin: 18px 0 16px; justify-content: flex-start; width: 240px; }
  .rule span:first-child { display: none; }
}
/* Wide screens: the miss banner sits low so the bauble in the cradle stays clear; 4-3 picker. */
@media (min-width: 1024px) and (min-aspect-ratio: 4/3) {
  .message { bottom: calc(3% + var(--safe-b)); }
  .chips { max-width: 560px; margin: 0 auto; }
}

/* Input-mode switch: key hints for keyboard+mouse, drag hint for touch. */
@media (pointer: coarse) { .keyhints { display: none; } }
@media (pointer: fine) { .drag-hint { display: none; } }
@media (pointer: coarse) {
  .grab-btn { width: 92px; height: 92px; }
  .grab-btn span { font-size: 27px; }
  .drag-hint { position: absolute; right: calc(100% + 14px); top: 50%; margin-top: -16px; }
}

/* ---------- Stub reveal (only used with the stub) ---------- */
.stub-reveal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(4, 12, 9, .7); padding: 20px; }
.stub-reveal__card {
  width: min(380px, 100%); padding: 30px 26px 26px; text-align: center; color: var(--ink);
  background: #f4ecdc; border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--gold-deep), inset 0 0 0 6px #f4ecdc, inset 0 0 0 7px rgba(184, 146, 74, .5), 0 24px 60px rgba(0, 0, 0, .5);
}
.stub-reveal__eyebrow { margin: 0 0 16px; font-size: 13px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--velvet); }
.stub-reveal__photo { width: 160px; height: 160px; margin: 0 auto; border-radius: 50%; background-size: cover; box-shadow: 0 0 0 3px var(--gold-deep); }
.stub-reveal__name { margin: 16px 0 22px; font-family: var(--f-display); font-size: 34px; }
.stub-reveal__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stub-reveal .btn--ghost { color: var(--ink); box-shadow: inset 0 0 0 1px var(--gold-deep); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; font-size: 18px; }

/* ---------- Phone ---------- */
@media (max-width: 560px) {
  .topbar { padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l)); }
  .title { font-size: clamp(28px, 8.6vw, 38px); }
  .lede { font-size: 15px; margin-bottom: 22px; }
  .deco-fan { display: none; }
  .screen--who { padding: calc(66px + var(--safe-t)) 12px calc(12px + var(--safe-b)); }
  .panel { padding: 24px 14px 16px; }
  .panel__sub { margin-bottom: 16px; }
  .chips { gap: 14px 4px; }
  .chips > li { width: calc((100% - 8px) / 3); }
  .chip { padding: 6px 2px 8px; gap: 8px; }
  .chip__photo { width: 78px; height: 78px; }
  .chip__name { font-size: 14px; }
  .message { padding: 20px 18px 18px; }
  .message__line { font-size: 15px; }
}
@media (max-width: 370px) {
  .chip__photo { width: 70px; height: 70px; }
  .chip__name { font-size: 13px; }
  .hint__text { font-size: 17px; }
}
/* Short phones: smaller button so the hint band fits under the pit. */
@media (pointer: coarse) and (max-height: 700px) and (orientation: portrait) {
  :root { --dock: calc(12px + 72px + 16px); }
  .controls { bottom: calc(12px + var(--safe-b)); }
  .grab-btn { width: 72px; height: 72px; }
  .grab-btn span { font-size: 22px; }
  .hint__card { padding: 10px 14px 9px; }
  .hint__label { font-size: 11px; margin-bottom: 2px; }
  .hint__text { font-size: 16px; line-height: 1.25; }
}
/* Short screens (small phones, landscape phones) */
@media (max-height: 680px) {
  .screen--title { padding-bottom: calc(4vh + var(--safe-b)); }
  .lede { margin-bottom: 18px; }
  .rule { margin: 10px auto; }
  .chip__photo { width: 68px; height: 68px; }
  .panel { padding-top: 20px; }
  .panel__sub { margin-bottom: 12px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .title { font-size: 30px; }
  .deco-fan { display: none; }
  .lede { font-size: 14px; margin-bottom: 12px; }
  .screen--who { padding-top: calc(10px + var(--safe-t)); }
  .panel { width: min(720px, calc(100% - 120px)); }
  .chips { flex-wrap: nowrap; }
  .chips > li { width: auto; flex: 1; }
  .controls { left: auto; right: calc(20px + var(--safe-r)); margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
