@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Newsreader:opsz,wght@6..72,400;6..72,500&family=Noto+Sans+KR:wght@400;500;700&display=swap");

:root {
  --ink: #182019;
  --muted: #687069;
  --paper: #f5f1e8;
  --paper-light: #fbfaf6;
  --forest: #244c38;
  --forest-dark: #173426;
  --sage: #cbd6c8;
  --gold: #c89c55;
  --line: rgba(24, 32, 25, 0.16);
  --danger: #a64235;
  --serif: "Newsreader", Georgia, serif;
  --sans: "DM Sans", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.34)),
    repeating-linear-gradient(90deg, transparent 0, transparent 119px, rgba(36, 76, 56, 0.025) 120px),
    #dedbd1;
  font-family: var(--sans);
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(200, 156, 85, 0.5);
  outline-offset: 3px;
}

.page-shell {
  width: min(1480px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px clamp(20px, 4vw, 64px) 36px;
  background: var(--paper);
  box-shadow: 0 0 70px rgba(27, 39, 29, 0.12);
}

.topbar, .session-actions, .hero, .editor-heading, .collection-toolbar, .card-top, .card-actions, .save-dock {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
}

.back-link, .text-button {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.session-actions { justify-content: flex-end; gap: 14px; }
.storage-mode, .user-email { color: var(--muted); }
.text-button { padding: 0; border: 0; background: none; cursor: pointer; }
.back-link:hover, .text-button:hover { color: var(--forest); }

.hero {
  justify-content: space-between;
  align-items: end;
  gap: 40px;
  min-height: 220px;
  padding: clamp(28px, 4vw, 52px) 0 26px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--forest);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.2em;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.4rem, 8vw, 7.2rem);
  font-weight: 500;
  line-height: 0.78;
  letter-spacing: -0.055em;
}

.hero-copy {
  margin: 18px 0 0;
  color: var(--muted);
  font-family: "Noto Sans KR", sans-serif;
  line-height: 1.85;
}

.hero-side {
  display: grid;
  width: min(310px, 100%);
  gap: 14px;
}

.count-card {
  padding: 22px 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.24);
}

.count-card strong {
  display: block;
  font-family: var(--serif);
  font-size: 3.2rem;
  font-weight: 400;
  line-height: 1;
}

.count-card span { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.08em; }

.add-button, .complete-button, .save-button, .reveal-button, .knew-button {
  min-height: 55px;
  border: 0;
  color: #fff;
  background: var(--forest);
  cursor: pointer;
  font-weight: 700;
}

.add-button:hover, .complete-button:hover, .save-button:hover, .reveal-button:hover, .knew-button:hover { background: var(--forest-dark); }
.add-button span { margin-right: 7px; font-size: 1.2rem; }
.game-button {
  min-height: 50px;
  border: 1px solid var(--forest);
  color: var(--forest);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}
.game-button:hover { color: #fff; background: var(--forest); }
.game-button:disabled { cursor: not-allowed; opacity: 0.42; }

.editor-panel {
  margin-bottom: 54px;
  padding: clamp(22px, 4vw, 40px);
  border: 1px solid var(--forest);
  background: var(--paper-light);
  box-shadow: 10px 10px 0 var(--sage);
}

.editor-heading { justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.editor-heading h2, .collection-toolbar h2 { margin: 0; font-family: var(--serif); font-weight: 400; }
.editor-heading h2 { font-size: clamp(2rem, 4vw, 3.4rem); }
.close-button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 2rem; line-height: 1; }

.entry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.entry-form label { display: grid; gap: 8px; }
.entry-form label > span { font-size: 0.78rem; font-weight: 700; }
.entry-form label em { color: var(--muted); font-style: normal; font-weight: 400; }
.wide-field { grid-column: 1 / -1; }

textarea, .search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: #fff;
}

textarea { min-height: 108px; padding: 14px 15px; line-height: 1.65; resize: vertical; }
textarea:focus, .search-box input:focus { border-color: var(--forest); }

.form-actions { display: flex; gap: 10px; }
.complete-button { min-width: 150px; padding: 0 26px; }
.cancel-button {
  min-height: 55px;
  padding: 0 24px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.collection { padding-top: 34px; border-top: 1px solid var(--ink); }
.collection-toolbar { justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 28px; }
.collection-toolbar h2 { font-size: clamp(2.3rem, 5vw, 4.7rem); letter-spacing: -0.04em; }
.search-box { width: min(330px, 100%); }
.search-box input { height: 47px; padding: 0 15px; }

.entry-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.entry-card {
  position: relative;
  display: flex;
  min-height: 330px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--paper-light);
  flex-direction: column;
  animation: card-in 420ms both;
  animation-delay: var(--delay, 0ms);
}

.entry-card:nth-child(4n + 2) { background: #edf0e8; }
.entry-card:nth-child(4n + 3) { background: #f0e8dc; }
.entry-card:nth-child(4n + 4) { background: #e5ebe7; }
.entry-card::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(36, 76, 56, 0.08);
  pointer-events: none;
}

.card-top { justify-content: space-between; color: var(--muted); font-size: 0.67rem; }
.card-number { color: var(--forest); font-weight: 700; letter-spacing: 0.08em; }
.entry-card h3 {
  margin: 34px 0 18px;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 2.5vw, 2.5rem);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.035em;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.card-divider { width: 36px; height: 2px; margin-bottom: 18px; background: var(--gold); }
.card-label { color: var(--forest); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.16em; }
.meaning { margin: 7px 0 0; font-family: "Noto Sans KR", sans-serif; line-height: 1.7; white-space: pre-line; overflow-wrap: anywhere; }
.note {
  margin: 18px 0 0;
  padding: 13px 0 0;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-family: "Noto Sans KR", sans-serif;
  font-size: 0.8rem;
  line-height: 1.65;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.card-actions { position: relative; z-index: 1; gap: 7px; margin-top: auto; padding-top: 25px; }
.card-action { padding: 6px 11px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 0.7rem; font-weight: 700; }
.card-action:hover { color: #fff; background: var(--forest); }
.card-action.delete:hover { border-color: var(--danger); background: var(--danger); }

.empty-state {
  grid-column: 1 / -1;
  min-height: 330px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
  white-space: pre-line;
}

.save-dock { justify-content: space-between; gap: 20px; margin-top: 44px; padding-top: 20px; border-top: 1px solid var(--ink); }
.save-dock-top {
  margin: 0 0 34px;
  padding: 14px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line);
}
.save-dock p { margin: 0; color: var(--muted); font-size: 0.78rem; }
.save-dock p.is-error { color: var(--danger); }
.save-button { min-height: 44px; padding: 0 22px; }
.save-button:disabled { cursor: wait; opacity: 0.6; }

body.game-open { overflow: hidden; }
.game-overlay {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 25, 18, 0.7);
  backdrop-filter: blur(8px);
}
.game-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 44px);
  overflow-y: auto;
  padding: clamp(24px, 5vw, 46px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: var(--paper-light);
  box-shadow: 16px 16px 0 rgba(200, 156, 85, 0.7), 0 28px 80px rgba(0, 0, 0, 0.35);
  animation: game-panel-in 220ms ease-out both;
}
.game-header, .game-status, .grade-actions {
  display: flex;
  align-items: center;
}
.game-header { justify-content: space-between; align-items: flex-start; gap: 24px; }
.game-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.5rem, 7vw, 5rem);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.045em;
}
.game-menu > p { margin: 28px 0 18px; color: var(--muted); line-height: 1.7; }
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode-button {
  min-height: 145px;
  padding: 22px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.mode-button:hover { border-color: var(--forest); background: #edf0e8; transform: translateY(-2px); }
.mode-button strong { display: block; margin-bottom: 9px; font-family: var(--serif); font-size: 1.65rem; }
.mode-button span { color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.game-status {
  justify-content: space-between;
  margin: 28px 0 12px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}
.game-status strong { color: var(--forest); font-size: 1rem; }
.quiz-card {
  min-height: 330px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(28px, 6vw, 58px);
  border: 1px solid var(--forest);
  background: #fff;
  flex-direction: column;
  text-align: center;
}
.quiz-label { color: var(--forest); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.2em; }
.quiz-prompt, .quiz-answer {
  margin: 18px 0 28px;
  font-family: var(--serif);
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.quiz-answer { margin-bottom: 0; color: var(--forest); font-size: clamp(1.7rem, 5vw, 3.5rem); }
.reveal-button, .knew-button { min-height: 48px; padding: 0 24px; }
.answer-panel {
  width: 100%;
  margin-top: 26px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}
.quiz-note {
  margin: 22px 0 0;
  padding: 13px;
  color: var(--muted);
  background: var(--paper);
  font-family: "Noto Sans KR", sans-serif;
  font-size: 0.78rem;
  line-height: 1.65;
  white-space: pre-line;
}
.grade-actions { justify-content: center; gap: 10px; margin-top: 14px; }
.missed-button {
  min-height: 48px;
  padding: 0 24px;
  border: 1px solid var(--danger);
  color: var(--danger);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}
.missed-button:hover { color: #fff; background: var(--danger); }
.game-result { padding: 52px 20px 18px; text-align: center; }
.game-result > span { color: var(--gold); font-size: 3rem; }
.game-result h3 { margin: 10px 0; font-family: var(--serif); font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 500; }
.game-result p { margin: 0 0 28px; color: var(--muted); }
.game-result p strong { color: var(--forest); font-size: 1.5rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes game-panel-in {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@media (max-width: 720px) {
  .page-shell { width: 100%; padding: 16px 16px 28px; }
  .topbar, .hero, .collection-toolbar, .save-dock { align-items: stretch; flex-direction: column; }
  .session-actions { justify-content: flex-start; flex-wrap: wrap; }
  .storage-mode, .user-email { width: 100%; }
  .hero { min-height: 0; padding: 34px 0 24px; }
  .hero-side { width: 100%; }
  .entry-form { grid-template-columns: 1fr; }
  .entry-form label, .wide-field { grid-column: auto; }
  .collection-toolbar { gap: 18px; }
  .search-box { width: 100%; }
  .entry-list { grid-template-columns: 1fr; }
  .entry-card { min-height: 300px; }
  .save-dock { gap: 14px; }
  .save-dock-top { margin-bottom: 26px; padding: 14px 0; }
  .save-button { width: 100%; }
  .game-overlay { padding: 10px; }
  .game-panel { max-height: calc(100vh - 20px); padding: 22px 18px; box-shadow: 6px 6px 0 rgba(200, 156, 85, 0.7); }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-button { min-height: 105px; }
  .quiz-card { min-height: 300px; padding: 28px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}
