:root {
  --paper: #f4f0e7;
  --paper-deep: #e9e2d5;
  --ink: #18312c;
  --muted: #65736d;
  --green: #163f36;
  --green-soft: #dce7df;
  --coral: #d45c3f;
  --coral-soft: #f4d9ce;
  --line: rgba(24, 49, 44, 0.14);
  --white: #fffdf9;
  --shadow: 0 18px 50px rgba(38, 52, 47, 0.1);
  --radius-lg: 30px;
  --radius-md: 20px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 5%, rgba(22, 63, 54, 0.1), transparent 24rem),
    linear-gradient(var(--paper), var(--paper));
  font-family: "IBM Plex Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(212, 92, 63, 0.26);
  outline-offset: 2px;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 38px;
}

.brand,
.icon-button,
.text-button,
.nav-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  color: var(--paper);
  background: var(--green);
  font-family: "Fraunces", serif;
  font-size: 19px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.streak {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(255, 253, 249, 0.58);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 253, 249, 0.65);
  font-size: 19px;
  transition: 160ms ease;
}

.icon-button:hover {
  transform: rotate(8deg);
  background: var(--white);
}

.hero {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 40px;
}

.hero-copy,
.progress-card {
  min-height: 270px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.hero-copy {
  position: relative;
  overflow: hidden;
  padding: clamp(30px, 5vw, 60px);
  background: var(--green);
  color: var(--paper);
}

.hero-copy::after {
  position: absolute;
  right: -60px;
  bottom: -105px;
  width: 300px;
  height: 300px;
  border: 52px solid rgba(244, 240, 231, 0.08);
  border-radius: 50%;
  content: "";
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow::before {
  width: 22px;
  height: 2px;
  background: currentColor;
  content: "";
}

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

h1 {
  max-width: 720px;
  margin-bottom: 18px;
  font-family: "Fraunces", "IBM Plex Sans KR", serif;
  font-size: clamp(38px, 6vw, 72px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.hero-copy p {
  max-width: 610px;
  margin-bottom: 0;
  color: rgba(244, 240, 231, 0.72);
  font-size: 16px;
  line-height: 1.75;
}

.progress-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 30px;
  background: var(--coral);
  color: #fff8f2;
}

.progress-card .metric {
  font-family: "Fraunces", serif;
  font-size: clamp(48px, 7vw, 76px);
  line-height: 1;
}

.progress-card p {
  margin-bottom: 8px;
  color: rgba(255, 248, 242, 0.78);
}

.progress-line {
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
}

.progress-line > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #fff8f2;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 0 2px 18px;
}

.section-head h2 {
  margin-bottom: 5px;
  font-family: "Fraunces", "IBM Plex Sans KR", serif;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: -0.04em;
}

.section-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.level-picker {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(255, 253, 249, 0.66);
}

.level-picker button {
  min-width: 72px;
  padding: 9px 15px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.level-picker button.active {
  color: var(--paper);
  background: var(--green);
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.topic-card {
  position: relative;
  min-height: 210px;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 249, 0.76);
  cursor: pointer;
  text-align: left;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.topic-card:hover {
  z-index: 1;
  transform: translateY(-5px);
  box-shadow: var(--shadow);
}

.topic-number {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  margin-bottom: 30px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: "Fraunces", serif;
  font-size: 13px;
}

.topic-card h3 {
  margin-bottom: 7px;
  font-size: 20px;
  letter-spacing: -0.035em;
}

.topic-card p {
  margin-bottom: 0;
  color: rgba(24, 49, 44, 0.62);
  font-size: 13px;
}

.topic-arrow {
  position: absolute;
  right: 18px;
  bottom: 16px;
  font-size: 24px;
  transition: transform 180ms ease;
}

.topic-card:hover .topic-arrow {
  transform: translateX(5px);
}

.custom-card {
  display: flex;
  grid-column: span 2;
  flex-direction: column;
  justify-content: space-between;
  min-height: 210px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--coral-soft);
}

.custom-card h3 {
  margin-bottom: 7px;
  font-size: 21px;
}

.custom-row {
  display: flex;
  gap: 9px;
}

.custom-row input {
  width: 100%;
  min-width: 0;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: var(--white);
}

.primary-button,
.secondary-button,
.danger-button,
.answer-button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 150ms ease, opacity 150ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover,
.answer-button:hover {
  transform: translateY(-2px);
}

.primary-button {
  padding: 13px 20px;
  color: var(--paper);
  background: var(--green);
}

.secondary-button {
  padding: 12px 18px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--white);
}

.danger-button {
  padding: 12px 18px;
  color: #9c3d2d;
  background: #f8ddd5;
}

.back-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}

.nav-button {
  padding: 8px 0;
  color: var(--muted);
  font-weight: 700;
}

.detail-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-bottom: 28px;
}

.detail-copy {
  padding: clamp(28px, 5vw, 54px);
  border-radius: var(--radius-lg);
  color: var(--paper);
  background: var(--green);
}

.detail-copy h1 {
  font-size: clamp(45px, 7vw, 76px);
}

.detail-copy p {
  color: rgba(244, 240, 231, 0.7);
  line-height: 1.7;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.detail-actions .primary-button {
  color: var(--green);
  background: var(--paper);
}

.preview-panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--white);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

.pill {
  padding: 6px 10px;
  border-radius: 99px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 11px;
  font-weight: 700;
}

.word-preview {
  display: grid;
  grid-template-columns: 0.8fr 1fr 1fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.word-preview:last-child {
  border-bottom: 0;
}

.word-preview strong {
  font-size: 14px;
}

.zh {
  font-family: "Noto Serif SC", serif;
}

.ja {
  font-family: "Noto Sans JP", sans-serif;
}

.source-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 249, 0.7);
}

.source-bar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.study-shell {
  width: min(760px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 60px;
}

.session-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

.session-progress {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--paper-deep);
}

.session-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--coral);
  transition: width 250ms ease;
}

.session-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.flashcard-wrap {
  perspective: 1400px;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: min(560px, 65vh);
  border: 0;
  background: transparent;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 550ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(28px, 6vw, 54px);
  border: 1px solid var(--line);
  border-radius: 34px;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.card-front {
  align-items: center;
  justify-content: center;
  color: var(--paper);
  background: var(--green);
}

.card-front .concept {
  font-family: "Fraunces", "IBM Plex Sans KR", serif;
  font-size: clamp(50px, 12vw, 92px);
  font-weight: 700;
  letter-spacing: -0.06em;
}

.flip-hint {
  position: absolute;
  bottom: 28px;
  color: rgba(244, 240, 231, 0.55);
  font-size: 12px;
  font-weight: 600;
}

.card-back {
  background: var(--white);
  transform: rotateY(180deg);
}

.back-concept {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.language-stack {
  display: grid;
  gap: 12px;
  margin: 24px 0;
}

.language-row {
  display: grid;
  grid-template-columns: 48px 1fr 42px;
  gap: 14px;
  align-items: center;
  padding: 18px;
  border-radius: 16px;
  background: var(--paper);
}

.lang-tag {
  color: var(--coral);
  font-family: "Fraunces", serif;
  font-weight: 700;
}

.language-main {
  font-size: clamp(21px, 4vw, 30px);
  font-weight: 600;
}

.romanization {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: "IBM Plex Sans KR", sans-serif;
  font-size: 12px;
  font-weight: 500;
}

.speak-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
}

.answer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.answer-button {
  padding: 16px;
  font-size: 15px;
}

.answer-button.unknown {
  color: #9c3d2d;
  background: var(--coral-soft);
}

.answer-button.known {
  color: var(--green);
  background: var(--green-soft);
}

.quiz-card {
  min-height: 500px;
  padding: clamp(26px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: 32px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.quiz-prompt {
  margin: 36px 0;
  text-align: center;
}

.quiz-prompt .target {
  margin-bottom: 12px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.quiz-prompt h1 {
  margin-bottom: 0;
  font-family: "Fraunces", "IBM Plex Sans KR", serif;
  font-size: clamp(44px, 10vw, 76px);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.choice {
  min-height: 82px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  cursor: pointer;
  font-size: 17px;
  font-weight: 600;
}

.choice:hover {
  border-color: var(--green);
}

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

.choice.wrong {
  color: #9c3d2d;
  border-color: var(--coral);
  background: var(--coral-soft);
}

.reveal-panel {
  margin-top: 20px;
  padding: 18px;
  border-radius: 16px;
  color: var(--paper);
  background: var(--green);
  animation: slide-up 240ms ease both;
}

.reveal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.reveal-grid span {
  display: block;
  margin-bottom: 4px;
  color: rgba(244, 240, 231, 0.55);
  font-size: 10px;
  font-weight: 700;
}

.reveal-panel .primary-button {
  width: 100%;
  color: var(--green);
  background: var(--paper);
}

.result-card {
  width: min(680px, calc(100% - 28px));
  margin: 40px auto;
  padding: clamp(34px, 7vw, 70px);
  border-radius: 36px;
  color: var(--paper);
  background: var(--green);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-ring {
  display: grid;
  width: 170px;
  height: 170px;
  place-items: center;
  margin: 22px auto 30px;
  border: 14px solid rgba(244, 240, 231, 0.14);
  border-top-color: var(--coral);
  border-radius: 50%;
  font-family: "Fraunces", serif;
  font-size: 46px;
}

.result-card h1 {
  font-size: clamp(42px, 8vw, 68px);
}

.result-card p {
  color: rgba(244, 240, 231, 0.68);
}

.result-card .detail-actions {
  justify-content: center;
}

.modal-layer {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 32, 27, 0.64);
  backdrop-filter: blur(8px);
}

.modal {
  width: min(580px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 28px;
  border-radius: 26px;
  background: var(--white);
  box-shadow: 0 30px 90px rgba(9, 25, 21, 0.3);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.modal-head h2 {
  margin: 0;
  font-family: "Fraunces", "IBM Plex Sans KR", serif;
  font-size: 30px;
}

.form-group {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.form-group label {
  font-size: 13px;
  font-weight: 700;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper);
}

.form-group small {
  color: var(--muted);
  line-height: 1.5;
}

.card-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

.bulk-import {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.managed-list {
  display: grid;
  gap: 8px;
  margin-top: 26px;
}

.managed-list h3 {
  margin-bottom: 6px;
  font-size: 16px;
}

.managed-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--paper);
}

.managed-card span {
  min-width: 0;
}

.managed-card strong,
.managed-card small {
  display: block;
}

.managed-card small {
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.danger-button.compact {
  flex: 0 0 auto;
  padding: 8px 11px;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.loading::before {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 99px;
  color: var(--paper);
  background: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty {
  padding: 34px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
}

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

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@media (max-width: 900px) {
  .topic-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero,
  .detail-hero {
    grid-template-columns: 1fr;
  }

  .progress-card {
    min-height: 210px;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 22px, 1180px);
    padding-top: 16px;
  }

  .topbar {
    margin-bottom: 22px;
  }

  .streak {
    display: none;
  }

  .hero-copy,
  .progress-card {
    min-height: 230px;
  }

  .section-head {
    display: block;
  }

  .level-picker {
    width: 100%;
    margin-top: 16px;
  }

  .level-picker button {
    min-width: 0;
  }

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

  .topic-card {
    grid-column: span 1;
    min-height: 180px;
    padding: 18px;
  }

  .topic-card h3 {
    font-size: 17px;
  }

  .custom-card {
    grid-column: span 2;
  }

  .custom-row {
    flex-direction: column;
  }

  .word-preview {
    grid-template-columns: 0.75fr 1fr 1fr;
  }

  .word-preview span:last-child {
    display: none;
  }

  .source-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .source-bar .detail-actions {
    display: grid;
  }

  .session-head {
    grid-template-columns: auto 1fr;
  }

  .session-count {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  .flashcard {
    min-height: 530px;
  }

  .language-row {
    grid-template-columns: 38px 1fr 38px;
    padding: 14px;
  }

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

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

  .card-field-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
