/* 基本・画面共通。色はすべて :root のトークン */
:root {
  --bg: #0b0720;
  --panel: rgba(24, 16, 62, 0.82);
  --panel-line: rgba(160, 140, 255, 0.45);
  --ink: #fff7ff;
  --ink-soft: #cfc4ff;
  --accent: #ff7ac8;
  --accent-ink: #2a0f3d;
  --accent2: #5ef0ff;
  --good: #a9ff8a;
  --warm: #ffe27a;
  --btn: rgba(255, 255, 255, 0.14);
  --btn-on: #7a5cff;
  --radius: 22px;
  --gutter: 16px;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font); font-weight: 700; touch-action: manipulation; user-select: none;
  -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }

#ui { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  padding: max(var(--gutter), env(safe-area-inset-top)) var(--gutter) max(var(--gutter), env(safe-area-inset-bottom));
}
.screen > *, .screen button { pointer-events: auto; }
.screen h1 {
  margin: 4vh 0 0; text-align: center; font-weight: 800; font-size: clamp(40px, 8vw, 92px);
  text-shadow: 0 0 24px var(--accent), 0 4px 0 rgba(0, 0, 0, 0.35); pointer-events: none;
}
.screen[data-screen="title"] { justify-content: space-between; }
.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 4vh; }

.btn {
  min-height: 56px; padding: 0 28px; border: 2px solid var(--panel-line); border-radius: 999px;
  background: var(--btn); font-size: 20px; font-weight: 800; backdrop-filter: blur(6px);
}
.btn:active { transform: scale(0.97); }
.btn.big { min-height: 72px; padding: 0 56px; font-size: 28px; background: var(--accent); color: var(--accent-ink); border-color: #fff; }
.btn.ghost { background: var(--panel); }
.btn:disabled { opacity: 0.4; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; background: var(--panel); border: 2px solid var(--panel-line); border-radius: var(--radius);
}
.bar h2 { margin: 0; font-size: clamp(20px, 3vw, 30px); text-align: center; flex: 1; }
.bar .btn { min-height: 48px; padding: 0 20px; font-size: 18px; }
.screen[data-screen="modes"] > footer { flex-wrap: wrap; justify-content: center; }
.screen[data-screen="modes"] > footer .btn.big { min-height: 60px; padding: 0 40px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  min-height: 48px; padding: 0 18px; border: 2px solid var(--panel-line); border-radius: 14px;
  background: var(--btn); font-size: 18px; font-weight: 800;
}
.seg-btn.is-on { background: var(--btn-on); border-color: #fff; box-shadow: 0 0 14px var(--btn-on); }

/* モード選択 */
#modes-grid {
  flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: minmax(150px, 250px); gap: 12px;
  overflow: auto; align-content: start;
}
.mode-card {
  position: relative; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; text-align: left;
  min-height: 150px; padding: 14px 16px; border: 3px solid color-mix(in srgb, var(--mode) 60%, white);
  border-radius: var(--radius); background: linear-gradient(160deg, color-mix(in srgb, var(--mode) 55%, #120a2e), #120a2e 90%);
}
.mode-card.is-selected { box-shadow: 0 0 0 4px #fff, 0 0 26px var(--mode); transform: translateY(-2px); }
.mode-card:disabled { filter: saturate(0.4) brightness(0.7); cursor: default; }
.mode-no { font-size: 15px; background: #fff; color: #120a2e; border-radius: 999px; padding: 0 10px; }
.mode-name { font-size: clamp(18px, 2.2vw, 24px); font-weight: 800; }
.mode-hint { font-size: 15px; color: var(--ink-soft); }
.mode-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.mode-tags i { font-style: normal; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); }
.mode-badge { position: absolute; right: 12px; top: 12px; font-style: normal; font-size: 14px; padding: 4px 12px; border-radius: 999px; background: var(--warm); color: var(--accent-ink); }

/* カード(ひとやすみ・結果・エラー) */
.screen:has(> .card) { align-items: center; justify-content: center; background: rgba(8, 4, 28, 0.55); }
.card {
  width: min(560px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 14px; align-items: center;
  padding: 24px; background: var(--panel); border: 3px solid var(--panel-line); border-radius: 28px;
}
.card h2 { margin: 0; font-size: 34px; }
.card .btn { width: 100%; }
.card .actions { width: 100%; margin: 0; }
#result-body { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.result-big { display: flex; align-items: baseline; justify-content: center; gap: 14px; font-size: 22px; color: var(--ink-soft); }
.result-big strong { font-size: 84px; line-height: 1; color: var(--warm); text-shadow: 0 0 20px var(--accent); }
.result-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; font-size: 20px; }
.result-facts dt { color: var(--ink-soft); }
.result-facts dd { margin: 0; text-align: right; }
.result-label { margin: 6px 0 0; font-size: 16px; color: var(--ink-soft); }
.result-dirs { display: flex; flex-wrap: wrap; gap: 8px; }
.dir-chip { padding: 6px 14px; border-radius: 999px; background: var(--btn); font-size: 22px; }
.result-settings { margin: 0; font-size: 15px; }

/* きろく */
#history-list { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: grid; grid-template-columns: 11em 1fr auto auto; gap: 12px; align-items: center; padding: 10px 16px;
  background: var(--panel); border: 2px solid var(--panel-line); border-radius: 16px; font-size: 18px;
}
.history-empty { text-align: center; font-size: 22px; color: var(--ink-soft); }
.h-done { color: var(--warm); }

#toast {
  position: fixed; left: 50%; bottom: 14vh; transform: translateX(-50%); padding: 12px 24px; border-radius: 999px;
  background: var(--accent2); color: var(--accent-ink); font-size: 20px; font-weight: 800; z-index: 20; pointer-events: none;
}

@media (max-width: 900px) {
  #modes-grid { grid-template-columns: repeat(2, 1fr); }
  .history-row { grid-template-columns: 1fr auto; }
  .h-at { grid-column: 1 / -1; font-size: 15px; color: var(--ink-soft); }
}
@media (max-width: 520px) {
  #modes-grid { grid-template-columns: 1fr; }
}
