/* Generic base styles for hub-game-template. Dark, mobile-first, safe-area aware.
   Restyle freely for your game. Class names are referenced by app.js + game-ui.js. */
:root {
  --bg: #141a24; --panel: #1e2733; --panel2: #18212d; --line: #2c3848;
  --fg: #eef2f7; --muted: #aeb8c6; --accent: #2f6bff; --danger: #d64545;
  --x: #4fa3ff; --o: #ffb454; --win: #2e7d4f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--fg);
  font-family: 'Apple SD Gothic Neo', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom */
}
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#app { max-width: 560px; margin: 0 auto; padding: 16px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }

/* ── buttons / inputs ── */
.btn { display: block; width: 100%; padding: 14px; margin-top: 10px; border: 0; border-radius: 12px;
  background: #28323f; color: #dbe3ee; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 13px; margin: 0; }
.btn.disabled { opacity: .5; cursor: not-allowed; }
.in { width: 100%; padding: 13px; margin-top: 6px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--fg); font-size: 15px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-top: 12px; }

/* ── cards / layout ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-top: 14px; }
.card.err, .card .err { color: #ff9a9a; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .btn { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.sep { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 4px; position: relative; }

/* ── home ── */
.home { padding-top: 10px; }
.brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 14px 0 4px; }
.brand-ic { width: 44px; height: 44px; border-radius: 12px; }
.brand h1 { font-size: 24px; margin: 0; }
.who { text-align: center; color: var(--muted); font-size: 13px; margin-top: 16px; }
.link { color: var(--x); margin-left: 10px; text-decoration: underline; }

/* ── room ── */
.roombar { display: flex; align-items: center; justify-content: space-between; }
.code { font-size: 15px; color: var(--muted); }
.code b { color: var(--fg); font-size: 20px; letter-spacing: 2px; margin-left: 4px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pl { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.pl.off { opacity: .45; }
.pl .dot { width: 8px; height: 8px; border-radius: 50%; background: #3ecf6b; }
.pl.off .dot { background: #6b7480; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #34425a; color: #cdd9ee; }
.tag.host { background: #5a4a1e; color: #ffe39c; }
.mini { border: 0; background: #2a3340; color: #cdd6e2; border-radius: 8px; padding: 2px 7px; font-size: 12px; cursor: pointer; }
.mini.danger { background: #4a2330; color: #ffb3c0; }

/* ── lobby seats (tic-tac-toe example) ── */
.seats { display: flex; gap: 12px; margin: 14px 0; }
.seat { flex: 1; background: var(--panel2); border: 2px solid var(--line); border-radius: 14px; padding: 18px 8px;
  cursor: pointer; color: var(--fg); }
.seat.mine { border-color: var(--accent); }
.seat.taken { opacity: .85; }
.seat-mark { font-size: 34px; font-weight: 800; }
.seat-by { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ── board (tic-tac-toe example) ── */
.status { text-align: center; font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.status.big { font-size: 20px; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; aspect-ratio: 1; max-width: 360px; margin: 0 auto; }
.cell { font-size: 13vw; max-font-size: 64px; font-weight: 800; border: 0; border-radius: 12px;
  background: var(--panel2); color: var(--fg); cursor: default; display: flex; align-items: center; justify-content: center; }
@media (min-width: 420px) { .cell { font-size: 56px; } }
.cell.f-X { color: var(--x); } .cell.f-O { color: var(--o); }
.cell.live { cursor: pointer; outline: 1px dashed #3a485c; }
.cell.live:active { background: #222d3a; }
.cell.win { background: var(--win); color: #fff; }

/* ── toasts ── */
#toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 10px); z-index: 9500;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #28323f; color: #eef2f7; padding: 10px 16px; border-radius: 999px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); opacity: 1; transition: opacity .3s; max-width: 90vw; }
.toast.out { opacity: 0; }
.toast.error { background: #4a2330; color: #ffc4cd; }
.toast.success { background: #1f4a30; color: #b8f0cc; }

/* ── roombar actions ── */
.roombar-actions { display: flex; gap: 6px; }

/* ── match history (전적) modal — used by public/history.js ── */
.hub-overlay { position: fixed; inset: 0; z-index: 9700; background: rgba(8,12,18,.66);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.hub-modal { width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 12px; }
.hub-modal-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; }
.hub-modal-head strong { font-size: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-tile { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-val { font-size: 20px; font-weight: 800; }
.stat-val.good { color: #5fd38a; } .stat-val.accent { color: var(--x); }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }
.split-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.split-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.split-title { font-size: 13px; font-weight: 700; }
.split-rate { font-size: 22px; font-weight: 800; color: var(--x); }
.hub-filter { display: flex; gap: 6px; }
.hist-list { display: flex; flex-direction: column; gap: 6px; }
.hist-row { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel2); border: 1px solid var(--line); border-left-width: 3px; border-radius: 10px; padding: 8px 10px; }
.hist-row.won { border-left-color: #3ecf6b; } .hist-row.lost { border-left-color: var(--danger); }
.hist-left { display: flex; align-items: center; gap: 8px; }
.hist-badge { font-size: 12px; font-weight: 800; width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.hist-badge.good { background: #1f4a30; color: #b8f0cc; } .hist-badge.bad { background: #4a2330; color: #ffc4cd; }
.tag-ai { background: #3a2e10; color: #ffe39c; } .tag-human { background: #16324a; color: #bfe0ff; }

/* ── reward / session-expired modal (public/reward-modal.js) ── */
.reward-modal { max-width: 360px; align-items: center; text-align: center; gap: 10px; }
.reward-emoji { font-size: 48px; }
.reward-title { font-size: 19px; }
.reward-amount { font-size: 34px; font-weight: 800; color: #ffd86b; }
.reward-cur { font-size: 18px; color: var(--muted); font-weight: 700; }
.reward-modal .btn { width: 100%; }

/* ── version tag ── */
#verTag { position: fixed; right: 8px; bottom: calc(env(safe-area-inset-bottom) + 6px); font-size: 11px; color: #4a5663; }

/* ════════════════════════════════════════════════════════════════════════════
   Chess (체스) — board, pieces, lobby, promotion, move log, rulebook
   ════════════════════════════════════════════════════════════════════════════ */
:root { --sq-light: #f0d9b5; --sq-dark: #769656; --sq-sel: #f6f669; --sq-last: #cdd26a; --sq-check: #e06666; }

/* lobby: mode + level + seats */
.mode-row .btn { margin-top: 0; }
.level-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; flex-wrap: wrap; }
.lvl { border: 1px solid var(--line); background: var(--panel2); color: var(--muted); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; font-weight: 700; cursor: pointer; }
.lvl.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.seat-pc { font-size: 34px; line-height: 1; }
.seat-w .seat-pc { color: #f3f3f3; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.seat-b .seat-pc { color: #1c1c1c; text-shadow: 0 1px 1px rgba(255,255,255,.25); }
.seat.bot { border-style: dashed; }

/* the board */
.chess-card { padding: 14px; }
.chessboard { display: grid; grid-template-columns: repeat(8, 1fr); width: min(94vw, 460px); aspect-ratio: 1;
  margin: 6px auto; border: 3px solid #3c2e1e; border-radius: 6px; overflow: hidden; touch-action: manipulation; }
.sq { position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; cursor: default; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::after { content: ''; position: absolute; inset: 0; background: var(--sq-last); opacity: .55; pointer-events: none; }
.sq.sel::after { content: ''; position: absolute; inset: 0; background: var(--sq-sel); opacity: .6; pointer-events: none; }
.sq.check::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, var(--sq-check) 30%, transparent 72%); opacity: .85; pointer-events: none; }
.sq .pc { position: relative; z-index: 2; font-size: min(9vw, 42px); line-height: 1; user-select: none; }
.sq .pc.w { color: #fbfbfb; text-shadow: 0 1px 0 #555, 0 0 2px #000, 1px 1px 1px rgba(0,0,0,.55); }
.sq .pc.b { color: #1a1a1a; text-shadow: 0 1px 0 #bbb, 0 0 1px #000; }
.sq.move, .sq.capture { cursor: pointer; }
.sq .dot { position: absolute; z-index: 3; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20,30,20,.32); pointer-events: none; }
.sq.capture .dot { width: 86%; height: 86%; background: transparent; border: 5px solid rgba(20,30,20,.34); box-sizing: border-box; }
/* squares that are legal destinations / your own movable pieces feel tappable */
.sq.move, .sq.capture, .sq .pc { -webkit-tap-highlight-color: transparent; }
.co { position: absolute; z-index: 4; font-size: 9px; font-weight: 700; opacity: .65; pointer-events: none; }
.co.rank { top: 1px; left: 2px; }
.co.file { bottom: 0; right: 2px; }
.sq.light .co { color: #8a6d3b; } .sq.dark .co { color: #e8efd6; }

/* seat tags above board */
.seat-tags { display: flex; gap: 8px; justify-content: center; margin: 4px 0 8px; }
.st { font-size: 12.5px; padding: 4px 12px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.st.active { border-color: var(--accent); color: var(--fg); font-weight: 700; }

/* promotion picker */
.promo-overlay { position: fixed; inset: 0; z-index: 9600; background: rgba(8,12,18,.6);
  display: flex; align-items: center; justify-content: center; }
.promo-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: 0 18px 50px rgba(0,0,0,.5); }
.promo-title { text-align: center; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.promo-row { display: flex; gap: 8px; }
.promo-pc { width: 56px; height: 56px; font-size: 36px; line-height: 1; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; }
.promo-pc.w { color: #fbfbfb; text-shadow: 0 1px 0 #555, 0 0 2px #000; }
.promo-pc.b { color: #1a1a1a; text-shadow: 0 1px 0 #bbb; }

/* move log */
.movelog { display: flex; flex-wrap: wrap; gap: 2px 14px; max-height: 88px; overflow-y: auto;
  margin-top: 12px; padding: 8px 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 12.5px; color: var(--muted); }
.movelog .mv { display: inline-flex; gap: 8px; min-width: 120px; }
.movelog .mvn { color: #6b7686; min-width: 22px; text-align: right; }
.movelog .mv span:not(.mvn) { color: var(--fg); min-width: 42px; }

/* rulebook */
.rules { font-size: 13.5px; line-height: 1.6; color: var(--fg); }
.rules h3 { font-size: 15px; margin: 14px 0 4px; color: var(--x); }
.rules ul { margin: 4px 0; padding-left: 18px; } .rules li { margin: 3px 0; }
.rules p { color: var(--muted); margin: 4px 0; }

/* ── Local pass-and-play (full-screen, board-first) ── */
.local-entry { margin-top: 12px; text-decoration: none; }
.local-root { position: fixed; inset: 0; z-index: 9000; background: var(--bg);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.local-bar { flex: none; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px; }
.lb-status { font-size: 15px; font-weight: 800; color: var(--fg); flex: 1; min-width: 0; }
.lb-status.over { color: #ffd86b; }
.lb-actions { display: flex; gap: 6px; flex: none; }
.lb-btn { background: #28323f; color: #dbe3ee; border: 0; border-radius: 9px; padding: 9px 12px;
  font-size: 13px; font-weight: 700; cursor: pointer; }
.lb-btn.exit { background: #3a2330; color: #ffc4cd; }
.local-board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px; }
/* Square board, as large as the smaller of viewport width / remaining height. */
.chessboard.local { width: min(98vw, calc(100dvh - 76px)); height: min(98vw, calc(100dvh - 76px));
  max-width: none; margin: 0; }
.local-root .sq .pc { font-size: min(9.2vw, 9.2dvh); }
.local-root .co { font-size: min(2.4vw, 11px); }

/* ── locked / read-only field (public/locked-field.js) ──
   A value that is FIXED on the client (SSO account name). Reads as "잠김": dashed +
   dimmed box (clearly not editable), persistent lock icon, visible help line + tooltip. */
.lf-wrap { position: relative; }
.in.locked {
  background: #161d27; color: var(--muted);
  border-style: dashed; cursor: not-allowed; padding-right: 40px;
  -webkit-user-select: text; user-select: text;       /* still copyable */
}
.in.locked:focus { outline: none; border-color: var(--muted); }
.lf-lock {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; line-height: 1; opacity: .85; pointer-events: none;
}
.lf-help { display: flex; align-items: flex-start; gap: 5px; margin-top: 6px; }
.lf-help-ic { flex: none; line-height: 1.5; }
