/* カーリング ストラテジーボード — TV中継風ダークテーマ */
:root {
  --bg: #0a0f15;
  --surface: #121a23;
  --surface-2: #18222d;
  --surface-3: #202c39;
  --border: #263340;
  --hairline: rgba(255, 255, 255, 0.06);
  --text: #eaf1f7;
  --text-dim: #8fa1b1;
  --accent: #3b9ae1;
  --accent-2: #6cc0ff;
  --red: #e03131;
  --yellow: #fcc419;
  --danger: #c92a2a;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-1: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 10px 34px rgba(0, 0, 0, 0.5);
  --num: "tnum" 1, "lnum" 1;
  /* --- CurlFlux Design System 由来のトークン（claude.ai/design と一致） --- */
  --text-faint: #868e96;
  --text-on-accent: #ffffff;
  --accent-3: #74c0fc;
  --accent-wash: rgba(59, 154, 225, 0.18);
  --accent-glow: 0 2px 12px rgba(59, 154, 225, 0.4);
  --topbar-bg: linear-gradient(180deg, #121c26, #0b1219);
  --scoreboard-bg: linear-gradient(180deg, rgba(18, 26, 35, 0.94), rgba(10, 15, 21, 0.94));
  --shadow-topbar: 0 1px 0 var(--hairline), 0 6px 20px rgba(0, 0, 0, 0.25);
  --blur-glass: blur(6px);
  --lift: translateY(-1px);
  --fill-subtle: rgba(255, 255, 255, 0.04);
  /* シート外周のグラナイト風フレーム（GameBoard デザイン） */
  --granite-1: #1a2530;
  --granite-2: #2c3e50;
  /* ダーク前提の UI。スクロールバー・date のカレンダー・number のスピナー・
     select のドロップダウンなどブラウザ描画の部品も暗い側で描かせる */
  color-scheme: dark;
  accent-color: var(--accent);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ドロップダウン一覧の地色は :root の color-scheme: dark でおおむね暗くなるが、
   追随しないブラウザ（Windows の一部・Linux）が残るので明示しておく。
   選択中の行はアクセント色で塗る */
option, optgroup {
  background: var(--surface-2);
  color: var(--text);
}
option:checked {
  background: var(--accent);
  color: #fff;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------------- ヘッダー ---------------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-topbar);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;              /* h1 の既定マージンを消す（見出しだがロゴとして扱う） */
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
}

/* ロゴのワードマークと同じ組み: Curl は Medium、Flux は ExtraBold、末尾の x だけ氷の青。
   Sora は「CurlFx」の6字だけをサブセットした可変フォント（1.6KB）を自前で配る */
@font-face {
  font-family: 'Sora Wordmark';
  src: url('../assets/fonts/sora-wordmark.woff2') format('woff2');
  font-weight: 500 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+43, U+46, U+6c, U+72, U+75, U+78;
}

.brand-main {
  font-family: 'Sora Wordmark', system-ui, sans-serif;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.bm-flux { font-weight: 800; }
.bm-x { color: var(--accent-2); }

.brand-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  margin-left: auto;
}

.mode-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.mode-tab.active {
  background: var(--accent);
  color: #fff;
}

#menu-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------------- レイアウト ---------------- */
#layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #0e141b;
}

/* シート外周のグラナイト風フレーム（GameBoard デザイン）。キャンバスの上に薄く重ねる */
#canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  box-shadow:
    inset 0 0 0 2px var(--granite-2),
    inset 0 0 0 10px var(--granite-1),
    inset 0 0 40px rgba(0, 0, 0, 0.45);
}
body.broadcast #canvas-wrap::after { box-shadow: none; }

#sheet-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

/* ---------------- キャンバスオーバーレイ ---------------- */
.chip {
  position: absolute;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(13, 20, 28, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  z-index: 2;
}

#score-chip { left: 10px; }
#info-chip { right: 10px; }
#info-chip:empty, #score-chip:empty { display: none; }

.score-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.score-count { color: var(--text-dim); }

.score-pred {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(59, 154, 225, 0.25);
  color: #74c0fc;
  margin-right: 2px;
}
.score-none { color: var(--text-dim); font-weight: 500; }

#canvas-buttons {
  position: absolute;
  right: 10px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}

#canvas-buttons button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(13, 20, 28, 0.82);
  backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

#canvas-buttons button:disabled {
  opacity: 0.35;
  cursor: default;
}

#canvas-buttons button.active {
  background: var(--accent);
  border-color: var(--accent);
}

#real-btn { font-size: 12px; letter-spacing: 0.05em; }

#canvas-buttons button.skip:not(:disabled) {
  background: rgba(59, 154, 225, 0.9);
  border-color: var(--accent);
}

/* 実戦モード: 投球パネルのウェイト番号表記を隠す */
body.real-mode #weight-desc { visibility: hidden; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  top: auto;
  right: auto;
  margin: 0;
  transform: translateX(-50%) translateY(10px);
  background: rgba(13, 20, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 3;
  max-width: min(90vw, 520px);
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast::backdrop { background: transparent; }

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- コントロールパネル ---------------- */
#panel {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-row {
  display: flex;
  gap: 8px;
}

.panel-row.wrap { flex-wrap: wrap; }

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.mode-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hidden { display: none !important; }

/* チームボタン */
.team-row { gap: 10px; }

.team-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.team-btn .count {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.75;
}

.team-btn.team-red.active {
  border-color: var(--red);
  background: rgba(224, 49, 49, 0.16);
  color: #ff8787;
}

.team-btn.team-yellow.active {
  border-color: var(--yellow);
  background: rgba(252, 196, 25, 0.14);
  color: #ffd43b;
}

/* セグメントボタン */
.seg button {
  flex: 1;
  padding: 9px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.seg button.active {
  border-color: var(--accent);
  background: rgba(59, 154, 225, 0.18);
  color: #74c0fc;
}

#weight-presets button { flex: 1 1 auto; min-width: 72px; }

/* ウェイトスライダー */
.weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.weight-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 28px;
}

.weight-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 108px;
}

#weight-value {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#weight-desc { font-size: 11px; }

.muted { color: var(--text-dim); }

/* 汎用ボタン */
.btn {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: default; }

.btn.danger { color: #ff8787; border-color: rgba(201, 42, 42, 0.5); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.big {
  padding: 13px;
  font-size: 15px;
  border-radius: 14px;
}

.panel-row .btn { flex: 1; white-space: nowrap; }

/* ---------------- ダイアログ ---------------- */
dialog {
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(92vw, 460px);        /* 標準ダイアログの幅（統一） */
  max-height: 88dvh;
  box-sizing: border-box;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 { font-size: 16px; }

#menu-close {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.dialog-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.dialog-body .btn { text-align: left; }

.menu-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  font-size: 13px;
  cursor: pointer;
}

.menu-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* 別の設定によって意味がなくなった項目（例: 配置図の表示ではハンドルを描かない） */
.menu-toggle.disabled {
  opacity: 0.45;
  cursor: default;
}

.about {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.about h3 { font-size: 13px; }

.about p {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}

/* ---------------- モバイル最適化 ---------------- */
@media (max-width: 560px) {
  #topbar { gap: 8px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand { font-size: 14px; }
  .brand-sub { display: none; }
  .mode-tab { font-size: 12px; padding: 7px 10px; }
  #menu-btn { width: 32px; height: 32px; font-size: 14px; }

  #panel { padding: 8px 10px; gap: 8px; }
  .hint { font-size: 11px; }
  .seg button { padding: 8px 6px; font-size: 12px; }
  #weight-presets button { min-width: 60px; }
  .team-btn { padding: 8px; font-size: 13px; }
  .btn.big { padding: 11px; font-size: 14px; }
  .weight-info { min-width: 92px; }
  #weight-value { font-size: 14px; }
}

/* ---------------- デスクトップレイアウト ---------------- */
@media (min-width: 880px) {
  #layout { flex-direction: row; }

  #panel {
    width: 320px;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 16px;
    gap: 14px;
    overflow-y: auto;
  }

  .brand { font-size: 17px; }
  .brand-sub { font-size: 11px; }
}

/* ---------------- アイコン・全体モード・ツール ---------------- */
.ic { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.app-modes {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}
.app-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.app-mode.active { background: #fff; color: #0b1117; }
.app-mode[data-app="live"].active { background: #e03131; color: #fff; }
.mode-tab { display: flex; align-items: center; gap: 6px; }
.lbl-short { display: none; }
#canvas-buttons button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 50px;
  height: 50px;
  padding: 0;
}
#canvas-buttons button .ic { width: 20px; height: 20px; }
#canvas-buttons button .cap { font-size: 9px; font-weight: 700; letter-spacing: 0.02em; line-height: 1; opacity: 0.85; }
#canvas-buttons button .speed-val { font-size: 14px; font-weight: 800; line-height: 1; }
#real-btn { font-size: inherit; letter-spacing: 0; }
.app-panel { display: flex; flex-direction: column; gap: 8px; }
.replay-info { font-size: 12px; line-height: 1.4; }
.replay-info b { font-size: 13px; }
.replay-info .muted { color: var(--text-dim); font-size: 11px; }
.replay-info .est-mark { border-bottom: 1px dotted var(--text-dim); cursor: help; }
.replay-info .est-note {
  margin-top: 5px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-dim);
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  border-radius: 6px;
  cursor: help;
}
.replay-info .est-note b { font-size: 11px; color: var(--text); }
/* 操作タブが隠れるモードでも、ハンバーガーは常に右端に固定する */
body.replay-mode #menu-btn, body.live-mode #menu-btn { margin-left: auto; }
body.replay-mode .team-row, body.replay-mode .mode-panel,
body.replay-mode #sandbox-btn, body.replay-mode #real-btn, body.replay-mode #suggest-btn, body.replay-mode #undo-btn { display: none !important; }
body.replay-mode .app-panel[data-app="replay"] { display: flex !important; }
body.live-mode .team-row, body.live-mode .mode-panel,
body.live-mode #sandbox-btn, body.live-mode #real-btn, body.live-mode #suggest-btn, body.live-mode #undo-btn,
body.live-mode #compare-btn, body.live-mode #trail-btn, body.live-mode #speed-btn { display: none !important; }

/* 投球モードの切替はリプレイ・ライブでは使わない。ただし消すとヘッダーの高さが変わって
   モード切替のたびにガタつくので、PC では場所だけ残して隠す（ゲームの高さに揃える）。
   狭い画面ではこの列が1行まるごと使うため、そちらは消す */
body.replay-mode #tool-tabs, body.live-mode #tool-tabs {
  visibility: hidden;
  pointer-events: none;
}
@media (max-width: 560px) {
  body.replay-mode #tool-tabs, body.live-mode #tool-tabs { display: none; }
}
body.live-mode .app-panel[data-app="live"] { display: flex !important; }
#photo-btn { display: inline-flex; align-items: center; gap: 6px; }
#ph-wrap { max-height: 60vh; overflow: auto; background: #000; border-radius: 8px; margin: 8px 0; }
#ph-canvas { display: block; max-width: 100%; height: auto; cursor: crosshair; }
.photo-k { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.photo-k input[type="range"] { width: 140px; }
/* 写真ダイアログのボタンはラベルを折り返さない（「保存: ハウス1」などが2行になるのを防ぐ） */
#photo-dialog .btn { white-space: nowrap; }
#photo-dialog .photo-k .btn { flex: 0 0 auto; }
@media (max-width: 560px) {
  /* 1段目: ブランド＋全体モード＋メニュー、2段目: 操作。上部をコンパクトにして盤面を広く使う */
  #topbar { flex-wrap: wrap; row-gap: 4px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); }
  .brand { order: 1; }
  .brand-main { font-size: 14px; }
  .app-modes { order: 2; flex: 1; justify-content: center; padding: 2px; }
  #menu-btn { order: 3; }
  .mode-tabs { order: 4; width: 100%; justify-content: center; margin-left: 0; padding: 2px; }
  .app-mode { font-size: 11px; padding: 5px 8px; gap: 4px; }
  .app-mode .ic { width: 15px; height: 15px; }
  .mode-tab { flex: 1; justify-content: center; padding: 5px 8px; }
  .mode-tab .lbl-full { display: none; }
  .mode-tab .lbl-short { display: inline; }
  /* 右下のボタンは2列に */
  #canvas-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; right: 8px; bottom: 8px; }
  #canvas-buttons button { width: 42px; height: 42px; }
  #canvas-buttons button .cap { font-size: 8px; }
  #canvas-buttons button.hidden { display: none; }
}
@media (min-width: 561px) and (max-width: 1023px) {
  .app-mode span { display: none; }
  .app-mode { padding: 6px 9px; }
}

/* リプレイ／ライブのパネルのボタンは2列で折り返す（縦書きにしない） */
.app-panel .panel-row.wrap > .btn, .app-panel .panel-row.wrap > .file-btn { flex: 1 1 calc(50% - 8px); white-space: nowrap; }
.replay-info .score-big { font-size: 18px; font-weight: 800; color: #74c0fc; margin: 0 4px; font-variant-numeric: tabular-nums; }

/* ---------------- ブロードキャスト・ポリッシュ ---------------- */
#topbar {
  background: linear-gradient(180deg, #121c26, #0b1219);
  box-shadow: 0 1px 0 var(--hairline), 0 6px 20px rgba(0, 0, 0, 0.25);
}
/* かつて白→淡青のグラデーションを流し込んでいたが、x だけを青くするロゴの組みと両立しないため外した
   （-webkit-text-fill-color: transparent が子要素の色を上書きしてしまう） */
.brand-sub { text-transform: uppercase; }
.app-mode, .mode-tab { transition: background 0.15s, color 0.15s, box-shadow 0.15s; }
.app-mode:hover:not(.active), .mode-tab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.05); }
.app-mode.active { box-shadow: 0 1px 6px rgba(0,0,0,0.3); }

/* ボタン全般: 髪の毛のような境界＋ホバーで少し持ち上がる */
#canvas-buttons button {
  background: rgba(16, 24, 32, 0.86);
  border-color: var(--hairline);
  box-shadow: var(--shadow-1);
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
#canvas-buttons button:not(:disabled):hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.16); background: rgba(24, 34, 45, 0.94); }
#canvas-buttons button.active { background: var(--accent); border-color: var(--accent); box-shadow: 0 2px 12px rgba(59,154,225,0.4); }
.btn { transition: transform 0.12s, background 0.15s, border-color 0.15s; }
.btn:not(:disabled):hover { transform: translateY(-1px); }

/* ---------------- ロゴマーク ---------------- */
.brand { gap: 8px; align-items: center; }
.brand-mark { width: 26px; height: 26px; flex-shrink: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
@media (max-width: 560px) { .brand-mark { width: 22px; height: 22px; } }
