:root {
  --paper: #fbf6ea;
  --ink: #27201a;
  --ink-soft: #635549;
  --ab: #d95734;
  --bd: #286db3;
  --ec: #168c6b;
  --path: #7644ad;
  --gold: #c98a2c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100vw; height: 100vh; overflow: hidden;
  background: #d6cec0;
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
  color: var(--ink); user-select: none;
}
#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; cursor: grab; touch-action: none; }
#stage.dragging-b { cursor: ew-resize; }
#stage.orbiting { cursor: grabbing; }

.top-left-menu {
  position: fixed; top: 14px; left: 16px; z-index: 42;
  display: flex; gap: 8px; align-items: center;
}
.circle-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1.5px solid rgba(39,32,26,0.22); background: rgba(251,246,234,0.95);
  color: var(--ink); font-size: 16px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: inline-flex; align-items: center; justify-content: center;
}
.circle-btn:hover { background: #fffdf8; }

.top-right-hud {
  position: fixed; top: 14px; right: 16px; z-index: 42;
  display: none; gap: 6px; flex-wrap: wrap; align-items: center;
  background: rgba(251,246,234,0.95); backdrop-filter: blur(6px);
  border: 1px solid rgba(39,32,26,0.18); padding: 5px 11px; border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.1);
  font-family: system-ui, -apple-system, sans-serif; font-size: 12px; font-weight: 600;
}
.top-right-hud.show { display: flex; }
.hud-tag { padding: 2px 8px; border-radius: 999px; background: #f0e6d2; }
.hud-tag.fwd { background: #fdeae3; color: #a6371b; }
.hud-tag.ret { background: #e8effc; color: #244c8a; }
.hud-tag.turn { background: #fdf3d7; color: #9c650c; }
.hud-tag.ok { background: #e2f5eb; color: #10553d; }

#loupe {
  position: fixed; width: 144px; height: 144px; border-radius: 50%;
  pointer-events: none; z-index: 25; display: none; transform: translate(-50%, -50%);
  border: 3px solid rgba(255,252,245,0.96);
  box-shadow: 0 10px 28px rgba(24,18,12,0.26), inset 0 0 12px rgba(130,175,195,0.22), 0 0 0 1.5px rgba(39,32,26,0.2);
  overflow: hidden; background: #fbf6ea;
}
#loupe canvas { width: 100%; height: 100%; display: block; }

#float-card {
  position: fixed; top: 58px; right: 16px; width: 368px;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 134px);
  overflow-y: auto; z-index: 38;
  background: rgba(252,248,239,0.97); backdrop-filter: blur(10px);
  border: 1.5px solid rgba(39,32,26,0.22); border-radius: 14px; padding: 13px 15px;
  box-shadow: 0 16px 38px rgba(25,18,12,0.2); display: none;
  font-family: system-ui, -apple-system, sans-serif; color: var(--ink);
  user-select: text;
}
#float-card.open { display: block; }
#float-card.preview-mode { pointer-events: none; }

.fc-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-bottom: 1px dashed rgba(39,32,26,0.2); padding-bottom: 7px; margin-bottom: 9px;
}
.fc-kicker { font-size: 11px; font-weight: 700; color: var(--ab); }
.fc-title { font-size: 15px; font-weight: 700; font-family: "Noto Serif SC", serif; margin: 2px 0 0; }
.fc-close {
  border: 1px solid rgba(39,32,26,0.22); background: #f3ead5; color: var(--ink);
  border-radius: 999px; padding: 3px 10px; font-size: 11.5px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.fc-body { font-size: 12.8px; line-height: 1.56; }
.math { font-family: "Times New Roman", Georgia, serif; font-style: italic; padding: 0 1px; }
.math-rm { font-family: "Times New Roman", Georgia, serif; font-style: normal; }

.fc-sec {
  background: #fffdf8; border: 1px solid rgba(39,32,26,0.14);
  border-radius: 9px; padding: 9px 11px; margin-bottom: 8px;
}
.fc-sec.note { background: #fdf5e2; border-color: rgba(201,138,44,0.45); font-size: 12px; }
.fc-sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.fc-sec-label { font-size: 11.5px; font-weight: 700; color: var(--bd); margin-bottom: 4px; display: block; }
.fc-sec-label.red { color: var(--ab); }
.fc-sec-label.green { color: var(--ec); }
.fc-sec-label.purple { color: var(--path); }

.choice-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.choice-btn {
  border: 1px solid rgba(39,32,26,0.24); background: #faf4e6; color: var(--ink);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.choice-btn.selected { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }

.in-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.in-txt {
  width: 72px; padding: 4px 6px; border: 1.5px solid rgba(39,32,26,0.34);
  border-radius: 6px; background: #fff; font-size: 13.5px;
  font-family: "Times New Roman", serif; text-align: center;
}
.in-txt.wide { width: 104px; }
.btn-act {
  background: #9d3d2d; color: #fff; border: none; border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.btn-act:hover { background: #812f21; }
.btn-sub {
  background: #f3ead5; color: var(--ink); border: 1px solid rgba(39,32,26,0.22);
  border-radius: 6px; padding: 4px 9px; font-size: 11.6px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.btn-sub:hover { background: #e8dcc0; }
.btn-sub.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.fb { margin-top: 6px; padding: 6px 9px; border-radius: 6px; font-size: 12px; line-height: 1.45; display: none; }
.fb.show { display: block; }
.fb.ok { background: #e2f5eb; color: #10553d; border: 1px solid #8fd1b4; }
.fb.warn { background: #fff2db; color: #7a4b06; border: 1px solid #e6be70; }

.proof-item {
  padding: 6px 8px; border-radius: 6px; border-left: 3px solid transparent;
  background: #faf5e8; margin-bottom: 5px; cursor: pointer; font-size: 12px; line-height: 1.46;
}
.proof-item:hover { background: #f2e8d2; }
.proof-item.lit { background: #fdf1d4; border-left-color: var(--gold); font-weight: 600; }

.rec-tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; margin-top: 6px; }
.rec-tbl th, .rec-tbl td { border: 1px solid rgba(39,32,26,0.18); padding: 3px 4px; text-align: center; }
.rec-tbl th { background: #efe5cf; }

.why-area {
  width: 100%; min-height: 52px; margin-top: 6px; padding: 6px; font-size: 12px;
  border: 1.5px solid rgba(39,32,26,0.25); border-radius: 6px; resize: vertical;
  font-family: system-ui, sans-serif;
}

.grid-paint { display: grid; grid-template-columns: repeat(3, 28px); gap: 3px; }
.grid-paint.r5 { grid-template-rows: repeat(5, 22px); }
.gp-cell { border: 1px solid rgba(39,32,26,0.28); border-radius: 3px; background: #fff; cursor: pointer; }
.gp-cell.on { background: #286db3; border-color: #1b4e7a; }

#pin-layer { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.pin {
  position: absolute; transform: translate(-50%, -100%);
  background: rgba(251,246,234,0.96); border: 1.5px solid var(--ink);
  border-radius: 5px; padding: 1px 6px; font-size: 11.5px; font-weight: 700;
  font-family: system-ui, sans-serif; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,0.16);
}
.pin.b { border-color: var(--ab); color: #a6371b; background: #fff6f2; }
.pin.c { border-color: var(--bd); color: #1b4e7a; background: #f0f7ff; }
.pin.e { border-color: var(--ec); color: #0f5f47; background: #ecfaf4; }
.pin.p { border-color: var(--path); color: #542885; background: #f5effc; }
.pin.below { transform: translate(-50%, 0); }

.badge-3d {
  position: absolute; transform: translate(-50%, -50%);
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700;
  font-family: system-ui, sans-serif; color: #fff; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.callout-3d {
  position: absolute; transform: translate(-50%, -100%);
  background: #fff9e6; border: 2.5px solid #d48817; color: #3d2504;
  padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 800;
  font-family: system-ui, sans-serif; white-space: nowrap;
  box-shadow: 0 8px 22px rgba(42,28,6,0.3); display: none;
}
.callout-3d::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  border-width: 8px 7px 0 7px; border-style: solid; border-color: #d48817 transparent transparent transparent;
}

.bottom-pill {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  z-index: 40; display: flex; align-items: center; gap: 6px;
  background: rgba(251,246,234,0.96); backdrop-filter: blur(8px);
  border: 1.5px solid rgba(39,32,26,0.2); border-radius: 999px;
  padding: 7px 14px; box-shadow: 0 8px 26px rgba(24,18,12,0.2);
  font-family: system-ui, -apple-system, sans-serif; max-width: calc(100vw - 24px); flex-wrap: nowrap;
}
.lesson-controls { display: flex; align-items: center; gap: 6px; }
.pill-hint { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.pill-btn {
  border: 1px solid rgba(39,32,26,0.18); background: #fffdf8; color: var(--ink);
  border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.pill-btn:hover { background: #f1e6cf; }
.pill-btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pill-btn.active { background: #9d3d2d; color: #fff; border-color: #9d3d2d; }
.pill-slider { width: 122px; accent-color: #9d3d2d; cursor: pointer; }
.pill-time { font-size: 12.5px; font-weight: 700; min-width: 56px; font-variant-numeric: tabular-nums; }
.pill-div { width: 1px; height: 18px; background: rgba(39,32,26,0.18); flex-shrink: 0; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(24,19,14,0.55);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 16px;
}
.modal-bg.open { display: flex; }
.modal-box {
  background: var(--paper); border: 2px solid var(--ink); border-radius: 14px;
  max-width: 580px; width: 100%; padding: 18px 22px;
  font-family: system-ui, sans-serif; font-size: 13.5px; line-height: 1.65;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
@media (max-width: 1020px) {
  .pill-slider { width: 82px; }
  .top-right-hud { display: none !important; }
  .bottom-pill { overflow-x: auto; gap: 5px; }
}

.page-turn-button {
  position: fixed;
  z-index: 21;
  transform: translate(-50%, -50%);
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid #d2c2a7;
  border-radius: 999px;
  background: #fffbf2;
  color: #534330;
  font: 600 11px system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}
.page-turn-button:hover:not(:disabled), .page-turn-button:focus-visible {
  border-color: var(--ab);
  color: #9d3d2d;
}
.page-turn-button:disabled {
  border-color: transparent;
  cursor: default;
  color: #786b59;
}
