:root {
  color-scheme: light;
  --ink: #17132b;
  --muted: #6c6880;
  --canvas: #f3f1f8;
  --paper: #ffffff;
  --line: #ddd9e8;
  --violet-950: #24145f;
  --violet-800: #43219a;
  --violet-600: #6d3be7;
  --violet-100: #eee8ff;
  --cyan: #14b8a6;
  --correct: #087f5b;
  --correct-bg: #e8f8f1;
  --wrong: #c23b54;
  --wrong-bg: #fff0f2;
  --shadow: 0 18px 50px rgba(34, 22, 74, 0.11);
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(109, 59, 231, 0.15), transparent 34rem),
    linear-gradient(180deg, #faf9fd 0, var(--canvas) 30rem);
}

button,
select {
  font: inherit;
}

button,
select,
.choice-button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.global-nav {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 2px 12px;
}

.global-nav a {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--violet-950);
  background: rgba(255, 255, 255, 0.82);
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
}

.global-nav a:focus-visible {
  outline: 3px solid rgba(109, 59, 231, 0.3);
  outline-offset: 2px;
}

.app-header {
  padding: 8px 2px 20px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 15px 5px 15px 5px;
  color: #fff;
  background: linear-gradient(145deg, var(--violet-600), var(--violet-950));
  box-shadow: 0 8px 22px rgba(67, 33, 154, 0.25);
  font-size: 1.3rem;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--violet-600);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  line-height: 1.35;
}

h1 span {
  color: var(--violet-800);
}

.chapter-note {
  margin: 10px 0 0 62px;
  color: var(--muted);
  font-size: 0.92rem;
}

.edition-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
  padding: 6px;
  border: 1px solid rgba(221, 217, 232, 0.9);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.edition-button {
  display: flex;
  min-width: 0;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.edition-button span {
  font-size: 0.9rem;
  font-weight: 800;
}

.edition-button strong {
  padding: 2px 7px;
  border-radius: 999px;
  color: inherit;
  background: rgba(108, 104, 128, 0.1);
  font-size: 0.72rem;
}

.edition-button.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--violet-600), var(--violet-950));
  box-shadow: 0 6px 16px rgba(67, 33, 154, 0.2);
}

.edition-button[data-edition="practical"].is-active {
  background: linear-gradient(135deg, #0f9c8e, #09645e);
  box-shadow: 0 6px 16px rgba(8, 115, 106, 0.2);
}

.edition-button.is-active strong {
  background: rgba(255, 255, 255, 0.17);
}

.control-panel {
  display: grid;
  grid-template-columns: 1.45fr 0.9fr 0.9fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid rgba(221, 217, 232, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
}

.control-panel label {
  display: grid;
  gap: 6px;
}

.control-panel label > span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: #fff;
  font-size: 0.92rem;
  cursor: pointer;
}

select:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(109, 59, 231, 0.28);
  outline-offset: 2px;
}

.progress-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  margin: 0 2px 12px;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #ded9eb;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--violet-600), var(--cyan));
  transition: width 240ms ease;
}

.lifetime-stat {
  display: grid;
  justify-items: end;
}

.lifetime-stat span {
  color: var(--muted);
  font-size: 0.7rem;
}

.lifetime-stat strong {
  color: var(--violet-800);
  font-size: 1.15rem;
}

.quiz-card,
.state-card {
  overflow: hidden;
  border: 1px solid rgba(221, 217, 232, 0.92);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.quiz-card {
  padding: clamp(20px, 5vw, 34px);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.edition-badge,
.chapter-badge,
.topic-badge,
.difficulty-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
}

.edition-badge {
  color: #fff;
  background: var(--violet-600);
}

.edition-badge.practical {
  background: #08736a;
}

.chapter-badge {
  color: #fff;
  background: var(--violet-950);
}

.topic-badge {
  color: var(--violet-800);
  background: var(--violet-100);
}

.difficulty-badge {
  color: #08736a;
  background: #e6f8f5;
}

.question-text {
  margin: 0 0 22px;
  font-size: clamp(1.08rem, 4.5vw, 1.35rem);
  line-height: 1.72;
  letter-spacing: 0.01em;
}

.question-text:has(+ .calculation-note:not([hidden])) {
  margin-bottom: 9px;
}

.calculation-note {
  margin: 0 0 17px;
  color: #08736a;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.5;
}

.choices {
  display: grid;
  gap: 11px;
}

.choice-button {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  line-height: 1.55;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.choice-button > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.choice-button:hover:not(:disabled) {
  border-color: var(--violet-600);
  background: #faf8ff;
  transform: translateY(-1px);
}

.choice-button:disabled {
  cursor: default;
  opacity: 1;
}

.choice-key {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 9px;
  color: var(--violet-800);
  background: var(--violet-100);
  font-size: 0.78rem;
  font-weight: 900;
}

.choice-button.is-correct {
  border-color: rgba(8, 127, 91, 0.55);
  background: var(--correct-bg);
}

.choice-button.is-correct .choice-key {
  color: #fff;
  background: var(--correct);
}

.choice-button.is-wrong {
  border-color: rgba(194, 59, 84, 0.55);
  background: var(--wrong-bg);
}

.choice-button.is-wrong .choice-key {
  color: #fff;
  background: var(--wrong);
}

.feedback {
  margin: 22px -34px -34px;
  padding: 22px 34px 28px;
  border-top: 1px solid var(--line);
  background: #faf9fc;
}

.feedback-result {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 900;
}

.feedback-result.correct {
  color: var(--correct);
}

.feedback-result.wrong {
  color: var(--wrong);
}

.correct-answer {
  margin: 0 0 15px;
  font-weight: 700;
  line-height: 1.55;
}

.explanation-block {
  padding: 14px 16px;
  border-left: 4px solid var(--violet-600);
  border-radius: 4px 12px 12px 4px;
  background: #fff;
}

.explanation-block span {
  color: var(--violet-800);
  font-size: 0.78rem;
  font-weight: 900;
}

.explanation-block p {
  margin: 5px 0 0;
  line-height: 1.75;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  padding: 10px 17px;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--violet-600), var(--violet-950));
  box-shadow: 0 8px 20px rgba(67, 33, 154, 0.2);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--violet-800);
  background: #fff;
}

.feedback .primary-button {
  width: 100%;
}

.state-card {
  padding: 38px 28px;
  text-align: center;
}

.state-card h2 {
  margin: 12px 0 8px;
}

.state-card > p:not(.eyebrow) {
  margin: 0 auto 22px;
  color: var(--muted);
  line-height: 1.65;
}

.state-icon {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto;
  place-items: center;
  border-radius: 18px;
  color: var(--correct);
  background: var(--correct-bg);
  font-size: 1.4rem;
  font-weight: 900;
}

.result-score {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 5px;
  margin-top: 6px;
  color: var(--violet-800);
}

.result-score strong {
  font-size: clamp(3.2rem, 14vw, 5rem);
  line-height: 1;
}

.result-score span {
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 800;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 4px 0;
  color: var(--muted);
  font-size: 0.75rem;
}

[hidden] {
  display: none !important;
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 13px;
  }

  .control-panel {
    grid-template-columns: 1fr 1fr;
  }

  .control-panel label:first-child {
    grid-column: 1 / -1;
  }

  .control-panel .secondary-button {
    grid-column: 1 / -1;
  }

  .quiz-card {
    padding: 20px 17px;
    border-radius: 20px;
  }

  .feedback {
    margin: 22px -17px -20px;
    padding: 20px 17px 22px;
  }

  footer {
    flex-direction: column;
    align-items: center;
  }
}

@media (max-width: 390px) {
  .edition-button {
    flex-direction: column;
    gap: 2px;
    padding-inline: 5px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .control-panel .secondary-button {
    grid-column: auto;
  }

  .control-panel label:first-child {
    grid-column: auto;
  }

  .chapter-note {
    margin-left: 0;
  }
}

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