:root {
  --ink: #24324a;
  --muted: #66758d;
  --line: #dfe7f1;
  --panel: #ffffff;
  --background: #f6f9fd;
  --primary: #4263eb;
  --primary-dark: #334ec4;
  --primary-soft: #eef2ff;
  --cyan: #59c3c3;
  --yellow: #f6c85f;
  --success: #177b64;
  --success-soft: #e8f8f2;
  --warm: #b85c38;
  --warm-soft: #fff2ea;
  --shadow: 0 18px 50px rgba(46, 70, 104, 0.11);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  font-family: "BIZ UDPGothic", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--background);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-width: 300px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 12%, rgba(123, 223, 242, .16), transparent 25rem),
    radial-gradient(circle at 92% 92%, rgba(246, 200, 95, .13), transparent 28rem),
    var(--background);
  color: var(--ink);
}

button, select, input { font: inherit; }
button { color: inherit; }
button:not(:disabled), select, input[type="range"], input[type="checkbox"] { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid rgba(66, 99, 235, .32);
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; }
.screen { display: none; min-height: 100vh; }
.screen.is-active { display: block; }

.home-header {
  width: min(1180px, calc(100% - 48px));
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.86);
  font-weight: 800;
  font-size: 1.12rem;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.icon-button:hover { transform: translateY(-1px); background: #fff; border-color: #cbd8e7; }

.home-grid {
  width: min(1120px, calc(100% - 56px));
  min-height: calc(100vh - 94px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(390px, 470px);
  gap: clamp(48px, 7vw, 96px);
  align-items: center;
  padding: 34px 0 76px;
}

.hero-copy { position: relative; padding: 20px 0 210px; }
.eyebrow, .question-kicker {
  color: #526a8d;
  font-size: .88rem;
  font-weight: 800;
  letter-spacing: .09em;
}
.eyebrow { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.eyebrow-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--cyan); transform: rotate(12deg); }
.hero-copy h1 {
  margin: 0;
  font-size: clamp(3.5rem, 7vw, 6.2rem);
  line-height: .98;
  letter-spacing: -.06em;
  color: #273653;
}
.subtitle { margin: 22px 0 0; color: var(--primary); font-weight: 800; font-size: clamp(1rem, 1.8vw, 1.3rem); }
.home-lead { margin: 24px 0 0; color: var(--muted); line-height: 1.9; font-size: 1rem; }

.net-illustration {
  position: absolute;
  left: 8%;
  bottom: 12px;
  width: 300px;
  height: 184px;
  filter: drop-shadow(0 12px 16px rgba(53,77,110,.14));
  transform: rotate(-4deg);
}
.mini-face {
  position: absolute;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(39,54,83,.42);
  font-weight: 900;
  color: rgba(39,54,83,.76);
  font-size: 1.1rem;
}
.mini-face.f1 { left: 62px; top: 0; background: #f6c85f; }
.mini-face.f2 { left: 0; top: 62px; background: #7bdff2; }
.mini-face.f3 { left: 62px; top: 62px; background: #b2f7ef; }
.mini-face.f4 { left: 124px; top: 62px; background: #cdb4db; }
.mini-face.f5 { left: 186px; top: 62px; background: #ff8fab; }
.mini-face.f6 { left: 62px; top: 124px; background: #a0c4ff; }

.start-card {
  padding: 32px;
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(210,221,235,.85);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.choice-group { border: 0; padding: 0; margin: 0 0 28px; }
.choice-group legend { width: 100%; margin: 0 0 14px; font-weight: 900; font-size: 1.02rem; }
.step-number {
  display: inline-grid; place-items: center; width: 27px; height: 27px; margin-right: 7px;
  background: #edf1f7; border-radius: 9px; color: #5c6e88; font-size: .8rem;
}
.mode-options { display: grid; gap: 10px; }
.choice-card {
  width: 100%;
  min-height: 76px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 45px 1fr 28px;
  gap: 13px;
  align-items: center;
  text-align: left;
  border: 2px solid #e4eaf2;
  border-radius: 16px;
  background: #fff;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.choice-card:hover { transform: translateY(-1px); border-color: #cbd6e7; }
.choice-card.is-selected { border-color: var(--primary); background: var(--primary-soft); }
.choice-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #fff6da; color: #a46f00; font-size: 1.35rem; }
.choice-icon.relation-icon { background: #e6f9f7; color: #167c78; }
.choice-card strong, .choice-card small { display: block; }
.choice-card strong { font-size: 1rem; }
.choice-card small { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.choice-check { opacity: 0; width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 900; }
.choice-card.is-selected .choice-check { opacity: 1; }

.difficulty-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.difficulty-button {
  min-height: 62px;
  border: 1px solid #dfe6ef;
  border-radius: 14px;
  background: #fff;
  padding: 8px 6px;
}
.difficulty-button span, .difficulty-button small { display: block; }
.difficulty-button span { font-size: .83rem; font-weight: 800; }
.difficulty-button small { margin-top: 5px; color: #d29b19; letter-spacing: 1px; font-size: .72rem; }
.difficulty-button.is-selected { border: 2px solid var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

.primary-button, .secondary-button, .small-button, .text-icon-button {
  border: 0;
  border-radius: 14px;
  font-weight: 900;
  transition: transform .15s ease, filter .15s ease, background .15s ease;
}
.primary-button { min-height: 52px; padding: 0 22px; background: var(--primary); color: #fff; box-shadow: 0 8px 18px rgba(66,99,235,.21); }
.primary-button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.04); }
.primary-button:disabled { background: #b9c2d0; box-shadow: none; cursor: not-allowed; }
.secondary-button { min-height: 50px; padding: 0 20px; color: #52627a; background: #eef2f7; }
.secondary-button:hover:not(:disabled), .small-button:hover:not(:disabled) { background: #e3e9f1; }
.secondary-button:disabled { opacity: .48; cursor: not-allowed; }
.start-button { width: 100%; min-height: 60px; display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 1.05rem; }
.start-button span { font-size: 1.35rem; }
.last-result { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: .82rem; }

/* Problem screen */
.screen-problem { padding-bottom: 24px; }
.problem-topbar {
  height: 72px;
  padding: 0 clamp(18px, 3vw, 42px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid rgba(215,225,237,.9);
  background: rgba(255,255,255,.84);
  backdrop-filter: blur(15px);
  position: relative;
  z-index: 5;
}
.topbar-left, .topbar-actions, .problem-meta { display: flex; align-items: center; gap: 9px; }
.topbar-actions { justify-content: flex-end; }
.brand-mini { font-weight: 900; letter-spacing: -.02em; }
.home-button { width: 39px; height: 39px; }
.meta-pill { padding: 7px 12px; border-radius: 999px; background: #edf4ff; color: #365a91; font-size: .78rem; font-weight: 900; white-space: nowrap; }
.difficulty-pill { background: #fff6da; color: #8d6814; }
.score-badge { min-width: 60px; padding-left: 7px; color: #708096; font-size: .82rem; }
.score-badge strong { color: var(--ink); font-size: 1.02rem; }
.text-icon-button { min-height: 40px; padding: 0 13px; color: #52647c; background: #eef3f8; }
.text-icon-button[aria-pressed="true"] { color: #fff; background: #50637f; }

.teacher-panel {
  width: min(1180px, calc(100% - 48px));
  margin: 12px auto -4px;
  padding: 10px 16px;
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  border: 1px dashed #9ba9bd;
  border-radius: 13px;
  background: #f2f5f9;
  color: #4e5d73;
  font-size: .84rem;
}
.teacher-panel[hidden] { display: none; }
.teacher-callout { padding: 5px 10px; border-radius: 999px; background: #fff1c8; color: #795912; font-weight: 900; }
.teacher-panel label { display: flex; gap: 7px; align-items: center; }
.teacher-panel select { max-width: 180px; border: 1px solid #cbd5e2; border-radius: 8px; padding: 5px; background: #fff; }

.problem-layout {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: clamp(22px, 3.5vh, 40px) 0 0;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, .85fr);
  gap: clamp(24px, 4vw, 48px);
  align-items: start;
}
.question-heading { min-height: 92px; }
.question-heading h2 { margin: 7px 0 0; font-size: clamp(1.35rem, 2.3vw, 2rem); line-height: 1.4; letter-spacing: -.025em; }
.question-kicker { display: inline-block; color: #6b7e98; }

.stage-card {
  position: relative;
  height: min(55vh, 540px);
  min-height: 360px;
  overflow: hidden;
  border: 1px solid #dce5ef;
  border-radius: 24px;
  background:
    linear-gradient(rgba(111,134,161,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(111,134,161,.055) 1px, transparent 1px),
    linear-gradient(145deg, #fff, #f3f8fc);
  background-size: 28px 28px, 28px 28px, auto;
  box-shadow: 0 12px 34px rgba(61,81,111,.08);
}
.stage { position: absolute; inset: 0; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 7px 12px;
  border: 1px solid rgba(204,215,229,.9);
  border-radius: 999px;
  background: rgba(255,255,255,.86);
  color: #687a93;
  font-size: .76rem;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
.stage-error { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; background: #fff8f5; color: #8c4b3c; }
.stage-error[hidden] { display: none; }

.progress-wrap { margin-top: 12px; padding: 8px 12px 2px; }
.progress-wrap label { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; color: #728097; font-size: .72rem; font-weight: 800; }
.progress-wrap label span:nth-child(2) { color: var(--primary); }
.progress-wrap label span:last-child { text-align: right; }
.progress-wrap input { width: 100%; accent-color: var(--primary); }

.answer-column { padding-top: 96px; }
.answer-card, .feedback-card {
  padding: 22px;
  border: 1px solid #dce5ef;
  border-radius: 21px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 30px rgba(61,81,111,.07);
}
.answer-prompt { margin-bottom: 14px; font-weight: 900; color: #53647d; font-size: .9rem; }
.answer-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.answer-option {
  min-height: 66px;
  padding: 10px 12px;
  border: 2px solid #dce5ef;
  border-radius: 16px;
  background: #fff;
  font-weight: 900;
  font-size: .96rem;
}
.answer-option:hover:not(:disabled) { border-color: #aebeda; background: #f9fbff; }
.answer-option.is-selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.answer-option:disabled:not(.is-selected) { opacity: .55; }
.answer-options.face-options { grid-template-columns: repeat(3, 1fr); }
.face-answer { min-height: 58px; font-size: 1.1rem; }
.face-swatch { display: inline-block; width: 13px; height: 13px; margin-right: 7px; border: 1px solid rgba(0,0,0,.2); border-radius: 4px; vertical-align: -1px; }

.fold-actions { margin-top: 16px; border-top: 1px solid #edf1f5; padding-top: 16px; }
.fold-button { width: 100%; min-height: 56px; }
.animation-tools { margin-top: 11px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 7px; }
.small-button { min-height: 38px; padding: 0 9px; background: #edf2f7; color: #53657c; font-size: .75rem; }
.small-button:disabled { opacity: .44; cursor: not-allowed; }
.speed-control { display: flex; align-items: center; gap: 5px; color: #6f7f93; font-size: .72rem; }
.speed-control select { height: 38px; border: 1px solid #d9e1eb; border-radius: 10px; background: #fff; padding: 0 6px; color: #53657c; font-size: .75rem; }

.feedback-card { margin-top: 13px; display: flex; gap: 14px; align-items: flex-start; box-shadow: none; }
.feedback-card[hidden] { display: none; }
.feedback-card.is-correct { background: var(--success-soft); border-color: #b9e5d6; }
.feedback-card.is-miss { background: var(--warm-soft); border-color: #f0c9ba; }
.feedback-mark { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--success); color: #fff; font-weight: 900; }
.is-miss .feedback-mark { background: var(--warm); }
.feedback-card h3 { margin: 1px 0 4px; font-size: 1.04rem; }
.feedback-card p { margin: 0; color: #53647a; line-height: 1.65; font-size: .86rem; }
.question-nav { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Result */
.screen-results.is-active { display: grid; place-items: center; padding: 36px 20px; }
.result-card {
  width: min(600px, 100%);
  padding: 38px;
  text-align: center;
  border: 1px solid #dce5ef;
  border-radius: 30px;
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
}
.result-icon { width: 50px; height: 50px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 15px; background: #fff3c9; color: #bd8614; font-size: 1.6rem; }
.result-kicker { margin: 0; color: var(--primary); font-weight: 900; font-size: .85rem; letter-spacing: .08em; }
.result-card h2 { margin: 7px 0 20px; font-size: 1.8rem; }
.score-ring {
  width: 150px; height: 150px; margin: 0 auto 24px; display: grid; place-content: center;
  border: 12px solid #e9eef6; border-top-color: var(--primary); border-right-color: var(--cyan); border-radius: 50%;
}
.score-ring strong { display: block; font-size: 2rem; color: var(--primary-dark); }
.score-ring span { color: #718099; font-size: .73rem; font-weight: 800; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.result-stats div { padding: 13px 7px; border-radius: 14px; background: #f5f8fb; }
.result-stats span, .result-stats strong { display: block; }
.result-stats span { color: #78879a; font-size: .72rem; }
.result-stats strong { margin-top: 4px; font-size: 1rem; }
.result-breakdown { margin-top: 11px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-breakdown[hidden] { display: none; }
.result-breakdown span { padding: 9px; border: 1px solid #e4eaf2; border-radius: 11px; color: #697a91; font-size: .75rem; }
.result-breakdown strong { margin-left: 4px; color: var(--ink); }
.result-message { min-height: 50px; margin: 20px 0; color: #53657b; line-height: 1.7; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Settings */
.settings-dialog {
  width: min(500px, calc(100% - 30px));
  padding: 0;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(28,40,57,.24);
}
.settings-dialog::backdrop { background: rgba(32,44,62,.36); backdrop-filter: blur(3px); }
.settings-dialog form { padding: 25px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.dialog-heading h2 { margin: 4px 0 0; }
.setting-row { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #edf1f5; }
.setting-row strong, .setting-row small { display: block; }
.setting-row small { margin-top: 4px; color: var(--muted); font-size: .75rem; }
.setting-row input { width: 22px; height: 22px; accent-color: var(--primary); }
.danger-link { margin: 18px 0; padding: 6px 0; border: 0; background: none; color: #a64a3f; text-decoration: underline; }
.dialog-done { width: 100%; }

body.teacher-mode .question-heading h2 { font-size: clamp(1.65rem, 2.65vw, 2.35rem); }
body.teacher-mode .score-badge { display: none; }
body.hide-student-answers .answer-options { visibility: hidden; }
body.hide-student-answers .answer-prompt::after { content: "みんなで予想してから、先生が答えを表示します。"; display: block; color: #846316; background: #fff5d7; padding: 12px; border-radius: 12px; margin-top: 10px; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
