:root {
  --bg: #0e1116; --panel: #171c24; --panel2: #1f2630; --line: #2b3441; --text: #eaeef4; --dim: #9aa6b6;
  --accent: #f5b942; --ok: #3ecf8e; --miss: #ff5d6c; --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.loading { padding: 2rem; color: var(--dim); }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: .7rem 1.1rem; border-radius: 999px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); }

/* ---------- home ---------- */
.home { max-width: 760px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.home h1 { font-size: 2.2rem; margin: .4rem 0 .2rem; letter-spacing: -.02em; }
.home h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); margin: 2rem 0 .7rem; }
.sub { color: var(--dim); margin: 0 0 1.2rem; }
.daily { display: grid; gap: .25rem; padding: 1rem 1.1rem; border-radius: var(--radius); background: linear-gradient(135deg, #3a2a08, #22190a); border: 1px solid #6b4d12; text-decoration: none; }
.daily-tag { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.daily strong { font-size: 1.2rem; }
.daily .go { color: var(--accent); font-weight: 600; }
.set-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
.set-card { display: grid; grid-template-columns: 132px 1fr; gap: .9rem; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; align-items: center; transition: transform .15s, border-color .15s; }
.set-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.collage { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: #000; }
.collage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.set-meta { display: grid; gap: .25rem; }
.set-meta .type { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.set-meta strong { font-size: 1.15rem; }
.set-meta .desc { color: var(--dim); font-size: .9rem; }

/* ---------- game layout ---------- */
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .7rem; padding: .6rem .9rem; background: rgba(14,17,22,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.back { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; text-decoration: none; background: var(--panel2); font-size: 1.2rem; }
.bar-title { flex: 1; display: grid; min-width: 0; }
.bar-title strong, .bar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title span { font-size: .78rem; color: var(--dim); }
.progress { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.cols { display: flex; flex-direction: column-reverse; max-width: 1000px; margin: 0 auto; }
.hand { position: sticky; bottom: 0; z-index: 15; padding: .6rem .8rem calc(.8rem + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -12px 20px rgba(14,17,22,.9); }
.hand.ended { position: static; box-shadow: none; }
.hand-label { font-size: .78rem; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; margin: .2rem .2rem .4rem; }
.hand-label span { text-transform: none; letter-spacing: 0; }
.tl-wrap { padding: .8rem .8rem 1rem; }
.axis-end { font-size: .8rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); padding: .2rem .4rem; }
.axis-end.bottom { text-align: right; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 3px solid var(--line); margin-left: .5rem; padding-left: .7rem; }

/* ---------- cards ---------- */
.poster { position: relative; background: var(--panel2); border-radius: 10px; overflow: hidden; flex: none; }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-drag: none; user-select: none; }
.poster.noimg { display: grid; place-items: center; text-align: center; padding: .5rem; font-weight: 700; color: var(--dim); }
.card { display: flex; gap: .8rem; padding: .7rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.hand-card { touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.hand-card .poster { width: 108px; }
.hand-card.dragging { opacity: .35; cursor: grabbing; }
.card-body { min-width: 0; flex: 1; }
.card-title { margin: 0; font-size: 1.1rem; line-height: 1.2; }
.card-sub { color: var(--dim); font-size: .85rem; margin-top: .1rem; }
.card-desc { margin: .35rem 0; font-size: .85rem; color: #c6cfdb; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.fields { margin: .3rem 0 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .15rem; font-size: .82rem; }
.field { display: flex; gap: .4rem; }
.field dt { color: var(--dim); flex: none; }
.field dt::after { content: ":"; }
.field dd { margin: 0; min-width: 0; flex: 1 1 0; }
.field.is-hidden dd { color: var(--accent); letter-spacing: .15em; font-weight: 700; }

.feedback { min-height: 0; }

/* timeline items */
.tl-item { position: relative; display: flex; gap: .7rem; align-items: stretch; padding: .5rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin: 0; }
.tl-item .poster.thumb { width: 64px; align-self: flex-start; }
.tl-item .card-title { font-size: 1rem; }
.tl-item .fields { font-size: .76rem; }
.tl-item::before { content: ""; position: absolute; left: -1.05rem; top: 50%; width: 11px; height: 11px; border-radius: 50%; background: var(--line); transform: translateY(-50%); }
.reveal { flex: none; display: grid; align-content: space-between; justify-items: end; text-align: right; }
.reveal-val { font-weight: 800; font-size: 1rem; color: var(--accent); max-width: 7.5rem; }
.mark { font-size: 1.3rem; font-weight: 800; }
.st-ok { border-color: #1f6a4b; } .st-ok .mark { color: var(--ok); } .st-ok::before { background: var(--ok); }
.st-miss { border-color: #7a2a33; } .st-miss .mark { color: var(--miss); } .st-miss::before { background: var(--miss); }
.starter .mark { color: var(--accent); }
.moving { transition: transform .6s cubic-bezier(.2,.8,.2,1); position: relative; z-index: 2; }
.enter { animation: enter .35s ease-out; }
@keyframes enter { from { opacity: 0; transform: scale(.92) translateY(-10px); } }
.flash-ok { animation: okglow 1s ease-out; }
.flash-miss { animation: shake .45s, missglow 1.1s ease-out; border-color: var(--miss); }
.flash-fix { animation: fixglow 1s ease-out; }
@keyframes okglow { 0% { box-shadow: 0 0 0 0 rgba(62,207,142,.8); } 100% { box-shadow: 0 0 0 16px rgba(62,207,142,0); } }
@keyframes missglow { 0% { box-shadow: 0 0 0 0 rgba(255,93,108,.8); } 100% { box-shadow: 0 0 0 16px rgba(255,93,108,0); } }
@keyframes fixglow { 0% { box-shadow: 0 0 0 0 rgba(245,185,66,.8); } 100% { box-shadow: 0 0 0 16px rgba(245,185,66,0); } }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

/* slots */
.slot-li { list-style: none; margin: 0; }
.slot { display: grid; place-items: center; width: 100%; height: 40px; background: transparent; border: 2px dashed var(--line); border-radius: 10px; color: var(--dim); font: inherit; font-size: .8rem; cursor: pointer; margin: 4px 0; transition: background .12s, border-color .12s, color .12s; }
.slot:hover:not(:disabled), .slot.hot, .slot:focus-visible { border-color: var(--accent); background: rgba(245,185,66,.12); color: var(--accent); }
.slot.hot { border-style: solid; transform: scale(1.02); }
.slot:disabled { opacity: .35; cursor: default; }
.slot span::before { content: "＋ "; }
.slot:disabled span::before { content: ""; }
.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }

.ghost { position: fixed; left: 0; top: 0; z-index: 100; width: 112px; pointer-events: none; display: grid; gap: .3rem; text-align: center; font-size: .78rem; filter: drop-shadow(0 14px 18px rgba(0,0,0,.6)); will-change: transform; }

.toast { white-space: nowrap; position: fixed; left: 50%; top: 64px; transform: translate(-50%, -20px); z-index: 60; padding: .6rem 1rem; border-radius: 999px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); color: #04210f; }
.toast.miss { background: var(--miss); color: #2a0509; }

/* end screen */
.end { text-align: center; padding: .6rem 0 .2rem; }
.end-msg { color: var(--dim); font-weight: 600; }
.end-score { font-size: 3.4rem; font-weight: 800; line-height: 1.1; color: var(--accent); }
.end-sub { color: var(--dim); font-size: .85rem; }
.squares { font-size: 1.7rem; letter-spacing: .1em; margin: .5rem 0; }
.share { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem; text-align: left; white-space: pre-wrap; word-break: break-word; font: .85rem/1.45 ui-monospace, monospace; margin: .4rem 0 .8rem; user-select: all; }
.end-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }

/* ---------- wide screens: hand on the left ---------- */
@media (min-width: 860px) {
  .cols { flex-direction: row; align-items: flex-start; gap: 1.5rem; padding: 0 1rem; }
  .hand, .hand.ended { position: sticky; top: 70px; bottom: auto; width: 360px; flex: none; background: none; padding: 1rem 0; border-top: 0; box-shadow: none; }
  .hand-card { flex-direction: column; }
  .hand-card .poster { width: 100%; max-width: 240px; margin: 0 auto; }
  .tl-wrap { flex: 1; }
  .tl-item .poster.thumb { width: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* compact timeline cards on narrow screens */
.tl-item .reveal { display: block; }
.tl-item .reveal-val { display: block; max-width: 4.8rem; font-size: .95rem; line-height: 1.15; }
.tl-item .mark { position: absolute; right: .6rem; bottom: .4rem; }
.tl-item .field dt { font-size: .72rem; }
.tl-item .field { gap: .3rem; }
