:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #61706a;
  --paper: #fffdf7;
  --surface: #ffffff;
  --line: #d9ded6;
  --green: #2f684f;
  --green-dark: #214b39;
  --coral: #b9474b;
  --gold: #d99f2b;
  --shadow: 0 18px 48px rgba(23, 32, 28, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(47, 104, 79, 0.08), rgba(255, 253, 247, 0) 280px),
    var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid rgba(217, 222, 214, 0.8);
  background: rgba(255, 253, 247, 0.92);
  backdrop-filter: blur(14px);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.topbar-actions,
.topnav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topnav {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.topnav-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.topnav-link.active {
  color: var(--green-dark);
  background: #edf4ed;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(47, 104, 79, 0.28);
  border-radius: 8px;
  color: var(--green-dark);
  background: #edf4ed;
  font-size: 1.8rem;
  font-weight: 900;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 1.18rem;
}

.ghost-button,
.link-button,
.danger-button {
  border: 0;
  background: transparent;
  font-weight: 750;
}

.ghost-button {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.64);
}

.link-button {
  padding: 0;
  color: var(--green);
}

.danger-button {
  padding: 0;
  color: var(--coral);
}

.app-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 20px clamp(14px, 4vw, 48px) 48px;
}

.study-hero {
  position: relative;
  display: grid;
  min-height: 230px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7eee6;
  box-shadow: var(--shadow);
}

.study-hero img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.study-hero::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(
    90deg,
    rgba(255, 253, 247, 0.97) 0%,
    rgba(255, 253, 247, 0.78) 44%,
    rgba(255, 253, 247, 0.16) 100%
  );
}

.study-hero-content {
  position: relative;
  z-index: 1;
  align-self: end;
  width: min(540px, 100%);
  padding: clamp(20px, 4vw, 34px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  max-width: 12ch;
  margin-bottom: 16px;
  font-size: 3.6rem;
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 6px;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stats-row span {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid rgba(47, 104, 79, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted);
  font-size: 0.92rem;
}

.stats-row strong {
  color: var(--ink);
  font-size: 1.1rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.editor-panel,
.import-panel,
.deck-panel,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 32px rgba(23, 32, 28, 0.08);
}

.side-stack {
  position: sticky;
  top: 82px;
  display: grid;
  gap: 12px;
}

.editor-panel,
.import-panel {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.panel-heading,
.deck-tools {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

label {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: 0;
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 12px;
}

input,
select {
  min-height: 44px;
  padding: 10px 12px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 104, 79, 0.14);
}

.field-hint,
.form-message,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.field-hint,
.form-message {
  min-height: 20px;
  margin: -2px 0 0;
}

.form-message[data-tone="success"] {
  color: var(--green);
}

.form-message[data-tone="error"],
.form-error {
  color: var(--coral);
}

.editor-panel > button[type="submit"],
.import-panel > button[type="submit"],
.primary-button,
.login-form button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 850;
}

.editor-panel > button[type="submit"]:hover,
.import-panel > button[type="submit"]:hover,
.primary-button:hover,
.login-form button:hover {
  background: var(--green-dark);
}

.secondary-button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(217, 159, 43, 0.5);
  border-radius: 8px;
  background: #fff8e9;
  color: #5d4920;
  font-weight: 850;
}

.secondary-button:hover {
  border-color: rgba(217, 159, 43, 0.85);
  background: #fff2d7;
}

.primary-button {
  padding: 8px 14px;
}

.format-details {
  color: var(--muted);
  font-size: 0.9rem;
}

.format-details summary {
  cursor: pointer;
  color: var(--green);
  font-weight: 800;
}

.format-details pre {
  overflow-x: auto;
  margin: 10px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.45;
}

.import-preview {
  display: grid;
  gap: 8px;
}

.import-preview[hidden] {
  display: none;
}

.import-preview-table-wrap,
.review-table-mode {
  overflow-x: auto;
}

.import-preview-table,
.review-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  font-size: 0.9rem;
}

.import-preview-table th,
.import-preview-table td,
.review-table th,
.review-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.import-preview-table th,
.review-table th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.korean-cell {
  font-family:
    "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", Inter, system-ui,
    sans-serif;
  font-weight: 760;
}

.deck-panel {
  min-width: 0;
  padding: 18px;
}

.deck-tools {
  align-items: center;
}

.deck-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  width: min(540px, 62%);
}

.search-field,
.select-field {
  display: grid;
  width: auto;
  gap: 6px;
}

.search-field {
  flex: 1 1 240px;
}

.select-field {
  flex: 0 0 160px;
}

.search-field span,
.select-field span {
  color: var(--muted);
  font-size: 0.78rem;
}

.tag-filter {
  margin: 16px 0;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.review-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid rgba(47, 104, 79, 0.2);
  border-radius: 8px;
  background: #f6fbf5;
}

.review-panel[hidden] {
  display: none;
}

.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.review-action-full {
  grid-column: 1 / -1;
}

.review-card {
  display: grid;
  min-height: 270px;
  gap: 20px;
  align-content: space-between;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  box-shadow: 0 12px 32px rgba(23, 32, 28, 0.08);
}

.review-card.showing-answer {
  border-color: rgba(217, 159, 43, 0.55);
  background: #fffaf0;
}

.review-text {
  overflow-wrap: anywhere;
  font-size: 2.7rem;
  font-weight: 900;
  line-height: 1.12;
}

.review-text.korean-text {
  font-size: 2.85rem;
}

.review-romanization {
  margin-top: 6px;
  color: var(--muted);
  font-size: 1.5rem;
  font-weight: 700;
  font-style: italic;
}

.review-romanization:empty {
  display: none;
}

.review-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 4vw, 48px) 48px;
}

.review-page-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.review-sidebar,
.review-page-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 32px rgba(23, 32, 28, 0.08);
}

.review-sidebar {
  position: sticky;
  top: 82px;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.review-sidebar h1 {
  max-width: none;
  margin-bottom: 2px;
  font-size: 2.8rem;
}

.review-search-field {
  width: 100%;
}

.review-page-panel {
  margin-bottom: 0;
  padding: 18px 18px 28px;
}

.review-page-panel .review-card {
  min-height: 430px;
}

.review-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 28px;
}

.review-card-mode {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 880px;
  margin-inline: auto;
}

.review-card-mode[hidden],
.review-table-mode[hidden] {
  display: none;
}

.review-table-mode {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}

.flashcard-item {
  min-width: 0;
}

.flashcard {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 220px;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 1100px;
}

.flashcard-side {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(23, 32, 28, 0.08);
  backface-visibility: hidden;
  transition:
    transform 180ms ease,
    border-color 180ms ease;
}

.flashcard:hover .flashcard-side,
.flashcard:focus-visible .flashcard-side {
  border-color: rgba(47, 104, 79, 0.55);
}

.flashcard-back {
  border-color: rgba(217, 159, 43, 0.45);
  background: #fffaf0;
  transform: rotateY(180deg);
}

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

.flashcard.flipped .flashcard-back {
  transform: rotateY(360deg);
}

.side-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.card-text {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 2.15rem;
  font-weight: 850;
  line-height: 1.16;
  text-align: left;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.korean-text {
  font-family:
    "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", Inter, system-ui,
    sans-serif;
  font-size: 2.5rem;
}

.romanization-text {
  margin-top: 4px;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 600;
  font-style: italic;
}

.card-footer {
  display: grid;
  gap: 10px;
  padding: 10px 2px 0;
}

.tag-list,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card-actions {
  justify-content: flex-end;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  background: #f7f1e6;
  color: #5d4920;
  font-size: 0.82rem;
  font-weight: 760;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 180px;
  padding: 28px;
  border: 1px dashed #c9d0c7;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
}

.empty-state h3 {
  color: var(--ink);
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(47, 104, 79, 0.12), rgba(185, 71, 75, 0.09)),
    var(--paper);
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  padding: 28px;
}

.login-panel h1 {
  max-width: none;
  margin: 14px 0 8px;
  font-size: 2.1rem;
  line-height: 1.05;
}

.login-panel p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.form-error {
  margin: 0;
  font-weight: 700;
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    position: static;
  }

  .side-stack {
    position: static;
  }

  .review-page-layout {
    grid-template-columns: 1fr;
  }

  .review-sidebar {
    position: static;
  }

  .review-page-panel {
    min-height: 0;
  }

  .deck-tools {
    display: grid;
    grid-template-columns: 1fr;
  }

  .deck-controls {
    justify-content: stretch;
    width: 100%;
  }

  .search-field {
    width: 100%;
  }

  .select-field {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar {
    min-height: 58px;
    align-items: flex-start;
  }

  .wordmark span:last-child {
    display: none;
  }

  .topbar-actions {
    flex: 1;
    justify-content: flex-end;
    gap: 8px;
  }

  .topnav-link {
    padding-inline: 8px;
  }

  .app-shell {
    padding-top: 14px;
  }

  .study-hero {
    min-height: 210px;
  }

  .study-hero::after {
    background: linear-gradient(
      180deg,
      rgba(255, 253, 247, 0.94) 0%,
      rgba(255, 253, 247, 0.78) 60%,
      rgba(255, 253, 247, 0.18) 100%
    );
  }

  h1 {
    max-width: 10ch;
    font-size: 2.35rem;
  }

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

  .flashcard {
    min-height: 205px;
  }

  .deck-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .review-card {
    min-height: 230px;
    padding: 18px;
  }

  .review-page-panel .review-card {
    min-height: 330px;
  }

  .review-sidebar h1 {
    font-size: 2.25rem;
  }

  .review-text {
    font-size: 2rem;
  }

  .review-text.korean-text {
    font-size: 2.15rem;
  }

  .card-text {
    font-size: 1.55rem;
  }

  .korean-text {
    font-size: 1.9rem;
  }

  .login-panel {
    padding: 22px;
  }
}
