:root {
  color-scheme: light;
  --sky: #58c4e8;
  --blue: #3d88d1;
  --green: #56a860;
  --lime: #abd470;
  --ink: #222;
  --ink-2: #555;
  --bg: #fbf8f2;
  --card: #fff;
  --line: #e6e0d6;
  --sauce: #4a240f;
  --mayo: #fff6d8;
  --warn-bg: #fff3d6;
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  /* 中身は本文（最大 560px）と同じ幅で中央に寄せる */
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(16px, calc((100% - 560px) / 2 + 16px)) 8px;
  background: #fff;
  border-bottom: 4px solid;
  border-image: linear-gradient(90deg, var(--sky) 0 25%, var(--blue) 25% 50%, var(--green) 50% 75%, var(--lime) 75%) 1;
}
.topbar-logo { width: 40px; height: 32px; object-fit: contain; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title .lab { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--blue); }
.topbar-title .app { font-size: 16px; font-weight: 800; }

main { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }
.screen { display: flex; flex-direction: column; gap: 16px; }

h1, h2 { margin: 0; line-height: 1.3; }
.page-title { font-size: 24px; }

/* トップ */
.hero { text-align: center; padding: 8px 0 0; }
.hero-logo, .lab-card img { mix-blend-mode: multiply; } /* ロゴの白背景をなじませる */
.hero-logo { width: 120px; height: auto; }
.hero h1 { font-size: 40px; font-weight: 900; margin-top: 8px; letter-spacing: .02em; }
.catch { font-size: 19px; margin: 8px 0 0; }
.catch strong { color: var(--blue); font-size: 22px; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.steps li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; font-weight: 600;
}
.step-no {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  color: #fff; font-weight: 800;
}
.steps li:nth-child(1) .step-no { background: var(--sky); }
.steps li:nth-child(2) .step-no { background: var(--blue); }
.steps li:nth-child(3) .step-no { background: var(--green); }

.privacy { margin: 0; font-size: 14px; color: var(--ink-2); text-align: center; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px;
  border: 0; border-radius: 999px;
  font: inherit; font-weight: 700; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 4px 0 #2b6aa8; }
.btn-secondary { background: #fff; color: var(--blue); border: 2px solid var(--blue); }
.btn-ghost { background: rgba(0,0,0,.06); color: var(--ink); font-size: 15px; padding: 10px 14px; }
.btn-big { min-height: 64px; font-size: 21px; width: 100%; }
.btn-link {
  background: none; border: 0; color: var(--blue); font: inherit; font-weight: 700;
  padding: 8px; cursor: pointer; align-self: center;
}

/* 撮影 */
.guide-text { margin: 0; text-align: center; font-size: 19px; font-weight: 700; }
.viewport {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  background: #111; border-radius: var(--radius); overflow: hidden;
}
.viewport video, .viewport #still {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.viewport-msg {
  position: absolute; inset: auto 12px 12px; padding: 10px 12px;
  background: rgba(0,0,0,.7); color: #fff; border-radius: 12px; font-size: 15px; text-align: center;
}
.camera-actions {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.camera-actions .btn:first-child { justify-self: start; }
.camera-actions label { justify-self: end; }
.shutter {
  width: 80px; height: 80px; border-radius: 50%;
  border: 5px solid var(--blue); background: #fff; padding: 6px; cursor: pointer;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--blue); }
.shutter:active span { background: #2b6aa8; }
.shutter:disabled { opacity: .4; }
.hint { margin: 0; font-size: 14px; color: var(--ink-2); text-align: center; }

/* 結果 */
.answer {
  text-align: center; border-radius: 24px; padding: 16px 16px 20px;
  background: radial-gradient(circle at 50% 45%, #6b3618 0%, var(--sauce) 70%);
  color: var(--mayo);
}
.answer-label { margin: 0; font-weight: 700; opacity: .9; }
.answer-digit {
  margin: 0; font-size: min(48vw, 220px); line-height: 1; font-weight: 900;
  text-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.answer-conf { margin: 4px 0 0; font-size: 18px; font-weight: 700; }
.answer.pop .answer-digit { animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.answer.swap { animation: swap .35s ease; }
@keyframes swap { 0% { opacity: .3; transform: translateX(var(--swap-from, 24px)); } 100% { opacity: 1; transform: none; } }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.warn {
  margin: 0; padding: 12px 14px; border-radius: 12px;
  background: var(--warn-bg); border: 1px solid #f0c96b; font-weight: 600;
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.card h2 { font-size: 17px; margin-bottom: 12px; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }

/* ロゴと同じ「棒グラフ」で確率を表示 */
.bars {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px;
  align-items: end; height: 180px;
}
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-pct { font-size: 11px; font-weight: 700; color: var(--ink-2); min-height: 1em; }
.bar-fill {
  width: 100%; min-height: 3px; border-radius: 4px 4px 0 0; background: #d9e3ec;
  transition: height .6s cubic-bezier(.2,.8,.2,1);
}
.bar-label { font-size: 18px; font-weight: 800; }
.bar.top .bar-fill { background: var(--blue); }
.bar.top .bar-pct, .bar.top .bar-label { color: var(--blue); }
.bar.second .bar-fill { background: var(--lime); }

.vision { display: flex; align-items: flex-start; justify-content: center; gap: 8px; }
.vision figure { margin: 0; flex: 1; max-width: 200px; text-align: center; }
.vision canvas {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; background: #000; display: block;
}
#photo-canvas { border-radius: 50%; }
#mnist-canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
.vision figcaption { font-size: 13px; color: var(--ink-2); margin-top: 6px; line-height: 1.4; white-space: nowrap; }
.arrow { font-size: 28px; font-weight: 800; color: var(--blue); align-self: center; margin-bottom: 1.6em; }
.note { font-size: 14px; color: var(--ink-2); margin-top: 12px !important; }

.result-actions { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

/* しくみ */
.flow { padding-left: 1.4em; margin: 8px 0 12px; }
.flow li { margin-bottom: 8px; }
.lab-card { display: flex; align-items: center; gap: 16px; }
.lab-card img { width: 72px; height: auto; }

/* スタッフ設定 */
.staff {
  margin-top: 24px; padding: 12px; border: 2px dashed var(--ink-2); border-radius: 12px; font-size: 15px;
}
.staff summary { font-weight: 700; cursor: pointer; }
.staff label { display: block; margin-top: 12px; font-weight: 600; }
.staff input[type=range] { width: 100%; }
.staff .check { display: flex; gap: 8px; align-items: center; }
.staff small { color: var(--ink-2); }
#staff-info { font-family: ui-monospace, monospace; font-size: 13px; color: var(--ink-2); }

/* モーダル・ローディング */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.7);
  display: grid; place-items: center; padding: 16px;
}
.modal-body {
  background: #fff; border-radius: var(--radius); padding: 16px; max-width: 420px; width: 100%;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.modal-body img { width: 100%; border-radius: 8px; -webkit-touch-callout: default; }
.modal-body p { margin: 0; }

.loading {
  position: fixed; inset: 0; z-index: 40; background: rgba(251,248,242,.85);
  display: grid; place-content: center; justify-items: center; gap: 12px; font-weight: 700;
}
.spinner {
  width: 56px; height: 56px; border-radius: 50%;
  border: 6px solid #d9e3ec; border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- バージョン（v1/v2）の切り替え（結果画面の比較カード内） ---- */
.topbar-home {
  flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.topbar-home:active { opacity: .6; }
.sound-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; font-size: 18px; cursor: pointer;
}
.engine { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 14px 0 4px; }
.engine-label { margin: 0 !important; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.engine-switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: #ece6da; border-radius: 999px; width: min(100%, 300px);
}
.engine-switch button {
  border: 0; border-radius: 999px; padding: 8px 12px; min-height: 44px; cursor: pointer; background: transparent;
  font: 800 16px/1.1 ui-monospace, Menlo, monospace; color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background-color .25s, color .25s;
  -webkit-tap-highlight-color: transparent;
}
.engine-switch button small { font: 700 12px/1 -apple-system, "Hiragino Sans", sans-serif; }
.engine-switch button[aria-checked="true"] { color: #fff; background: var(--blue); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.engine-switch button[data-version="v1"][aria-checked="true"] { background: #8a9a5b; }
.compare-col { cursor: pointer; transition: border-color .25s, transform .15s; -webkit-tap-highlight-color: transparent; }
.compare-col:active { transform: scale(.97); }

.answer-engine {
  margin: 0 0 4px; font: 800 12px/1 ui-monospace, Menlo, monospace; letter-spacing: .12em; opacity: .75;
}

.compare-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-col {
  margin: 0; padding: 10px; border-radius: 12px; border: 2px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.compare-col.current { border-color: var(--blue); }
.compare-col canvas {
  width: 100%; max-width: 120px; aspect-ratio: 1 / 1; background: #000; border-radius: 8px;
  image-rendering: pixelated;
}
.compare-col figcaption { font-weight: 800; font-size: 15px; line-height: 1.3; }
.compare-col figcaption .big { font-size: 28px; display: block; }
.compare-col figcaption .ok { color: var(--green); }
.compare-col figcaption .ng { color: #c0392b; }
.tag { font: 800 12px/1 ui-monospace, Menlo, monospace; padding: 5px 8px; border-radius: 6px; color: #fff; }
.tag-v1 { background: #8a9a5b; }
.tag-v2 { background: var(--blue); }

/* ---- リンク集 ---- */
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.links a {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; text-decoration: none; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); min-height: 52px;
}
.links a:active { transform: scale(.98); }
.link-kicker {
  font-size: 11px; font-weight: 800; color: #fff; padding: 3px 7px; border-radius: 6px; background: var(--green);
}
.links li:nth-child(1) .link-kicker { background: var(--sky); }
.links li:nth-child(2) .link-kicker { background: var(--blue); }
.links b { font-size: 15px; line-height: 1.35; }
.link-go { font-size: 22px; color: var(--blue); font-weight: 800; }
.links-lead { font-size: 15px; }

/* ---- 解析アニメーション ---- */
.analyzer {
  position: fixed; inset: 0; z-index: 60; background: #030b16;
  padding-top: env(safe-area-inset-top, 0px); cursor: pointer;
}
.analyzer canvas { position: absolute; inset: 0; display: block; }

.improve { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.improve summary { font-weight: 800; color: var(--blue); cursor: pointer; }
.improve ol { margin: 8px 0 0; padding-left: 1.3em; font-size: 14px; line-height: 1.6; }
.improve li { margin-bottom: 6px; }

/* ---- しくみ画面 ---- */
.world { gap: 16px; }
.world-hero p { margin: 8px 0 0; }
.world-toc { list-style: none; padding: 0; margin: 12px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; counter-reset: lv; }
.world-toc li { counter-increment: lv; }
.world-toc a {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; text-decoration: none;
  color: var(--ink); font-weight: 700; font-size: 14px; background: #fff; border: 1px solid var(--line);
}
.world-toc a::before {
  content: counter(lv); display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font: 800 12px ui-monospace, Menlo, monospace; color: #fff; background: var(--blue);
}
.world-toc li:nth-child(1) a::before { background: var(--sky); }
.world-toc li:nth-child(3) a::before { background: var(--green); }
.world-toc li:nth-child(4) a::before { background: var(--lime); }
.world-nodata { font-size: 13px; color: var(--ink-2); }

.level {
  padding: 18px 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line);
  scroll-margin-top: 80px;
}
.level h2 { font-size: 20px; margin: 4px 0 12px; }
.level h3 { font-size: 15px; color: var(--blue); margin: 18px 0 8px; }
.level p { margin: 0 0 10px; }
.level-no { margin: 0 !important; font: 800 12px/1 ui-monospace, Menlo, monospace; letter-spacing: .15em; color: var(--green); }

.mnist-sheet {
  display: block; width: 100%; max-width: 420px; margin: 0 auto 12px; border-radius: 8px; image-rendering: pixelated;
}
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.facts div { padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.facts dt { font-size: 12px; color: var(--ink-2); }
.facts dd { margin: 2px 0 0; font: 900 22px/1.2 ui-monospace, Menlo, monospace; color: var(--blue); }
.facts dd small { display: block; font: 600 12px/1.4 -apple-system, "Hiragino Sans", sans-serif; color: var(--ink-2); }

.grid-toggle {
  position: relative; display: block; width: 100%; max-width: 420px; margin: 0 auto 12px; padding: 0;
  border: 0; border-radius: 10px; overflow: hidden; background: #000; cursor: pointer;
}
.grid-toggle canvas { display: block; width: 100%; aspect-ratio: 1 / 1; }
.grid-toggle-label {
  position: absolute; right: 8px; bottom: 8px; padding: 6px 10px; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 800;
}

.pipeline { display: grid; gap: 6px; margin: 12px 0 6px; }
.pipe-head, .pipe-row { display: grid; grid-template-columns: 30px repeat(4, 1fr) 34px; gap: 5px; align-items: center; }
.pipe-head span { font-size: 10px; font-weight: 700; color: var(--ink-2); text-align: center; line-height: 1.2; word-break: keep-all; }
.pipe-row canvas { width: 100%; aspect-ratio: 1 / 1; border-radius: 6px; background: #000; image-rendering: pixelated; }
.pipe-row canvas[data-step="photo"] { image-rendering: auto; }
.pipe-row .tag { padding: 4px 4px; text-align: center; }
.pipe-answer { font: 900 24px/1 ui-monospace, Menlo, monospace; text-align: center; color: #8a9a5b; }
.pipe-row[data-version="v2"] .pipe-answer { color: var(--blue); }
.pipe-legend { font-size: 12px; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.pipe-legend .nw { display: inline-flex; align-items: center; gap: 4px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.sw-ok { background: #58e6ff; } .sw-ng { background: #ff5064; }
.sw-pos { background: var(--lime); } .sw-neg { background: var(--blue); }

.improve-cards { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; counter-reset: imp; }
.improve-cards li {
  counter-increment: imp; position: relative; padding: 12px 12px 12px 48px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); font-size: 14px; line-height: 1.6;
}
.improve-cards li::before {
  content: counter(imp); position: absolute; left: 12px; top: 12px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font: 900 14px ui-monospace, Menlo, monospace; color: #fff; background: var(--blue);
}
.improve-cards li > b { display: block; font-size: 16px; margin-bottom: 2px; }

.arch { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.arch-box {
  flex: 1 1 28%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px 4px; border-radius: 8px; background: var(--bg); border: 2px solid var(--line); text-align: center;
}
.arch-box b { font-size: 13px; }
.arch-box span { font: 700 11px/1.2 ui-monospace, Menlo, monospace; color: var(--ink-2); }
.arch-box.c1 { border-color: var(--sky); } .arch-box.c2 { border-color: var(--blue); }
.arch-box.c3 { border-color: var(--green); } .arch-box.fc, .arch-box.out { border-color: var(--lime); }

.tiles { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 6px 0 10px; }
.tiles canvas { width: 100%; aspect-ratio: 1 / 1; border-radius: 4px; image-rendering: pixelated; }
.maps-deep { grid-template-columns: repeat(16, 1fr); gap: 2px; }
.level-lab .lab-card { margin-bottom: 12px; }

/* 改行させたくない語句 */
.nw { white-space: nowrap; }
.btn-pick .ico { margin-right: 2px; }
.camera-actions .btn { white-space: nowrap; }

/* 小さい画面（幅 360px 以下） */
@media (max-width: 360px) {
  .camera-actions { gap: 6px; }
  .camera-actions .btn { font-size: 13px; padding: 8px 10px; }
  .btn-pick .ico { display: none; }
  .shutter { width: 72px; height: 72px; }
}
