/* 色は config.js の PALETTE を main.js が --c-* に流す。ここの値は読み込み前の控え */
:root {
  --c-ink: #120f2e; --c-deep: #1b1740; --c-violet: #6d5cff; --c-lavender: #b9a8ff; --c-white: #f4f2ff;
  --c-cyan: #6fe7ff; --c-pink: #ff8fd0; --c-gold: #ffd97a; --c-warn: #ff5470; --c-ok: #8ff0c0;
  --panel: rgba(18, 15, 46, 0.78);
  --panel-solid: rgba(27, 23, 64, 0.94);
  --line: rgba(185, 168, 255, 0.4);
  --dim: rgba(244, 242, 255, 0.68);
  --radius: 14px;
  --font-en: "Chakra Petch", "Zen Kaku Gothic New", sans-serif;
  --font-ja: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--c-ink); color: var(--c-white); font-family: var(--font-ja); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
[hidden] { display: none !important; }
h1, h2, h3, h4, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }

#app { position: fixed; inset: 0; }
#stage, #hud { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { pointer-events: none; }
#boot { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--c-lavender); background: var(--c-ink); }

/* ---- ボタン */
.btn {
  font: 700 16px/1.2 var(--font-ja); color: var(--c-white); cursor: pointer;
  min-height: 48px; padding: 10px 20px; border-radius: 999px;
  border: 1.5px solid var(--line); background: rgba(244, 242, 255, 0.06);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--c-violet); border-color: var(--c-lavender); }
.btn.primary:hover:not(:disabled) { background: #7d6dff; }
.btn.ghost:hover { background: rgba(244, 242, 255, 0.14); }
.btn.big { min-height: 58px; padding: 14px 34px; font-size: 19px; letter-spacing: 0.06em; }
.btn.chip { min-height: 42px; padding: 8px 14px; font-size: 14.5px; font-weight: 500; }
.btn.chip.is-on { background: var(--c-white); color: var(--c-ink); border-color: var(--c-white); font-weight: 700; }
.hud-btn { position: absolute; top: 12px; z-index: 3; background: var(--panel); min-width: 52px; }
#pause { right: 12px; padding: 10px 0; }
#peek { left: 50%; top: auto; bottom: 14px; transform: translateX(-50%); }

.row { display: flex; gap: 12px; align-items: center; justify-content: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: 260px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.eyebrow { font: 700 13px/1 var(--font-en); letter-spacing: 0.2em; color: var(--c-cyan); }
.note { font-size: 13.5px; line-height: 1.7; color: var(--dim); }

/* ---- 画面の土台 */
#overlay {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto; touch-action: pan-y;
  background: linear-gradient(180deg, rgba(18, 15, 46, 0.72), rgba(27, 23, 64, 0.84));
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
#overlay.clear { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; pointer-events: none; }
.screen { min-height: 100%; padding: max(24px, env(safe-area-inset-top)) 24px 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }

/* ---- タイトル */
.title { text-align: center; }
.logo { font: 700 clamp(46px, 9vw, 96px)/1 var(--font-en); letter-spacing: 0.08em; text-shadow: 0 0 34px rgba(109, 92, 255, 0.75); }
.logo-sub { font-size: clamp(16px, 2.4vw, 22px); letter-spacing: 0.3em; color: var(--c-lavender); }
.tagline { max-width: 34em; line-height: 1.8; color: var(--dim); }
.features { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: min(960px, 100%); }
.feature { text-align: left; padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.feature b { font-size: 15px; color: var(--c-cyan); }
.feature span { font-size: 13px; line-height: 1.6; color: var(--dim); }
.level-pick { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; }
.level-pick .label { font: 700 13px var(--font-en); letter-spacing: 0.15em; color: var(--c-lavender); }
.level-pick .best { font: 500 14px var(--font-en); color: var(--c-gold); }

/* ---- 設定 */
.settings { justify-content: flex-start; align-items: stretch; max-width: 980px; margin: 0 auto; }
.bar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 2; padding: 10px 0; background: linear-gradient(180deg, var(--c-ink) 70%, transparent); }
.settings-body { display: flex; flex-direction: column; gap: 16px; }
.group { padding: 16px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.group h3 { font-size: 15px; color: var(--c-cyan); margin-bottom: 6px; letter-spacing: 0.08em; }
.setting { display: grid; grid-template-columns: 220px 1fr; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid rgba(185, 168, 255, 0.16); }
.setting-name { display: flex; flex-direction: column; gap: 3px; }
.setting-name b { font-size: 15px; }
.setting-name small { font-size: 12px; line-height: 1.5; color: var(--dim); }

/* ---- マーカー */
.calib-frame { width: min(560px, 100%); aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden; border: 1.5px solid var(--line); background: #000; }
.calib-frame video, #camera-preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
video.mirror { transform: scaleX(-1); }
.calib-status { font-size: 17px; font-weight: 700; }
.calib-detail { font-size: 12px; color: var(--c-warn); }
#camera-preview { position: absolute; left: 12px; top: 84px; width: 132px; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); opacity: 0.85; z-index: 2; pointer-events: none; }

/* ---- 指令 */
.brief-card { width: min(620px, 100%); padding: 24px 26px; border-radius: 18px; background: var(--panel-solid); border: 1.5px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.brief-card h2 { font-size: 26px; letter-spacing: 0.04em; }
.brief-card h4 { font-size: 13px; color: var(--c-lavender); letter-spacing: 0.12em; display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.brief-note { font-size: 15px; line-height: 1.7; color: var(--dim); }
.steps { display: flex; flex-wrap: wrap; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 999px; background: rgba(244, 242, 255, 0.08); font-weight: 700; font-size: 17px; }
.steps.numbered li:not(:last-child)::after { content: "→"; margin-left: 6px; color: var(--c-lavender); }
.step-n { font: 700 14px var(--font-en); color: var(--c-ink); background: var(--c-gold); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.step-mark { font: 700 17px var(--font-en); width: 34px; height: 34px; border-radius: 50%; border: 2px solid; display: grid; place-items: center; background: var(--c-ink); }
.rules { display: flex; flex-direction: column; gap: 6px; }
.rules li { font-size: 15.5px; line-height: 1.6; padding-left: 1.1em; position: relative; }
.rules li::before { content: ""; position: absolute; left: 0; top: 0.62em; width: 7px; height: 7px; background: var(--c-pink); transform: rotate(45deg); }
.rules.added li { color: var(--c-gold); }
.rules.added li::before { background: var(--c-gold); }
.lamp, .dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.brief-card.compact { padding: 14px 16px; gap: 8px; border-radius: var(--radius); }
.brief-card.compact .steps li { font-size: 14px; padding: 5px 10px 5px 5px; }
.brief-card.compact .step-mark { width: 26px; height: 26px; font-size: 13px; }
.brief-card.compact .rules li, .brief-card.compact .brief-note { font-size: 13px; }
.timer { display: flex; align-items: center; gap: 12px; width: min(620px, 100%); font-size: 14px; color: var(--c-lavender); }
.timer-bar { flex: 1; height: 6px; border-radius: 3px; background: rgba(244, 242, 255, 0.16); overflow: hidden; }
.timer-bar i { display: block; height: 100%; width: 100%; background: var(--c-cyan); }
.timer-num { font: 700 20px var(--font-en); color: var(--c-white); min-width: 3em; text-align: right; }

/* ---- 計画 */
.plan { flex-direction: row; align-items: stretch; gap: 16px; padding: 16px; height: 100%; }
.plan-map-wrap { flex: 1; min-width: 0; border-radius: 18px; background: var(--panel); border: 1.5px solid var(--line); overflow: hidden; position: relative; }
.plan-map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
.plan-side { width: 320px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.plan-side h2 { font-size: 22px; }
.plan-msg { font-size: 14.5px; line-height: 1.6; min-height: 3.2em; color: var(--c-white); }
.plan-stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.plan-stats dt { font-size: 13px; color: var(--dim); }
.plan-stats dd { font: 700 17px var(--font-en); text-align: right; }
.is-warn { color: var(--c-warn); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--dim); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .line { display: inline-block; width: 26px; height: 0; border-top: 5px solid var(--c-white); }
.legend .line.narrow { border-top: 2px solid var(--c-pink); }
.legend .line.wind { border-top: 4px dotted var(--c-cyan); }
.plan-side > .btn.big { margin-top: auto; }

/* ---- カウント */
.count { pointer-events: none; }
.count-num { font: 700 clamp(90px, 22vw, 190px)/1 var(--font-en); text-shadow: 0 0 40px rgba(109, 92, 255, 0.9); }
.count-num.pop { animation: pop 0.5s ease-out; }
.count-guide { padding: 10px 20px; border-radius: 999px; background: var(--panel); font-weight: 700; }
@keyframes pop { from { transform: scale(1.5); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

/* ---- あそび中に重ねるもの */
#float { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
#float > * { pointer-events: auto; }
.notice { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); width: min(520px, calc(100% - 32px)); padding: 20px 24px; border-radius: 18px; background: var(--panel-solid); border: 2px solid var(--c-warn); display: flex; flex-direction: column; gap: 8px; text-align: center; cursor: pointer; animation: pop 0.3s ease-out; }
.notice.add { border-color: var(--c-gold); }
.notice.close .eyebrow { color: var(--c-warn); }
.notice.add .eyebrow { color: var(--c-gold); }
.notice-line { font-size: 22px; font-weight: 700; line-height: 1.5; }
.notice-sub { font-size: 14px; color: var(--dim); }
.peek { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(480px, calc(100% - 32px)); z-index: 8; cursor: pointer; }
.peek .timer-bar { margin-top: 6px; flex: none; }
.memo { position: absolute; left: 12px; top: 84px; width: 250px; opacity: 0.94; pointer-events: none !important; }
.has-camera .memo { top: 196px; }

.pause h2 { font: 700 34px var(--font-en); letter-spacing: 0.2em; }

/* ---- 結果 */
.result { justify-content: flex-start; max-width: 1080px; margin: 0 auto; align-items: stretch; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.result-head h2 { font: 700 clamp(28px, 5vw, 46px)/1.2 var(--font-en); letter-spacing: 0.08em; margin: 6px 0; }
.result.is-fail .result-head h2 { color: var(--c-warn); }
.result-title { font-size: 17px; font-weight: 700; }
.result-nums { font-size: 14px; color: var(--dim); margin-top: 4px; }
.rank { width: 112px; height: 112px; flex: none; border-radius: 50%; border: 2px solid var(--c-gold); display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--panel); }
.rank span { font: 700 11px var(--font-en); letter-spacing: 0.2em; color: var(--c-gold); }
.rank b { font: 700 58px/1 var(--font-en); }
.rank-D { border-color: var(--line); }
.rank-D span { color: var(--c-lavender); }
.domains { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.domain, .routes, .history-box { padding: 16px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.domain header { display: flex; justify-content: space-between; align-items: baseline; }
.domain h3, .routes h3, .history-box h3 { font-size: 15px; color: var(--c-cyan); letter-spacing: 0.06em; }
.domain-score { font: 700 34px/1 var(--font-en); }
.gauge { height: 6px; border-radius: 3px; background: rgba(244, 242, 255, 0.16); overflow: hidden; }
.gauge i { display: block; height: 100%; background: linear-gradient(90deg, var(--c-violet), var(--c-cyan)); }
.domain dl { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; }
.domain dt { font-size: 13px; color: var(--dim); }
.domain dd { font-size: 14px; font-weight: 700; text-align: right; }
.result-lower { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; }
.route-map-wrap { height: 300px; position: relative; border-radius: 10px; background: rgba(18, 15, 46, 0.6); }
.route-map { position: absolute; inset: 0; width: 100%; height: 100%; }
.history { width: 100%; border-collapse: collapse; font-size: 13px; }
.history th { font-weight: 500; color: var(--dim); font-size: 12px; text-align: center; padding: 4px; }
.history td { text-align: center; padding: 6px 4px; border-top: 1px solid rgba(185, 168, 255, 0.16); font-family: var(--font-en); }
.disclaimer { padding: 12px 16px; border-left: 3px solid var(--c-lavender); background: rgba(244, 242, 255, 0.05); border-radius: 0 10px 10px 0; }

/* ---- せまい画面 */
@media (max-width: 860px) {
  .features { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setting { grid-template-columns: 1fr; }
  .domains, .result-lower { grid-template-columns: 1fr; }
  .plan { flex-direction: column; height: auto; min-height: 100%; }
  .plan-map-wrap { min-height: 56vh; }
  .plan-side { width: auto; overflow: visible; }
  .memo { width: 200px; }
}
@media (max-height: 560px) {
  .screen { gap: 10px; padding-top: 14px; padding-bottom: 14px; justify-content: flex-start; }
  .features { display: none; }
  .plan { flex-direction: row; height: 100%; }
}
@media (prefers-reduced-motion: reduce) { .count-num.pop, .notice { animation: none; } }
