:root {
  color-scheme: light;
  --ink: #172321;
  --ink-soft: #52605d;
  --paper: #f3f7f5;
  --surface: #ffffff;
  --line: #cbd6d2;
  --line-strong: #8fa19b;
  --teal: #087f79;
  --teal-dark: #075c59;
  --yellow: #f4ca52;
  --coral: #d95d51;
  --green: #28795c;
  --shadow: 0 16px 45px rgba(23, 35, 33, 0.1);
  font-family: "BIZ UDPGothic", "Yu Gothic UI", "Yu Gothic", sans-serif;
  font-synthesis: none;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(8, 127, 121, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(8, 127, 121, 0.055) 1px, transparent 1px);
  background-size: 32px 32px;
}

button,
select,
input {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(8, 127, 121, 0.28);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 14px max(24px, calc((100vw - 1180px) / 2));
  color: #fff;
  background: var(--ink);
  border-bottom: 4px solid var(--yellow);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--ink);
  font-weight: 900;
  background: var(--yellow);
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 18px;
}

.brand small {
  margin-top: -2px;
  color: #aebbb7;
  font-family: Consolas, monospace;
  font-size: 10px;
}

.header-count {
  margin: 0;
  color: #aebbb7;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.header-count strong {
  color: var(--yellow);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-logout {
  padding: 7px 0;
  color: #fff;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--yellow);
}

.header-logout:hover { color: var(--yellow); }

.login-main {
  display: grid;
  min-height: calc(100vh - 82px);
  place-items: center;
  padding: 40px 0;
}

.login-card {
  width: min(100%, 480px);
  padding: clamp(28px, 5vw, 48px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 8px 8px 0 var(--yellow), var(--shadow);
}

.login-card h1 { margin: 0; font-size: 36px; }

.login-form {
  display: grid;
  gap: 9px;
  margin-top: 30px;
}

.login-form label { font-weight: 800; }

.login-form input {
  width: 100%;
  height: 48px;
  margin-bottom: 13px;
  padding: 10px 14px;
  background: #fbfcfc;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.login-form .button { margin-top: 8px; }

.login-error { margin: 0; color: #a43830; font-weight: 700; }

main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

.view {
  animation: reveal 320ms ease-out both;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-heading {
  display: flex;
  gap: 32px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 36px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-family: Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  letter-spacing: 0;
}

.view-heading h1 {
  max-width: 720px;
  margin: 0;
  font-size: 40px;
  line-height: 1.2;
}

.lead {
  max-width: 650px;
  margin: 12px 0 0;
  color: var(--ink-soft);
}

.total-stamp,
.score-stamp {
  display: grid;
  min-width: 150px;
  min-height: 116px;
  padding: 18px;
  align-content: center;
  color: #fff;
  text-align: center;
  background: var(--teal-dark);
  border: 1px solid var(--ink);
  box-shadow: 7px 7px 0 var(--yellow);
}

.total-stamp strong,
.score-stamp strong {
  font-family: Consolas, monospace;
  font-size: 42px;
  line-height: 1;
}

.total-stamp span,
.score-stamp span {
  margin-top: 9px;
  font-family: Consolas, monospace;
  font-size: 11px;
}

.resume-panel {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding: 18px 20px;
  background: #fff9dc;
  border: 1px solid #d8bb4f;
}

.resume-panel p {
  display: inline;
  margin: 0 0 0 8px;
  color: var(--ink-soft);
  font-size: 14px;
}

.management-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.management-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
  padding: 20px 24px;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 4px 4px 0 #dce9e5;
}

.management-link:hover { border-color: var(--teal); background: #f2faf7; }

.management-link strong,
.management-link small { display: block; }

.management-link small { color: var(--ink-soft); font-size: 12px; }

.management-link-count { flex: 0 0 auto; color: var(--teal-dark); }

.management-link-count strong { display: inline; font: 700 24px Consolas, monospace; }

.management-back { display: inline-grid; flex: 0 0 auto; place-items: center; text-decoration: none; }

.management-actions { display: flex; justify-content: flex-end; margin-top: 24px; }

#wrong-view .wrong-list,
#excluded-view .excluded-list { max-height: none; overflow: visible; }

.wrong-filter-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
  background: #fffaf0;
}

.wrong-filter-label {
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
}

.wrong-filter-label input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--teal);
}

.wrong-filter-label strong,
.wrong-filter-label small {
  display: block;
}

.wrong-filter-label small,
.wrong-filter-count,
.wrong-item-meta {
  color: var(--ink-soft);
  font-size: 13px;
}

.wrong-filter-count { white-space: nowrap; }

.wrong-list {
  display: grid;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
}

.wrong-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.wrong-item p { margin: 4px 0 0; white-space: pre-wrap; }

.wrong-item .button { flex: 0 0 auto; }

.excluded-list,
.sessions-list {
  display: grid;
  gap: 10px;
}

.excluded-list {
  max-height: 260px;
  overflow-y: auto;
  color: var(--ink-soft);
}

.excluded-item,
.exclude-control {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
}

.excluded-item {
  padding: 9px 12px;
  background: #f8faf9;
  border: 1px solid var(--line);
}

.excluded-item input,
.exclude-control input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--teal);
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.session-item p {
  margin: 4px 0 0;
  color: var(--ink-soft);
}

.exclude-control {
  width: fit-content;
  margin: -12px 0 22px;
  padding: 9px 12px;
  color: var(--teal-dark);
  font-weight: 700;
  background: #e9f5f2;
  border: 1px solid #b5d7d1;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  background: var(--green);
  border-radius: 50%;
}

.setup-form {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.year-form {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  padding: 24px 32px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: 5px 5px 0 #dce9e5;
}

.year-form h2 { margin: 0; font-size: 24px; }
.year-form .field-note { margin: 6px 0 0; }

.year-controls {
  display: flex;
  flex: 0 0 auto;
  align-items: end;
  gap: 12px;
}

.year-controls label { align-self: center; font-weight: 800; }

.year-controls select {
  min-width: 145px;
  height: 48px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line-strong);
}

.setup-block {
  min-width: 0;
  margin: 0;
  padding: 28px 32px 32px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.setup-block legend {
  width: 100%;
  padding: 0;
  font-size: 20px;
  font-weight: 800;
}

.setup-block legend span,
.count-field b {
  margin-right: 10px;
  color: var(--teal);
  font-family: Consolas, monospace;
  font-size: 13px;
}

.field-note {
  margin: 3px 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

.source-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.source-option,
.category-option {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  cursor: pointer;
}

.source-option {
  min-height: 76px;
  padding: 14px 16px;
  background: #f8faf9;
  border: 1px solid var(--line);
}

.source-option:has(input:checked) {
  background: #e9f5f2;
  border-color: var(--teal);
  box-shadow: inset 4px 0 0 var(--teal);
}

.source-option input,
.category-option input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--teal);
}

.source-copy {
  min-width: 0;
}

.source-copy strong,
.source-copy small {
  display: block;
}

.source-copy strong {
  font-size: 15px;
  line-height: 1.45;
}

.source-copy small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-family: Consolas, monospace;
  font-size: 11px;
}

.category-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 18px;
}

.category-option {
  min-height: 44px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.4;
}

.category-option small {
  margin-left: auto;
  color: var(--ink-soft);
  font-family: Consolas, monospace;
  white-space: nowrap;
}

.empty-categories {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--coral);
}

.session-config {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(140px, auto) minmax(220px, auto);
  gap: 24px;
  align-items: end;
  padding: 26px 32px;
  background: #edf2f0;
}

.count-field span {
  display: block;
  margin-bottom: 7px;
  font-weight: 800;
}

.count-field select {
  width: 100%;
  height: 48px;
  padding: 0 42px 0 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
}

.pool-status {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-height: 48px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--line);
}

.pool-status span {
  margin-right: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

.pool-status strong {
  font-family: Consolas, monospace;
  font-size: 22px;
}

.pool-status small {
  margin-left: 3px;
}

.button {
  min-height: 48px;
  padding: 11px 22px;
  cursor: pointer;
  font-weight: 800;
  border: 1px solid transparent;
  border-radius: 4px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button-primary {
  color: #fff;
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.button-primary:not(:disabled):hover {
  background: var(--teal);
}

.button-secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--ink);
}

.button-secondary:hover,
.button-quiet:hover {
  background: #edf2f0;
}

.button-quiet {
  color: var(--ink);
  background: transparent;
  border-color: var(--line-strong);
}

.quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.text-button {
  padding: 7px 0;
  cursor: pointer;
  color: var(--teal-dark);
  font-weight: 800;
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
}

.progress-copy {
  display: flex;
  gap: 18px;
  align-items: center;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.progress-copy strong {
  color: var(--green);
}

.progress-track {
  display: block;
  width: 100%;
  height: 7px;
  margin-bottom: 28px;
  overflow: hidden;
  appearance: none;
  background: #d9e1de;
  border: 0;
}

.progress-track::-webkit-progress-bar {
  background: #d9e1de;
}

.progress-track::-webkit-progress-value {
  background: var(--yellow);
  transition: width 220ms ease;
}

.progress-track::-moz-progress-bar {
  background: var(--yellow);
}

.question-panel {
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.question-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.question-meta span {
  padding: 4px 8px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
  background: #e9f5f2;
  border: 1px solid #b5d7d1;
}

.question-title {
  max-width: 920px;
  margin: 0 0 28px;
  font-size: 25px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.inline-code {
  padding: 2px 5px;
  font-family: Consolas, monospace;
  font-size: 0.9em;
  font-weight: 500;
  background: #edf2f0;
  border: 1px solid #d3ddda;
}

.inline-math {
  font-family: Cambria, "Times New Roman", serif;
  font-style: italic;
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.choice-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 84px;
  padding: 14px 16px;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.choice-button:not(:disabled):hover {
  border-color: var(--teal);
}

.choice-button.selected {
  background: #e9f5f2;
  border-color: var(--teal);
  box-shadow: inset 4px 0 0 var(--teal);
}

.choice-button.correct {
  background: #e6f3ec;
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
}

.choice-button.incorrect {
  background: #fbeceb;
  border-color: var(--coral);
  box-shadow: inset 4px 0 0 var(--coral);
}

.choice-key {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  font-family: Consolas, monospace;
  font-size: 17px;
  font-weight: 900;
  background: #fff;
  border: 1px solid var(--line-strong);
}

.choice-text {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.feedback-panel {
  margin-top: 24px;
  padding: 22px;
  background: #f5f8f7;
  border-left: 5px solid var(--green);
}

.feedback-panel.is-wrong {
  border-left-color: var(--coral);
}

.feedback-heading {
  display: flex;
  gap: 14px;
  align-items: center;
}

.feedback-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  font-weight: 900;
  background: var(--green);
  border-radius: 50%;
}

.is-wrong .feedback-mark {
  background: var(--coral);
}

.feedback-heading p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.feedback-explanation {
  margin-top: 14px;
  padding-top: 14px;
  color: #34423f;
  border-top: 1px solid var(--line);
  white-space: pre-wrap;
}

.question-actions,
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 28px;
}

.question-actions .button-quiet {
  margin-right: auto;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 42px;
  background: #fff;
  border: 1px solid var(--line-strong);
}

.result-summary div {
  display: flex;
  min-height: 100px;
  padding: 22px;
  align-items: center;
  justify-content: space-between;
  border-right: 1px solid var(--line);
}

.result-summary div:last-child {
  border-right: 0;
}

.result-summary span {
  color: var(--ink-soft);
}

.result-summary strong {
  font-family: Consolas, monospace;
  font-size: 34px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
}

.section-heading h2 {
  margin: 0;
  font-size: 22px;
}

.section-heading span {
  color: var(--ink-soft);
  font-family: Consolas, monospace;
  font-size: 12px;
}

.review-list {
  display: grid;
  gap: 12px;
}

.review-item,
.review-empty {
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
}

.review-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.7fr);
  gap: 24px;
}

.review-item h3 {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.55;
}

.review-item p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.answer-compare {
  align-self: center;
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.answer-compare span {
  display: block;
  margin: 3px 0;
  font-size: 13px;
}

.answer-compare strong {
  display: inline-block;
  min-width: 22px;
  color: var(--green);
  font-family: Consolas, monospace;
}

.answer-compare .selected-wrong {
  color: var(--coral);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: min(420px, calc(100% - 48px));
  padding: 14px 18px;
  color: #fff;
  background: var(--coral);
  border: 1px solid #97372f;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .management-links { grid-template-columns: 1fr; }

  .year-form { align-items: stretch; flex-direction: column; }

  .category-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .session-config {
    grid-template-columns: 1fr 1fr;
  }

  .session-config .button-primary {
    grid-column: 1 / -1;
  }

  .choice-list {
    grid-template-columns: 1fr;
  }

  .review-item {
    grid-template-columns: 1fr;
  }

  .answer-compare {
    padding: 14px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .wrong-filter-block,
  .wrong-item {
    align-items: stretch;
    flex-direction: column;
  }

  .wrong-filter-block { padding: 20px 18px; }

  .management-link { padding: 18px; }

  .management-actions .button { width: 100%; }

  .session-item {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header {
    min-height: 68px;
    padding: 12px 16px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .header-count {
    display: none;
  }

  main {
    width: min(100% - 28px, 1180px);
    padding: 34px 0 56px;
  }

  .view-heading {
    align-items: stretch;
    flex-direction: column;
    margin-bottom: 28px;
  }

  .view-heading h1 {
    font-size: 30px;
  }

  .total-stamp,
  .score-stamp {
    grid-template-columns: auto auto;
    gap: 10px;
    min-width: 0;
    min-height: 72px;
    align-items: center;
    justify-content: center;
    box-shadow: 5px 5px 0 var(--yellow);
  }

  .total-stamp strong,
  .score-stamp strong {
    font-size: 32px;
  }

  .total-stamp span,
  .score-stamp span {
    margin-top: 0;
  }

  .resume-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .resume-panel p {
    display: block;
    margin: 5px 0 0 20px;
  }

  .setup-block,
  .session-config,
  .question-panel {
    padding: 22px 18px;
  }

  .year-form { padding: 22px 18px; }
  .year-controls { flex-wrap: wrap; }
  .year-controls .button { width: 100%; }

  .source-options,
  .category-options,
  .session-config {
    grid-template-columns: 1fr;
  }

  .session-config .button-primary {
    grid-column: auto;
  }

  .quiz-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .progress-copy {
    width: 100%;
    justify-content: space-between;
  }

  .question-title {
    font-size: 20px;
  }

  .choice-button {
    grid-template-columns: 36px minmax(0, 1fr);
    min-height: 76px;
  }

  .choice-key {
    width: 36px;
    height: 36px;
  }

  .question-actions,
  .result-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .question-actions .button-quiet {
    margin-right: 0;
  }

  .result-summary {
    grid-template-columns: 1fr;
  }

  .result-summary div {
    min-height: 72px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .result-summary div:last-child {
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}