/* Tile Bag. A quiet table: indigo linen, hinoki wood, honed stone, bronze. Bone-white words, one
   vermilion seal colour for what matters. Square edges, no bubbles. */
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url(/fonts/cormorant-garamond-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Inter'; src: url(/fonts/inter-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Inter'; src: url(/fonts/inter-latin-500-normal.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Inter'; src: url(/fonts/inter-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --indigo: #1d2d68;
  --indigo-deep: #121d47;
  --indigo-veil: rgba(16, 26, 64, 0.9);
  --bone: #f1e8d6;
  --bone-dim: rgba(241, 232, 214, 0.62);
  --bone-faint: rgba(241, 232, 214, 0.22);
  --ink: #3a2414;
  --ink-soft: rgba(58, 36, 20, 0.62);
  --seal: #d8452b;
  --seal-deep: #b3361f;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: var(--indigo); color: var(--bone); font-family: var(--sans); font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; user-select: text; -webkit-user-select: text; }

#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; background: var(--indigo); }
#scene { display: block; position: absolute; inset: 0; touch-action: none; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; font-family: var(--serif); font-size: 22px; text-align: center; }
#view { position: absolute; inset: 0; pointer-events: none; }
#view > section { position: absolute; inset: 0; }
#view button, #view input, #view a, #view .seg, #view .shelf, #view .endpanel, #view .scroll { pointer-events: auto; }

/* ---------- buttons: a vermilion slab, or a bone outline ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; padding: 0 26px;
  background: var(--seal); color: #fff7ea; font-family: var(--sans); font-weight: 600; font-size: 16px; letter-spacing: 0.02em;
  border-radius: 3px; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.16) inset, 0 6px 18px rgba(8, 12, 36, 0.35); transition: background 0.15s, transform 0.1s; white-space: nowrap; }
.btn:hover { background: #e2512f; }
.btn:active { transform: translateY(1px); background: var(--seal-deep); }
.btn:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }
.btn.alt { background: transparent; color: var(--bone); box-shadow: inset 0 0 0 1px var(--bone-faint); }
.btn.alt:hover { box-shadow: inset 0 0 0 1px var(--bone-dim); background: rgba(241, 232, 214, 0.05); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 2px; font: 500 11px var(--sans);
  background: rgba(0, 0, 0, 0.18); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28); color: inherit; }
.link { color: var(--bone-dim); font-size: 13px; letter-spacing: 0.02em; padding: 8px 2px; }
.link:hover { color: var(--bone); }

/* ---------- home ---------- */
.home .mark { position: absolute; top: calc(var(--safe-t) + 6vh); left: 0; right: 0; text-align: center;
  font-family: var(--serif); font-weight: 600; font-size: clamp(46px, 13vw, 104px); line-height: 1; color: var(--bone);
  letter-spacing: 0.18em; text-indent: 0.18em; text-shadow: 0 2px 24px rgba(8, 12, 40, 0.45); pointer-events: none; }
.home .mark i { display: inline-block; width: 0.35em; }
.home .mark span { display: inline-block; animation: rise 0.9s cubic-bezier(.2, .7, .2, 1) both; }
.home .mark span:nth-child(2) { animation-delay: 0.05s; } .home .mark span:nth-child(3) { animation-delay: 0.1s; }
.home .mark span:nth-child(5) { animation-delay: 0.18s; } .home .mark span:nth-child(6) { animation-delay: 0.23s; } .home .mark span:nth-child(7) { animation-delay: 0.28s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.home .actions { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 18px); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 16px; }
.home .actions > .btn { width: min(320px, 100%); }
.home .links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 2px; }
.home .shelf { width: 100%; max-width: 640px; }
.home .shelf:empty { display: none; }

/* ---------- sheets: a column of indigo cloth laid over the table ---------- */
.sheet { background: linear-gradient(90deg, var(--indigo-veil) 0, var(--indigo-veil) min(100%, 560px), rgba(16, 26, 64, 0.35) min(100%, 760px), rgba(16, 26, 64, 0) 100%); }
.sheet .stack { pointer-events: auto; position: absolute; inset: 0; right: auto; width: min(100%, 560px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  padding: calc(var(--safe-t) + 18px) 24px calc(var(--safe-b) + 28px); display: flex; flex-direction: column; gap: 22px; }
.sheet .stack > .btn { align-self: stretch; }
.top { display: flex; align-items: center; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--bone-faint); }
.top h2 { font-family: var(--serif); font-weight: 600; font-size: 34px; line-height: 1.1; letter-spacing: 0.01em; }
.back { width: 40px; height: 40px; font-size: 22px; color: var(--bone-dim); border-radius: 2px; }
.back:hover { color: var(--bone); background: rgba(241, 232, 214, 0.06); }
.field-row { display: flex; flex-direction: column; gap: 10px; }
.label { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--bone-dim); }
.seg { display: flex; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--bone-faint); overflow: hidden; }
.seg button { flex: 1; min-height: 46px; padding: 0 12px; font-weight: 500; color: var(--bone-dim); }
.seg button + button { box-shadow: inset 1px 0 0 var(--bone-faint); }
.seg button[aria-pressed="true"] { background: var(--bone); color: var(--indigo-deep); box-shadow: none; }
.seg.small button { min-height: 34px; font-size: 13px; padding: 0 10px; }
.field { width: 100%; min-height: 50px; padding: 0 14px; border-radius: 3px; border: 0; background: rgba(241, 232, 214, 0.08);
  box-shadow: inset 0 0 0 1px var(--bone-faint); color: var(--bone); font-size: 17px; outline: none; }
.field:focus { box-shadow: inset 0 0 0 1px var(--bone-dim); }
.code-in { text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.row { display: flex; gap: 10px; } .row .field { flex: 1; min-width: 0; }
.code { font-family: var(--serif); font-weight: 600; font-size: 54px; letter-spacing: 0.24em; line-height: 1; }
.seat-list { display: flex; flex-direction: column; }
.seat-row { display: flex; align-items: center; gap: 12px; min-height: 56px; border-bottom: 1px solid rgba(241, 232, 214, 0.1); }
.seat-row .who { flex: 1; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.seat-row.empty .who { color: var(--bone-faint); }
.tag { font-size: 12px; color: var(--bone-dim); letter-spacing: 0.06em; }
.x { width: 36px; height: 36px; font-size: 20px; color: var(--bone-dim); }
.waiting { color: var(--bone-dim); font-family: var(--serif); font-size: 20px; }
.seal { display: inline-grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--seal); color: #fff4e6;
  font: 600 16px/1 var(--serif); box-shadow: inset 0 0 0 2px rgba(255, 240, 220, 0.25); }
.seal.off { background: transparent; box-shadow: inset 0 0 0 1px var(--bone-faint); }
.cr { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid rgba(241, 232, 214, 0.08); }
.cr b { font-weight: 500; } .cr span { color: var(--bone-dim); font-size: 13px; } .cr a { color: var(--bone); }

.ico { width: 34px; height: 34px; object-fit: contain; vertical-align: middle; }
.ico.coin { width: 18px; height: 18px; }
.ico.coin.big { width: 44px; height: 44px; }

/* how to play */
.how { display: flex; flex-direction: column; }
.how-step { display: grid; grid-template-columns: 132px 1fr; gap: 16px; align-items: center; padding: 16px 0; border-bottom: 1px solid rgba(241, 232, 214, 0.1); }
.how-step .ill { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.how-step p { color: var(--bone); font-size: 15px; }
.card-ill { display: flex; gap: 2px; }
.card-ill .ci { display: flex; flex-direction: column; align-items: center; font: 600 16px var(--serif); }
.card-ill .ico { width: 26px; height: 26px; }
.big-n { font: 600 26px var(--serif); margin: 0 6px 0 2px; }
.bagword { font: italic 500 20px var(--serif); color: var(--bone-dim); }
.how-step .use { background: rgba(8, 14, 40, 0.5); }

/* ---------- the table ---------- */
.table .hud { position: absolute; top: 0; left: 0; right: 0; height: calc(var(--safe-t) + 58px); padding: var(--safe-t) 14px 0;
  display: flex; align-items: center; gap: 14px; pointer-events: none; }
.hud .round { display: flex; align-items: baseline; gap: 6px; font-family: var(--serif); }
.hud .round span { font-size: 18px; color: var(--bone-dim); font-weight: 500; }
.hud .round b { font-size: 30px; font-weight: 600; }
.hud .bagcount { margin-left: auto; display: flex; align-items: baseline; gap: 6px; }
.hud .bagcount b { font: 600 26px var(--serif); }
.hud .bagcount span { font-size: 12px; color: var(--bone-dim); letter-spacing: 0.04em; }
.clock { width: 40px; height: 40px; position: relative; display: grid; place-items: center; }
.clock svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.clock circle { fill: none; stroke-width: 2; }
.clock .tr { stroke: var(--bone-faint); }
.clock .fg { stroke: var(--bone); stroke-dasharray: 100.5; transition: stroke-dashoffset 0.25s linear; }
.clock b { font: 600 18px var(--serif); }
.clock.hot .fg { stroke: var(--seal); } .clock.hot b { color: #ff8a6e; }
.menu { width: 40px; height: 40px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; border-radius: 2px; }
.menu i { display: block; width: 20px; height: 1.5px; background: var(--bone); }
.menu:hover { background: rgba(241, 232, 214, 0.08); }

.table .bar { position: absolute; left: 0; right: 0; bottom: 0; min-height: calc(var(--safe-b) + 74px); padding: 10px 14px calc(var(--safe-b) + 12px);
  display: flex; align-items: center; gap: 14px; background: linear-gradient(0deg, rgba(14, 22, 56, 0.75), rgba(14, 22, 56, 0)); pointer-events: none; }
.bar .msg { flex: 1; min-width: 0; font-size: 14px; color: var(--bone); line-height: 1.35; display: flex; flex-direction: column; gap: 4px; }
.bar .msg .keys { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--bone-dim); }
.bar .acts { flex: none; display: flex; gap: 8px; min-width: 150px; justify-content: flex-end; }
.bar .acts .btn { min-width: 150px; }

/* ---------- labels pinned to the table ---------- */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lb { position: absolute; left: 0; top: 0; translate: -50% -50%; white-space: nowrap; will-change: transform; }
.lb.none, .lb:empty { display: none; }
.lb.roll { color: var(--seal-deep); font: 600 clamp(11px, calc(var(--u) * 0.36), 15px) var(--serif); }
.lb.uses { display: flex; gap: 4px; translate: 0 -50%; }
[data-marks="off"] .lb.uses { display: none; }
.use { display: inline-flex; align-items: baseline; gap: 3px; padding: 0 6px 1px; border-radius: 2px; font-size: clamp(10px, calc(var(--u) * 0.28), 12px); color: var(--bone-dim); background: rgba(8, 14, 40, 0.32); }
.use b { font: 600 clamp(12px, calc(var(--u) * 0.36), 15px) var(--serif); color: var(--bone); }
.use.me { color: var(--indigo-deep); background: var(--bone); } .use.me b { color: var(--indigo-deep); }
.lb.stake { translate: -50% -50%; }
.lb.stake b { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px; border-radius: 2px; background: var(--bone); color: var(--indigo-deep); font: 600 16px var(--serif); }
.lb.empty { font: italic 500 18px var(--serif); color: var(--ink-soft); }
.lb.plaque { display: flex; align-items: center; gap: 8px; color: var(--bone); }
.lb.plaque .pn { font: 600 clamp(13px, calc(var(--u) * 0.42), 18px) var(--serif); }
.lb.plaque .ps { display: inline-flex; align-items: center; gap: 3px; font: 600 clamp(12px, calc(var(--u) * 0.38), 16px) var(--serif); }
.lb.plaque .ico.coin { width: clamp(12px, calc(var(--u) * 0.4), 18px); height: auto; }
.lb.plaque.win .pn { color: #ff9a80; }
.lockmark { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--seal); color: #fff4e6; font-size: 10px; font-weight: 700; }
.lb.need { font: 600 clamp(11px, calc(var(--u) * 0.4), 16px) var(--serif); color: var(--ink); }
.lb.need.ok { color: var(--seal-deep); }
.lb.spare { font: italic 500 13px var(--serif); color: var(--ink-soft); translate: 10% -50%; }
.lb.bankn { font: 500 13px var(--sans); color: var(--bone-dim); letter-spacing: 0.02em; translate: 0 -30%; }
.lb.bankn b { font: 600 20px var(--serif); color: var(--bone); }
.lb.bankn span { color: var(--bone-dim); }
.lb.stamp { padding: 3px 10px 4px; border-radius: 2px; background: var(--indigo-deep); color: var(--bone); font: 500 clamp(11px, calc(var(--u) * 0.36), 14px) var(--sans); letter-spacing: 0.03em;
  box-shadow: 0 4px 12px rgba(8, 12, 36, 0.35); animation: stampin 0.3s cubic-bezier(.2, .8, .2, 1) both; }
.lb.stamp.mine { background: var(--seal); color: #fff4e6; }
.lb.stamp.void { background: #0b1233; color: #ffb59f; }
.lb.stamp.quiet { background: rgba(8, 14, 40, 0.5); color: var(--bone-dim); }
@keyframes stampin { from { opacity: 0; scale: 1.25; } }
.use.bidtag { background: rgba(8, 14, 40, 0.6); color: var(--bone); }
.use.bidtag.hi { background: var(--seal); color: #fff4e6; } .use.bidtag.hi b { color: #fff4e6; }
.use.bidtag.tie { background: #0b1233; color: #ffb59f; } .use.bidtag.tie b { color: #ffb59f; }

/* ---------- results ---------- */
.results .head { font-family: var(--serif); font-weight: 600; font-size: 44px; line-height: 1.05; }
.results .why { color: var(--bone-dim); margin-top: -12px; }
.res-list { display: flex; flex-direction: column; }
.res-row { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; border-bottom: 1px solid rgba(241, 232, 214, 0.1); }
.res-row .who { display: flex; align-items: center; gap: 10px; }
.res-row .who b { font: 600 20px var(--serif); }
.res-row .who > span:last-child { margin-left: auto; color: var(--bone-dim); font-size: 13px; }
.res-row:not(.win) .seal { background: transparent; box-shadow: inset 0 0 0 1px var(--bone-faint); color: var(--bone-dim); }
.res-card { display: flex; gap: 10px; flex-wrap: wrap; }
.rc { display: inline-flex; align-items: center; gap: 3px; font: 600 16px var(--serif); color: var(--bone-dim); }
.rc i { font-style: normal; font-size: 13px; color: var(--bone-faint); }
.rc .ico { width: 26px; height: 26px; }
.rc.ok b { color: var(--bone); }
.row2 { display: flex; gap: 10px; } .row2 .btn { flex: 1; }
.endpanel:empty { display: none; }

/* ---------- menu, toast, options ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 12, 36, 0.6); padding: 16px; z-index: 20; }
.modal .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 26px 22px; background: var(--indigo-deep); box-shadow: inset 0 0 0 1px var(--bone-faint), 0 30px 60px rgba(0, 0, 0, 0.4); border-radius: 3px; }
.modal h3 { font: 600 24px var(--serif); margin-bottom: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translate(-50%, 12px); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 3px;
  background: var(--bone); color: var(--indigo-deep); font-weight: 500; font-size: 14px; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 30; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#tweaks { position: fixed; right: 10px; top: calc(var(--safe-t) + 66px); z-index: 25; width: 230px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--indigo-deep); box-shadow: inset 0 0 0 1px var(--bone-faint); border-radius: 3px; font-size: 12px; }
#tweaks .tw { display: flex; flex-direction: column; gap: 4px; }
[data-screen="game"] #tweaks { top: auto; bottom: calc(var(--safe-b) + 90px); }

/* ---------- shapes ---------- */
@media (max-width: 460px) { .how-step { grid-template-columns: 1fr; gap: 10px; } }
@media (max-width: 380px) {
  .btn { padding: 0 18px; font-size: 15px; }
  .bar .acts, .bar .acts .btn { min-width: 128px; }
  .bar .msg { font-size: 13px; }
  .hud .round b { font-size: 26px; }
}
@media (max-height: 620px) {
  .table .hud { height: calc(var(--safe-t) + 48px); }
  .table .bar { min-height: calc(var(--safe-b) + 64px); padding-top: 6px; padding-bottom: calc(var(--safe-b) + 8px); }
  .btn { min-height: 44px; }
  .home .mark { top: calc(var(--safe-t) + 3vh); }
}
@media (min-width: 900px) {
  .table .hud { padding: var(--safe-t) 28px 0; height: 72px; }
  .table .bar { padding: 12px 28px 18px; }
  .bar .msg { flex-direction: row; align-items: center; gap: 18px; font-size: 15px; }
}
