:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #12141a;
  --muted: #667085;
  --card: #ffffff;
  --line: #e6e8ee;
  --accent: #3157e5;
  --ok: #067647;
  --wait: #b54708;
  --shadow: 0 10px 30px rgba(18, 20, 26, 0.08);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
button, .home, .menu-face, .tok { touch-action: manipulation; }
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
  background:
    radial-gradient(880px 420px at 50% -120px, #4d6ae8 0%, transparent 68%),
    #1a274f;
}
.gate-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 28px;
  padding: 34px 28px 22px;
  box-shadow: 0 28px 70px rgba(8, 14, 40, 0.38);
  text-align: center;
}
.glossa-mark {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  margin: 0 auto 16px;
  display: block;
  box-shadow: 0 10px 24px rgba(26, 39, 79, 0.22);
}
.gate-card h1 { font-size: 1.85rem; }
.gate-lead { margin: 8px 0 0; line-height: 1.45; }
.gate-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 26px;
  text-align: left;
}
.gate-card .field { margin-top: 0; font-weight: 600; letter-spacing: 0.01em; }
.gate-card .field input {
  margin-top: 2px;
  background: #f4f6f8;
  border-color: transparent;
  padding: 14px 14px;
  font-weight: 450;
  color: var(--ink);
}
.gate-card .field input:focus { background: #fff; }
.gate-card .primary {
  width: 100%;
  margin-top: 4px;
  padding: 14px 16px;
  font-weight: 650;
}
.gate-alt { margin-top: 18px; color: var(--muted); font-size: 0.92rem; }
.gate-alt button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 650;
  padding: 0;
}
.gate-card .error { min-height: 1.2em; text-align: center; }
@media (pointer: coarse) {
  .ghost, .primary, .menu button { min-height: 44px; }
  .tok { padding: 0 0.02em; cursor: pointer; }
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.7rem; letter-spacing: -0.03em; font-weight: 650; }
.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 22px 32px 6px;
}
.top-title { flex: 1; min-width: 0; }
.top-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.face-slot .menu { left: 0; right: auto; }
.home, .menu-face {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0;
  display: grid;
  place-items: center;
  flex: none;
}
.home svg { width: 20px; height: 20px; fill: var(--ink); }
.menu-face {
  overflow: hidden;
  background: #e7ebf3;
  font-size: 1rem;
  font-weight: 650;
}
.menu-face img { width: 100%; height: 100%; object-fit: cover; }
.menu-face.over { outline: 3px solid var(--accent); outline-offset: 3px; }
.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 6;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.menu[hidden] { display: none; }
.menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 10px;
  padding: 10px 12px;
}
.menu button:hover { background: #f4f6f8; }
.glossary { padding-bottom: 48px; }
.glossary-tools { padding: 8px 32px 0; max-width: 720px; }
.proof {
  margin: 18px 32px;
  background: #fff;
  border-radius: 18px;
  padding: 28px 32px;
  box-shadow: var(--shadow);
}
.proof-kicker { color: var(--accent); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.proof h2 { margin: 4px 0 6px; }
.proof h3 { margin: 22px 0 8px; font-size: 1rem; }
.gloss { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.gloss th, .gloss td { text-align: left; vertical-align: top; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); }
.gloss th { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.anki-space { margin-top: 6vh; }
.anki-space .ghost { margin-bottom: 18px; }
.who { color: var(--muted); font-size: 0.92rem; }
.anki-pill {
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}
.anki-pill.ready { color: var(--ok); }
.anki-pill.wait { color: var(--wait); }

.login {
  max-width: 640px;
  margin: 12vh auto;
  padding: 0 20px;
}
.people {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin-top: 32px;
}
.person, .add-person {
  width: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: center;
}
.face {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #e7ebf3;
  color: var(--ink);
  font-size: 1.7rem;
  font-weight: 650;
}
.face img, .mini-face { width: 100%; height: 100%; object-fit: cover; }
.person.over .face { outline: 3px solid var(--accent); outline-offset: 3px; }
.crop-stage {
  width: 260px;
  height: 260px;
  margin: 16px auto;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  background: #d5dbe6;
  touch-action: none;
  cursor: grab;
}
.crop-stage img { position: absolute; max-width: none; user-select: none; }
.crop-modal .field input[type="range"] { padding: 12px 0; }
.person strong { font-size: 0.95rem; }
.person-tools { display: flex; gap: 8px; color: var(--muted); font-size: 0.75rem; }
.person-tools button, .person-tools label { border: 0; background: transparent; color: var(--muted); padding: 0; font-size: 0.75rem; }
.add-person .face { background: #fff; border: 1px dashed #c5cad6; color: var(--muted); }
.who-line { display: flex; align-items: center; gap: 10px; }
.mini-face { width: 36px; height: 36px; border-radius: 50%; }
.profile, .primary, .ghost {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
}
.profile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  min-height: 112px;
  text-align: left;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(18, 20, 26, 0.04);
}
.profile:hover { border-color: #c9d4f8; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef2ff;
  color: var(--accent);
  font-weight: 700;
}
.profile.selected, .primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.profile.selected .avatar { background: rgba(255,255,255,.14); color: #fff; }
.ghost { background: transparent; }
.pin-row { display: flex; gap: 8px; margin-top: 18px; }
.pin-row input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
}
.pin-row input:focus, .field input:focus, .field select:focus, .chapter-bar select:focus {
  outline: 2px solid #c9d4f8;
  border-color: var(--accent);
}
.error { color: #c01048; margin-top: 12px; }

.shelves { padding: 8px 0 56px; }
.shelf { margin-top: 28px; }
.shelf h2 {
  padding: 0 32px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 2px 32px 18px;
}
.book {
  scroll-snap-align: start;
  position: relative;
  flex: 0 0 156px;
  height: 232px;
  overflow: hidden;
  border-radius: 16px;
  background: var(--cover, #243044);
  color: #fff;
  box-shadow: var(--shadow);
}
.cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-open {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: linear-gradient(to top, rgba(10, 14, 22, .82), rgba(10, 14, 22, .05) 62%);
  color: inherit;
  text-align: left;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
}
.book-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.94);
  color: #12141a;
  font-size: 18px;
  line-height: 1;
}
.book strong { font-size: 1rem; line-height: 1.25; font-weight: 650; }
.meta { color: rgba(255,255,255,.82); font-size: 0.75rem; }
.drop {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: calc(100% - 64px);
  margin: 22px 32px 0;
  padding: 18px 20px;
  border: 1px dashed #cfd5e2;
  border-radius: 16px;
  background: var(--card);
  text-align: left;
}
.drop.over { border-color: var(--accent); background: #f5f7ff; }
.drop-title { font-size: 1rem; font-weight: 650; }
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(18, 20, 26, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal, .lookup {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(18, 20, 26, 0.22);
}
.modal h2 { margin-bottom: 6px; letter-spacing: -0.03em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.lookup {
  position: absolute;
  right: 18px;
  bottom: 72px;
  z-index: 5;
}
.lookup[hidden] { display: none; }
.lookup-kicker { color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.lookup-word { font-size: 1.15rem; margin-top: 4px; color: var(--muted); }
.lookup-sentence { font-size: 1.2rem; line-height: 1.5; margin: 12px 0; font-family: "Iowan Old Style", Palatino, Georgia, serif; }
.lookup-sentence mark { background: #fde68a; color: inherit; border-radius: 4px; padding: 0 3px; }
.tip {
  position: fixed;
  z-index: 8;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #12141a;
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  pointer-events: none;
}
.tip[hidden] { display: none; }
.tok {
  display: inline;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.tok:hover, .tok:focus, .tok-on { background: #fde68a; }
.empty { padding: 12px 32px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); margin-top: 12px; }

.liseuse {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #eef1f5;
}
.reader-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}
.reader-main { min-height: 0; display: flex; flex-direction: column; }
.live-gloss {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-left: 1px solid var(--line);
}
.live-gloss header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
}
.live-gloss header .primary { padding: 8px 10px; font-size: 0.82rem; }
.live-gloss ul { list-style: none; margin: 0; padding: 0 12px 16px; overflow: auto; }
.live-gloss li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.live-gloss li span { display: block; color: var(--muted); font-size: 0.85rem; }
.live-gloss button[data-drop-card] { border: 0; background: transparent; font-size: 1.2rem; line-height: 1; }
.hold {
  position: fixed;
  z-index: 9;
  width: 28px;
  height: 28px;
  pointer-events: none;
}
.hold[hidden] { display: none; }
.hold circle { fill: #fff; stroke: #e6e8ee; stroke-width: 4; }
.hold circle.meter {
  fill: none;
  stroke: #3157e5;
  stroke-linecap: round;
  stroke-dasharray: 88;
  stroke-dashoffset: 88;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.hold.run circle.meter { animation: hold-meter 3s linear forwards; }
@keyframes hold-meter { to { stroke-dashoffset: 0; } }
.sync-back {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(18, 20, 26, 0.28);
}
.sync-card {
  width: min(340px, calc(100% - 48px));
  background: #fff;
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.sync-label { font-size: 0.95rem; }
.sync-track {
  height: 6px;
  margin-top: 14px;
  border-radius: 999px;
  background: #e7ebf3;
  overflow: hidden;
}
.sync-bar {
  height: 100%;
  width: 40%;
  border-radius: inherit;
  background: var(--accent);
  animation: sync-slide 1.05s ease-in-out infinite;
}
.sync-bar.sync-done { animation: none; width: 100%; transition: width 0.35s ease; }
.sync-bar.sync-fail { animation: none; width: 100%; background: #c01048; }
@keyframes sync-slide {
  0% { transform: translateX(-130%); }
  100% { transform: translateX(280%); }
}
.liseuse-top, .liseuse-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
}
.reader-title { min-width: 0; text-align: center; }
.reader-title strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.liseuse-foot { display: block; padding-top: 0; }
.chapter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 8px;
}
.chapter-bar[hidden] { display: none; }
.chapter-bar select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  padding: 8px 12px;
}
.chapter-bar .ghost { min-width: 40px; padding: 8px 0; font-size: 1.2rem; line-height: 1; background: #fff; }
.liseuse-foot input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  border-radius: 99px;
  background: #d5dbe6;
}
.liseuse-foot input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
}
.spread {
  --edge: 56px;
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--edge) minmax(0, 1fr) var(--edge);
}
.flag-wrap {
  position: absolute;
  top: 0;
  right: calc(var(--edge) + 22px);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.flag {
  width: 22px;
  height: 16px;
  padding: 0;
  border: 0;
  background: #f3c1cb;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 68%, 0 100%);
}
.flag.on {
  height: 48px;
  background: #e11d48;
}
.flag-count {
  margin-top: 4px;
  min-width: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #e11d48;
  font-size: 0.75rem;
  font-weight: 700;
}
.flag-menu {
  margin-top: 6px;
  min-width: 190px;
  max-width: 260px;
  padding: 6px;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.flag-menu button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 12px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}
.flag-menu button span { color: var(--muted); flex: none; }
.flag-menu button:hover { background: #f4f6f8; }
.sheet {
  background: #fff;
  margin: 0 0 12px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 42px 48px;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: stretch;
}
.sheet canvas { max-width: 100%; max-height: 100%; }
.font-size { display: flex; gap: 6px; }
.font-size .ghost { padding: 8px 12px; min-width: 44px; background: #fff; }
.font-inc { font-size: 1.15rem; }
.font-size button:disabled { opacity: 0.35; }
.sheet-text {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: var(--reading-size, 21px);
  line-height: 1.55;
  white-space: pre-wrap;
  hyphens: auto;
  text-align: left;
}
.sheet-text h1, .sheet-text h2, .sheet-text h3 {
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin: 0 0 0.75em;
}
.sheet-text h1 { font-size: 1.45em; }
.sheet-text h2 { font-size: 1.18em; }
.sheet-text p, .sheet-text li, .sheet-text blockquote { margin: 0 0 0.9em; }
.sheet-text > :last-child { margin-bottom: 0; }
.sheet-text em { font-style: italic; }
.probe {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  left: 0;
  top: 0;
}
.zone { border: 0; background: transparent; padding: 0; }
.zone-prev { cursor: w-resize; }
.zone-next { cursor: e-resize; }
.toast { min-height: 1.2em; color: var(--muted); margin-top: 8px; font-size: 0.85rem; }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .proof { margin: 0; padding: 0; box-shadow: none; border-radius: 0; }
  .gloss th, .gloss td { border-bottom: 1px solid #ccc; }
}
@media (max-width: 800px) {
  .drop { width: auto; margin: 16px 16px 0; }
  .top, .shelf h2, .row { padding-left: 16px; padding-right: 16px; }
  .sheet { padding: 28px 22px; border-radius: 0; margin: 0; }
  .spread { --edge: 28px; }
  .reader-body { grid-template-columns: 1fr; }
  .live-gloss { max-height: 34vh; border-left: 0; border-top: 1px solid var(--line); }
  .lookup { left: 12px; right: 12px; width: auto; }
}
