:root {
  color-scheme: light;
  --paper: #fbf7ef;
  --surface: #fffdf8;
  --surface-strong: #f3eadb;
  --ink: #23201d;
  --muted: #736b60;
  --line: #ded3c2;
  --sage: #496b58;
  --sage-ink: #f7fbf5;
  --clay: #a65f3d;
  --gold: #c89643;
  --blue: #385a7c;
  --shadow: 0 18px 50px rgba(52, 42, 30, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Avenir Next", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--paper);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: auto;
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--clay);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: STHeiti, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 800;
  line-height: 1.02;
  word-break: keep-all;
}

h2 {
  font-size: 1.12rem;
  line-height: 1.3;
}

.hero {
  position: relative;
  display: grid;
  min-height: clamp(440px, 52vw, 640px);
  align-items: center;
  margin: 0 0 22px;
  overflow: hidden;
  border: 1px solid rgba(222, 211, 194, 0.78);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(251, 247, 239, 0.92) 0%, rgba(251, 247, 239, 0.76) 33%, rgba(251, 247, 239, 0.12) 62%),
    url("images/hero-korean-memory-flashcards.jpg") right center / cover no-repeat;
}

.hero::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(35, 32, 29, 0), rgba(35, 32, 29, 0.06));
  content: "";
  pointer-events: none;
}

.hero-copy {
  position: relative;
  z-index: 1;
  max-width: 700px;
  padding: clamp(28px, 7vw, 74px);
}

.hero h1 {
  max-width: 680px;
  font-size: clamp(2.2rem, 4.2vw, 3.45rem);
  line-height: 1.12;
}

.hero-lede {
  max-width: 430px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: clamp(1.2rem, 2vw, 1.72rem);
  font-weight: 600;
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
  color: var(--sage);
  font-weight: 800;
}

.hero-link {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  padding: 0 22px;
  border-radius: 999px;
  color: var(--sage-ink);
  background: var(--sage);
  text-decoration: none;
}

.summary-strip {
  position: absolute;
  z-index: 1;
  right: 24px;
  bottom: 24px;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 8px;
  min-width: 280px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.74);
  backdrop-filter: blur(12px);
}

.summary-strip div {
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--surface);
}

.summary-strip span {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
}

.summary-strip small {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1.08fr) minmax(340px, 0.92fr) minmax(280px, 0.62fr);
  gap: 18px;
  align-items: start;
}

.workspace > * {
  min-width: 0;
}

.study-panel,
.editor-panel,
.library-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}

.study-panel {
  padding: 18px;
}

.editor-panel,
.library-panel {
  padding: 18px;
}

.panel-heading,
.study-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.icon-actions,
.study-controls,
.review-row,
.data-actions {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover,
.ghost-button:hover,
.soft-button:hover,
.link-button:hover,
.ghost-upload:hover {
  transform: translateY(-1px);
  border-color: rgba(73, 107, 88, 0.55);
}

.flashcard {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 560px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(73, 107, 88, 0.28);
  border-radius: var(--radius);
  color: inherit;
  background:
    linear-gradient(145deg, rgba(255, 253, 248, 0.96), rgba(243, 234, 219, 0.72)),
    var(--surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.54);
  transform-style: preserve-3d;
  transition: transform 260ms ease, border-color 200ms ease;
}

.flashcard:hover {
  border-color: rgba(73, 107, 88, 0.72);
}

.flashcard.is-flipped .card-front {
  opacity: 0;
  transform: rotateY(180deg);
  pointer-events: none;
}

.flashcard.is-flipped .card-back {
  opacity: 1;
  transform: rotateY(0deg);
}

.card-face {
  grid-area: 1 / 1;
  display: flex;
  min-height: 560px;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: clamp(24px, 5vw, 54px);
  transition: opacity 220ms ease, transform 320ms ease;
  backface-visibility: hidden;
}

.card-front {
  opacity: 1;
  transform: rotateY(0deg);
}

.card-back {
  opacity: 0;
  transform: rotateY(-180deg);
}

.card-tag {
  align-self: flex-start;
  padding: 7px 11px;
  border: 1px solid rgba(73, 107, 88, 0.35);
  border-radius: 999px;
  color: var(--sage);
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(73, 107, 88, 0.08);
}

.korean-word {
  font-family: "Noto Serif KR", "Apple SD Gothic Neo", "Songti TC", serif;
  font-size: clamp(3.4rem, 9vw, 7.3rem);
  font-weight: 800;
  line-height: 1;
  overflow-wrap: anywhere;
}

.pronunciation {
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.5rem);
}

.visual-frame {
  display: grid;
  min-height: 170px;
  margin-top: 10px;
  padding: 22px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--blue);
  font-family: "Songti TC", "Noto Serif CJK TC", serif;
  font-size: clamp(1.2rem, 2.4vw, 1.7rem);
  line-height: 1.45;
  text-align: center;
  background:
    linear-gradient(90deg, rgba(56, 90, 124, 0.08), rgba(200, 150, 67, 0.1)),
    var(--surface);
}

.visual-frame img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 6px;
}

.visual-frame.has-image {
  min-height: 250px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
}

.visual-frame.has-image img {
  height: 100%;
  max-height: 340px;
  object-fit: cover;
}

.meaning {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
  line-height: 1.15;
}

.cue-box,
.scene-box {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.82);
  text-align: left;
}

.cue-label {
  color: var(--clay);
  font-size: 0.78rem;
  font-weight: 800;
}

.study-controls,
.review-row {
  margin-top: 10px;
}

.study-controls button {
  flex: 1;
}

.review-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.primary-button,
.ghost-button,
.soft-button,
.link-button,
.ghost-upload {
  min-height: 42px;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
  white-space: normal;
}

.primary-button {
  width: 100%;
  color: var(--sage-ink);
  border-color: var(--sage);
  background: var(--sage);
  font-weight: 800;
}

.ghost-button,
.ghost-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 253, 248, 0.74);
  text-decoration: none;
}

.soft-button {
  padding: 0 12px;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-strong);
}

.soft-button.success {
  color: var(--sage);
  background: rgba(73, 107, 88, 0.12);
}

.soft-button.danger {
  color: var(--clay);
  background: rgba(166, 95, 61, 0.12);
}

.link-button {
  min-height: auto;
  padding: 8px 0;
  color: var(--sage);
  border: 0;
  background: transparent;
  font-weight: 800;
}

.card-form,
.library-tools {
  display: grid;
  gap: 13px;
}

.form-grid,
.library-tools {
  grid-template-columns: 1fr 0.82fr;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(255, 253, 248, 0.86);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(200, 150, 67, 0.26);
  outline-offset: 2px;
}

.file-drop {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(243, 234, 219, 0.42);
}

.file-drop input {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.file-drop small {
  color: var(--muted);
  font-weight: 500;
}

.data-actions {
  margin: 14px 0;
}

.data-actions > * {
  flex: 1;
}

.ghost-upload {
  position: relative;
  overflow: hidden;
}

.ghost-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.card-list {
  display: grid;
  gap: 8px;
  max-height: 570px;
  overflow: auto;
  padding-right: 2px;
}

.library-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.75);
}

.library-card.is-active {
  border-color: rgba(73, 107, 88, 0.78);
  background: rgba(73, 107, 88, 0.08);
}

.library-card strong {
  display: block;
  font-family: "Noto Serif KR", "Apple SD Gothic Neo", serif;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.library-card span {
  color: var(--muted);
  font-size: 0.87rem;
}

.library-select-button {
  text-align: left;
}

.library-card-actions {
  display: flex;
  align-items: start;
  gap: 5px;
}

.tiny-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface);
}

.empty-state {
  margin: 18px 0 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(73, 107, 88, 0.34);
  border-radius: var(--radius);
  color: var(--sage-ink);
  background: var(--sage);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.clipboard-fallback {
  position: fixed;
  left: -9999px;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(360px, 1.2fr) minmax(320px, 0.8fr);
  }

  .library-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 18px 14px 28px;
  }

  .hero {
    min-height: 650px;
    align-items: start;
    background:
      linear-gradient(180deg, rgba(251, 247, 239, 0.96) 0%, rgba(251, 247, 239, 0.82) 38%, rgba(251, 247, 239, 0.16) 74%),
      url("images/hero-korean-memory-flashcards.jpg") 64% bottom / auto 100% no-repeat;
  }

  .hero-copy {
    padding: 24px;
  }

  .hero-lede {
    max-width: 330px;
    margin-top: 14px;
  }

  .hero-actions {
    margin-top: 22px;
  }

  .summary-strip {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 100%;
    min-width: 0;
    max-width: calc(100% - 28px);
  }

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

  .flashcard,
  .card-face {
    min-height: 500px;
  }

  .form-grid,
  .library-tools,
  .review-row {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 520px) {
  h1 {
    font-size: 2.24rem;
  }

  .workspace > *,
  .summary-strip {
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
  }

  .study-panel,
  .editor-panel,
  .library-panel {
    padding: 14px;
  }

  .flashcard,
  .card-face {
    min-height: 450px;
  }

  .card-face {
    padding: 22px;
  }

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

  .summary-strip div {
    padding: 10px 8px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }
}
