:root {
  color-scheme: light;
  --ink-950: #0d2832;
  --ink-800: #173e49;
  --teal-700: #087267;
  --teal-600: #0b8a7c;
  --teal-100: #dff5f1;
  --blue-100: #e5f0f4;
  --paper: #ffffff;
  --surface: #eef3f5;
  --surface-2: #f7fafb;
  --line: #cedbdf;
  --muted: #63777f;
  --correct: #087257;
  --correct-bg: #e2f7ef;
  --wrong: #bc3f53;
  --wrong-bg: #fff0f2;
  --shadow: 0 18px 46px rgba(13, 40, 50, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--surface);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink-950);
  background-color: var(--surface);
  background-image:
    linear-gradient(rgba(13, 40, 50, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 40, 50, 0.018) 1px, transparent 1px);
  background-size: 30px 30px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button,
select,
.quiz-card,
.state-card {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(11, 138, 124, 0.3);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100% - 28px, 920px);
  margin: 0 auto;
  padding: 22px 0 calc(34px + 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(--ink-800);
  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(11, 138, 124, 0.3);
  outline-offset: 2px;
}

.app-header {
  position: relative;
  display: flex;
  min-height: 124px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  overflow: hidden;
  padding: 24px 26px;
  border-radius: 24px 24px 9px 24px;
  color: #fff;
  background:
    linear-gradient(90deg, transparent 0 68%, rgba(255, 255, 255, 0.045) 68% 68.4%, transparent 68.4%),
    linear-gradient(135deg, var(--ink-800), var(--ink-950));
  box-shadow: var(--shadow);
}

.app-header::after {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 34%;
  height: 5px;
  background: var(--teal-600);
  content: "";
}

.brand-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 54px;
  height: 58px;
  align-content: center;
  gap: 7px;
  padding: 12px 11px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px 9px 3px 9px;
  background: rgba(255, 255, 255, 0.09);
}

.brand-mark span {
  height: 4px;
  border-radius: 999px;
  background: #fff;
}

.brand-mark span:nth-child(2) {
  width: 72%;
  background: #65d5c7;
}

.eyebrow {
  margin: 0 0 5px;
  color: #9ddfd7;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1.25;
  letter-spacing: 0.01em;
}

h1 span {
  display: block;
  margin-top: 2px;
  color: #d9f4f0;
  font-size: 0.58em;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.coverage-card {
  display: grid;
  flex: 0 0 auto;
  gap: 4px;
  min-width: 148px;
  padding: 13px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px 14px 4px 14px;
  background: rgba(255, 255, 255, 0.08);
}

.coverage-card span {
  color: #afd0d6;
  font-size: 0.78rem;
}

.coverage-card strong {
  font-size: 0.95rem;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
}

.summary-strip > div {
  display: grid;
  gap: 2px;
  min-height: 68px;
  align-content: center;
  padding: 11px 18px;
  border-right: 1px solid var(--line);
}

.summary-strip > div:last-child {
  border-right: 0;
}

.summary-strip span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.summary-strip strong {
  color: var(--ink-800);
  font-size: 0.94rem;
}

.summary-strip b {
  color: var(--teal-700);
  font-size: 1.2rem;
}

.control-panel {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 7px 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 28px rgba(13, 40, 50, 0.055);
}

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

.control-panel label > span {
  padding-left: 2px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 38px 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-950);
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-800) 50%), linear-gradient(135deg, var(--ink-800) 50%, transparent 50%);
  background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
  appearance: none;
  cursor: pointer;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  padding: 10px 17px;
  border-radius: 10px 10px 4px 10px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  border: 1px solid var(--teal-700);
  color: #fff;
  background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
  box-shadow: 0 8px 18px rgba(8, 114, 103, 0.2);
}

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

.control-panel .secondary-button {
  white-space: nowrap;
}

.progress-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  margin-bottom: 12px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal-600);
  border-radius: 7px 16px 16px 7px;
  background: #fff;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--ink-800);
  font-size: 0.875rem;
  font-weight: 800;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--blue-100);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal-600), #38b9aa);
  transition: width 260ms ease;
}

.lifetime-stat {
  display: grid;
  min-width: 148px;
  gap: 2px;
  text-align: right;
}

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

.lifetime-stat strong {
  color: var(--teal-700);
  font-size: 1.22rem;
}

.quiz-card,
.state-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px 22px 8px 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

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

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

.chapter-badge,
.topic-badge,
.difficulty-badge {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  padding: 4px 10px;
  border-radius: 7px 7px 3px 7px;
  font-size: 0.78rem;
  font-weight: 800;
}

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

.topic-badge {
  color: var(--teal-700);
  background: var(--teal-100);
}

.difficulty-badge {
  color: #526c75;
  background: var(--blue-100);
}

.question-text {
  margin: 0 0 24px;
  font-size: clamp(1.18rem, 3.8vw, 1.42rem);
  line-height: 1.65;
  letter-spacing: 0.01em;
}

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

.calculation-note {
  margin: 0 0 18px;
  color: var(--teal-700);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.5;
}

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

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

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

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

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

.choice-key {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px 8px 3px 8px;
  color: var(--ink-800);
  background: var(--blue-100);
  font-size: 0.8rem;
  font-weight: 900;
}

.choice-button.is-correct {
  border-color: rgba(8, 114, 87, 0.5);
  background: var(--correct-bg);
}

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

.choice-button.is-wrong {
  border-color: rgba(188, 63, 83, 0.52);
  background: var(--wrong-bg);
}

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

.feedback {
  margin: 24px -36px -36px;
  padding: 22px 36px 28px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.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: 800;
  line-height: 1.6;
}

.explanation-block {
  padding: 15px 17px;
  border-left: 4px solid var(--teal-600);
  border-radius: 4px 12px 12px 4px;
  background: #fff;
}

.explanation-block span {
  color: var(--teal-700);
  font-size: 0.8rem;
  font-weight: 900;
}

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

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

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

.state-card h2 {
  margin: 12px 0 7px;
  font-size: 1.35rem;
}

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

.state-icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto;
  place-items: center;
  border-radius: 12px 12px 4px 12px;
  color: #fff;
  background: var(--teal-600);
  font-size: 1.5rem;
  font-weight: 900;
}

.result-eyebrow {
  color: var(--teal-700);
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}

.result-score strong {
  color: var(--ink-950);
  font-size: clamp(3.1rem, 13vw, 4.8rem);
  line-height: 1;
}

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

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

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

@media (max-width: 760px) {
  .control-panel {
    grid-template-columns: 1fr 1fr;
  }

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

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

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 920px);
    padding-top: 9px;
  }

  .app-header {
    min-height: auto;
    padding: 18px;
    border-radius: 18px 18px 7px 18px;
  }

  .brand-mark {
    width: 48px;
    height: 52px;
  }

  .coverage-card {
    display: none;
  }

  .summary-strip > div {
    min-height: 61px;
    padding: 9px 11px;
  }

  .summary-strip span {
    font-size: 0.72rem;
  }

  .summary-strip strong {
    font-size: 0.8rem;
  }

  .summary-strip b {
    font-size: 1.05rem;
  }

  .progress-panel {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .lifetime-stat {
    display: flex;
    justify-content: space-between;
    text-align: left;
  }

  .quiz-card {
    padding: 21px 17px;
    border-radius: 18px 18px 6px 18px;
  }

  .choice-button {
    grid-template-columns: 34px 1fr;
    gap: 10px;
    padding: 11px 12px;
  }

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

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

@media (max-width: 390px) {
  .control-panel {
    grid-template-columns: 1fr;
  }

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

  .summary-strip > div:last-child {
    display: none;
  }

  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-strip > div:nth-child(2) {
    border-right: 0;
  }

  .result-actions {
    flex-direction: column;
  }
}

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