:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #20201d;
  --muted: #686357;
  --line: #d8cebd;
  --panel: #fffaf1;
  --panel-deep: #efe5d2;
  --accent: #0f6b61;
  --accent-dark: #094f48;
  --warn: #b64b27;
  --shadow: 0 18px 50px rgba(56, 45, 28, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 350px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.library-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 24px 20px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.brand-block {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.05;
}

.summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.summary-line span {
  padding: 5px 9px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.search-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: #fffdf8;
  color: var(--ink);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 97, 0.16);
}

.draw-panel {
  border-radius: 16px;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.78);
}

.draw-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.draw-panel-header h2 {
  margin-top: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  line-height: 1.1;
}

.draw-button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: white;
  cursor: pointer;
  flex: 0 0 auto;
  min-width: 74px;
  min-height: 44px;
  padding: 0 12px;
}

.draw-button:hover {
  background: var(--accent-dark);
}

.draw-button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: var(--panel-deep);
  color: var(--muted);
}

.draw-card {
  border-radius: 12px;
  display: grid;
  gap: 5px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--accent);
  background:
    linear-gradient(135deg, rgba(15, 107, 97, 0.12), rgba(182, 75, 39, 0.1)),
    var(--panel);
  box-shadow: none;
}

.draw-card.is-drawing {
  border-color: var(--warn);
  will-change: transform;
}

:is(button, a, input):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.storage-notice {
  color: var(--warn);
  font-size: 12px;
}

.draw-card span,
.draw-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.draw-card strong {
  min-width: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.tree-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 13px;
}

.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--ink);
  cursor: pointer;
}

.select-all-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.selection-summary {
  color: var(--muted);
  font-size: 12px;
}

.draw-ceremony {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 250, 241, 0.92) 0 12%, rgba(15, 107, 97, 0.34) 30%, transparent 58%),
    rgba(18, 18, 16, 0.66);
  pointer-events: none;
}

.ceremony-vignette {
  position: absolute;
  inset: -12%;
  background:
    radial-gradient(circle at 50% 44%, transparent 0 28%, rgba(18, 18, 16, 0.46) 58%, rgba(18, 18, 16, 0.84) 100%),
    linear-gradient(90deg, rgba(15, 107, 97, 0.22), transparent 28% 72%, rgba(182, 75, 39, 0.2));
}

.ceremony-beam {
  position: absolute;
  top: -16vh;
  width: 26vw;
  height: 110vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 250, 241, 0.76), rgba(15, 107, 97, 0.18) 42%, transparent 72%);
  opacity: 0;
  transform-origin: top center;
}

.ceremony-beam-left {
  left: 19vw;
  transform: rotate(19deg);
}

.ceremony-beam-right {
  right: 19vw;
  transform: rotate(-19deg);
}

.ceremony-ring {
  position: absolute;
  left: 50%;
  top: 53%;
  width: min(58vw, 560px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 250, 241, 0.78);
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent 80%, rgba(15, 107, 97, 0.14) 94%, rgba(255, 250, 241, 0.18) 98%, transparent 100%);
  box-shadow: 0 0 0 18px rgba(255, 250, 241, 0.08);
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}

.ceremony-rail {
  position: absolute;
  top: max(62px, 10vh);
  left: 50%;
  display: grid;
  gap: 6px;
  width: min(560px, calc(100vw - 48px));
  padding: 14px 18px;
  border: 1px solid rgba(255, 250, 241, 0.62);
  background: rgba(255, 250, 241, 0.86);
  box-shadow: 0 22px 56px rgba(18, 18, 16, 0.28);
  transform: translateX(-50%);
  text-align: center;
}

.ceremony-rail-label,
.ceremony-status {
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-style: italic;
}

.ceremony-rail-title {
  min-width: 0;
  color: var(--ink);
  font-size: clamp(18px, 3vw, 31px);
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ceremony-carousel {
  position: absolute;
  left: 50%;
  top: 53%;
  z-index: 2;
  width: 1040px;
  height: 420px;
  max-width: calc(100vw - 80px);
  transform: translate(-50%, -50%);
}

.ceremony-carousel::before {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(255, 250, 241, 0.72);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse closest-side, transparent 87%, rgba(15, 107, 97, 0.16) 94%, rgba(255, 250, 241, 0.12) 98%, transparent 100%);
  box-shadow: 0 0 0 12px rgba(255, 250, 241, 0.05);
}

.ceremony-carousel::after {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(100% + 18px);
  height: calc(100% + 18px);
  border: 1px solid rgba(15, 107, 97, 0.32);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.ceremony-carousel-card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 34px;
  height: 34px;
  border: 2px solid rgba(255, 250, 241, 0.96);
  border-radius: 999px;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.96) 0 12%, hsla(var(--ball-hue), 88%, 72%, 0.96) 22%, hsla(var(--ball-hue), 76%, 43%, 1) 62%, hsla(var(--ball-hue), 82%, 24%, 1) 100%);
  box-shadow: 0 0 12px hsla(var(--ball-hue), 85%, 62%, 0.55);
  /* These bounded, temporary layers are removed with the ceremony. */
  will-change: transform, opacity;
}

.ceremony-carousel-card::after {
  position: absolute;
  inset: -12px;
  border: 2px solid rgba(255, 250, 241, 0.85);
  border-radius: 50%;
  background: radial-gradient(circle, transparent 40%, hsla(var(--ball-hue), 90%, 68%, 0.35) 65%, transparent 72%);
  content: "";
  opacity: 0;
}

.ceremony-carousel-card.is-focus::after {
  opacity: 1;
}

.ceremony-card {
  position: relative;
  z-index: 3;
  display: grid;
  gap: 12px;
  width: min(640px, calc(100vw - 42px));
  min-height: 260px;
  padding: clamp(24px, 5vw, 42px);
  border: 2px solid var(--accent);
  background:
    linear-gradient(145deg, rgba(255, 253, 248, 0.98), rgba(239, 229, 210, 0.94)),
    var(--panel);
  box-shadow:
    0 34px 90px rgba(18, 18, 16, 0.42),
    0 0 0 10px rgba(255, 250, 241, 0.18);
  text-align: center;
}

.ceremony-card::before,
.ceremony-card::after {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(15, 107, 97, 0.18);
  content: "";
  pointer-events: none;
}

.ceremony-card::after {
  inset: 22px;
  border-color: rgba(182, 75, 39, 0.18);
}

.ceremony-title {
  align-self: center;
  min-width: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 6vw, 64px);
  line-height: 1.02;
  overflow-wrap: anywhere;
}

.ceremony-meta {
  color: var(--muted);
  font-size: clamp(14px, 2.2vw, 19px);
  font-style: normal;
  overflow-wrap: anywhere;
}

.ceremony-spark {
  position: absolute;
  left: var(--spark-x);
  top: var(--spark-y);
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: radial-gradient(circle, #fffaf1 0 12%, rgba(255, 250, 241, 0.5) 20%, rgba(15, 107, 97, 0.15) 45%, transparent 70%);
}

.tree-root {
  display: grid;
  align-content: start;
  flex: 1;
  min-height: 160px;
  scrollbar-gutter: stable;
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
}

.date-group {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.76);
}

.date-group.is-excluded {
  background: rgba(255, 253, 248, 0.42);
}

.date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.date-header:hover {
  background: rgba(15, 107, 97, 0.08);
}

.date-main {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.date-title {
  display: flex;
  align-items: center;
  min-width: 0;
  font-weight: 700;
}

.date-check-label {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  cursor: pointer;
}

.date-check {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.date-group.is-excluded .date-title {
  color: var(--muted);
}

.date-expand {
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.date-expand::before {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid var(--accent);
  content: "";
  transform: translate(-50%, -50%) rotate(90deg);
}

.date-expand:hover {
  background: rgba(15, 107, 97, 0.1);
}

.date-group.is-collapsed .date-expand::before {
  transform: translate(-50%, -50%);
}

.date-count {
  flex: 0 0 auto;
  min-width: 32px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.card-list {
  display: grid;
  padding: 0 8px 8px;
}

.date-group.is-collapsed .card-list {
  display: none;
}

.card-row {
  position: relative;
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  padding: 9px 44px 9px 10px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.card-row:hover,
.card-row.is-active {
  border-left-color: var(--accent);
  background: rgba(15, 107, 97, 0.08);
}

.card-row strong,
.card-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-row strong {
  font-size: 14px;
}

.card-row span {
  color: var(--muted);
  font-size: 12px;
}

.card-draw-count {
  position: absolute;
  right: 10px;
  bottom: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
}

/* Study workspace: one scroll area per panel, with navigation always visible. */
[hidden] { display: none !important; }
button, a { -webkit-tap-highlight-color: transparent; }
button { border-radius: 10px; }
button:disabled { cursor: not-allowed; opacity: .55; }
.brand-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.search-feedback { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 20px; color: var(--muted); font-size: 12px; }
.text-button { color: var(--accent-dark); border: 0; background: transparent; padding: 4px; min-height: 32px; cursor: pointer; flex-shrink: 0; }
.text-button:hover { text-decoration: underline; }
.animation-option { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; cursor: pointer; min-height: 28px; }
.animation-option input, .card-check { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
.card-selection-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 5px; }
.card-item { display: flex; align-items: center; gap: 4px; }
.card-check { margin: 12px 6px; cursor: pointer; }
.card-row { min-width: 0; border-radius: 8px; }
.date-check-label { min-height: 44px; }
.preview-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 12px; min-width: 0; min-height: 0; padding: 24px; }
.preview-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.preview-heading { min-width: 0; flex: 1 1 360px; }
.active-date { color: var(--accent); font-size: 12px; font-weight: 600; }
.preview-header h2 { margin-top: 6px; font-size: clamp(20px, 2vw, 28px); line-height: 1.35; overflow-wrap: anywhere; }
.active-path { margin-top: 6px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.preview-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.secondary-button, .open-link { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); text-decoration: none; font-size: 13px; cursor: pointer; }
.secondary-button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }
.open-link { border-color: var(--accent); background: var(--accent); color: white; }
.open-link:hover { background: var(--accent-dark); }
.open-link.is-disabled { pointer-events: none; background: var(--panel-deep); border-color: var(--line); color: var(--muted); }
.study-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
#cardPosition { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preview-content { position: relative; min-height: 0; }
.card-frame { display: block; width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 4px 20px rgba(56, 45, 28, .05); }
.empty-state, .frame-status { display: grid; place-content: center; justify-items: center; gap: 12px; height: 100%; padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--muted); text-align: center; line-height: 1.6; }
.empty-state { display: none; }
.empty-state strong, .frame-status strong { font-size: 22px; color: var(--ink); }
.frame-status { position: absolute; z-index: 1; inset: 0; }
.preview-panel.is-empty .empty-state { display: grid; }
.preview-panel.is-empty .card-frame { display: none; }
.keyboard-hint { text-align: center; color: var(--muted); font-size: 11px; }
.mobile-navigation { display: none; }
.skip-link { position: fixed; left: 20px; top: -100px; z-index: 100; padding: 12px; border-radius: 8px; background: var(--accent); color: white; }
.skip-link:focus { top: 12px; }
.toast { position: fixed; z-index: 120; bottom: 24px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); width: max-content; border-radius: 12px; padding: 12px 18px; background: var(--accent-dark); color: white; font-size: 13px; box-shadow: var(--shadow); }
body.is-focused .app-shell { grid-template-columns: minmax(0, 1fr); }
body.is-focused .library-panel { display: none; }
body.is-focused .preview-panel { width: min(1400px, 100%); margin-inline: auto; }
@media (max-width: 1100px) and (min-width: 861px) {
  .preview-panel { padding: 20px 16px; }
}
@media (max-width: 860px) {
  .app-shell { display: block; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .library-panel { height: 100%; padding: 20px 16px 12px; border: 0; gap: 10px; }
  .brand-block { gap: 6px; padding-bottom: 12px; }
  .brand-block h1 { font-size: 26px; }
  .brand-block .eyebrow { display: none; }
  .summary-line { font-size: 12px; }
  .summary-line span { padding: 3px 7px; border-radius: 6px; }
  .draw-panel { gap: 8px; padding: 12px; }
  .draw-panel-header h2 { font-size: 19px; }
  .draw-panel-header .eyebrow { display: none; }
  .draw-panel-header { align-items: center; }
  .draw-card { min-height: 66px; padding: 9px 12px; }
  .draw-card strong { font-size: 16px; }
  .draw-card em { display: none; }
  .animation-option { min-height: 32px; }
  .tree-root { min-height: 160px; }
  .preview-panel { display: none; height: 100%; padding: 16px 12px 8px; gap: 8px; }
  .preview-header { gap: 10px; }
  .preview-header h2 { font-size: 19px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .active-path, .keyboard-hint, #focusButton { display: none; }
  .preview-heading { flex-basis: 100%; }
  .preview-actions { width: 100%; }
  .preview-actions > * { flex: 1; }
  .study-toolbar { padding: 4px 0; }
  .card-frame { border-radius: 12px; }
  .preview-panel { grid-template-rows: auto auto minmax(0, 1fr); }
  body.is-studying .library-panel { display: none; }
  body.is-studying .preview-panel { display: grid; }
  body.is-focused:not(.is-studying) .library-panel { display: flex; }
  .mobile-navigation { display: grid; grid-template-columns: 1fr 1fr; position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); gap: 12px; background: var(--panel); border-top: 1px solid var(--line); }
  .mobile-navigation button { min-height: 46px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
  .mobile-navigation button[aria-current] { background: var(--accent); color: white; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .ceremony-card { min-height: 220px; }
  .ceremony-ring { width: min(88vw, 420px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
