/* 3Dオセロ UI スタイル */
:root {
  --bg: #05070d;
  --panel: rgba(15, 20, 34, 0.82);
  --panel-border: rgba(120, 170, 255, 0.18);
  --text: #e8edf7;
  --text-dim: #9aa8c2;
  --accent: #4da3ff;
  --accent-2: #7c5cff;
  --gold: #ffd166;
  --danger: #ff6b6b;
  --black-stone: #17171d;
  --white-stone: #f2f3f6;
  --radius: 14px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  position: fixed;
  inset: 0;
}

#scene-container {
  position: absolute;
  inset: 0;
}

#scene-container canvas {
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ===== オーバーレイ ===== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 35%, rgba(20, 30, 60, 0.55), rgba(4, 6, 12, 0.92) 75%);
  backdrop-filter: blur(6px);
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.center-panel {
  text-align: center;
  min-width: min(420px, calc(100vw - 32px));
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ===== メニュー ===== */
.menu-box {
  text-align: center;
  max-width: 460px;
  width: 100%;
  animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.title {
  font-size: clamp(38px, 8vw, 58px);
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, #fff 20%, #9cc8ff 55%, #b9a8ff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
}

.title-sub {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.5em;
  margin-top: 6px;
  color: transparent;
}

.subtitle {
  color: var(--text-dim);
  margin: 14px 0 28px;
  font-size: 14px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== ボタン ===== */
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-lg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 22px;
  font-size: 18px;
}

.btn-sub {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  box-shadow: 0 8px 26px rgba(77, 163, 255, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #66b4ff, #8f74ff);
  box-shadow: 0 10px 32px rgba(77, 163, 255, 0.5);
}

.btn-secondary {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.35), rgba(77, 163, 255, 0.28));
  border: 1px solid rgba(150, 170, 255, 0.4);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.55), rgba(77, 163, 255, 0.45));
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 9px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: #8cc4ff;
}

/* ===== オンラインメニュー ===== */
.panel:not(.center-panel):not(.rules-panel) {
  margin-top: 20px;
  padding: 20px;
}

.waiting-hint {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 16px;
}

.form-error {
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
}

.menu-footer {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.update-status {
  font-size: 11px;
  color: var(--text-dim);
  min-height: 14px;
}

.update-status .update-link {
  color: var(--gold);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 11px;
  font-family: inherit;
  text-decoration: underline;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
  pointer-events: none;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-center {
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

#hud .btn {
  pointer-events: auto;
}

.chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}

.score {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 20px;
  backdrop-filter: blur(8px);
}

.score-sep {
  color: var(--text-dim);
}

.stone {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stone-black {
  background: radial-gradient(circle at 32% 30%, #55555f, var(--black-stone) 65%);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.7), 0 1px 3px rgba(0, 0, 0, 0.6);
}

.stone-white {
  background: radial-gradient(circle at 32% 30%, #ffffff, #d9dce4 70%);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.4);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 700;
  backdrop-filter: blur(8px);
}

.turn-indicator .stone {
  width: 14px;
  height: 14px;
}

.turn-indicator.waiting {
  color: var(--gold);
}

/* ===== マッチング待機 ===== */
.waiting-text {
  color: var(--text-dim);
  font-size: 14px;
  margin: 18px 0 6px;
  line-height: 1.7;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 10px auto 20px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== 結果 ===== */
.result-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 34px;
  font-weight: 800;
  margin: 16px 0 6px;
}

.result-score .stone {
  width: 26px;
  height: 26px;
}

.result-message {
  color: var(--text-dim);
  font-size: 15px;
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.rematch-status {
  margin-top: 14px;
  color: var(--gold);
  font-size: 13px;
}

/* ===== ルール ===== */
.rules-panel {
  max-width: min(560px, calc(100vw - 32px));
  max-height: min(80vh, 700px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.rules-body {
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-dim);
  padding-right: 6px;
}

.rules-body h3 {
  color: var(--text);
  font-size: 15px;
  margin: 14px 0 4px;
}

.rules-body ul {
  padding-left: 20px;
}

.rules-body strong {
  color: var(--gold);
  font-weight: 700;
}

.rules-panel .btn {
  align-self: center;
}

/* ===== トースト ===== */
#toasts {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  background: rgba(18, 24, 40, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.25s ease;
  text-align: center;
}

.toast.toast-warn {
  border-color: rgba(255, 210, 102, 0.5);
  color: var(--gold);
}

.toast.toast-error {
  border-color: rgba(255, 107, 107, 0.55);
  color: #ff9b9b;
}

.toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ===== 狭い画面 ===== */
@media (max-width: 640px) {
  #hud {
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .hud-left,
  .hud-right {
    align-self: stretch;
    justify-content: center;
    order: 2;
  }

  .hud-center {
    order: 1;
  }

  .score {
    font-size: 17px;
    padding: 6px 14px;
  }

  .panel {
    padding: 22px 18px;
  }
}
