:root {
  --bg: #0f1320;
  --panel: #1a2030;
  --panel-2: #222a3d;
  --line: #313b53;
  --text: #e7ecf6;
  --muted: #9aa6c0;
  --accent: #5b8cff;
  --ok: #2ca24c;
  --danger: #e23b3b;
  --gold: #ffd479;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 800px at 70% -10%, #1b2740, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

.app { max-width: 1100px; margin: 0 auto; padding: 18px 16px 48px; }

h1, h2, h3 { margin: 0 0 8px; }
h1 { font-size: 24px; letter-spacing: 0.04em; }
a { color: var(--accent); }

.title-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.title-row .sub { color: var(--muted); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  font-size: 15px;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; }

input[type="text"] {
  background-color: #0d1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 16px;
  width: 100%;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

select {
  background-color: #0d1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 15px;
}
select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
select:disabled { opacity: 0.45; cursor: not-allowed; }
.dbg-sel { padding: 8px 10px; }

.settings { display: flex; flex-direction: column; gap: 12px; }
.set-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.set-row .set-label { min-width: 150px; font-weight: 600; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 160px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.spacer { flex: 1; }

.lobby-actions { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .lobby-actions { grid-template-columns: 1fr; } }

.code-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: #0d1220; border: 1px dashed var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 20px; letter-spacing: 0.18em; font-weight: 700;
}

.players { display: flex; flex-direction: column; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid transparent;
}
.swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.6); flex: none; }
.player .name { font-weight: 600; }
.player .meta { color: var(--muted); font-size: 12px; margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.player .meta b { color: var(--text); font-size: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); }
.dot.off { background: #57607a; }
.done-chk { color: var(--ok); font-weight: 800; }
.win-mark { color: var(--gold); font-weight: 900; font-size: 16px; }

/* ===== Game layout ===== */
.game-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .game-grid { grid-template-columns: 1fr; } }
.side { display: flex; flex-direction: column; gap: 14px; }

/* ===== Phase banners ===== */
.phase-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 10px; margin-bottom: 14px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 15px;
}
.phase-banner.input { border-color: var(--accent); }
.phase-banner.reveal { background: #2a2440; border-color: #6a5acd; }
.phase-banner.winner { background: #163a22; border-color: var(--ok); }
.phase-banner strong { font-size: 17px; }
.round-timer {
  margin-left: auto; font-weight: 900; font-variant-numeric: tabular-nums;
  font-size: 22px; background: #0d1220; border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 12px;
}
.round-timer.danger { color: #ff8a8a; border-color: var(--danger); }

/* ===== Board (3x7 katakana tiles) ===== */
.board {
  display: grid; gap: 7px; width: 100%; max-width: 760px;
  margin: 0 auto 14px;
}
.tile {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1c2740, #0d1220);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(20px, 5vw, 40px);
  font-weight: 800;
  user-select: none;
  box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

/* ===== Input area ===== */
.input-area .seat-input { margin-bottom: 12px; }
.input-area .seat-input .row { margin-top: 8px; }
.seat-label { margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.seat-done {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; border-radius: 8px; background: var(--panel-2); margin-bottom: 8px;
}

/* ===== Reveal list ===== */
.reveal-list { display: flex; flex-direction: column; gap: 8px; }
.reveal-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; background: var(--panel-2);
  transition: background 0.2s, transform 0.2s;
}
.reveal-row .rv-mark { width: 22px; font-size: 20px; font-weight: 900; color: var(--gold); text-align: center; }
.reveal-row .rv-name { width: 92px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reveal-row .rv-word { font-weight: 800; font-size: 17px; }
.reveal-row .rv-reading { margin-left: 4px; }
.reveal-row .rv-len { margin-left: auto; font-size: 14px; }
.reveal-row .rv-len b { font-size: 18px; color: var(--accent); }
.reveal-row .rv-plus { color: var(--gold); font-weight: 900; font-size: 16px; }
.reveal-row.winner {
  background: #163a22; border: 1px solid var(--ok);
  transform: scale(1.02);
  box-shadow: 0 0 18px rgba(44,162,76,0.35);
}
.reveal-row.none { opacity: 0.6; }

.feed { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.log-line { font-size: 12px; color: var(--muted); padding: 3px 0; border-bottom: 1px solid #232b3e; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.warn { background: #4a3a12; color: #ffd479; }
.badge.ok { background: #163a22; color: #7fe0a0; }

/* ===== Winner ===== */
.winner-banner {
  text-align: center; padding: 22px; border-radius: var(--radius);
  background: linear-gradient(180deg, #213256, #161d2e); border: 1px solid var(--accent);
}
.winner-banner .crown { font-size: 38px; }
.scores { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.score-row { display: flex; align-items: center; gap: 10px; }
.score-row .bar { height: 14px; border-radius: 7px; flex: 1; background: #0d1220; overflow: hidden; }
.score-row .bar > i { display: block; height: 100%; }

/* ===== Rules slides ===== */
.overlay { position: fixed; inset: 0; z-index: 60; padding: 20px; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; }
.rules-modal { max-width: 640px; width: 100%; max-height: 88vh; display: flex; flex-direction: column; }
.rules-viewport { overflow: hidden; }
.rules-track { display: flex; transition: transform 0.28s ease; }
.rules-slide { min-width: 100%; box-sizing: border-box; padding: 2px; }
.rules-slide h3 { font-size: 18px; margin-bottom: 10px; color: var(--accent); }
.rules-slide-body { font-size: 14px; line-height: 1.7; max-height: 56vh; overflow-y: auto; }
.rules-slide-body p { margin: 8px 0; }
.rules-slide-body b { color: #fff; }
.rule-steps { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.rule-steps > div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; }
.rule-steps strong { display: block; margin-bottom: 2px; }
.rule-steps span { color: var(--muted); font-size: 13px; }
.rule-list { margin: 8px 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.rule-ex { background: #0d1220; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.rule-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.rules-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.rules-dots { display: flex; gap: 6px; }
.rules-dot { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; font-size: 12px; font-weight: 700; }
.rules-dot.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #2a1620; color: #ffd9d9; border: 1px solid var(--danger);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90vw;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
