:root {
  --bg: #171210;
  --panel: #2a2119;
  --ink: #f6ecdc;
  --ink-dim: #c4b4a0;
  --muted: #8d7d6b;
  --wood: #d8a869;
  --red: #c4442f;
  --line: rgba(255, 235, 205, 0.12);
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, #3a2a1d 0%, #1b1512 45%, #100d0b 100%);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) clamp(10px, 2.4vw, 28px) max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 2px;
  text-align: left;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6d6154 0%, #2a2621 45%, #0e0c0a 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08), 0 2px 6px rgba(0, 0, 0, 0.6);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.brand-text {
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 15px;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
}

.brand-text small {
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--muted);
  font-weight: 600;
  margin-top: 3px;
}

.top-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn, .text-btn {
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn { width: 34px; font-weight: 700; }
.text-btn { padding: 0 12px; font-size: 12px; letter-spacing: 0.04em; }
.icon-btn:hover, .text-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.icon-btn.off { opacity: 0.4; text-decoration: line-through; }

#main { flex: 1; min-height: 0; display: flex; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

#screen-menu { overflow-y: auto; align-items: center; }

.menu-inner {
  width: min(680px, 100%);
  margin: auto;
  padding: clamp(6px, 2vh, 24px) 2px 18px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--wood);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 54px);
  letter-spacing: 0.04em;
  line-height: 1.05;
  font-weight: 800;
  background: linear-gradient(180deg, #fff2dc 0%, #e0b57a 70%, #b9834d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
}

.tagline {
  margin: 10px auto 20px;
  max-width: 30em;
  color: var(--ink-dim);
  font-size: 13px;
  line-height: 1.75;
}

.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.mode {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px;
  background: linear-gradient(160deg, rgba(255, 235, 205, 0.07), rgba(255, 235, 205, 0.02));
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.mode:hover { transform: translateY(-2px); border-color: rgba(216, 168, 105, 0.5); background: rgba(255, 235, 205, 0.08); }
.mode:active { transform: translateY(0); }
.mode-primary { border-color: rgba(216, 168, 105, 0.42); }

.mode-icon {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(216, 168, 105, 0.12);
  font-size: 19px;
}

.mode-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mode-body b { font-size: 14px; font-weight: 700; }
.mode-body small { font-size: 11px; color: var(--muted); }

.rules-cta {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid rgba(216, 168, 105, 0.28);
  background: linear-gradient(120deg, rgba(216, 168, 105, 0.13), rgba(216, 168, 105, 0.03));
  text-align: left;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.rules-cta:hover { transform: translateY(-1px); border-color: rgba(216, 168, 105, 0.55); background: rgba(216, 168, 105, 0.15); }
.rules-cta:active { transform: translateY(0); }

.rules-cta-icon {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(216, 168, 105, 0.14);
  font-size: 17px;
}

.rules-cta-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rules-cta-text b { font-size: 13px; font-weight: 700; }
.rules-cta-text small { font-size: 10.5px; color: var(--muted); }
.rules-cta-arrow { margin-left: auto; color: var(--wood); font-size: 21px; line-height: 1; }

.options-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 18px 0 4px;
  flex-wrap: wrap;
}

.options-label { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
}

.segmented button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented button.active { background: var(--wood); color: #241a10; font-weight: 700; }

.spec-line { margin: 18px 0 6px; font-size: 10.5px; color: var(--muted); letter-spacing: 0.04em; }

.lan-access {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10.5px;
}

.lan-access code {
  color: var(--wood);
  background: rgba(216, 168, 105, 0.09);
  border: 1px solid rgba(216, 168, 105, 0.18);
  border-radius: 7px;
  padding: 3px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

.lan-access .link-btn { font-size: 10.5px; }

.link-btn {
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(216, 168, 105, 0.4);
  color: var(--wood);
  font-size: 11.5px;
  padding: 2px 0;
}
.link-btn.muted { color: var(--muted); border-color: transparent; }

#screen-game { gap: 8px; }

#hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  flex: none;
}

.player {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.035);
  transition: border-color 0.2s ease, background 0.2s ease;
  min-width: 0;
}

.player.active { border-color: rgba(216, 168, 105, 0.6); background: rgba(216, 168, 105, 0.1); }
.player-b { justify-content: flex-end; text-align: right; }

.player-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.player-meta b { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-meta small { font-size: 10.5px; color: var(--muted); }

.puck-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.puck-dot.dark { background: radial-gradient(circle at 35% 30%, #565049, #17140f 70%); }
.puck-dot.light { background: radial-gradient(circle at 35% 30%, #fffdf6, #cfc3ab 75%); }

.turn-box { display: flex; align-items: center; gap: 6px; justify-content: center; min-width: 0; }

#turn-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(216, 168, 105, 0.16);
  border: 1px solid rgba(216, 168, 105, 0.32);
  color: #f0d5ac;
  white-space: nowrap;
}

#turn-label.thinking { background: rgba(126, 168, 107, 0.16); border-color: rgba(126, 168, 107, 0.4); color: #cfe4bd; }

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--ink-dim);
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}
.timer.warn { color: #ffb19c; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, rgba(120, 88, 58, 0.25), transparent 60%), #100d0b;
  border: 1px solid rgba(255, 235, 205, 0.07);
  box-shadow: var(--shadow);
  touch-action: none;
}

#board { width: 100%; height: 100%; display: block; touch-action: none; }

.stage-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: 0.18em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(12, 9, 7, 0.6);
  border: 1px solid rgba(255, 235, 205, 0.12);
  color: var(--ink-dim);
  pointer-events: none;
  white-space: nowrap;
}

.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 8, 6, 0.62);
  backdrop-filter: blur(3px);
  z-index: 5;
  padding: 16px;
}

.result-card {
  width: min(340px, 100%);
  padding: 24px 22px 20px;
  border-radius: 20px;
  background: linear-gradient(170deg, #33271d, #241b14);
  border: 1px solid rgba(216, 168, 105, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.result-kicker { margin: 0 0 6px; font-size: 9.5px; letter-spacing: 0.3em; color: var(--wood); }
.result-card h2 { margin: 0 0 8px; font-size: 26px; letter-spacing: 0.02em; }
.result-detail { margin: 0 0 18px; font-size: 12px; color: var(--ink-dim); line-height: 1.7; }
.result-buttons { display: flex; gap: 8px; justify-content: center; }

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 11px;
  padding: 10px 18px;
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.11); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: linear-gradient(180deg, #e0b073, #c48f52); color: #241a10; border-color: transparent; }
.btn-primary:hover { background: linear-gradient(180deg, #ecc084, #cf9a5b); }

.hint-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  min-height: 30px;
  padding: 0 2px;
}

#hint-text { flex: 1; line-height: 1.45; }

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 10.5px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.chip-danger { color: #e79a87; border-color: rgba(196, 68, 47, 0.3); }

#screen-online { overflow-y: auto; align-items: center; }

.online-inner { width: min(480px, 100%); margin: auto; padding: 12px 2px 24px; text-align: center; }
.online-inner h2 { margin: 0 0 6px; font-size: 28px; }

.net-status {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  display: inline-block;
  margin: 6px 0 16px;
}
.net-status.ok { color: #b9d9a8; }
.net-status.err { color: #f0a390; }

.name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

.name-input {
  width: 160px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  font-size: 12px;
}

.name-input:focus { outline: 1px solid var(--wood); }

.online-actions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.join-row { display: flex; gap: 8px; }

.code-input {
  width: 120px;
  text-align: center;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 8px;
}
.code-input:focus { outline: 1px solid var(--wood); }

.room-panel {
  margin-top: 8px;
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.room-code-label { margin: 0; font-size: 10px; letter-spacing: 0.24em; color: var(--muted); }
.room-code { margin: 6px 0 2px; font-size: 40px; letter-spacing: 0.28em; font-weight: 800; color: var(--wood); }

.room-slots { display: flex; flex-direction: column; gap: 6px; margin: 16px 0 10px; }
.slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 12px;
  text-align: left;
}
.slot .dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.slot.filled .dot { background: var(--wood); }
.slot .tag { margin-left: auto; font-size: 9.5px; color: var(--muted); }

.room-note { font-size: 11px; color: var(--muted); margin: 8px 0 12px; }
.net-help { font-size: 10.5px; color: var(--muted); line-height: 1.8; margin-top: 18px; white-space: pre-line; }

#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 6, 5, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: min(84dvh, 760px);
  overflow-y: auto;
  background: linear-gradient(170deg, #30251b, #201811);
  border: 1px solid rgba(216, 168, 105, 0.24);
  border-radius: 18px;
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 4px; font-size: 21px; padding-right: 28px; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.24);
  color: var(--ink-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.modal-close:hover { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.modal h3 { margin: 18px 0 6px; font-size: 12.5px; color: var(--wood); letter-spacing: 0.04em; }
.modal p, .modal li { font-size: 12px; line-height: 1.85; color: var(--ink-dim); }
.modal ol, .modal ul { margin: 6px 0; padding-left: 18px; }
.modal table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 11.5px; }
.modal th, .modal td { text-align: left; padding: 6px 4px; border-bottom: 1px solid rgba(255, 235, 205, 0.08); }
.modal th { color: var(--muted); font-weight: 600; }
.modal .close-row { display: flex; justify-content: flex-end; margin-top: 14px; }
.modal .note { font-size: 10.5px; color: var(--muted); }

#footer {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: rgba(196, 180, 160, 0.45);
  padding: 0 2px;
}

#footer #conn-label { color: rgba(216, 168, 105, 0.6); }

.gap-debug {
  position: fixed;
  right: 14px;
  bottom: 44px;
  z-index: 15;
  width: 236px;
  padding: 10px 11px;
  border-radius: 12px;
  background: rgba(22, 16, 12, 0.94);
  border: 1px solid rgba(216, 168, 105, 0.4);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 10px;
  backdrop-filter: blur(4px);
}

.gap-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--wood);
  letter-spacing: 0.06em;
}

.gap-debug-head b { color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }

.gap-debug-head button {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-dim);
  width: 18px;
  height: 18px;
  border-radius: 5px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  margin-left: 6px;
}

.gap-debug.collapsed .gap-presets,
.gap-debug.collapsed input[type="range"],
.gap-debug.collapsed .gap-note {
  display: none;
}

.gap-presets { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 6px; }

.gap-presets button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-dim);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 9.5px;
}

.gap-presets button.active {
  background: var(--wood);
  border-color: transparent;
  color: #241a10;
  font-weight: 700;
}

.gap-debug input[type="range"] {
  width: 100%;
  accent-color: var(--wood);
  margin: 2px 0 0;
}

.gap-debug input[type="range"]:disabled { opacity: 0.35; }

.gap-note { margin: 6px 0 0; color: var(--muted); font-size: 9.5px; line-height: 1.5; }

@media (max-width: 620px) {
  .gap-debug { left: 8px; right: 8px; bottom: 38px; width: auto; }
}

html[data-device="mobile"] #app {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

html[data-device="mobile"] .menu-inner { width: 100%; }
html[data-device="mobile"] .modes { grid-template-columns: 1fr; gap: 8px; }
html[data-device="mobile"] .mode { padding: 12px; }
html[data-device="mobile"] .tagline { font-size: 12px; margin-bottom: 16px; }
html[data-device="mobile"] h1 { font-size: clamp(34px, 10vw, 46px); }
html[data-device="mobile"] .spec-line { margin-top: 12px; }
html[data-device="mobile"] .lan-access { margin-top: 10px; }
html[data-device="mobile"] #hud { gap: 4px; }
html[data-device="mobile"] .player { padding: 6px 8px; gap: 6px; }
html[data-device="mobile"] .player-meta b { font-size: 11.5px; }
html[data-device="mobile"] .puck-dot { width: 20px; height: 20px; }
html[data-device="mobile"] #turn-label { font-size: 10px; padding: 6px 9px; }
html[data-device="mobile"] .hint-bar { font-size: 10px; }
html[data-device="mobile"] #footer span:first-child { display: none; }
html[data-device="mobile"] #footer { justify-content: flex-end; }

html[data-layout="mobile-landscape"] .menu-inner { padding-top: 2px; }
html[data-layout="mobile-landscape"] .tagline { margin-bottom: 10px; }
html[data-layout="mobile-landscape"] .options-row { margin-top: 8px; }

@media (max-width: 620px) {
  .modes { grid-template-columns: 1fr; gap: 8px; }
  .mode { padding: 11px 12px; }
  .mode-icon { width: 34px; height: 34px; font-size: 17px; }
  .tagline { font-size: 12px; margin-bottom: 14px; }
  h1 { font-size: 38px; }
  #hud { gap: 4px; }
  .player { padding: 6px 8px; gap: 6px; }
  .player-meta b { font-size: 11.5px; }
  .puck-dot { width: 20px; height: 20px; }
  #turn-label { font-size: 10px; padding: 6px 9px; }
  .hint-bar { font-size: 10px; }
  #footer span:first-child { display: none; }
  #footer { justify-content: flex-end; }
}

@media (max-height: 560px) {
  .tagline, .spec-line, .options-row { margin-top: 8px; margin-bottom: 4px; }
  .menu-inner { padding-top: 0; }
  h1 { font-size: 30px; }
}
