/* Client styling. Tokens & mosaic primitives come from theme.css.
   Direction: quiet-luxury atelier — Fraunces display, Jost UI, brass details,
   the board presented as a framed artwork. */

.wrap { max-width: 720px; margin: 0 auto; padding: 30px 18px 72px; position: relative; z-index: 1; }

/* Tactile paper grain + a soft warm glow, fixed behind everything. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 460px at 50% -10%, var(--accent-soft), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  background-blend-mode: normal; opacity: .5;
  mix-blend-mode: multiply;
}
@media (prefers-color-scheme: dark) { body::before { mix-blend-mode: screen; opacity: .22; } }

/* ---- Header ---- */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 16px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 13px; }
.logo { width: 30px; height: 30px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; overflow: hidden; border: 1px solid var(--accent); box-shadow: 0 0 0 1px var(--panel) inset; }
.logo span:nth-child(1){background:var(--c0)} .logo span:nth-child(2){background:var(--c2)}
.logo span:nth-child(3){background:var(--c3)} .logo span:nth-child(4){background:var(--c1)}
h1 { font-family: var(--font-serif); font-size: 1.42rem; font-weight: 500; margin: 0; letter-spacing: .005em; line-height: 1; }
h2 { font-family: var(--font-serif); font-size: 1.16rem; font-weight: 500; margin: 0 0 2px; letter-spacing: .005em; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }

.lede { color: var(--muted); font-size: .95rem; max-width: 52ch; margin: 8px 0 26px; line-height: 1.6; }
.stack { display: flex; flex-direction: column; gap: 15px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
.center { text-align: center; }
.small { font-size: .84rem; }
.grow { flex: 1 1 auto; }
.divider { height: 1px; background: var(--line); margin: 3px 0; }

/* ---- Forms ---- */
label { font-family: var(--font-sans); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: 6px; }
input[type=text], input[type=number] {
  width: 100%; padding: 12px 13px; font: inherit; font-size: .95rem; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; min-height: 46px;
}
input::placeholder { color: var(--muted); opacity: .7; }
input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.code { font-family: var(--font-mono); letter-spacing: .16em; text-transform: uppercase; }

/* ---- Buttons (extras beyond theme) ---- */
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); min-height: 40px; padding: 8px 14px; }
.btn.ghost:hover { color: var(--ink); border-color: var(--accent); }
.toolbar { gap: 8px; }

/* ---- Lobby ---- */
.bigcode { font-family: var(--font-serif); font-size: 2.6rem; font-weight: 500; letter-spacing: .3em; text-indent: .3em; line-height: 1.1; }
.players { display: flex; flex-direction: column; gap: 9px; }
.pl { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.pl .who { display: flex; align-items: center; gap: 10px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--c3); box-shadow: 0 0 0 3px rgba(79,122,84,.18); }
.dot.off { background: var(--c0); }
.badge { font-size: .6rem; text-transform: uppercase; letter-spacing: .18em; color: var(--accent); font-weight: 500; }

/* ---- Board framing (client uses .board-frame from theme) ---- */
.framewrap { display: flex; justify-content: center; }
.board.play .cell { cursor: default; }
.board.play .cell.empty.placeable { outline: 1px dashed var(--accent); outline-offset: -3px; cursor: pointer; transition: outline-color .2s ease; }
.board.play .cell.preview { cursor: pointer; position: relative; box-shadow: inset 0 0 0 2px var(--accent); animation: previewpulse 1.3s ease-in-out infinite; }
@keyframes previewpulse { 0%,100% { box-shadow: inset 0 0 0 2px var(--accent); } 50% { box-shadow: inset 0 0 0 3px var(--accent), 0 0 16px var(--accent-soft); } }
.board.play .cell.slidable { cursor: pointer; outline: 1px solid var(--accent); outline-offset: -3px; opacity: 1; transition: box-shadow .2s ease; }
.board.play .cell.slidable:hover { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---- Draft ---- */
.turnbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 18px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.yourturn { color: var(--accent); font-weight: 500; letter-spacing: .04em; animation: livedot 1.6s ease-in-out infinite; }
@keyframes livedot { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
.timer { font-family: var(--font-serif); font-variant-numeric: tabular-nums; font-weight: 500; font-size: 1.05rem; }
.timer.warn { color: var(--c0); animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.candidates { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.cand { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px; border-radius: 6px; border: 1px solid transparent; transition: transform .14s ease, border-color .2s ease, box-shadow .2s ease; }
.cand:not([aria-disabled="true"]) { cursor: pointer; }
.cand:not([aria-disabled="true"]):hover { transform: translateY(-3px); }
.cand.selected { border-color: var(--accent); box-shadow: 0 10px 26px rgba(38,34,28,.14); transform: translateY(-3px); }
.cand .lbl { font-size: .64rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.staging { align-items: center; gap: 12px; justify-content: center; }
.tile { box-shadow: 0 2px 8px rgba(38,34,28,.1); }
.cand .tile, .slot .tile { box-shadow: 0 1px 4px rgba(38,34,28,.12); }

/* ---- Score panel ---- */
.scores { display: flex; flex-direction: column; gap: 11px; }
.scorerow { display: grid; grid-template-columns: 66px 1fr 40px; align-items: center; gap: 12px; }
.swatch { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; letter-spacing: .02em; }
.swatch b { width: 11px; height: 11px; display: inline-block; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.2,.7,.3,1); }
.num { text-align: right; font-family: var(--font-serif); font-variant-numeric: tabular-nums; font-size: .95rem; }
.scorerow.counted .swatch { color: var(--ink); font-weight: 500; }
.scorerow.counted .num { color: var(--accent); }
.total { display: flex; align-items: baseline; justify-content: space-between; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.total .muted { text-transform: uppercase; letter-spacing: .14em; font-size: .66rem; }
.total .n { font-family: var(--font-serif); font-size: 2.1rem; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---- Results ---- */
.results-table { width: 100%; border-collapse: collapse; }
.results-table th { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: .62rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.results-table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.results-table td.n { text-align: right; font-family: var(--font-serif); font-variant-numeric: tabular-nums; }
.results-table tr.elim td { color: var(--c0); }
.results-table tr.elim td:last-child { font-size: .62rem; letter-spacing: .16em; text-transform: uppercase; }
.miniboards { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 18px; justify-content: center; }

/* ---- Modals ---- (entrance animation only on the fresh/open render, so a
   background re-render from another player's move never re-flashes the sheet) */
.overlay { position: fixed; inset: 0; background: rgba(20,16,10,.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
.overlay.fresh { animation: ovin .2s ease both; }
.overlay.fresh .sheet { animation: sheetin .26s cubic-bezier(.2,.7,.3,1) both; }
@keyframes ovin { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetin { from { opacity: 0; transform: translateY(16px) scale(.985); } to { opacity: 1; transform: none; } }
.sheet { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 26px; width: 100%; max-width: 680px; max-height: 86vh; overflow: auto; }
.sheet-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: .9rem; line-height: 1; }
.sheet-close:hover { color: var(--ink); border-color: var(--accent); }

/* ---- Rulebook ---- */
.langtoggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang { border: 0; background: var(--panel-2); color: var(--muted); font-family: var(--font-sans); font-size: .78rem; letter-spacing: .02em; padding: 8px 13px; cursor: pointer; }
.lang.on { background: var(--ink); color: var(--panel); }
.rules h3 { font-family: var(--font-serif); font-weight: 500; font-size: 1.05rem; margin: 20px 0 5px; }
.rules .rule:first-of-type h3 { margin-top: 10px; }
.rules p { margin: 0 0 9px; color: var(--muted); line-height: 1.62; font-size: .92rem; }

/* ---- Full-pool track ---- */
.track { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 6px; justify-content: center; margin-top: 14px; }
.slot { position: relative; width: 40px; height: 40px; }
.slot .tile { width: 40px; height: 40px; }
.slot.taken { opacity: .14; }
.slot.iscand .tile { box-shadow: 0 0 0 2px var(--accent); }
.slot.marker::after { content: "▸"; position: absolute; left: -11px; top: 50%; transform: translateY(-50%); color: var(--accent); font-size: .95rem; }

/* ---- Toast ---- */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 11px 18px; border-radius: 8px; font-size: .84rem; letter-spacing: .02em; box-shadow: var(--shadow-lg); z-index: 40; max-width: 90%; animation: toastin .24s cubic-bezier(.2,.8,.3,1) both; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---- Select (create form) ---- */
.select { width: 100%; padding: 12px 13px; font: inherit; font-size: .95rem; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; min-height: 46px; appearance: none; cursor: pointer; }
.select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Join row / alignment fix ---- */
.joinrow { align-items: flex-end; }

/* ---- Turn emphasis: border/glow around the board & bar when it's your turn ---- */
.turnbar.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow); }
.board-frame.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 0 26px var(--accent-soft), var(--shadow); animation: frameglow 2.4s ease-in-out infinite; }
@keyframes frameglow { 0%,100% { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 20px var(--accent-soft), var(--shadow); } 50% { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 34px var(--accent-soft), var(--shadow); } }

/* ---- Candidate motion: slide in on a new turn, fly out when placed ---- */
.candin { animation: candin .34s cubic-bezier(.2,.75,.3,1) both; }
.candin:nth-child(2) { animation-delay: .05s; }
.candin:nth-child(3) { animation-delay: .1s; }
@keyframes candin { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }
.cand.flyout { animation: flyout .22s ease forwards; pointer-events: none; }
@keyframes flyout { to { opacity: 0; transform: translateY(-26px) scale(.85); } }

/* ---- Live score (draft bottom) ---- */
.livescore .livenum { font-family: var(--font-serif); font-size: 1.7rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.pips { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; }
.pip { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pip i { width: 11px; height: 11px; display: inline-block; }
.pip.on { color: var(--ink); font-weight: 500; }
.pip.on em { color: var(--accent); font-style: normal; }

/* ---- Lowest score, popped out ---- */
.lowest { margin-top: 14px; padding: 14px 18px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lowest-label { font-size: .64rem; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); font-weight: 500; }
.lowest-num { font-family: var(--font-serif); font-size: 2.6rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); }
.lowest.blackout { opacity: .7; border-style: dashed; }

/* ---- Ready check / finished ---- */
.badge.done { color: var(--c3); }
.pl.done { border-color: var(--c3); box-shadow: inset 0 0 0 1px rgba(79,122,84,.25); }

/* ---- Chat ---- */
.chatbtn { position: relative; }
.unread { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: var(--c0); color: #fff; font-size: .66rem; font-weight: 600; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.chat { display: flex; flex-direction: column; gap: 12px; }
.chatlist { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; padding: 4px 2px; }
.chatlist.empty { align-items: center; justify-content: center; min-height: 80px; }
.chatmsg { font-size: .92rem; line-height: 1.4; }
.chatmsg b { color: var(--accent); font-weight: 500; margin-right: 7px; }
.chatmsg span { color: var(--ink); overflow-wrap: anywhere; }
.chatinput { display: flex; gap: 8px; }
.chatinput input { flex: 1 1 auto; }

/* ---- Results: winner / loser ---- */
.result-banner { position: relative; overflow: hidden; text-align: center; padding: 30px 20px 26px; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, var(--accent-soft), transparent); box-shadow: var(--shadow); }
.result-banner .eyebrow { animation: risein .5s ease both; }
.winner-name { font-family: var(--font-serif); font-size: 2.4rem; font-weight: 600; line-height: 1.05; margin: 4px 0 2px; letter-spacing: -.01em; animation: risein .5s .08s ease both; }
.winner-score { font-family: var(--font-serif); color: var(--accent); font-variant-numeric: tabular-nums; animation: risein .5s .16s ease both; }
@keyframes risein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -12px; width: 7px; height: 11px; opacity: .9; animation: fall 2.4s linear forwards; }
@keyframes fall { to { transform: translateY(360px) rotate(540deg); opacity: 0; } }
.resboard { transition: opacity .4s ease; }
.resboard.win .board { box-shadow: 0 0 0 2px var(--accent), 0 0 26px var(--accent-soft); animation: winpulse 1.8s ease-in-out infinite; }
@keyframes winpulse { 0%,100% { box-shadow: 0 0 0 2px var(--accent), 0 0 18px var(--accent-soft); } 50% { box-shadow: 0 0 0 2px var(--accent), 0 0 32px var(--accent-soft); } }
.resboard.win .small { color: var(--accent); font-weight: 500; }
.resboard.out { opacity: .5; filter: grayscale(.5); }
.results-table tr.winrow td { color: var(--accent); font-weight: 500; }
.results-table tr.winrow td:first-child { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .yourturn, .timer.warn, .board.play .cell.preview, .overlay.fresh, .overlay.fresh .sheet, .toast,
  .board-frame.active, .candin, .result-banner .eyebrow, .winner-name, .winner-score, .resboard.win .board, .confetti i { animation: none; }
  .btn, .cand, .bar > i, .resboard { transition: none; }
  .confetti { display: none; }
}
