:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #62706c;
  --line: #d8e2df;
  --surface: #f7faf8;
  --paper: #ffffff;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #d97706;
  --danger: #b42318;
  --success: #067647;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

body.has-site-promo .app-shell {
  padding-top: calc(max(16px, env(safe-area-inset-top)) + 72px);
}

.top-band {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 0 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 36px;
  line-height: 1.1;
}

.lead {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.score-chip {
  flex: 0 0 auto;
  display: grid;
  min-width: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
}

.score-chip span {
  color: var(--muted);
  font-size: 12px;
}

.score-chip strong {
  font-size: 26px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.status-grid article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.mode-tabs button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-weight: 700;
}

.mode-tabs button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.app-status {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0;
}

.app-status span {
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.site-promo-banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 60;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
  width: min(calc(100% - 32px), 760px);
  min-height: 58px;
  padding: 10px;
  border-radius: 8px;
  background: #075bbb;
  box-shadow: 0 14px 28px rgba(7, 91, 187, 0.24);
  transform: translateX(-50%);
}

.site-promo-banner.is-hidden {
  display: none;
}

.site-promo-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: #fff;
  text-decoration: none;
}

.site-promo-link img {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 7px;
}

.site-promo-link strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-promo-link small {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.45;
}

.site-promo-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.site-promo-close:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

.question-panel,
.result-panel,
.focus-tools,
.persona-panel,
.history-panel,
.log-panel,
.settings-panel,
.data-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.question-meta,
.result-head,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

#question-text {
  margin: 16px 0;
  font-size: 20px;
  line-height: 1.55;
}

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

.choice {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  line-height: 1.5;
}

.choice.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.16);
}

.choice.correct {
  border-color: var(--success);
  background: #ecfdf3;
}

.choice.wrong {
  border-color: var(--danger);
  background: #fef3f2;
}

.feedback {
  margin-top: 12px;
  padding: 12px;
  border-left: 4px solid var(--brand);
  background: #eef8f6;
  line-height: 1.6;
}

.feedback strong {
  display: block;
  margin-bottom: 4px;
}

.result-head {
  align-items: flex-start;
  margin-bottom: 12px;
}

.result-head h2 {
  margin-bottom: 0;
}

.result-score {
  display: grid;
  min-width: 112px;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.result-score span {
  color: var(--muted);
  font-size: 13px;
}

.result-score strong {
  color: var(--brand-dark);
  font-size: 16px;
}

.breakdown-list {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.breakdown-row {
  display: grid;
  gap: 6px;
}

.breakdown-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.breakdown-top span {
  color: var(--muted);
}

.breakdown-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeec;
}

.breakdown-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.next-topics {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.next-topics.compact {
  margin-bottom: 0;
}

.next-topics h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.next-topics ul {
  display: grid;
  gap: 6px;
  padding-left: 18px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.domain-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.domain-buttons button {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.domain-buttons button.active {
  border-color: var(--brand);
  background: #eef8f6;
  color: var(--brand-dark);
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.history-stats article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.history-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.history-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.score-trend {
  display: flex;
  align-items: end;
  gap: 6px;
  height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(to top, #ecfdf3 0 70%, #fff7ed 70% 100%);
}

.score-trend span {
  flex: 1;
  min-width: 10px;
  border-radius: 6px 6px 0 0;
  background: var(--accent);
}

.score-trend span.passing {
  background: var(--brand);
}

.history-message {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.panel-note,
.backup-message {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.backup-message {
  font-size: 13px;
}

#exam-year-summary {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.field-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-row select {
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

#backup-summary {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  padding: 20px 0 8px;
}

.legal-links a,
.legal-back {
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 700;
}

.legal-page section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.legal-page h2 {
  margin-bottom: 8px;
  font-size: 18px;
}

.legal-page p {
  color: var(--muted);
  line-height: 1.7;
}

.legal-updated {
  margin-top: 20px;
  font-size: 13px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.primary,
.secondary,
.text-button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 700;
}

.primary {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--brand-dark);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--danger);
}

#restart-exam-button {
  width: 100%;
  margin-top: 8px;
}

.weak-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  margin: 12px 0 0;
  list-style: none;
}

.weak-list li {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 13px;
  font-weight: 700;
}

#log-list {
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .top-band {
    align-items: stretch;
    flex-direction: column;
  }

  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 32px;
  }

  .status-grid {
    grid-template-columns: 1fr 1fr;
  }

  .history-stats {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .mode-tabs button {
    min-height: 42px;
    font-size: 12px;
  }

  .app-status {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
