/* 囲碁スタジオ - メインスタイル */

:root {
  --primary: #2D5016;
  --primary-light: #4A7C2D;
  --primary-dark: #1A3009;
  --accent: #C8A84B;
  --accent-light: #E8C86A;
  --bg: #1A1A1A;
  --bg-card: #252525;
  --bg-panel: #2E2E2E;
  --text: #E8E8E8;
  --text-muted: #999;
  --border: #404040;
  --black-stone: #1A1A1A;
  --white-stone: #F5F5F5;
  --danger: #E53E3E;
  --success: #38A169;
  --info: #3182CE;
  --warning: #D69E2E;

  /* ナビ高さ（スマホ用） */
  --bottom-nav-h: 56px;
  --topbar-h: 44px;
}

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

html {
  height: 100%;
  /* スマホでのバウンス無効化 */
  -webkit-overflow-scrolling: touch;
}

body {
  height: 100%;
  font-family: 'Hiragino Kaku Gothic Pro', 'Meiryo', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  /* PCではbodyのスクロール禁止、スマホは後述のメディアクエリで上書き */
  overflow: hidden;
}

/* =====================================================
   デスクトップ レイアウト（769px以上）
   ===================================================== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== サイドバー（デスクトップ左） ===== */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 14px 14px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-logo { font-size: 20px; flex-shrink: 0; }

.sidebar-title {
  font-size: 15px;
  font-weight: bold;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover  { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active {
  background: rgba(74,124,45,0.2);
  border-left-color: var(--primary-light);
  color: var(--accent-light);
}

.nav-icon  { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }
.nav-label { font-size: 13px; font-weight: 500; }

/* ===== メインコンテンツ（デスクトップ） ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ===== トップバー ===== */
.topbar {
  height: 48px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: bold;
  color: var(--accent);
  flex: 1;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ===== ページ（デスクトップ） ===== */
.page {
  flex: 1;
  display: none;
  overflow: hidden;
  min-height: 0;
}

.page.active { display: flex; }

/* 学習・設定・棋譜ページはスクロール可能 */
#page-learn.active,
#page-settings.active,
#page-kifu.active {
  overflow-y: auto;
  flex-direction: column;
}

/* ===== 対局レイアウト ===== */
.game-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-width: 0;
  overflow: hidden;
}

.board-container {
  position: relative;
  width: min(calc(100vh - 100px), calc(100% - 10px), 600px);
  max-width: 600px;
  aspect-ratio: 1;
}

.board-container canvas {
  width: 100% !important;
  height: 100% !important;
  cursor: crosshair;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  touch-action: none; /* タッチ誤動作防止 */
}

/* ===== 右パネル（デスクトップ） ===== */
.right-panel {
  width: 290px;
  min-width: 270px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}

.panel-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 20px;
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

/* =====================================================
   共通コンポーネント
   ===================================================== */

/* ===== プレイヤー情報 ===== */
.player-info { display: flex; justify-content: space-between; gap: 10px; }

.player-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.player-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.stone-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  margin: 0 auto 6px;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}

.stone-icon.black { background: radial-gradient(circle at 35% 35%, #555, #111); }
.stone-icon.white { background: radial-gradient(circle at 35% 35%, #fff, #ccc); border: 1px solid #aaa; }

.player-name  { font-size: 12px; font-weight: bold; margin-bottom: 4px; color: var(--text); }
.captured-count { font-size: 11px; color: var(--text-muted); }
.captured-num { font-size: 16px; font-weight: bold; color: var(--accent); }

/* ===== 棋譜リスト ===== */
.kifu-scroll {
  overflow-y: auto;
  min-height: 60px;
  max-height: 180px;
}

.kifu-list { list-style: none; padding: 0; }

.kifu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.kifu-item:hover    { background: rgba(255,255,255,0.05); }
.kifu-item.current  { background: rgba(74,124,45,0.3); color: var(--accent-light); }

.kifu-num    { color: var(--text-muted); width: 28px; text-align: right; flex-shrink: 0; }
.kifu-stone  { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.kifu-stone.black { background: radial-gradient(circle at 35% 35%, #555, #111); }
.kifu-stone.white { background: radial-gradient(circle at 35% 35%, #fff, #ccc); border: 1px solid #888; }
.kifu-coord  { flex: 1; font-family: monospace; }
.kifu-capture { font-size: 10px; color: var(--danger); }

/* ===== ボタン ===== */
.controls { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* スマホでタップしやすい最小サイズ */
  min-height: 40px;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary  { background: var(--primary-light); color: white; }
.btn-primary:hover:not(:disabled)  { background: var(--primary); }
.btn-accent   { background: var(--accent); color: #1A1A1A; }
.btn-accent:hover:not(:disabled)   { background: var(--accent-light); }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.08); }
.btn-danger   { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled)   { background: #C53030; }

.btn-icon { padding: 8px 10px; font-size: 16px; line-height: 1; }
.btn-sm   { padding: 6px 10px; font-size: 12px; min-height: 36px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== 再生コントロール ===== */
.playback-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.playback-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.playback-btn:hover:not(:disabled) { background: var(--primary-light); color: white; }
.playback-btn.playing { background: var(--accent); color: #1A1A1A; }
.playback-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== スライダー ===== */
.move-slider { width: 100%; margin: 8px 0; accent-color: var(--primary-light); }

.move-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== スコア表示 ===== */
.score-display {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  text-align: center;
}

.score-num   { font-size: 28px; font-weight: bold; color: var(--accent); }
.score-label { font-size: 11px; color: var(--text-muted); }
.score-vs    { font-size: 12px; color: var(--text-muted); }

/* ===== タブ ===== */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.tab:hover  { color: var(--text); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

/* ===== フォーム ===== */
.form-group { margin-bottom: 12px; }

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 6px;
  font-size: 14px; /* スマホで16px未満だとiOSがズームする */
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-light);
}

.form-select option { background: var(--bg-card); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
  font-family: monospace;
  font-size: 12px;
}

/* ===== ステータスバー ===== */
.status-bar {
  height: 30px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 8px;
  flex-shrink: 0;
}

.status-indicator.warning { background: var(--warning); }
.status-indicator.error   { background: var(--danger); }
.status-indicator.info    { background: var(--info); }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 16px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title { font-size: 17px; font-weight: bold; color: var(--accent); }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover { color: var(--text); }

/* ===== トースト通知 ===== */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  max-width: 300px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ===== バッジ ===== */
.info-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.info-badge.turn-black { background: #111; color: #ddd; border: 1px solid #555; }
.info-badge.turn-white { background: #eee; color: #333; border: 1px solid #aaa; }

/* ===== SGF textarea ===== */
.sgf-area {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  background: #111;
  color: #7EC8E3;
  border-color: #333;
}

/* ===== シチョウ固有 ===== */
.ladder-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-selector { display: flex; gap: 8px; margin-bottom: 10px; }

.color-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 42px;
}

.color-btn.black-btn { background: #2A2A2A; color: #ccc; }
.color-btn.white-btn { background: #E8E8E8; color: #333; }
.color-btn.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ===== 棋譜一覧ページ ===== */
.kifu-full-list { flex: 1; overflow-y: auto; }

.kifu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px;
}

.kifu-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.kifu-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.kifu-card-title { font-size: 14px; font-weight: bold; margin-bottom: 6px; color: var(--text); }
.kifu-card-meta  { font-size: 11px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== 問題カード ===== */
.puzzle-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.puzzle-card:hover { border-color: var(--accent); }
.puzzle-card-info  { flex: 1; }
.puzzle-card-name  { font-size: 13px; font-weight: bold; margin-bottom: 3px; }
.puzzle-card-meta  { font-size: 11px; color: var(--text-muted); }
.puzzle-card-actions { display: flex; gap: 4px; }

/* ===== 設定ページ ===== */
.settings-content {
  padding: 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ===== サイドバーフッター ===== */
.sidebar-footer {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer-brand {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-links {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

.sidebar-footer-links span {
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-footer-links span:not(.sidebar-footer-sep):hover {
  color: var(--accent);
  text-decoration: underline;
}

.sidebar-footer-sep {
  color: var(--border);
  cursor: default !important;
}

/* ===== ステータスバー右寄せ ===== */
.status-bar-right {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.status-bar-right span[onclick]:hover {
  color: var(--accent);
}

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ===== プリセット ===== */
.preset-list { display: grid; gap: 6px; }

.preset-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.preset-item:hover { border-color: var(--accent); background: rgba(200,168,75,0.05); }
.preset-name { font-size: 13px; font-weight: bold; margin-bottom: 2px; }
.preset-desc { font-size: 11px; color: var(--text-muted); }

/* ===== 速度スライダー ===== */
.speed-control { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.speed-control input[type="range"] { flex: 1; accent-color: var(--accent); }

/* ===== アニメーション ===== */
.fade-in { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pulse { animation: pulse 1s ease infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== ツールチップ ===== */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 9999;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ===== スプリッター ===== */
.panel-resizer {
  width: 4px;
  background: var(--border);
  cursor: col-resize;
  transition: background 0.2s;
  flex-shrink: 0;
}
.panel-resizer:hover { background: var(--primary-light); }

/* =====================================================
   スマホ・タブレット レイアウト（768px以下）
   ===================================================== */
@media (max-width: 768px) {

  /* html/bodyのoverflowを解放してページ全体がスクロールできるように */
  html, body {
    overflow: auto;
    height: auto;
    min-height: 100%;
    /* iOS Safariのアドレスバー考慮 */
    min-height: -webkit-fill-available;
  }

  /* アプリコンテナ：縦積み＋スクロール */
  .app-container {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: visible;
  }

  /* メインコンテンツ：高さ固定しない */
  .main-content {
    flex: none;
    order: 1;
    overflow: visible;
    min-height: 0;
  }

  /* トップバー */
  .topbar {
    height: 44px;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 200;
  }

  .topbar-title { font-size: 14px; }

  /* ===== ボトムナビ ===== */
  .sidebar {
    order: 2;
    width: 100% !important;
    min-width: unset !important;
    height: var(--bottom-nav-h);
    min-height: var(--bottom-nav-h);
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 200;
  }

  .sidebar-header { display: none; }
  .sidebar-footer  { display: none; }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
    width: 100%;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }

  .nav-item {
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    border-left: none !important;
    border-top: 3px solid transparent;
    flex: 1;
    min-width: 56px;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
  }

  .nav-item.active {
    border-top-color: var(--primary-light);
    border-left-color: transparent !important;
    background: rgba(74,124,45,0.15);
  }

  .nav-label { display: block !important; font-size: 10px; }
  .nav-icon  { font-size: 16px; width: auto; margin: 0 auto; }

  /* ===== ページ：スクロール可能に ===== */
  .page {
    display: none;
    overflow: visible;
    min-height: 0;
    height: auto;
  }

  .page.active {
    display: block;
    overflow: visible;
  }

  /* 学習・設定・棋譜ページ */
  #page-learn.active,
  #page-settings.active,
  #page-kifu.active {
    overflow: visible;
    flex-direction: unset;
  }

  /* ===== ゲームレイアウト：縦積み ===== */
  .game-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* ===== 盤面エリア ===== */
  .board-area {
    padding: 8px;
    min-height: 0;
    overflow: visible;
  }

  /* 盤面サイズ：画面幅に合わせる */
  .board-container {
    width: calc(100vw - 16px);
    max-width: 480px;
    margin: 0 auto;
  }

  /* ===== 右パネル：全幅で下に並ぶ ===== */
  .right-panel {
    width: 100% !important;
    min-width: unset !important;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow: visible;    /* スクロールはページ全体で担う */
    flex-shrink: 0;
    /* 高さ固定しない */
    height: auto;
  }

  /* 棋譜スクロールエリア（タブ内）：高さ上限 */
  .kifu-scroll {
    max-height: 200px;
  }

  /* タブコンテンツ内部もoverflow visible */
  #kifu-tab,
  #action-tab,
  #sgf-tab,
  #score-tab {
    overflow: visible !important;
    height: auto !important;
  }

  /* モーダル */
  .modal {
    padding: 16px;
    max-height: 85dvh;
  }

  /* ステータスバー */
  .status-bar {
    height: 28px;
    font-size: 11px;
    padding: 0 12px;
  }

  /* スマホでは右寄せの開発元・リンクを折り返さず短縮 */
  .status-bar-right {
    font-size: 9px;
    gap: 1px;
  }

  /* トースト位置：画面幅に合わせる */
  .toast-container {
    top: 50px;
    right: 8px;
    left: 8px;
    align-items: flex-end;
  }

  .toast {
    max-width: 100%;
  }

  /* スコア表示 */
  .score-num { font-size: 24px; }

  /* 棋譜グリッド：1列 */
  .kifu-grid {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 10px;
  }

  .kifu-full-list {
    overflow: visible;
    height: auto;
  }
}

/* =====================================================
   小画面スマホ（480px以下）
   ===================================================== */
@media (max-width: 480px) {
  .sidebar {
    height: 52px;
    min-height: 52px;
  }

  .nav-item {
    padding: 4px 2px;
    min-width: 48px;
  }

  .nav-label { font-size: 9px; }
  .nav-icon  { font-size: 15px; }

  .topbar {
    height: 40px;
    padding: 0 10px;
  }

  .topbar-title { font-size: 13px; }

  .board-container {
    width: calc(100vw - 12px);
    max-width: 100%;
  }

  .board-area { padding: 6px; }

  .panel-section { padding: 10px 12px; }

  .btn {
    font-size: 12px;
    padding: 8px 10px;
    min-height: 40px;
  }

  .playback-btn {
    width: 38px;
    height: 38px;
    font-size: 13px;
  }

  .ladder-controls {
    grid-template-columns: 1fr; /* スマホではシチョウボタンを縦並びに */
    gap: 6px;
  }
}

/* =====================================================
   極小画面（360px以下）
   ===================================================== */
@media (max-width: 360px) {
  .nav-label {
    display: none !important;
  }

  .nav-item {
    padding: 8px 4px;
    min-width: 44px;
  }

  .nav-icon { font-size: 18px; }
}

/* =====================================================
   認証UI・アカウントページ
   ===================================================== */

/* サイドバーのアカウントエリア */
.sidebar-account {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.sidebar-account-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-account-info:hover { background: var(--bg-card); }

.sidebar-account-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  flex-shrink: 0;
}

.sidebar-account-text {
  min-width: 0;
  overflow: hidden;
}
.sidebar-account-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-account-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-account-guest {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  transition: background 0.15s, color 0.15s;
}
.sidebar-account-guest:hover {
  background: var(--bg-card);
  color: var(--accent);
}
.sidebar-account-icon { font-size: 16px; }

/* トップバーのアカウントボタン */
.topbar-account-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.topbar-account-btn:hover { background: var(--accent); color: var(--bg-panel); }

/* 認証エラーメッセージ */
.auth-error {
  font-size: 12px;
  color: var(--danger);
  padding: 8px 10px;
  background: rgba(220,50,50,0.1);
  border-radius: 6px;
  margin-bottom: 10px;
}

/* モバイルでのサイドバーアカウント非表示 */
@media (max-width: 768px) {
  .sidebar-account {
    display: none;
  }
}
