:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #f0f7f2;
  --ink: #202422;
  --muted: #66716b;
  --line: #dbe2dc;
  --accent: #157f5f;
  --accent-strong: #0f684f;
  --accent-soft: #dff1e9;
  --gold: #c18b2e;
  --danger: #c7362f;
  --danger-soft: #ffe7e4;
  --success: #167348;
  --success-soft: #ddf4e6;
  --shadow: 0 12px 28px rgba(25, 34, 30, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0) 180px),
    var(--bg);
  color: var(--ink);
  font-family:
    "Noto Sans KR",
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: rgba(246, 244, 239, 0.92);
  border-bottom: 1px solid rgba(219, 226, 220, 0.9);
  backdrop-filter: blur(12px);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 18px 14px calc(28px + env(safe-area-inset-bottom));
}

.screen {
  display: grid;
  gap: 16px;
}

.screen-heading {
  display: grid;
  gap: 6px;
}

.kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

h2,
h3,
p {
  overflow-wrap: anywhere;
}

h2 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.25;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

p {
  margin: 0;
}

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

.loading-screen {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 64px 0;
  color: var(--muted);
}

.loader {
  width: 34px;
  height: 34px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.icon-button,
.text-button,
.unit-card,
.menu-card,
.answer-button,
.image-choice,
.segment-button,
.pager-button,
.result-action,
.search-result {
  border: 0;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border-radius: 50%;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.text-button,
.pager-button,
.result-action {
  min-height: 42px;
  padding: 0 14px;
  color: var(--surface);
  background: var(--accent);
  border-radius: var(--radius);
  font-weight: 800;
}

.text-button.compact {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.text-button.secondary,
.pager-button.secondary,
.result-action.secondary {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.text-button:disabled,
.pager-button:disabled {
  cursor: default;
  color: #9aa39e;
  background: #e5e9e5;
}

.unit-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.unit-card,
.menu-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 15px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(32, 36, 34, 0.05);
}

.unit-card {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.unit-card strong,
.menu-card strong {
  font-size: 1.02rem;
  line-height: 1.3;
}

.unit-card span,
.menu-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.unit-card:hover,
.menu-card:hover,
.unit-card:focus-visible,
.menu-card:focus-visible {
  border-color: var(--accent);
  outline: 3px solid rgba(21, 127, 95, 0.14);
}

.menu-list {
  display: grid;
  gap: 10px;
}

.segment {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segment-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.segment-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segment-button {
  min-height: 40px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 800;
}

.segment-button.is-active {
  color: var(--surface);
  background: var(--accent);
  border-color: var(--accent);
}

.study-top,
.quiz-top {
  display: grid;
  align-items: center;
  gap: 8px;
}

.study-top {
  grid-template-columns: auto minmax(52px, 1fr) auto minmax(52px, 1fr);
}

.quiz-top {
  grid-template-columns: auto 1fr auto;
}

.progress-pill {
  justify-self: center;
  min-width: 78px;
  padding: 7px 10px;
  color: var(--accent-strong);
  text-align: center;
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
}

.study-nav-button {
  min-height: 38px;
  padding: 0 10px;
  color: var(--surface);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

.study-nav-button:disabled {
  cursor: default;
  color: #9aa39e;
  background: #e5e9e5;
}

.point-title {
  display: grid;
  gap: 4px;
}

.image-panel {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 260px;
  margin: 0;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.image-panel img {
  display: block;
  width: 100%;
  max-height: 58vh;
  object-fit: contain;
}

.info-block {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.info-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.info-list li {
  position: relative;
  padding-left: 15px;
  color: #37413b;
  line-height: 1.55;
}

.info-list li::before {
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 5px;
  height: 5px;
  background: var(--gold);
  border-radius: 50%;
  content: "";
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quiz-card {
  display: grid;
  gap: 14px;
}

.question-name {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.question-name strong {
  font-size: 2rem;
  line-height: 1.15;
}

.choice-grid {
  display: grid;
  gap: 10px;
}

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

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

.answer-button {
  min-height: 52px;
  padding: 13px 14px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 800;
}

.choice-grid.names .answer-button {
  display: grid;
  place-items: center;
  min-height: 56px;
  padding: 10px 6px;
  text-align: center;
}

.image-choice {
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.image-choice img {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: contain;
}

.answer-button:hover,
.image-choice:hover,
.answer-button:focus-visible,
.image-choice:focus-visible {
  border-color: var(--accent);
  outline: 3px solid rgba(21, 127, 95, 0.14);
}

.answer-button.is-correct,
.image-choice.is-correct {
  color: var(--success);
  background: var(--success-soft);
  border-color: var(--success);
}

.answer-button.correct-reveal,
.image-choice.correct-reveal {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

.answer-button.is-wrong,
.image-choice.is-wrong {
  color: var(--danger);
  background: #fff4f2;
  border-color: #e7a59f;
}

.feedback {
  min-height: 42px;
  padding: 10px 12px;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid rgba(22, 115, 72, 0.2);
  border-radius: var(--radius);
  font-weight: 800;
}

.feedback.is-wrong {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(199, 54, 47, 0.22);
}

.result-panel {
  display: grid;
  gap: 14px;
}

.score-box {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.score-number {
  font-size: 2.25rem;
  font-weight: 900;
}

.wrong-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wrong-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.wrong-item img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet[hidden] {
  display: none;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 25, 23, 0.42);
}

.search-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 12px;
  width: min(100%, 760px);
  max-height: min(82vh, 720px);
  margin: 0 auto;
  padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
}

.search-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.search-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21, 127, 95, 0.14);
}

.search-results {
  display: grid;
  gap: 8px;
}

.search-result {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: center;
  padding: 9px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-result img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.7);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

@media (min-width: 620px) {
  .unit-grid,
  .menu-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .image-choice,
  .image-choice img {
    min-height: 190px;
    height: 190px;
  }
}
