:root {
  color-scheme: light;
  --bg: #f7f8f4;
  --surface: #ffffff;
  --surface-soft: #eef5f0;
  --text: #1f2937;
  --muted: #667085;
  --line: #d9e1dc;
  --primary: #147d64;
  --primary-strong: #0d5f4d;
  --primary-soft: #dff4ed;
  --blue: #2563a8;
  --blue-soft: #e7f0fb;
  --amber: #b35b00;
  --amber-soft: #fff0dc;
  --danger: #b42318;
  --danger-soft: #ffebe7;
  --ok: #087443;
  --ok-soft: #def7ec;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.08);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.screen {
  width: min(760px, 100%);
  margin: 0 auto;
}

.app-header,
.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header {
  margin-bottom: 16px;
}

.brand-block,
.session-title {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.18;
}

h2 {
  margin-bottom: 8px;
  font-size: 20px;
  line-height: 1.3;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
  line-height: 1.35;
}

.muted {
  color: var(--muted);
}

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.danger-button,
.choice-button,
.pill-button,
.chip-button,
.mode-button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(31, 41, 55, 0.05);
}

.icon-button:active,
.text-button:active,
.primary-button:active,
.secondary-button:active,
.danger-button:active,
.choice-button:active,
.pill-button:active,
.chip-button:active,
.mode-button:active {
  transform: translateY(1px);
}

.text-button {
  min-height: 42px;
  padding: 0 12px;
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  min-height: 50px;
  padding: 13px 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
}

.primary-button:disabled,
.secondary-button:disabled,
.mode-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hero-panel,
.quiz-card,
.result-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel p,
.result-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.stats-grid,
.summary-grid {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-tile,
.summary-item {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat-tile {
  min-height: 78px;
}

.stat-value {
  display: block;
  margin-bottom: 4px;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.stat-label,
.summary-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-item {
  text-align: center;
}

.summary-item strong {
  display: block;
  font-size: 20px;
  line-height: 1;
}

.summary-item span {
  display: block;
  margin-top: 5px;
}

.mode-list,
.home-actions,
.choice-list,
.text-answer-form,
.matching-list,
.sequence-zone,
.quiz-actions {
  display: grid;
  gap: 10px;
}

.mode-list,
.home-actions {
  margin-top: 14px;
}

.mode-button {
  width: 100%;
  min-height: 92px;
  padding: 14px;
  text-align: left;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.mode-button strong {
  display: block;
  margin-bottom: 6px;
  font-size: 17px;
}

.mode-button span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.mode-button.primary-mode {
  border-color: rgba(20, 125, 100, 0.35);
  background: var(--primary-soft);
}

.session-top {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -16px -16px 14px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(247, 248, 244, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.session-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.session-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  background: #e3e9e5;
  border-radius: 999px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: inherit;
  transition: width 180ms ease;
}

.quiz-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
}

.quiz-card.result-ok {
  animation: correct-pulse 360ms ease;
}

.quiz-card.result-bad {
  animation: wrong-shake 320ms ease;
}

.badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.question-text {
  margin-bottom: 16px;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.instruction {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: var(--blue-soft);
  border: 1px solid #cbdff5;
  border-radius: 8px;
  color: #174a7c;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
}

.choice-button {
  position: relative;
  width: 100%;
  min-height: 56px;
  padding: 13px 14px 13px 50px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  text-align: left;
  line-height: 1.45;
}

.choice-index {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  background: var(--surface-soft);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.choice-button.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.choice-button.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

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

.answer-input {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 17px;
}

.answer-input:focus {
  outline: 3px solid rgba(20, 125, 100, 0.18);
  border-color: var(--primary);
}

.match-row {
  padding: 12px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.match-prompt {
  margin-bottom: 10px;
  font-weight: 900;
  line-height: 1.4;
}

.pill-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.pill-button {
  min-height: 44px;
  padding: 9px 10px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.pill-button.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-strong);
}

.sequence-box {
  min-height: 88px;
  padding: 10px;
  background: #fbfcfa;
  border: 1px dashed #b8c5be;
  border-radius: 8px;
}

.sequence-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-button {
  min-height: 42px;
  padding: 9px 11px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.chip-button.ordered {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.empty-hint {
  min-height: 42px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.feedback {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
}

.feedback.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.feedback.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.feedback-title {
  margin-bottom: 8px;
  font-size: 15px;
}

.feedback-line {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding-top: 6px;
}

.feedback-line span {
  color: currentColor;
  opacity: 0.78;
}

.feedback-line strong {
  color: var(--text);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.quiz-actions {
  margin-top: 14px;
}

.loading-view {
  min-height: 70vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.loading-mark {
  width: 34px;
  height: 34px;
  border: 4px solid #d8e5df;
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes correct-pulse {
  0% {
    box-shadow: var(--shadow);
  }
  40% {
    box-shadow: 0 0 0 5px rgba(8, 116, 67, 0.18), var(--shadow);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

@keyframes wrong-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 28px;
  }

  h1 {
    font-size: 32px;
  }

  .hero-panel,
  .quiz-card,
  .result-card {
    padding: 22px;
  }

  .home-actions,
  .quiz-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
