:root {
  color-scheme: light;
  --bg: #efeae1;
  --bg-deep: #e6dfd3;
  --paper: #faf7f2;
  --ink: #1b1916;
  --muted: #6e685f;
  --faint: #8d867c;
  --line: rgba(27, 25, 22, 0.1);
  --accent: #1c4638;
  --accent-soft: rgba(28, 70, 56, 0.1);
  --star: #9a7420;
  --star-fill: #c6962c;
  --shadow: 0 24px 60px rgba(48, 36, 18, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "Cascadia Code", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121411;
    --bg-deep: #0d0f0c;
    --paper: #1b1e1a;
    --ink: #f4f0e8;
    --muted: #b1aa9f;
    --faint: #8d877d;
    --line: rgba(244, 240, 232, 0.1);
    --accent: #d7c4a2;
    --accent-soft: rgba(215, 196, 162, 0.12);
    --star: #e2c16a;
    --star-fill: #e2c16a;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(198, 150, 44, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(28px + var(--safe-top)) 0 calc(24px + var(--safe-bottom));
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
}

.kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.top-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.top-actions { display: flex; gap: 8px; }

.read-open {
  color: var(--bg);
  background: var(--ink);
  border-color: var(--ink);
  font-weight: 650;
}

.count {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sky-open {
  color: #f4f0e8;
  background: #14161c;
  border-color: #14161c;
  font-weight: 650;
}

.study-open, .quiz-open {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
  font-weight: 650;
}

.tools { display: grid; gap: 12px; margin-bottom: 18px; }

.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 14px 18px;
  outline: none;
  box-shadow: var(--shadow);
}

.search input:focus { border-color: var(--accent); }

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

.chip, .star, .speak, .back {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
}

.chip {
  padding: 7px 12px;
  color: var(--muted);
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-height: calc(100vh - 240px);
}

.list-pane, .detail {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.list-pane {
  max-height: calc(100vh - 230px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list { overflow: auto; padding: 8px; }

.word-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px;
  align-items: center;
  border-radius: 14px;
  padding: 4px 6px 4px 4px;
  content-visibility: auto;
  contain-intrinsic-size: auto 76px;
}

.open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  width: 100%;
  margin: 0;
  padding: 8px 8px 8px 4px;
  border: 0;
  background: transparent;
  text-align: left;
}

.word-row:hover, .word-row:focus-visible { background: var(--accent-soft); }

.word-row[aria-current="true"] {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.word-row .name {
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.1;
}

.word-row .pos, .meta {
  color: var(--faint);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.word-row .def {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.star, .speak {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
}

.star { color: var(--star); }
.speak { color: var(--accent); }

.icon-actions { display: flex; align-items: center; gap: 8px; }

.star[aria-pressed="true"] { background: rgba(198, 150, 44, 0.16); }

.star svg, .speak svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.star[aria-pressed="true"] svg { fill: var(--star-fill); stroke: var(--star-fill); }

.detail {
  position: sticky;
  top: 16px;
  min-height: 420px;
  padding: 28px 32px 36px;
}

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

.detail h2 {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(3rem, 6vw, 5.4rem);
  letter-spacing: -0.04em;
  line-height: 0.9;
}

.definition {
  margin: 28px 0 0;
  max-width: 38rem;
  font-size: 1.28rem;
  line-height: 1.45;
}

.pairs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.pairs h3 {
  margin: 0 0 6px;
  color: var(--faint);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.pairs p {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
}

.back { display: none; }

.empty {
  margin: 0;
  padding: 28px 18px 32px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app { width: min(100% - 20px, 720px); padding-top: calc(16px + var(--safe-top)); }
  .top { align-items: flex-start; }
  h1 { font-size: 2.3rem; }
  .layout { grid-template-columns: 1fr; min-height: 0; }
  .list-pane { max-height: none; }
  .list { max-height: calc(100vh - 280px); }
  .detail {
    position: fixed;
    z-index: 3;
    inset: 0;
    border-radius: 0;
    overflow: auto;
    padding: calc(18px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
  }
  .detail[hidden] { display: none; }
  .back { display: inline-flex; align-items: center; padding: 8px 12px; }
  .pairs { grid-template-columns: 1fr; }
}

:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chip, .star, .speak, .back, .word-row, .search input {
  transition:
    background-color 180ms var(--ease-out),
    border-color 180ms var(--ease-out),
    color 180ms var(--ease-out),
    box-shadow 220ms var(--ease-out),
    transform 180ms var(--ease-out);
}

.chip:active, .back:active { transform: scale(0.97); }
.star:active, .speak:active { transform: scale(0.88); }

.star svg, .speak svg { transition: fill 200ms var(--ease-out), stroke 200ms var(--ease-out); }
.star.pop svg { animation: star-pop 420ms var(--ease-spring); }

@keyframes star-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.35) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}

.detail-body.enter-forward > *,
.detail-body.enter-back > *,
.reader-stage.enter-forward > *,
.reader-stage.enter-back > * {
  animation: detail-in 460ms var(--ease-out) both;
}

.detail-body.enter-back > *,
.reader-stage.enter-back > * { animation-name: detail-in-back; }

.detail-body > :nth-child(2) { animation-delay: 30ms; }
.detail-body > :nth-child(3) { animation-delay: 60ms; }
.detail-body > :nth-child(4) { animation-delay: 110ms; }
.detail-body > :nth-child(5) { animation-delay: 170ms; }

.detail-body h2 { transform-origin: left bottom; }

@keyframes detail-in {
  from { opacity: 0; transform: translateY(14px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

@keyframes detail-in-back {
  from { opacity: 0; transform: translateY(-14px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.list.list-swap { animation: list-swap 260ms var(--ease-out); }

@keyframes list-swap {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.list.list-intro .word-row { animation: row-in 520ms var(--ease-out) both; }
.list.list-intro .word-row:nth-child(1) { animation-delay: 0ms; }
.list.list-intro .word-row:nth-child(2) { animation-delay: 30ms; }
.list.list-intro .word-row:nth-child(3) { animation-delay: 60ms; }
.list.list-intro .word-row:nth-child(4) { animation-delay: 90ms; }
.list.list-intro .word-row:nth-child(5) { animation-delay: 120ms; }
.list.list-intro .word-row:nth-child(6) { animation-delay: 150ms; }
.list.list-intro .word-row:nth-child(7) { animation-delay: 180ms; }
.list.list-intro .word-row:nth-child(8) { animation-delay: 210ms; }
.list.list-intro .word-row:nth-child(9) { animation-delay: 240ms; }
.list.list-intro .word-row:nth-child(n + 10) { animation-delay: 270ms; }

@keyframes row-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .detail.sheet-in { animation: sheet-in 380ms var(--ease-out); }
}

@keyframes sheet-in {
  from { opacity: 0.4; transform: translateY(32px); }
  to { opacity: 1; transform: none; }
}

.study, .quiz {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
}

.study[hidden], .quiz[hidden] { display: none; }

body:has(.study:not([hidden])),
body:has(.reader:not([hidden])),
body:has(.quiz:not([hidden])),
body:has(.sky:not([hidden])) { overflow: hidden; }

.study-card, .quiz-card {
  width: min(640px, 100%);
  min-height: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 28px 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  max-height: 100%;
  overflow: auto;
  animation: sheet-in 380ms var(--ease-out);
}

.study-top, .grades {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.study-top .kicker { margin: 0; }

.study-progress {
  height: 3px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.study-progress span {
  display: block;
  height: 100%;
  width: calc(var(--done) * 100%);
  background: var(--accent);
  transition: width 280ms var(--ease-out);
}

.study-left, .study-hint {
  margin: 0;
  color: var(--faint);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.study-face { display: flex; flex-direction: column; flex: 1; }
.study-face.enter { animation: detail-in 460ms var(--ease-out); }

.study-face h2 {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.8rem, 7vw, 4.8rem);
  letter-spacing: -0.04em;
  line-height: 0.92;
}

.study-answer { animation: detail-in 420ms var(--ease-out); }
.study-answer .definition { margin-top: 22px; }
.study-answer .pairs { margin-top: 22px; }

.reveal {
  margin-top: 28px;
  min-height: 132px;
  border: 0;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 650;
}

.grades { margin-top: auto; }
.grades .chip { flex: 1; padding: 14px 16px; text-align: center; }

.know {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.reader {
  position: fixed;
  z-index: 6;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 50% 12%, rgba(198, 150, 44, 0.12), transparent 58%),
    var(--bg);
  padding: calc(18px + var(--safe-top)) 0 calc(16px + var(--safe-bottom));
}

.reader[hidden] { display: none; }

.reader-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 28px;
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
}

.bar-close {
  justify-self: start;
  width: max-content;
  padding: 4px 11px;
  font-size: 0.78rem;
  line-height: 1.2;
}

.reader-bar .icon-actions { justify-self: end; }

.reader-place, .reader-hint {
  margin: 0;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  text-align: center;
}

.reader-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: min(18vw, 120px);
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 2.4rem;
  line-height: 1;
}

.reader-edge.prev { left: 0; }
.reader-edge.next { right: 0; }
.reader-edge:hover { color: var(--ink); }
.reader-edge:disabled { opacity: 0; }

.reader-stage {
  width: min(920px, calc(100% - 96px));
  margin: auto;
  padding-bottom: 4vh;
}

.reader-stage h2 {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(3.4rem, 11vw, 7.6rem);
  letter-spacing: -0.045em;
  line-height: 0.9;
}

.reader-stage .definition {
  max-width: 38rem;
  margin: 28px 0 0;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  line-height: 1.45;
}

.reader-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-top: 32px;
}

.reader-pairs h3 {
  margin: 0 0 4px;
  color: var(--faint);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.reader-pairs p {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.4rem;
}

.reader-hint { padding-bottom: 4px; }

.quiz-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.choices { display: grid; gap: 8px; }

.choice {
  display: flex;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: transparent;
  text-align: left;
  line-height: 1.4;
}

.choice-key {
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

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

.choice.is-wrong {
  background: rgba(140, 54, 40, 0.1);
  border-color: #8c4638;
}

.choice:disabled { cursor: default; }

.sky {
  position: fixed;
  z-index: 6;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(900px 520px at 50% 45%, rgba(226, 193, 106, 0.08), transparent 60%),
    #07080d;
  color: #f4f0e8;
  padding: calc(16px + var(--safe-top)) 0 calc(14px + var(--safe-bottom));
}

.sky[hidden] { display: none; }

.sky-stars {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  pointer-events: none;
}

.sky-bar, .sky-key, .sky-hint {
  position: relative;
  z-index: 2;
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
}

.sky-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 28px;
}

.sky-bar .icon-actions { justify-self: end; }
.sky-bar .chip, .sky-bar .speak { color: #f4f0e8; border-color: rgba(244, 240, 232, 0.24); }

.sky-title, .sky-key, .sky-hint {
  margin: 0;
  text-align: center;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: rgba(244, 240, 232, 0.82);
}

.sky-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.sky-stage:active { cursor: grabbing; }

.sky-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  overflow: visible;
  transform-origin: 0 0;
}

.sky-lines {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.sky-lines line { stroke-width: 1.4; filter: url(#sky-glow); }
.sky-lines line.kind-synonym { stroke: #e4c36a; }
.sky-lines line.kind-antonym { stroke: #7eb8c9; }
.sky-lines line.kind-akin { stroke: #c6b39a; stroke-dasharray: 4 7; }
.sky-lines text {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  paint-order: stroke;
  stroke: #07080d;
  stroke-width: 5px;
}
.sky-lines text.kind-synonym { fill: #f0d48a; }
.sky-lines text.kind-antonym { fill: #b7dbe4; }
.sky-lines text.kind-akin { fill: #e6d7c2; }

.sky-nodes { position: absolute; left: 0; top: 0; overflow: visible; }

.sky-zoom {
  position: absolute;
  right: 16px;
  bottom: 14px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sky-zoom button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(244, 240, 232, 0.28);
  background: rgba(8, 10, 14, 0.78);
  color: #f4f0e8;
  font-size: 1.2rem;
  line-height: 1;
}

.sky-node {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(244, 240, 232, 0.86);
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 0 16px rgba(244, 240, 232, 0.28);
}

.sky-node.kind-center { color: #fff8ea; }

.sky-node.is-focus {
  font-size: 28px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff8ea;
  text-shadow: 0 0 18px rgba(228, 195, 106, 0.85), 0 0 48px rgba(228, 195, 106, 0.35);
}

.sky-node.phrase { letter-spacing: 0; text-transform: none; }
.sky-node.kind-synonym { color: #f0d48a; }
.sky-node.kind-antonym { color: #b7dbe4; }
.sky-node.kind-akin { color: #e6d7c2; }
.sky-node.is-entry { cursor: pointer; }
.sky-node.is-entry:hover span,
.sky-node.is-focus span { text-shadow: 0 0 18px currentColor; }
.sky-node.is-focus { color: #fff8ea; }

.sky-tip {
  position: absolute;
  z-index: 3;
  width: min(280px, 70vw);
  padding: 14px 16px;
  border: 1px solid rgba(244, 240, 232, 0.16);
  border-radius: 16px;
  background: rgba(8, 10, 14, 0.92);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.sky-tip .kicker { margin: 0 0 4px; color: #e4c36a; }
.sky-tip strong { font-family: var(--serif); font-size: 1.35rem; font-weight: 500; }
.sky-tip p:last-child { margin: 8px 0 0; color: rgba(244, 240, 232, 0.82); line-height: 1.4; }

.sky-key { display: flex; justify-content: center; flex-wrap: wrap; gap: 16px; padding-top: 4px; }
.sky-key i { width: 18px; height: 0; margin-right: 6px; border-top: 2px solid; display: inline-block; vertical-align: middle; }
.sky-key .syn { border-color: #e4c36a; }
.sky-key .ant { border-color: #7eb8c9; }
.sky-key .akin { border-color: #c6b39a; border-top-style: dashed; }
.sky-hint { padding: 6px 0 2px; }

.reader-stage.enter-forward > :nth-child(2),
.reader-stage.enter-back > :nth-child(2) { animation-delay: 40ms; }
.reader-stage.enter-forward > :nth-child(3),
.reader-stage.enter-back > :nth-child(3) { animation-delay: 90ms; }
.reader-stage.enter-forward > :nth-child(4),
.reader-stage.enter-back > :nth-child(4) { animation-delay: 140ms; }

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