:root {
  --bg: #0f1320;
  --panel: #1a2030;
  --panel-2: #222a3d;
  --line: #313b53;
  --text: #e7ecf6;
  --muted: #9aa6c0;
  --accent: #5b8cff;
  --ok: #2ca24c;
  --danger: #e23b3b;
  --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; }

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); }

.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 ===== */
.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;
}
.player.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.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; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); }
.dot.off { background: #57607a; }

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

.turn-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.turn-banner.mine { background: #163a22; border-color: var(--ok); }
.turn-banner strong { font-size: 16px; }

/* ===== Board ===== */
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  width: 100%;
  max-width: 820px;
}
.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1220;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, 2.6vw, 26px);
  font-weight: 700;
  user-select: none;
}
.cell.empty { background: transparent; border: 1px dashed #2a3147; opacity: 0.35; }
.cell.secured { border-width: 2px; box-shadow: 0 0 10px rgba(0,0,0,0.35) inset; }
.cell .lock {
  position: absolute; top: 3px; right: 4px;
  font-size: 10px; font-weight: 800; line-height: 1;
  padding: 1px 3px; border-radius: 4px;
  background: rgba(0,0,0,0.45); color: #fff;
}
.pips {
  position: absolute; bottom: 3px; left: 0; right: 0;
  display: flex; gap: 3px; justify-content: center; flex-wrap: wrap;
}
.pip {
  min-width: 13px; height: 13px; padding: 0 2px;
  border-radius: 7px;
  font-size: 9px; font-weight: 800; line-height: 13px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.55);
  color: #fff;
}
/* 「ん」は board と同じグリッドで描画するため専用幅は持たせない */

.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .box { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); }

/* ===== Side panel ===== */
.side { display: flex; flex-direction: column; gap: 14px; }
.input-area .row { margin-top: 8px; }
.feed { max-height: 230px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.feed .item { font-size: 13px; padding: 6px 8px; border-radius: 8px; background: var(--panel-2); }
.feed .item .w { font-weight: 700; }
.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);
}
