:root {
  --bg: #1e2a3a;
  --bg2: #16202c;
  --panel: #25344a;
  --panel2: #2d3f59;
  --ink: #eef3f8;
  --muted: #9fb0c4;
  --line: #3a4d68;
  --red: #d2402f;
  --red-d: #9e2a1d;
  --blue: #2f7fd0;
  --blue-d: #1f5896;
  --neutral: #d9c7a3;
  --neutral-d: #b9a47c;
  --assassin: #15171a;
  --parch: #ead9b6;
  --parch-d: #d8c193;
  --gold: #f4c542;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}
#app { max-width: 760px; margin: 0 auto; padding: 12px 12px 64px; }
.loading { text-align: center; padding: 80px 0; color: var(--muted); }

h1, h2, h3 { margin: 0 0 8px; }
button {
  font: inherit; font-weight: 700; border: none; border-radius: 12px;
  padding: 12px 16px; cursor: pointer; color: #fff; background: #3d5170;
  transition: filter .12s ease, transform .05s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #3f8be0, #2f6fc0); }
button.red { background: linear-gradient(180deg, var(--red), var(--red-d)); }
button.blue { background: linear-gradient(180deg, var(--blue), var(--blue-d)); }
button.gold { background: linear-gradient(180deg, #f6d15f, #e0a92a); color: #3a2a00; }
button.ghost { background: #2c3c54; }
button.danger { background: linear-gradient(180deg, #e0573f, #b23a26); }
button:not(:disabled):hover { filter: brightness(1.08); }
input, select {
  font: inherit; background: #1c2736; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
input:focus, select:focus { outline: 2px solid var(--blue); }
label { color: var(--muted); font-size: 13px; }

.card-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #33455f; }
.pill.red { background: var(--red-d); } .pill.blue { background: var(--blue-d); }
.brand { text-align: center; letter-spacing: .04em; }
.brand .ko { font-size: 30px; font-weight: 800; }
.brand .en { color: var(--muted); font-size: 12px; letter-spacing: .35em; text-transform: uppercase; }

/* ── Landing ── */
.landing-actions { gap: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ── Lobby ── */
.code-box { font-size: 30px; font-weight: 800; letter-spacing: .35em; color: var(--gold); text-align: center; padding: 6px 0; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team-col { border-radius: 14px; padding: 10px; border: 1px solid var(--line); }
.team-col.red { background: rgba(210,64,47,.12); border-color: var(--red-d); }
.team-col.blue { background: rgba(47,127,208,.12); border-color: var(--blue-d); }
.team-col h3 { text-align: center; }
.plist { list-style: none; margin: 6px 0; padding: 0; min-height: 24px; }
.plist li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 8px; font-size: 14px; }
.plist li .role { font-size: 11px; color: var(--muted); margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #6c829b; }
.dot.on { background: #57d28a; }
.dot.off { background: #6c829b; opacity: .5; }
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.role-grid button { padding: 10px; font-size: 14px; }
.role-grid button.sel { outline: 3px solid var(--gold); }

/* ── Game header ── */
.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.score { font-size: 30px; font-weight: 800; text-align: center; border-radius: 12px; padding: 4px 0; }
.score.red { color: #ffb3a6; background: rgba(210,64,47,.15); }
.score.blue { color: #a8d0f7; background: rgba(47,127,208,.15); }
.score.turn { outline: 3px solid var(--gold); }
.turninfo { text-align: center; font-size: 13px; }
.turninfo b { font-size: 15px; }

/* ── Board ── */
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 4px 0; }
.card {
  position: relative; aspect-ratio: 1 / 0.66; border-radius: 9px;
  background: linear-gradient(180deg, var(--parch), var(--parch-d));
  color: #2a2118; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 2px; font-weight: 800; user-select: none;
  border: 2px solid #00000022; box-shadow: 0 1px 2px #0006; overflow: hidden;
}
.card .word { font-size: clamp(10px, 3.1vw, 17px); line-height: 1.05; word-break: keep-all; }
.card.selectable { cursor: pointer; }
.card.selectable:hover { filter: brightness(1.04); }
.card.proposed { outline: 4px solid var(--gold); outline-offset: -2px; z-index: 2; }
/* spymaster key tint (not yet revealed) */
.card.keyed.red { background: linear-gradient(180deg, #f0b3a8, #e08a78); border-color: var(--red-d); }
.card.keyed.blue { background: linear-gradient(180deg, #aacbf0, #7ba8e0); border-color: var(--blue-d); }
.card.keyed.neutral { background: linear-gradient(180deg, #e7d8b6, var(--neutral-d)); }
.card.keyed.assassin { background: linear-gradient(180deg, #59606b, #2b2f36); color: #f0f0f0; border-color: #000; }
.card.keyed.assassin .word { color: #fff; }
/* revealed agents */
.card.revealed { color: #fff; box-shadow: inset 0 0 0 100px #0000000d, 0 1px 2px #0006; }
.card.revealed .word { opacity: .96; }
.card.revealed.red { background: linear-gradient(180deg, var(--red), var(--red-d)); }
.card.revealed.blue { background: linear-gradient(180deg, var(--blue), var(--blue-d)); }
.card.revealed.neutral { background: linear-gradient(180deg, var(--neutral), var(--neutral-d)); color: #4a3f28; }
.card.revealed.assassin { background: linear-gradient(180deg, #2b2f36, var(--assassin)); }
.card.revealed::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 35%, #ffffff22, transparent 60%); }
.card .agent-ic { position: absolute; top: 3px; right: 4px; font-size: 12px; opacity: .85; }

/* ── Action area ── */
.clue-now { text-align: center; padding: 8px; border-radius: 12px; background: var(--panel2); }
.clue-now .word { font-size: 26px; font-weight: 800; color: var(--gold); }
.clue-now .n { font-size: 16px; color: var(--ink); }
.guesses { font-size: 13px; color: var(--muted); }
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.full { grid-column: 1 / -1; }
.report-btn { display: flex; align-items: center; justify-content: center; gap: 6px; }
.clue-form { display: grid; grid-template-columns: 1fr 84px; gap: 8px; }
.clue-form .full { grid-column: 1 / -1; }

/* ── Report overlay ── */
.judging { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 10px; background: rgba(244,197,66,.12); border: 1px solid var(--gold); border-radius: 12px; }
.spinner { width: 18px; height: 18px; border: 3px solid #ffffff44; border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Log ── */
.log { max-height: 160px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.log .l { padding: 3px 6px; border-radius: 6px; background: #1d2736; }
.log .l.clue { color: var(--gold); }
.log .l.correct { color: #8fe3ad; }
.log .l.enemy, .log .l.assassin, .log .l.penalty { color: #ff9c87; }
.log .l.bystander { color: var(--neutral); }
.log .l.judge { color: #c9b3ff; background: #241d36; }
.log .l.reward { color: var(--gold); }
.log .l.win { color: var(--gold); font-weight: 800; }

/* ── End banner ── */
.endbanner { text-align: center; padding: 18px; border-radius: 16px; font-size: 22px; font-weight: 800; }
.endbanner.red { background: linear-gradient(180deg, var(--red), var(--red-d)); }
.endbanner.blue { background: linear-gradient(180deg, var(--blue), var(--blue-d)); }

/* ── Toasts ── */
#toasts { position: fixed; top: 8px; left: 0; right: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: #0e1622ee; border: 1px solid var(--line); color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; max-width: 90%; box-shadow: 0 4px 16px #0008; animation: pop .2s ease; }
.toast.success { border-color: #3fae6e; } .toast.warn { border-color: var(--gold); }
.toast.danger { border-color: var(--red); } .toast.info { border-color: var(--blue); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }

@media (min-width: 560px) {
  .card .word { font-size: clamp(13px, 2.2vw, 18px); }
}

/* ── Version tag + rulebook modal ── */
.hidden { display: none !important; }
.fab {
  position: fixed; bottom: 14px; right: 12px; z-index: 40;
  background: #2c3c54; color: var(--ink); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 700;
  box-shadow: 0 2px 8px #0006; cursor: pointer;
}
.fab:active { transform: translateY(1px); }
#verTag { position: fixed; bottom: 8px; left: 10px; z-index: 5; color: #5d6f86; font-size: 11px; letter-spacing: .05em; pointer-events: none; }
.modal-root { position: fixed; inset: 0; z-index: 60; background: #0009; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; max-width: 560px; width: 100%; max-height: 88dvh; display: flex; flex-direction: column; box-shadow: 0 12px 44px #000a; animation: pop .15s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head button { padding: 6px 12px; }
.modal-body { padding: 12px 16px 18px; overflow-y: auto; }
.modal-body h3 { margin: 14px 0 6px; font-size: 15px; color: var(--gold); }
.modal-body h3:first-child { margin-top: 0; }
.modal-body p { font-size: 14px; line-height: 1.5; margin: 4px 0; }
.modal-body ul, .modal-body ol { margin: 6px 0; padding-left: 20px; }
.modal-body li { margin: 5px 0; font-size: 14px; line-height: 1.45; }
.ex.ok li { color: #b7e6c8; }
.ex.bad li { color: #f3b0a2; }
.pack-sel { background: #1c2736; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 13px; max-width: 65%; }
.board.picture .card { aspect-ratio: 1 / 0.82; }
.board.picture .card .word.pics { display: flex; gap: 3px; align-items: center; justify-content: center; flex-wrap: wrap; }
.omji { width: clamp(24px, 10.5vw, 50px); height: auto; }
.timer { display: inline-block; margin-top: 4px; font-size: 18px; font-weight: 800; color: var(--gold); }
.timer.low { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
