/* =====================================================================
 * base.css — トークン / リセット / レイアウト / 骨格コンテナ枠 / 共通部品クラス
 *
 * 所有権（仕様 §6）: ここに書くのは
 *   - :root トークン
 *   - §3 の骨格 id に対応するコンテナ枠（.menubar .modebar .stage … .cookie-banner）
 *   - 列挙された共通クラス（.big-btn .btn .btn-ghost .btn-danger .card .chip .gauge
 *     .slider-row .table .badge .fine-print .stamp .emoji .greeting .app-title）
 * 各モジュールが生成する要素の CSS は、そのモジュールが util.injectCSS で供給する。
 * ===================================================================== */

/* ---------- トークン ---------- */
:root {
  --bg: #12121c;
  --bg-2: #1b1b2b;
  --panel: #22223a;
  --panel-2: #2b2b46;
  --line: rgba(255, 255, 255, .1);
  --text: #f4f4f8;
  --muted: #a9a9c2;
  --accent: #e63946;        /* main.js が dish.theme で上書き */
  --accent-soft: #ff8fa3;   /* 同上 */
  --gold: #ffd166;          /* 同上 */
  --gold-2: #ffb703;
  --danger: #ff5d5d;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 8px;
  --menubar-h: 48px;
  --modebar-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --kb: 0px;        /* ui.js が visualViewport から設定（仮想キーボード高） */
  --cookie-h: 0px;  /* hidden.js が Cookie バナー表示中に設定 */
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans CJK JP", "Noto Sans JP", system-ui, sans-serif;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --dur: .2s;       /* 共通部品の transition 時間（reduced-motion で短縮） */
  color-scheme: dark;
}

/* ---------- リセット ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  overflow-x: hidden;              /* 横スクロール禁止（viewport に伝播） */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* 固定メニューバーの分だけ本文を下げる（sticky なモードバーの自然位置がこの直下になる） */
  padding-top: calc(var(--menubar-h) + var(--safe-top));
  /* overflow-x:hidden にすると body がスクロールコンテナ化して .modebar の sticky が壊れるため clip を使う */
  overflow-x: clip;
  overscroll-behavior-y: none;
  overflow-wrap: anywhere;
  background: var(--bg) linear-gradient(180deg, #1d1d32 0, var(--bg) 420px) no-repeat;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, ul, ol, figure, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, canvas, svg, video { display: block; max-width: 100%; }
a { color: var(--gold); text-decoration-thickness: 1px; text-underline-offset: 2px; }
strong, b { font-weight: 800; }
small { font-size: .85em; }
pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
  text-align: inherit;
}
button:disabled { cursor: not-allowed; }

/* 入力要素: iOS の自動ズームを防ぐため 16px 以上 */
input, select, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--text);
}
input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
select, textarea {
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-width: 100%;
}
input[type="checkbox"], input[type="radio"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}
textarea { resize: vertical; line-height: 1.5; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ---------- 操作要素の共通規約 ---------- */
button, a.btn, .big-btn, .chip, #brand, [role="button"], canvas {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 骨格コンテナ枠 ---------- */

/* メニューバー（menubar.js が中身を構築、.mb- で装飾） */
.menubar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--menubar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  display: flex;
  align-items: center;
  background: rgba(18, 18, 28, .94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
}

/* モードバー（modes.js がチップを生成）。モバイルは横スクロール、PC は折返し */
.modebar {
  position: sticky;
  top: calc(var(--menubar-h) + var(--safe-top));
  z-index: 90;
  height: var(--modebar-h);
  padding: 0 calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  background: rgba(18, 18, 28, .94);
  border-bottom: 1px solid var(--line);
}
.modebar::-webkit-scrollbar { display: none; }
.modebar > * { flex: 0 0 auto; scroll-snap-align: start; }

@media (min-width: 768px) {
  .modebar {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 6px;
    height: auto;
    min-height: var(--modebar-h);
    padding-top: 6px;
    padding-bottom: 6px;
    overflow: visible;
  }
}

/* ステージ本体 */
main.stage {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  /* 上の menubar 分は body の padding-top で確保済み */
  padding: 12px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stage-head {
  text-align: center;
  padding: 8px 0 0;
}

.app-title {
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: .02em;
  color: var(--gold);
  background: linear-gradient(180deg, #fff3c4 0%, var(--gold) 45%, var(--gold-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
}

.greeting {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}
.greeting:empty { display: none; }

.mode-root {
  position: relative;
  /* core.run が scrollIntoView するので固定バーの下に潜らないようにする */
  scroll-margin-top: calc(var(--menubar-h) + var(--modebar-h) + var(--safe-top) + 8px);
}

.result-root { position: relative; }

/* フッター（共有領域。各モジュールが <p data-owner> を append するだけ） */
.footer {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 14px calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}
.footer:empty { display: none; }
.footer p { margin: 0; }

/* 全画面 canvas（fx.js） */
.fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 400;
  pointer-events: none;
}

/* 実況テロップ（ui.ticker。内部装飾は ui.js が上書き可） */
.ticker {
  position: fixed;
  z-index: 300;
  top: calc(var(--menubar-h) + var(--modebar-h) + var(--safe-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(720px, calc(100% - 32px - var(--safe-left) - var(--safe-right)));
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(10, 10, 18, .88);
  border: 1px solid rgba(255, 209, 102, .4);
  color: var(--gold);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: ticker-in .25s ease-out both;
}
@keyframes ticker-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* オーバーレイ層（ui.js の modal / sheet / ドロワー） */
.overlay-root {
  position: fixed;
  inset: 0;
  z-index: 600;
  pointer-events: none;   /* 空のときページを塞がない */
}
.overlay-root > * { pointer-events: auto; }

/* トースト層 */
.toast-root {
  position: fixed;
  z-index: 700;
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom) + var(--kb) + var(--cookie-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast-root > * { pointer-events: auto; max-width: 100%; }

/* 偽 Cookie バナー（hidden.js が中身を構築） */
.cookie-banner {
  position: fixed;
  z-index: 800;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + var(--kb));
  padding: 12px calc(16px + var(--safe-right)) 12px calc(16px + var(--safe-left));
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .35);
  color: var(--text);
  font-size: 14px;
}

/* ---------- 共通部品クラス ---------- */

/* 大ボタン（ui.bigButton） */
.big-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  max-width: 420px;
  min-height: 64px;
  margin: 0 auto;
  padding: 12px 28px;
  border-radius: 999px;
  position: relative;
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: .06em;
  line-height: 1.25;
  text-align: center;
  background: linear-gradient(135deg, var(--accent-soft) -30%, var(--accent) 55%, var(--accent) 100%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .28), inset 0 -2px 0 rgba(0, 0, 0, .18);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  transition: transform .12s ease, box-shadow var(--dur) ease, opacity var(--dur) ease;
}
.big-btn:active { transform: scale(.97); }
.big-btn:disabled, .big-btn[aria-disabled="true"] { opacity: .55; transform: none; }
.big-btn small, .big-btn .sub {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  opacity: .9;
}

/* 通常ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  transition: background var(--dur), border-color var(--dur), color var(--dur), transform .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; transform: none; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-danger {
  background: rgba(255, 93, 93, .12);
  border-color: rgba(255, 93, 93, .55);
  color: var(--danger);
}

/* カード */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

/* チップ（モード切替・一覧表示） */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--dur), color var(--dur), border-color var(--dur), box-shadow var(--dur);
}
button.chip, a.chip, .chip[role="button"] { min-height: 44px; }   /* タップ領域 44px */
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

/* ゲージ（子要素 1 つを width:% で伸ばす） */
.gauge {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.gauge > * {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .15s linear;
}

/* スライダー行: [ラベル] [range] [現在値] */
.slider-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 44px;
}
.slider-row input[type="range"] {
  flex: 1 1 140px;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.slider-row input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.slider-row input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--gold); outline-offset: 2px; }
.slider-row input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--gold); outline-offset: 2px; }

/* 表 */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
}
.table tfoot td { font-weight: 800; color: var(--gold); }

/* バッジ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 209, 102, .14);
  border: 1px solid rgba(255, 209, 102, .45);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1.4;
  white-space: nowrap;
  vertical-align: middle;
}

/* 注釈（9px だがタップ領域は padding で 44px 確保） */
.fine-print {
  display: block;
  margin: 0;
  padding: 16px 8px;
  min-height: 44px;
  color: var(--muted);
  opacity: .6;
  font-size: 9px;
  line-height: 1.5;
  text-align: center;
  letter-spacing: .02em;
}
.fine-print a, .fine-print button {
  display: inline-block;
  padding: 16px 8px;
  margin: -16px -8px;
  color: inherit;
  font: inherit;
  text-decoration: underline;
}

/* 朱印（決定通知書など）。.on を付けると押印アニメ */
.stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  height: 84px;
  padding: 6px;
  border-radius: 50%;
  border: 3px solid #d23c2a;
  box-shadow: inset 0 0 0 2px rgba(210, 60, 42, .4);
  color: #d23c2a;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: .08em;
  text-align: center;
  opacity: .92;
  transform: rotate(-12deg);
  forced-color-adjust: none;
}
.stamp.on { animation: stamp-in .38s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes stamp-in {
  0%   { opacity: 0;   transform: rotate(-12deg) scale(2.4); }
  60%  { opacity: 1;   transform: rotate(-12deg) scale(.92); }
  100% { opacity: .92; transform: rotate(-12deg) scale(1); }
}

/* 絵文字（システムのカラー絵文字フォントを明示） */
.emoji {
  font-family: var(--font-emoji);
  font-style: normal;
  font-weight: 400;
  line-height: 1;
}

/* ---------- hover はポインタ環境のみ ---------- */
@media (hover: hover) {
  a:hover { color: var(--gold-2); }
  .btn:hover { background: var(--panel); border-color: rgba(255, 255, 255, .28); }
  .btn-ghost:hover { color: var(--text); }
  .btn-danger:hover { background: rgba(255, 93, 93, .22); }
  .btn:disabled:hover { background: var(--panel-2); border-color: var(--line); }
  .big-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .32), inset 0 -2px 0 rgba(0, 0, 0, .18); }
  .big-btn:disabled:hover { transform: none; }
  .chip:hover:not(.active) { color: var(--text); border-color: rgba(255, 255, 255, .28); }
}

/* ---------- 動きを減らす ---------- */
@media (prefers-reduced-motion: reduce) {
  :root { --dur: .05s; }
  .big-btn, .btn { transition-duration: .05s; }
  .big-btn:active, .btn:active { transform: none; }
  .gauge > * { transition: none; }
  .stamp.on { animation-duration: .12s; }
  .ticker { animation-duration: .1s; }
}

/* ---------- 強制カラー（Windows ハイコントラスト） ---------- */
@media (forced-colors: active) {
  .big-btn, .btn, .chip, .card { border: 1px solid ButtonText; }
  .fine-print, .greeting, .big-btn:disabled, .btn:disabled { opacity: 1; }
  .app-title {
    background: none;
    -webkit-text-fill-color: currentColor;
    color: CanvasText;
  }
  .chip.active { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  .gauge > * { background: Highlight; }
  .badge { border-color: CanvasText; }
  .ticker { border-color: CanvasText; }
}
