:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #15253d;
  background: #f4f6fa;
  line-height: 1.55;
  --background: #f4f6fa;
  --surface: #ffffff;
  --muted: #4d5e76;
  --border: #cfd8e4;
  --primary: #234c93;
  --primary-hover: #18396f;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid #2a65c5;
  outline-offset: 3px;
}

h1, h2, p {
  margin: 0;
}

h1, h2 {
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

h1 {
  font-size: clamp(1.75rem, 4.5vw, 2.5rem);
  letter-spacing: -0.035em;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(calc(100% - 2rem), 42rem);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: center;
  min-height: 4rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 750;
  letter-spacing: -0.02em;
}

main {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.view {
  padding-block: clamp(1.5rem, 5vw, 3rem) 2rem;
}

.topic-list, .missed-list {
  display: grid;
  gap: 0.75rem;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.topic-list:empty {
  margin: 0;
}

.topic-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  width: 100%;
  min-height: 4.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--surface);
  text-align: left;
}

.topic-name {
  font-size: 1.125rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.topic-count, .progress, .status {
  color: var(--muted);
}

.topic-count, .progress {
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.status {
  margin-top: 0.75rem;
}

.status + .button {
  margin-top: 1rem;
}

.study-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.study-header .button {
  flex-shrink: 0;
}

.progress {
  margin-top: 0.375rem;
}

.flashcard {
  min-height: 13rem;
  padding: clamp(1.25rem, 4.5vw, 2.5rem);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 6px 20px rgb(23 43 77 / 5%);
}

.question {
  font-size: clamp(1.375rem, 4vw, 1.875rem);
  letter-spacing: -0.025em;
  white-space: pre-line;
}

.answer {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.answer-label {
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 700;
}

#answer-lines, .missed-answers {
  display: grid;
  gap: 0.375rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  overflow-wrap: anywhere;
  white-space: pre-line;
  word-break: keep-all;
}

#answer-lines {
  font-size: 1.125rem;
}

.study-actions, .result-actions {
  margin-top: 1rem;
}

.study-actions > .button {
  width: 100%;
}

.grading-actions, .result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.button {
  min-height: 3rem;
  padding: 0.625rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.625rem;
  font-weight: 700;
}

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

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

.missed-section {
  margin-top: 1.5rem;
}

.missed-section h2 {
  font-size: 1.125rem;
}

.missed-list {
  margin-top: 0.75rem;
}

.missed-list > li {
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  background: var(--surface);
}

.missed-question {
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

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

@media (hover: hover) {
  .topic-button:hover, .button-secondary:hover {
    border-color: #8498b3;
    background: #edf2f9;
  }

  .button-primary:hover {
    background: var(--primary-hover);
  }
}

@media (max-width: 40rem) {
  #study-view {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding-bottom: 0;
  }

  .study-actions {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding-block: 1rem max(1rem, env(safe-area-inset-bottom));
    background: var(--background);
  }
}
