:root {
  --bg0: #070511;
  --bg1: #120a1e;
  --ink: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --faint: rgba(255, 255, 255, 0.44);
  --card: rgba(255, 255, 255, 0.045);
  --card2: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
  --accent: #d9b6ff;
  --accent2: #ffb7d2;
  --danger: #ff6b6b;
  --ok: #8ff0c7;
  --radius: 14px;
  --radius2: 10px;
  --ring: 0 0 0 4px rgba(217, 182, 255, 0.24);

  color-scheme: dark;
}

:root[data-theme="dawn"] {
  --bg0: #f7f1ea;
  --bg1: #fffaf2;
  --ink: rgba(33, 20, 14, 0.92);
  --muted: rgba(33, 20, 14, 0.64);
  --faint: rgba(33, 20, 14, 0.42);
  --card: rgba(255, 255, 255, 0.8);
  --card2: rgba(255, 255, 255, 0.92);
  --border: rgba(33, 20, 14, 0.12);
  --shadow: 0 24px 70px rgba(105, 61, 98, 0.16);
  --accent: #9d4edd;
  --accent2: #c9184a;
  --danger: #d62828;
  --ok: #2a9d8f;
  --ring: 0 0 0 4px rgba(157, 78, 221, 0.2);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--ink);
  background:
    radial-gradient(760px 420px at 8% -12%, rgba(217, 182, 255, 0.14), transparent 64%),
    radial-gradient(640px 380px at 108% 6%, rgba(255, 183, 210, 0.09), transparent 62%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  overflow: hidden;
}

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 330px 1fr;
}

.sidebar {
  height: 100%;
  overflow: auto;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  background: rgba(255,255,255,0.035);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 8px 12px;
  border: 1px solid transparent;
}

.sigil {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 120% at 20% 10%, rgba(217,182,255,0.22), transparent 60%),
    radial-gradient(120% 120% at 80% 30%, rgba(255,183,210,0.16), transparent 58%),
    rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}

.brand-text h1 {
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-weight: 650;
  margin: 0;
  letter-spacing: 0.02em;
  font-size: 22px;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: grid;
  gap: 9px;
  padding: 0 8px 12px;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row.row-single { grid-template-columns: 1fr; }

.control-label {
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 4px 2px -2px;
}

.control-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.025);
  padding: 8px;
}

.control-group > summary {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.control-group > summary::-webkit-details-marker { display: none; }

.control-group-body {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: none;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
  user-select: none;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.18); background: var(--card2); }
.btn:active { transform: translateY(0px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn.primary {
  border-color: rgba(217,182,255,0.32);
  background: linear-gradient(135deg, rgba(217,182,255,0.18), rgba(255,183,210,0.12));
}

.btn.danger { border-color: rgba(255, 107, 107, 0.35); }

.btn.icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.btn.small {
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 12px;
  box-shadow: none;
}

.search, .filters, .list-header { padding: 0 8px 12px; }

.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 6px;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.link {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
}
.link:hover { color: var(--ink); }
.link:focus-visible { outline: none; text-decoration: underline; }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
}

:root[data-theme="dawn"] .input,
:root[data-theme="dawn"] .textarea,
:root[data-theme="dawn"] .select { background: rgba(255, 255, 255, 0.55); }

.input:focus, .textarea:focus, .select:focus { box-shadow: var(--ring); border-color: rgba(217,182,255,0.4); }

.textarea { resize: vertical; line-height: 1.45; }

.select-multi {
  min-height: 148px;
  padding: 8px;
}
.select-multi option {
  border-radius: 10px;
  padding: 7px 8px;
}

.ask-results,
.today-grid,
.shelf-list,
.timeline-list {
  display: grid;
  gap: 12px;
}

.ask-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -2px 0 12px;
}

.ask-assistant {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.assistant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.assistant-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.assistant-card h4,
.assistant-card p,
.assistant-card ul {
  margin: 0;
}

.assistant-card ul {
  padding-left: 18px;
}

.streaks-hero {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255,183,210,0.12), rgba(217,182,255,0.10));
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 14px;
}

.streak-ring {
  --streak-progress: 0%;
  align-items: center;
  aspect-ratio: 1;
  background: conic-gradient(var(--accent) var(--streak-progress), rgba(255,255,255,0.10) 0);
  border-radius: 999px;
  display: grid;
  min-width: 94px;
  place-items: center;
  position: relative;
}

.streak-ring::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: inherit;
  background: var(--panel);
}

.streak-ring strong,
.streak-ring span {
  position: relative;
  z-index: 1;
}

.streak-ring strong {
  font-size: 28px;
  line-height: 1;
}

.streak-ring span {
  color: var(--muted);
  font-size: 11px;
  margin-top: 28px;
  position: absolute;
}

.streak-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.streak-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  display: grid;
  gap: 10px;
  padding: 12px;
}

.streak-card.done {
  border-color: rgba(255, 183, 210, 0.4);
  background: rgba(255, 183, 210, 0.10);
}

.streak-card-head {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.streak-card h3,
.streak-card p,
.streak-rewards h3 {
  margin: 0;
}

.streak-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.streak-count {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 800;
  min-width: 42px;
  padding: 6px 8px;
  text-align: center;
}

.streak-bar {
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.streak-bar span {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  display: block;
  height: 100%;
}

.streak-rewards {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.reward-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.reward-badge {
  border: 1px solid rgba(255, 220, 130, 0.28);
  border-radius: 999px;
  background: rgba(255, 220, 130, 0.10);
  display: grid;
  gap: 2px;
  padding: 9px 12px;
}

.reward-badge span {
  color: var(--muted);
  font-size: 11px;
}

.streak-pop {
  animation: streakPop 420ms ease;
}

@keyframes streakPop {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.025); }
  100% { transform: scale(1); }
}

.friend-share-card,
.friend-leaderboard {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
}

.friend-share-card h3,
.friend-share-card p,
.friend-leaderboard h3 {
  margin: 0;
}

.friend-code {
  font-family: var(--mono);
  min-height: 74px;
  resize: vertical;
}

.friend-row {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  padding: 10px;
}

.friend-row.is-self {
  border-color: rgba(255, 183, 210, 0.4);
  background: rgba(255, 183, 210, 0.09);
}

.friend-row h4,
.friend-row p {
  margin: 0;
}

.friend-row p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.friend-rank {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  display: grid;
  font-weight: 800;
  height: 34px;
  place-items: center;
  width: 34px;
}

.friend-score {
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  min-width: 58px;
  padding: 6px 8px;
  text-align: center;
}

.friend-score strong {
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
}

.friend-score span {
  color: var(--muted);
  font-size: 11px;
}

.friend-remove {
  white-space: nowrap;
}

.shared-groups-list {
  display: grid;
  gap: 10px;
}

.shared-group-row {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: 10px;
}

.shared-group-row.active {
  border-color: rgba(255, 183, 210, 0.42);
  background: rgba(255, 183, 210, 0.09);
}

.shared-group-row h4,
.shared-group-row p {
  margin: 0;
}

.feature-summary {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.045);
  padding: 10px 12px;
  display: grid;
  gap: 3px;
}

.feature-summary strong {
  color: var(--ink);
  font-size: 13px;
}

.feature-summary span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.section-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-headline h3 {
  margin: 0;
}

.tools-hub {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.tool-group {
  display: grid;
  gap: 8px;
}

.tool-group h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.tool-card {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 6px;
  min-height: 126px;
}

.tool-card:hover {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.075);
}

.tool-card:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.tool-title {
  font-weight: 700;
  font-size: 14px;
}

.tool-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tool-count {
  align-self: end;
  justify-self: start;
  color: var(--faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
}

.home-action-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.home-action-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  padding: 10px;
}

.home-action-group h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wizard-preview-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin: 10px 0 4px;
}

.astro-chip-row,
.timing-forecast {
  display: grid;
  gap: 8px;
}

.timing-forecast.planner {
  margin-top: 12px;
}

.planner-row .link {
  justify-self: start;
}

.astro-chip-row {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.astro-chip,
.book-topic {
  justify-self: start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-topic {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 9px;
}

.timing-day {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
  display: grid;
  gap: 7px;
}

.timing-day strong {
  color: var(--ink);
  font-size: 13px;
}

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

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

.insight-columns h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.reader-jump {
  max-width: 96px;
  padding: 8px 10px;
}

.today-panel.compact {
  margin-top: 14px;
}

.info-grid,
.safety-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.info-row,
.safety-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  padding: 10px;
  display: grid;
  gap: 5px;
}

.info-row strong,
.safety-card strong {
  font-size: 12px;
  color: var(--ink);
}

.info-row span,
.safety-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.use-btn.static {
  cursor: default;
}

.timeline-item {
  border-left: 2px solid rgba(217,182,255,0.3);
  padding-left: 10px;
}

.shelf-card h3,
.ask-section h3,
.crosslink-panel h3,
.safety-panel h3 {
  margin-top: 0;
}

.filter-block { margin-bottom: 12px; }

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

.chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.chip:hover { color: var(--ink); border-color: rgba(255,255,255,0.18); background: rgba(255,255,255,0.06); }
.chip[aria-pressed="true"] { color: var(--ink); border-color: rgba(217,182,255,0.34); background: rgba(217,182,255,0.12); }
.chip:focus-visible { outline: none; box-shadow: var(--ring); }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.spell-list {
  list-style: none;
  padding: 0 8px 0 10px;
  margin: 0;
  display: grid;
  gap: 10px;
}

.spell-item-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.spell-item-check {
  margin-top: 14px;
  accent-color: var(--accent2);
}

.spell-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius2);
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.spell-item:hover { transform: translateY(-1px); background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.18); }
.spell-item[aria-selected="true"] { background: rgba(217,182,255,0.12); border-color: rgba(217,182,255,0.34); }
.spell-item:focus-visible { outline: none; box-shadow: var(--ring); }

.spell-item.cat-glamour {
  border-color: rgba(255, 183, 210, 0.34);
  background: linear-gradient(135deg, rgba(255, 183, 210, 0.14), rgba(255, 107, 107, 0.06));
}
.spell-item.cat-glamour:hover {
  border-color: rgba(255, 183, 210, 0.46);
  background: linear-gradient(135deg, rgba(255, 183, 210, 0.18), rgba(255, 107, 107, 0.08));
}
.spell-item.cat-glamour[aria-selected="true"] {
  border-color: rgba(255, 183, 210, 0.62);
  background: linear-gradient(135deg, rgba(255, 183, 210, 0.22), rgba(255, 107, 107, 0.10));
}

.spell-item.cat-love {
  border-color: rgba(255, 146, 173, 0.34);
  background: linear-gradient(135deg, rgba(255, 146, 173, 0.14), rgba(255, 183, 210, 0.08));
}
.spell-item.cat-love:hover {
  border-color: rgba(255, 146, 173, 0.46);
  background: linear-gradient(135deg, rgba(255, 146, 173, 0.18), rgba(255, 183, 210, 0.10));
}
.spell-item.cat-love[aria-selected="true"] {
  border-color: rgba(255, 146, 173, 0.62);
  background: linear-gradient(135deg, rgba(255, 146, 173, 0.22), rgba(255, 183, 210, 0.12));
}

.spell-item.cat-protection {
  border-color: rgba(143, 240, 199, 0.32);
  background: linear-gradient(135deg, rgba(143, 240, 199, 0.14), rgba(217, 182, 255, 0.08));
}
.spell-item.cat-protection:hover {
  border-color: rgba(143, 240, 199, 0.44);
  background: linear-gradient(135deg, rgba(143, 240, 199, 0.18), rgba(217, 182, 255, 0.10));
}
.spell-item.cat-protection[aria-selected="true"] {
  border-color: rgba(143, 240, 199, 0.60);
  background: linear-gradient(135deg, rgba(143, 240, 199, 0.22), rgba(217, 182, 255, 0.12));
}

.spell-item.cat-money {
  border-color: rgba(96, 226, 152, 0.34);
  background: linear-gradient(135deg, rgba(96, 226, 152, 0.18), rgba(35, 166, 117, 0.08));
}
.spell-item.cat-money:hover {
  border-color: rgba(96, 226, 152, 0.48);
  background: linear-gradient(135deg, rgba(96, 226, 152, 0.22), rgba(35, 166, 117, 0.10));
}
.spell-item.cat-money[aria-selected="true"] {
  border-color: rgba(96, 226, 152, 0.62);
  background: linear-gradient(135deg, rgba(96, 226, 152, 0.26), rgba(35, 166, 117, 0.12));
}

.spell-item.cat-banishing {
  border-color: rgba(160, 174, 192, 0.34);
  background: linear-gradient(135deg, rgba(160, 174, 192, 0.14), rgba(90, 103, 216, 0.06));
}
.spell-item.cat-banishing:hover {
  border-color: rgba(160, 174, 192, 0.46);
  background: linear-gradient(135deg, rgba(160, 174, 192, 0.18), rgba(90, 103, 216, 0.08));
}
.spell-item.cat-banishing[aria-selected="true"] {
  border-color: rgba(160, 174, 192, 0.62);
  background: linear-gradient(135deg, rgba(160, 174, 192, 0.22), rgba(90, 103, 216, 0.10));
}

.spell-item.cat-divination {
  border-color: rgba(217, 182, 255, 0.34);
  background: linear-gradient(135deg, rgba(217, 182, 255, 0.16), rgba(143, 240, 199, 0.04));
}
.spell-item.cat-divination:hover {
  border-color: rgba(217, 182, 255, 0.46);
  background: linear-gradient(135deg, rgba(217, 182, 255, 0.20), rgba(143, 240, 199, 0.06));
}
.spell-item.cat-divination[aria-selected="true"] {
  border-color: rgba(217, 182, 255, 0.62);
  background: linear-gradient(135deg, rgba(217, 182, 255, 0.24), rgba(143, 240, 199, 0.08));
}

.spell-item.cat-glamour .cat-icon { border-color: rgba(255, 183, 210, 0.42); background: rgba(255, 183, 210, 0.12); color: rgba(255, 183, 210, 0.95); }
.spell-item.cat-love .cat-icon { border-color: rgba(255, 146, 173, 0.42); background: rgba(255, 146, 173, 0.10); color: rgba(255, 146, 173, 0.95); }
.spell-item.cat-protection .cat-icon { border-color: rgba(143, 240, 199, 0.40); background: rgba(143, 240, 199, 0.10); color: rgba(143, 240, 199, 0.95); }
.spell-item.cat-money .cat-icon { border-color: rgba(96, 226, 152, 0.42); background: rgba(96, 226, 152, 0.12); color: rgba(96, 226, 152, 0.96); }
.spell-item.cat-banishing .cat-icon { border-color: rgba(160, 174, 192, 0.40); background: rgba(160, 174, 192, 0.10); color: rgba(215, 226, 240, 0.92); }
.spell-item.cat-divination .cat-icon { border-color: rgba(217, 182, 255, 0.40); background: rgba(217, 182, 255, 0.10); color: rgba(217, 182, 255, 0.95); }

.spell-title {
  font-weight: 650;
  font-size: 13px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.spell-title-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.spell-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.cat-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.12);
  color: var(--muted);
  flex: 0 0 auto;
}
.cat-icon svg { width: 14px; height: 14px; display: block; }

.pin {
  font-size: 12px;
  color: var(--accent);
}

.spell-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar-footer { padding: 14px 10px 0; }

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.14);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
}

.detail {
  height: 100%;
  overflow: auto;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin: -16px -18px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0,0,0,0.25), rgba(0,0,0,0.02));
  backdrop-filter: blur(10px);
}

:root[data-theme="dawn"] .topbar {
  background: linear-gradient(180deg, rgba(255,255,255,0.86), rgba(255,255,255,0.65));
}

.topbar-spacer { flex: 1; }

.card {
  max-width: 980px;
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
}

:root[data-theme="dawn"] .card { background: rgba(255,255,255,0.85); }

.empty {
  padding: 26px 14px;
  text-align: center;
}

.empty h2 {
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  margin: 0 0 8px;
  letter-spacing: 0.02em;
}

.empty p { margin: 0; color: var(--muted); }

.entry-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.home-card h2 {
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 28px;
  margin: 0;
  letter-spacing: 0.02em;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.overview-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
}

.home-actions {
  margin-top: 14px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.entry-title h2 {
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 26px;
  margin: 0;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  padding: 6px 10px;
  border-radius: 999px;
}

.entry-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.entry-summary span {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.035);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 9px;
}

.section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

:root[data-theme="dawn"] .section { border-top-color: rgba(33,20,14,0.1); }

.section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.entry-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.025);
  padding: 0;
  overflow: hidden;
}

.entry-section + .entry-section { margin-top: 10px; }

.entry-section summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 12px 10px;
}

.entry-section summary::-webkit-details-marker { display: none; }

.entry-section summary h3 {
  margin: 0;
}

.entry-section summary::after {
  content: "Open";
  float: right;
  color: var(--faint);
  font-size: 12px;
  margin-top: -18px;
}

.entry-section[open] summary::after { content: "Close"; }

.entry-section .text {
  padding: 0 12px 12px;
}

.section .text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
}

.metrics-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.metric-card {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 10px;
}

.metric-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 650;
  color: var(--ink);
}

.metric-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.metric-progress {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
}

.metric-progress > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(143, 240, 164, 0.72), rgba(114, 255, 233, 0.8));
}

.link-preview-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.link-preview-card {
  display: block;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 14px;
  padding: 10px 12px;
  text-decoration: none;
}

.link-preview-card:hover {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
}

.link-preview-title {
  color: var(--ink);
  font-weight: 650;
  font-size: 13px;
  line-height: 1.35;
}

.link-preview-site {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.link-preview-url {
  margin-top: 6px;
  color: var(--faint);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.pill {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.12);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.log-item {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 12px;
}

.log-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.log-title { font-weight: 650; font-size: 13px; }
.log-meta { color: var(--muted); font-size: 12px; }

.log-notes {
  margin: 8px 0 0;
  white-space: pre-wrap;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

.log-notes.compact {
  color: var(--muted);
  margin: 6px 0 0;
  padding: 0 2px;
}

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

.shopping-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 10px;
}

.shopping-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 10px 12px;
}

.shopping-thumb {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.18);
  overflow: hidden;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}
.shopping-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.shopping-emoji {
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.35));
}

.shopping-item input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--accent2);
}

.shopping-main { flex: 1; min-width: 0; }
.shopping-name { font-weight: 650; font-size: 13px; }
.shopping-note { margin-top: 2px; color: var(--muted); font-size: 12px; }
.shopping-link { margin-top: 6px; font-size: 12px; }

.shopping-item.done .shopping-name {
  text-decoration: line-through;
  color: var(--muted);
}

.shopping-item.done .shopping-note { color: var(--faint); }

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

.use-panel { margin-top: 12px; }

.use-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.use-title { font-weight: 650; font-size: 13px; color: var(--ink); }

.use-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.use-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.use-btn:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.18); background: rgba(255,255,255,0.06); }
.use-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.use-btn .use-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.attachment-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(110px, 150px));
  gap: 10px;
}

.log-photo-grid {
  margin-top: 10px;
}

.attachment-card {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 10px;
}

.attachment-card img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.12);
}

.attachment-name {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog {
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 0;
  background: linear-gradient(180deg, rgba(18,10,30,0.98), rgba(9,7,17,0.96));
  color: var(--ink);
  box-shadow: var(--shadow);
  width: min(820px, calc(100vw - 24px));
}

:root[data-theme="dawn"] .dialog { background: rgba(255,255,255,0.96); }

.dialog-body { padding: 16px 16px 14px; }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-title {
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid.compact {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field { display: grid; gap: 6px; }

.span2 { grid-column: 1 / -1; }

.editor-advanced {
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  padding: 10px 12px;
}

.editor-advanced.inline {
  border-style: solid;
  border-color: rgba(255,255,255,0.08);
  padding: 8px 10px;
}

.editor-advanced > summary {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.editor-advanced > summary::-webkit-details-marker { display: none; }

.editor-advanced-body {
  margin-top: 10px;
  display: grid;
  gap: 12px;
}

.chip-scroll {
  max-height: 120px;
  overflow: auto;
  padding-right: 2px;
}

:root[data-ui-mode="comfort"] body {
  background: linear-gradient(180deg, var(--bg1), var(--bg0));
}

:root[data-ui-mode="comfort"] .sidebar,
:root[data-ui-mode="comfort"] .topbar,
:root[data-ui-mode="comfort"] .dialog {
  backdrop-filter: none;
}

:root[data-ui-mode="comfort"] .spell-list { gap: 12px; }

:root[data-ui-mode="comfort"] .btn,
:root[data-ui-mode="comfort"] .input,
:root[data-ui-mode="comfort"] .textarea,
:root[data-ui-mode="comfort"] .select {
  font-size: 15px;
}

:root[data-ui-mode="comfort"] .btn {
  min-height: 44px;
}

:root[data-ui-mode="comfort"] .meta {
  font-size: 13px;
}

:root[data-ui-mode="comfort"] .spell-title {
  font-size: 15px;
}

:root[data-ui-mode="comfort"] .spell-sub {
  font-size: 13px;
}

:root[data-ui-mode="comfort"] .card {
  max-width: 840px;
}

:root[data-ui-mode="comfort"] .section h3 {
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
}

:root[data-ui-mode="comfort"] .section .text {
  font-size: 16px;
  line-height: 1.85;
}

:root[data-ui-mode="comfort"] .dialog .grid {
  grid-template-columns: 1fr;
}

:root[data-ui-mode="comfort"] .dialog .span2 {
  grid-column: 1;
}

:root[data-ui-mode="comfort"] .btn,
:root[data-ui-mode="comfort"] .chip,
:root[data-ui-mode="comfort"] .spell-item,
:root[data-ui-mode="comfort"] .sidebar,
:root[data-ui-mode="comfort"] .link-preview-card {
  transition: none !important;
}

:root[data-ui-mode="comfort"] .btn:focus-visible,
:root[data-ui-mode="comfort"] .input:focus,
:root[data-ui-mode="comfort"] .textarea:focus,
:root[data-ui-mode="comfort"] .select:focus,
:root[data-ui-mode="comfort"] .chip:focus-visible,
:root[data-ui-mode="comfort"] .spell-item:focus-visible {
  box-shadow: 0 0 0 4px rgba(143, 240, 199, 0.34);
  border-color: rgba(143, 240, 199, 0.68);
}

.dialog-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

:root[data-theme="dawn"] .dialog-foot { border-top-color: rgba(33,20,14,0.1); }

.dialog-spacer { flex: 1; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); user-select: none; }
.check input { accent-color: var(--accent); }

.choices { border: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
}
.choice input { margin-top: 2px; accent-color: var(--accent); }
.choice strong { display: block; margin-bottom: 2px; }
.choice.compact {
  align-items: center;
  border-radius: 999px;
  flex: 0 0 auto;
  padding: 8px 10px;
}
.choice.compact input { margin-top: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 46px rgba(0,0,0,0.32);
  color: var(--ink);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  max-width: min(92vw, 720px);
  text-align: center;
}

.undo {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 250;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(18,10,30,0.98), rgba(9,7,17,0.96));
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.undo-text { color: var(--ink); font-size: 13px; }

.templates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.template-card {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 18px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.template-title { font-weight: 700; }
.template-meta { color: var(--muted); font-size: 12px; line-height: 1.35; }
.template-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.corr-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 10px;
}
.corr-section {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 8px 0 0;
  text-transform: uppercase;
}
.corr-item {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 16px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}
.corr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.corr-title { font-weight: 700; font-size: 13px; }
.corr-type { color: var(--muted); font-size: 12px; }
.corr-body { color: var(--muted); font-size: 12px; line-height: 1.35; }
.corr-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.corr-actions .link { white-space: nowrap; }

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.knowledge-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: min(62vh, 640px);
  overflow: auto;
  padding-right: 4px;
}

.knowledge-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.035);
  padding: 12px;
  display: grid;
  gap: 8px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.knowledge-item:hover,
.knowledge-item:focus-visible {
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.06);
  transform: translateY(-1px);
  outline: none;
}

.knowledge-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.knowledge-title {
  font-weight: 750;
  font-size: 14px;
}

.knowledge-source {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.knowledge-summary,
.knowledge-detail {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.knowledge-detail { color: var(--muted); }

.knowledge-match-reason {
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  margin: 8px 0 0;
}

.knowledge-passage {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0,0,0,0.14);
  color: var(--ink);
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 13px;
  line-height: 1.55;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.knowledge-passage.preview {
  max-height: none;
}

.search-mark {
  background: rgba(255, 220, 130, 0.38);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
}

.knowledge-image-link {
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.92);
}

.knowledge-image {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

.knowledge-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.knowledge-tags span {
  color: var(--faint);
  font-size: 11px;
}

.knowledge-actions {
  display: flex;
  justify-content: flex-start;
}

.reader-dialog {
  width: min(1120px, calc(100vw - 18px));
}

.reader-body {
  max-height: min(88vh, 920px);
}

.reader-library-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.reader-library-controls.compact {
  margin-bottom: 8px;
}

.reader-library-search {
  flex: 1 1 260px;
}

.reader-library-sort {
  flex: 0 0 180px;
}

.runes-toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.runes-toolbar .input {
  flex: 1 1 260px;
}

.rune-note {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--muted);
  display: grid;
  gap: 4px;
  line-height: 1.45;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.rune-note strong {
  color: var(--ink);
}

.rune-draw-result {
  margin-bottom: 12px;
}

.rune-prompt-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
}

.rune-prompt-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  max-height: 260px;
  overflow: auto;
}

.rune-prompt-card {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  text-align: left;
}

.rune-prompt-card:hover,
.rune-prompt-card:focus-visible {
  border-color: rgba(217, 182, 255, 0.34);
  background: rgba(217, 182, 255, 0.1);
  outline: none;
}

.rune-prompt-head {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.rune-prompt-head small,
.rune-prompt-text {
  color: var(--muted);
}

.rune-prompt-text {
  line-height: 1.4;
}

.source-dashboard {
  display: grid;
  gap: 12px;
}

.source-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 10px;
  padding: 12px;
}

.source-card-head {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.source-card-head div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.source-card-head strong {
  color: var(--ink);
}

.source-card-head span {
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.personal-patterns-panel {
  display: grid;
  gap: 10px;
}

.personal-pattern-stat-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.personal-pattern-stat,
.personal-pattern-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 6px;
  padding: 10px;
}

.personal-pattern-stat span,
.personal-pattern-stat small {
  color: var(--muted);
  line-height: 1.35;
}

.reader-study-stat-row.compact {
  gap: 8px 10px;
}

.rune-journal-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
}

.rune-journal-list {
  display: grid;
  gap: 10px;
  max-height: min(42vh, 440px);
  overflow: auto;
}

.rune-journal-filter-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rune-journal-filter-row .input {
  flex: 1 1 240px;
}

.rune-journal-filter-row .select {
  flex: 0 0 170px;
}

.rune-journal-stats {
  display: grid;
  gap: 8px;
}

.rune-journal-stat-strip {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rune-journal-stat-strip b,
.rune-journal-stat-strip span {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 999px;
  background: rgba(255,255,255,0.035);
  color: var(--muted);
  font-size: 0.82rem;
  padding: 5px 8px;
}

.rune-journal-stat-strip b {
  color: var(--ink);
}

.rune-journal-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.rune-journal-head {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.rune-journal-head div {
  display: grid;
  gap: 2px;
}

.rune-journal-head span,
.rune-journal-card p {
  color: var(--muted);
}

.rune-journal-card p {
  line-height: 1.45;
  margin: 0;
}

.rune-journal-runes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rune-journal-runes span {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 999px;
  background: rgba(255,255,255,0.035);
  color: var(--muted);
  font-size: 0.84rem;
  padding: 5px 8px;
}

.bind-rune-builder {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
}

.section-head.compact h3 {
  margin: 0 0 4px;
}

.rune-select-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.rune-select-chip,
.rune-suggestion-chip {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  text-align: left;
}

.rune-select-chip {
  align-items: center;
}

.rune-select-chip[aria-pressed="true"],
.rune-suggestion-chip:hover,
.rune-suggestion-chip:focus-visible,
.rune-select-chip:hover,
.rune-select-chip:focus-visible {
  border-color: rgba(217, 182, 255, 0.34);
  background: rgba(217, 182, 255, 0.1);
  outline: none;
}

.rune-select-symbol {
  color: var(--accent);
  flex: 0 0 auto;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
}

.rune-select-chip span:last-child,
.rune-suggestion-chip {
  display: grid;
  gap: 2px;
}

.rune-select-chip small,
.rune-suggestion-chip span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.bind-rune-output {
  display: grid;
  gap: 8px;
}

.bind-rune-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.mini-list {
  color: var(--muted);
  margin: 0;
  padding-left: 18px;
}

.rune-suggestion-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
}

.rune-suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rune-grid,
.rune-draw-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.rune-list {
  max-height: min(58vh, 620px);
  overflow: auto;
  padding-right: 2px;
}

.rune-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.rune-card-head {
  align-items: center;
  display: flex;
  gap: 12px;
}

.rune-symbol {
  align-items: center;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: var(--accent);
  display: inline-flex;
  flex: 0 0 54px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.1rem;
  justify-content: center;
  min-height: 54px;
}

.rune-title {
  color: var(--ink);
  font-weight: 700;
}

.rune-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.rune-card p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.reader-study-goal-label {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.86rem;
  gap: 6px;
}

.reader-study-goal-input {
  min-height: 34px;
  padding: 6px 8px;
  width: 64px;
}

.reader-annotations-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  margin: 0 0 14px;
  padding: 12px;
}

.reader-study-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  margin: 0 0 14px;
  padding: 12px;
}

.reader-contents-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  padding: 12px;
}

.reader-annotations-list {
  display: grid;
  gap: 8px;
  max-height: 310px;
  overflow: auto;
}

.reader-study-list {
  display: grid;
  gap: 10px;
  max-height: min(48vh, 500px);
  overflow: auto;
}

.reader-study-stats {
  display: grid;
  gap: 10px;
  margin: 0 0 10px;
}

.reader-study-stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}

.reader-study-stat-row strong,
.reader-study-stat-row span {
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(255,255,255,0.035);
  padding: 7px 9px;
}

.reader-study-stat-row strong {
  border-radius: 999px 0 0 999px;
  border-right: 0;
  color: var(--accent);
}

.reader-study-stat-row span {
  border-radius: 0 999px 999px 0;
  color: var(--muted);
  margin: 0 8px 6px -1px;
}

.reader-study-breakdown {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.study-stat-chip {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: inline-grid;
  gap: 2px;
  padding: 8px 10px;
  text-align: left;
}

.study-stat-chip.compact {
  grid-auto-flow: column;
  align-items: baseline;
  gap: 8px;
}

.study-stat-chip:hover,
.study-stat-chip:focus-visible {
  border-color: rgba(217, 182, 255, 0.3);
  background: rgba(217, 182, 255, 0.09);
  outline: none;
}

.study-stat-chip[aria-pressed="true"] {
  border-color: rgba(217, 182, 255, 0.45);
  background: rgba(217, 182, 255, 0.14);
}

.study-stat-chip strong {
  color: var(--ink);
  font-size: 12px;
}

.study-stat-chip span {
  color: var(--muted);
  font-size: 11px;
}

.reader-contents-list {
  display: grid;
  gap: 8px;
  max-height: min(46vh, 460px);
  overflow: auto;
}

.reader-annotation-hit {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.reader-annotation-hit:hover,
.reader-annotation-hit:focus-visible {
  border-color: rgba(255, 183, 210, 0.3);
  background: rgba(255, 183, 210, 0.1);
  outline: none;
}

.reader-annotation-hit span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.reader-annotation-hit strong {
  font-size: 13px;
}

.reader-annotation-hit small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.reader-study-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.reader-study-session-card {
  border-color: rgba(217, 182, 255, 0.28);
  background: linear-gradient(135deg, rgba(217, 182, 255, 0.1), rgba(255,255,255,0.045));
}

.study-cover {
  border: 1px dashed rgba(255,255,255,0.18);
  border-radius: 10px;
  min-height: 120px;
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

.study-cover strong {
  color: var(--ink);
  font-size: 15px;
}

.study-cover span {
  font-size: 12px;
}

.reader-study-head {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: flex-start;
}

.reader-study-head div {
  display: grid;
  gap: 3px;
}

.reader-study-head span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.reader-study-head strong {
  font-size: 13px;
}

.reader-study-head small {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.reader-study-card blockquote {
  margin: 0;
  color: var(--ink);
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 15px;
  line-height: 1.55;
}

.reader-contents-hit {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.reader-contents-hit:hover,
.reader-contents-hit:focus-visible,
.reader-contents-hit[aria-current="true"] {
  border-color: rgba(217, 182, 255, 0.32);
  background: rgba(217, 182, 255, 0.1);
  outline: none;
}

.reader-contents-hit span {
  font-size: 13px;
  font-weight: 760;
}

.reader-contents-hit small,
.reader-contents-hit em {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  font-style: normal;
}

.book-shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  max-height: min(64vh, 680px);
  overflow: auto;
  padding: 4px 4px 10px;
  perspective: 1000px;
}

.book-tile {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 8px;
  text-align: left;
  min-width: 0;
}

.book-cover {
  min-height: 210px;
  aspect-ratio: 2 / 3;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px 12px 12px 8px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.35), transparent 15%, rgba(255,255,255,0.08) 18%, transparent 24%),
    linear-gradient(135deg, var(--cover-a), var(--cover-b));
  box-shadow: 0 18px 36px rgba(0,0,0,0.28);
  display: flex;
  align-items: flex-end;
  padding: 14px;
  position: relative;
  transform-origin: left center;
  transition: transform 220ms ease, box-shadow 220ms ease;
  overflow: hidden;
}

.book-cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.book-cover.has-image {
  background:
    linear-gradient(90deg, rgba(0,0,0,0.45), transparent 18%, rgba(255,255,255,0.08) 21%, transparent 28%),
    linear-gradient(135deg, var(--cover-a), var(--cover-b));
}

.book-cover.has-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.05), rgba(0,0,0,0.72));
  z-index: 1;
  pointer-events: none;
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  pointer-events: none;
}

.book-cover span {
  position: relative;
  z-index: 2;
  color: white;
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 18px;
  font-weight: 760;
  line-height: 1.1;
  text-wrap: balance;
}

.book-tile:hover .book-cover,
.book-tile:focus-visible .book-cover {
  transform: rotateY(-10deg) translateY(-2px);
  box-shadow: 0 24px 44px rgba(0,0,0,0.34);
}

.book-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 10px;
}

.book-name {
  font-weight: 750;
  font-size: 13px;
  line-height: 1.25;
}

.book-meta {
  color: var(--muted);
  font-size: 12px;
}

.reader-panel {
  display: grid;
  gap: 12px;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.reader-speed-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.reader-speed-select {
  flex: 0 0 92px;
}

.reader-search {
  flex: 1 1 220px;
  min-width: 180px;
}

.reader-search-results {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  max-height: 220px;
  overflow: auto;
  padding: 10px;
}

.reader-search-meta {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 8px;
}

.reader-search-list {
  display: grid;
  gap: 8px;
}

.reader-search-hit {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  text-align: left;
}

.reader-search-hit:hover,
.reader-search-hit:focus-visible {
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.065);
  outline: none;
}

.reader-search-hit span {
  font-size: 13px;
  font-weight: 750;
}

.reader-search-hit small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.reader-sidepanel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.75fr);
  gap: 12px;
}

.reader-note-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  padding: 12px;
  display: grid;
  gap: 8px;
}

.reader-note-card.span2 {
  grid-column: 1 / -1;
}

.reader-note-input {
  min-height: 96px;
}

.reader-note-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.reader-bookmarks {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
}

.reader-bookmark-hit {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  text-align: left;
}

.reader-bookmark-hit:hover,
.reader-bookmark-hit:focus-visible,
.reader-bookmark-hit[aria-current="true"] {
  border-color: rgba(255, 183, 210, 0.3);
  background: rgba(255, 183, 210, 0.1);
  outline: none;
}

.reader-bookmark-hit span {
  font-size: 13px;
  font-weight: 750;
}

.reader-bookmark-hit small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.reader-quotes,
.reader-highlights {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.reader-quote-card,
.reader-highlight-card {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.reader-highlight-card {
  border-color: rgba(217, 182, 255, 0.22);
  background: rgba(217, 182, 255, 0.075);
}

.reader-quote-card blockquote,
.reader-highlight-card blockquote {
  margin: 0;
  color: var(--ink);
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: 14px;
  line-height: 1.55;
}

.reader-highlight {
  background: rgba(255, 220, 130, 0.36);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
}

.reader-quote-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.reader-toolbar .btn[aria-pressed="true"],
.reader-controls .btn[aria-pressed="true"] {
  border-color: rgba(255, 183, 210, 0.38);
  background: rgba(255, 183, 210, 0.13);
}

.reader-progress {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.reader-source {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.book-page {
  background:
    linear-gradient(90deg, rgba(0,0,0,0.045), transparent 7%, transparent 93%, rgba(0,0,0,0.035)),
    #fbf4e7;
  color: #261a14;
  border-radius: 12px;
  border: 1px solid rgba(38,24,18,0.12);
  box-shadow: 0 22px 44px rgba(0,0,0,0.22);
  max-height: min(68vh, 760px);
  overflow: auto;
  padding: clamp(24px, 5vw, 64px);
  transform-origin: left center;
  scroll-padding: 40px;
}

.book-page h3 {
  max-width: 60ch;
  margin: 0 auto 20px;
  color: #241a14;
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: calc(28px * var(--reader-scale, 1));
  line-height: 1.22;
  letter-spacing: 0;
}

.reader-summary {
  max-width: 62ch;
  color: #5c4a42;
  margin: 0 auto 22px;
  font-size: 14px;
  line-height: 1.7;
}

.reader-text {
  max-width: 62ch;
  margin: 0 auto;
  font-family: ui-serif, "Iowan Old Style", "Palatino", Georgia, serif;
  font-size: calc(19px * var(--reader-scale, 1));
  line-height: 1.86;
  letter-spacing: 0.01em;
  overflow-wrap: break-word;
}

.reader-text p {
  margin: 0 0 1.25em;
  text-indent: 0;
}

.reader-text p + p {
  margin-top: 0.15em;
}

.reader-panel[data-reader-theme="night"] .book-page {
  background:
    linear-gradient(90deg, rgba(255,255,255,0.035), transparent 7%, transparent 93%, rgba(255,255,255,0.03)),
    #141018;
  color: #f4eadf;
  border-color: rgba(255,255,255,0.12);
}

.reader-panel[data-reader-theme="night"] .book-page h3 {
  color: #fff5e9;
}

.reader-panel[data-reader-theme="night"] .reader-summary {
  color: #cdbfb3;
}

.book-page.page-turn {
  animation: pageTurn 260ms ease;
}

@keyframes pageTurn {
  0% { opacity: 0.35; transform: rotateY(-8deg) translateX(8px); }
  100% { opacity: 1; transform: rotateY(0deg) translateX(0); }
}

@media (max-width: 640px) {
  .reader-library-search,
  .reader-library-sort {
    flex-basis: 100%;
  }
  .reader-toolbar .btn.small {
    flex: 1 1 calc(33.333% - 10px);
  }
  .reader-speed-label {
    flex: 0 0 auto;
  }
  .reader-speed-select {
    flex: 1 1 110px;
  }
  .reader-controls .btn.small {
    flex: 1 1 calc(25% - 10px);
  }
  .reader-search {
    flex-basis: 100%;
  }
  .reader-sidepanel {
    grid-template-columns: 1fr;
  }
  .reader-progress {
    flex-basis: 100%;
    margin-left: 0;
  }
  .book-page {
    max-height: min(66vh, 640px);
    padding: 22px 18px;
  }
  .book-page h3 {
    font-size: calc(23px * var(--reader-scale, 1));
    max-width: 100%;
  }
  .reader-text {
    max-width: 100%;
    font-size: calc(18px * var(--reader-scale, 1));
    line-height: 1.78;
  }
}

.pill.as-button {
  cursor: pointer;
  font: inherit;
}

.intent-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 14px;
}
.intent-panel {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.035);
  border-radius: 16px;
  padding: 12px;
}
.intent-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.intent-tab {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
}
.intent-tab[aria-pressed="true"] {
  border-color: rgba(214,178,255,0.75);
  background: rgba(214,178,255,0.16);
}
.intent-results,
.intent-selected {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.intent-card {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.13);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 6px;
}
.intent-card-head {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
.intent-card-title { font-weight: 700; font-size: 13px; }
.intent-card-meta { color: var(--muted); font-size: 12px; line-height: 1.35; }
.intent-card-actions { display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .overview-grid { grid-template-columns: 1fr; }
  .home-action-groups { grid-template-columns: 1fr; }
  .insight-columns { grid-template-columns: 1fr; }
  .intent-layout { grid-template-columns: 1fr; }
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.cal-cell {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  border-radius: 14px;
  padding: 8px;
  min-height: 104px;
  cursor: pointer;
  display: grid;
  align-content: start;
  gap: 6px;
}
.cal-cell:hover { border-color: rgba(255,255,255,0.18); background: rgba(255,255,255,0.05); }
.cal-today {
  border-color: rgba(255, 183, 210, 0.45);
  background: rgba(255, 183, 210, 0.08);
}
.cal-dow {
  color: var(--faint);
  font-size: 11px;
  text-align: center;
  padding: 6px 0;
}
.cal-day {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.cal-badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 2px 6px;
}
.cal-muted { opacity: 0.5; }
.cal-astro {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.25;
}
.cal-moon {
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}
.cal-sun {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}
.cal-dotrow { display: flex; gap: 4px; flex-wrap: wrap; }
.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 183, 210, 0.75);
}
.cal-dot.worked { background: rgba(143, 240, 199, 0.75); }
.cal-dot.notworked { background: rgba(255, 110, 110, 0.75); }
.cal-dot.planned { background: rgba(217, 182, 255, 0.9); }

.astro-panel {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.astro-moon-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.astro-moon-glyph {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--accent);
  background: rgba(0,0,0,0.16);
  font-size: 26px;
  line-height: 1;
}

.astro-positions {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.astro-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(255,255,255,0.025);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.astro-row:last-child { border-bottom: 0; }
.astro-body { font-weight: 750; font-size: 12px; }
.astro-pos { color: var(--muted); font-size: 12px; line-height: 1.35; }

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

@media (max-width: 980px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .sidebar {
    position: fixed;
    inset: 0;
    z-index: 50;
    transform: translateX(-102%);
    transition: transform 220ms ease;
    width: min(420px, 92vw);
    box-shadow: 26px 0 90px rgba(0,0,0,0.45);
  }
  .app.library-open .sidebar { transform: translateX(0); }
  .detail { padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px)); }
  .topbar { margin: -14px -14px 12px; padding: 10px 10px; }
  .friend-row {
    align-items: stretch;
    grid-template-columns: auto minmax(0, 1fr);
  }
  .friend-score,
  .friend-remove {
    grid-column: 2;
    justify-self: start;
  }
  .shared-group-row {
    grid-template-columns: 1fr;
  }
  .shared-group-row .btn {
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .chip, .spell-item, .sidebar { transition: none; }
}

.notice {
  margin: 8px 0 0;
  border: 1px solid rgba(255, 92, 135, 0.35);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 92, 135, 0.08), rgba(18,10,30,0.55));
  padding: 12px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.22);
}
.notice-title {
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}
.notice-text { color: var(--muted); font-size: 0.95rem; line-height: 1.35; }
.notice.soft {
  border-color: rgba(123, 213, 255, 0.35);
  background: linear-gradient(180deg, rgba(80, 170, 255, 0.12), rgba(18,10,30,0.55));
}
:root[data-theme="dawn"] .notice {
  background: linear-gradient(180deg, rgba(255, 92, 135, 0.10), rgba(255,255,255,0.95));
  border-color: rgba(210, 32, 96, 0.25);
}
:root[data-theme="dawn"] .notice.soft {
  background: linear-gradient(180deg, rgba(80, 170, 255, 0.15), rgba(255,255,255,0.95));
  border-color: rgba(47, 133, 201, 0.25);
}

/* GrimoireGPT - ChatGPT-style embedded chat */
.ai-chat-dialog {
  padding: 0;
}

.ai-chat-dialog::backdrop {
  background: rgba(3, 2, 8, 0.74);
  backdrop-filter: blur(7px);
}

.ai-chat-dialog .dialog-body,
.ai-chat-body {
  width: min(1180px, 97vw);
  height: min(940px, 94vh);
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow: hidden;
}

.ai-chat-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-chat-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ai-chat-brand .dialog-title {
  margin-bottom: 2px;
}

.ai-chat-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.22), rgba(255, 183, 210, 0.09));
  color: var(--accent);
  box-shadow: var(--shadow-soft);
  flex: 0 0 auto;
}

.ai-chat-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ai-chat-modebar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  overflow: auto;
}

.ai-chat-modebar button {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
}

.ai-chat-modebar button.is-active {
  background: rgba(255, 183, 210, 0.15);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 183, 210, 0.22);
}

.ai-chat-messages {
  flex: 1 1 auto;
  min-height: 330px;
  overflow: auto;
  padding: 24px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background:
    radial-gradient(circle at top left, rgba(255, 183, 210, 0.08), transparent 32%),
    radial-gradient(circle at bottom right, rgba(123, 213, 255, 0.055), transparent 32%),
    rgba(255, 255, 255, 0.025);
  scroll-behavior: smooth;
}

.ai-chat-empty {
  max-width: 760px;
  margin: 9vh auto 22px;
  display: grid;
  justify-items: center;
  gap: 11px;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 26px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.038);
  box-shadow: var(--shadow-soft);
}

.ai-chat-empty-orb {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 183, 210, 0.10);
  color: var(--accent);
}

.ai-chat-empty strong {
  color: var(--text);
  font-size: 1.32rem;
}

.ai-chat-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  max-width: 880px;
  margin: 0 auto 20px;
}

.ai-chat-row.user {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.ai-chat-row.user .ai-chat-avatar {
  grid-column: 2;
  grid-row: 1;
}

.ai-chat-row.user .ai-chat-bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  max-width: min(680px, 88%);
  background: rgba(255, 183, 210, 0.13);
  border-color: rgba(255, 183, 210, 0.25);
}

.ai-chat-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 800;
  user-select: none;
}

.ai-chat-row.assistant .ai-chat-avatar {
  color: var(--accent);
  background: rgba(255, 183, 210, 0.10);
}

.ai-chat-bubble {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.058);
  box-shadow: var(--shadow-soft);
}

.ai-chat-row.assistant .ai-chat-bubble {
  border-top-left-radius: 8px;
}

.ai-chat-row.user .ai-chat-bubble {
  border-top-right-radius: 8px;
}

.ai-chat-row.local .ai-chat-bubble {
  border-style: dashed;
}

.ai-chat-message-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.ai-chat-message-head strong {
  color: var(--text);
}

.ai-chat-message-body {
  line-height: 1.66;
  font-size: 1rem;
}

.ai-chat-message-body p,
.ai-chat-message-body ul,
.ai-chat-message-body ol,
.ai-chat-message-body blockquote,
.ai-chat-message-body pre {
  margin: 0 0 0.9em;
}

.ai-chat-message-body p:last-child,
.ai-chat-message-body ul:last-child,
.ai-chat-message-body ol:last-child,
.ai-chat-message-body blockquote:last-child,
.ai-chat-message-body pre:last-child {
  margin-bottom: 0;
}

.ai-chat-message-body ul,
.ai-chat-message-body ol {
  padding-left: 1.25rem;
}

.ai-chat-message-body li {
  margin: 0.28em 0;
}

.ai-chat-message-body h3,
.ai-chat-message-body h4,
.ai-chat-message-body h5,
.ai-chat-message-body h6 {
  margin: 1em 0 0.35em;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

.ai-chat-message-body h3:first-child,
.ai-chat-message-body h4:first-child,
.ai-chat-message-body h5:first-child,
.ai-chat-message-body h6:first-child {
  margin-top: 0;
}

.ai-chat-message-body code {
  padding: 0.1em 0.35em;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
}

.ai-chat-message-body pre {
  overflow: auto;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}

.ai-chat-message-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.ai-chat-message-body blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.ai-chat-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 2px;
  border-radius: 999px;
  background: currentColor;
  vertical-align: -0.12em;
  animation: aiCursorBlink 0.95s infinite;
}

@keyframes aiCursorBlink {
  0%, 45% { opacity: 0.88; }
  46%, 100% { opacity: 0; }
}

.ai-chat-evidence {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.84rem;
}

.ai-chat-evidence summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}

.ai-chat-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.ai-chat-suggestions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.ai-chat-suggestions[hidden] {
  display: none;
}

.ai-chat-suggestions button {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.ai-chat-suggestions button:hover {
  border-color: rgba(255, 183, 210, 0.45);
  background: rgba(255, 183, 210, 0.08);
}

.ai-chat-composer-shell {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
}

.ai-chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.066);
  box-shadow: var(--shadow-soft);
}

.ai-chat-composer textarea {
  min-height: 46px;
  max-height: 175px;
  resize: none;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 12px 13px;
  line-height: 1.45;
}

.ai-chat-composer textarea:focus {
  outline: none;
  box-shadow: none;
}

.ai-chat-send,
.ai-chat-stop {
  min-height: 46px;
  border-radius: 18px;
}

.ai-chat-send {
  min-width: 46px;
  font-size: 1.2rem;
}

.ai-chat-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
}

.ai-chat-disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 2px 2px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: aiTypingPulse 1.15s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes aiTypingPulse {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.25; }
  40% { transform: translateY(-4px); opacity: 0.85; }
}

@media (max-width: 860px) {
  .ai-chat-dialog .dialog-body,
  .ai-chat-body {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 12px;
  }

  .ai-chat-topbar {
    align-items: flex-start;
  }

  .ai-chat-top-actions {
    max-width: 44%;
  }

  .ai-chat-modebar {
    width: 100%;
  }

  .ai-chat-suggestions {
    grid-template-columns: 1fr 1fr;
  }

  .ai-chat-row,
  .ai-chat-row.user {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 9px;
  }

  .ai-chat-row.user .ai-chat-avatar {
    grid-column: 1;
  }

  .ai-chat-row.user .ai-chat-bubble {
    grid-column: 2;
    justify-self: stretch;
    max-width: none;
  }

  .ai-chat-composer {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }
}

@media (max-width: 560px) {
  .ai-chat-brand .meta,
  .ai-chat-disclaimer {
    display: none;
  }

  .ai-chat-suggestions {
    grid-template-columns: 1fr;
  }

  .ai-chat-toolbar .dialog-spacer {
    display: none;
  }

  .ai-chat-toolbar {
    justify-content: center;
  }

  .ai-chat-top-actions {
    max-width: none;
  }
}

/* Correspondence Mixer */
.corr-mixer-dialog {
  width: min(1080px, calc(100vw - 24px));
}

.corr-mixer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
  gap: 14px;
}

.corr-mixer-panel {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.035);
  border-radius: 16px;
  padding: 12px;
  min-width: 0;
}

.corr-mixer-output-panel {
  display: grid;
  gap: 10px;
  align-content: start;
}

.corr-mixer-results,
.corr-mixer-selected,
.corr-mixer-output {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.corr-mixer-results {
  max-height: min(48vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.corr-mixer-card,
.corr-mixer-selected-card,
.mixer-analysis-block,
.mixer-score-card,
.mixer-facet-grid > div {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.13);
  border-radius: 12px;
  padding: 10px;
}

.corr-mixer-card {
  display: grid;
  gap: 6px;
}

.corr-mixer-card.selected {
  border-color: rgba(214,178,255,0.65);
  background: rgba(214,178,255,0.12);
}

.corr-mixer-selected-card {
  align-items: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.mixer-score-card {
  align-items: center;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  background: rgba(214,178,255,0.10);
}

.mixer-score {
  align-items: center;
  border: 1px solid rgba(214,178,255,0.55);
  border-radius: 999px;
  display: inline-flex;
  font-size: 22px;
  font-weight: 800;
  justify-content: center;
  min-height: 58px;
  min-width: 58px;
}

.mixer-facet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mixer-facet-grid strong,
.mixer-facet-grid span {
  display: block;
}

.mixer-facet-grid strong {
  font-size: 12px;
  margin-bottom: 4px;
}

.mixer-facet-grid span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.mixer-analysis-block h3 {
  font-size: 13px;
  margin: 0 0 6px;
}

.mixer-analysis-block p,
.mixer-analysis-block li {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.mixer-analysis-block ul,
.mixer-analysis-block ol {
  margin: 0;
  padding-left: 18px;
}

.mixer-analysis-block.warning {
  border-color: rgba(255, 190, 108, 0.38);
  background: rgba(255, 190, 108, 0.07);
}

.mixer-analysis-block.subtle {
  background: rgba(255,255,255,0.025);
}

.mixer-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mixer-mini-chip,
.mixer-personal {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  padding: 3px 7px;
}

.mixer-personal {
  justify-self: start;
  color: var(--ink);
  background: rgba(143, 240, 199, 0.08);
}

@media (max-width: 860px) {
  .corr-mixer-layout,
  .mixer-facet-grid {
    grid-template-columns: 1fr;
  }
  .corr-mixer-results {
    max-height: 320px;
  }
}

/* Correspondence Mixer — research upgrade */
.corr-mixer-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.corr-mixer-check {
  min-height: auto;
  padding: 8px 10px;
  font-size: 12px;
}

.mixer-pair-list,
.mixer-role-list {
  display: grid;
  gap: 8px;
}

.mixer-pair-row,
.mixer-role-row {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  background: rgba(255,255,255,0.025);
  display: grid;
  gap: 4px;
  padding: 8px;
}

.mixer-pair-row strong,
.mixer-role-row strong {
  color: var(--ink);
  font-size: 12px;
}

.mixer-pair-row span,
.mixer-role-row span,
.mixer-role-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}

.mixer-pair-row.reinforce {
  border-color: rgba(143, 240, 199, 0.24);
  background: rgba(143, 240, 199, 0.055);
}

.mixer-pair-row.tension {
  border-color: rgba(255, 190, 108, 0.30);
  background: rgba(255, 190, 108, 0.060);
}

.mixer-research-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.mixer-research-grid > div {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  background: rgba(255,255,255,0.025);
  padding: 8px;
}

.mixer-research-grid strong,
.mixer-research-grid span {
  display: block;
}

.mixer-research-grid strong {
  color: var(--ink);
  font-size: 12px;
  margin-bottom: 4px;
}

.mixer-research-grid span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

@media (max-width: 720px) {
  .corr-mixer-options,
  .mixer-research-grid {
    grid-template-columns: 1fr;
  }
}

/* Practical upgrade: real AI chat layout, materials inventory, oil shelf, tarot, and evidence calibration */
.ai-chat-dialog {
  width: min(1160px, 96vw);
  max-width: 1160px;
  height: min(900px, 92vh);
}
.ai-chat-dialog::backdrop { backdrop-filter: blur(6px); }
.ai-chat-body {
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ai-chat-messages {
  flex: 1 1 auto;
  min-height: 420px;
  max-height: none;
  overflow: auto;
  padding-bottom: 18px;
}
.ai-chat-composer-shell { flex: 0 0 auto; }
.ai-chat-composer textarea {
  min-height: 52px;
  max-height: 210px;
  resize: none;
  font-size: 1rem;
  line-height: 1.45;
}
.ai-chat-message.assistant .ai-chat-message-body p:first-child { margin-top: 0; }
.ai-chat-disclaimer { max-width: 420px; }

.material-inventory-dialog,
.tarot-dialog {
  width: min(1120px, 96vw);
  max-width: 1120px;
}
.material-inventory-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.material-panel,
.mixer-analysis-block.evidence-calibration {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  padding: 14px;
}
.material-panel h3,
.mixer-analysis-block.evidence-calibration h3 { margin-top: 0; }
.material-results,
.material-owned-list,
.tarot-history {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}
.material-result-card,
.inventory-owned-card,
.tarot-history-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.material-result-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.material-result-card.owned {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.inventory-owned-head,
.inventory-card-actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
.inventory-edit-grid {
  display: grid;
  grid-template-columns: 0.6fr 1fr 1.4fr;
  gap: 8px;
  margin-top: 10px;
}
.inventory-edit-grid label {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}
.inventory-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
}
.inventory-badge.owned {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--text);
}
.inventory-badge.missing {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--text);
}
.material-sub-panel { margin-top: 16px; }
.tarot-actions { margin: 12px 0; flex-wrap: wrap; }
.tarot-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.tarot-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--card) 94%, transparent), color-mix(in srgb, var(--surface) 90%, transparent));
  min-height: 190px;
}
.tarot-card.reversed {
  border-style: dashed;
}
.tarot-position {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.tarot-card h3 { margin: 6px 0; }
.mixer-analysis-block.evidence-calibration h4 { margin-bottom: 6px; }
@media (max-width: 820px) {
  .material-inventory-layout,
  .inventory-edit-grid {
    grid-template-columns: 1fr;
  }
  .ai-chat-dialog { width: 100vw; height: 100dvh; max-width: none; border-radius: 0; }
  .ai-chat-messages { min-height: 45vh; }
}

/* Feature continuation upgrade: cleaner AI, evidence lab, material checks, oil shelf, tarot guide */
.ai-chat-dialog.ai-chat-expanded {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
}

.ai-chat-dialog.ai-chat-expanded .ai-chat-body {
  width: 100vw;
  height: 100dvh;
  max-height: none;
  padding: 18px clamp(12px, 3vw, 34px);
}

.ai-chat-settings-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
}

.ai-chat-settings-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
}

.ai-chat-settings-row .select {
  min-height: 34px;
  padding: 4px 28px 4px 10px;
  font-size: 0.86rem;
}

.ai-chat-expanded .ai-chat-messages {
  min-height: 52vh;
}

.evidence-lab-dialog,
.oil-shelf-dialog {
  width: min(1120px, 96vw);
  max-width: 1120px;
}

.evidence-lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.evidence-lab-card,
.material-check-card,
.oil-card,
.tarot-guide-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  padding: 13px;
  box-shadow: var(--shadow-soft);
}

.planet-guide-row,
.evidence-test-row {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.planet-guide-row:last-child,
.evidence-test-row:last-child {
  border-bottom: 0;
}

.table-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.mini-table th,
.mini-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.mini-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inventory-advanced-fields {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.4fr) minmax(130px, 1fr);
  gap: 9px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.inventory-advanced-fields label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.material-check-output {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.material-check-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.oil-shelf-grid,
.tarot-guide-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.oil-card h3,
.tarot-guide-card strong {
  margin-top: 4px;
}

.tarot-advanced-panel {
  margin-top: 14px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
}

.advanced-evidence-map ul {
  padding-left: 1.1rem;
}

@media (max-width: 760px) {
  .evidence-lab-grid,
  .inventory-advanced-fields {
    grid-template-columns: 1fr;
  }
  .ai-chat-settings-row {
    align-items: stretch;
  }
  .ai-chat-settings-row label {
    width: 100%;
    justify-content: space-between;
  }
  .material-check-card {
    grid-template-columns: 1fr;
  }
}

/* Feature continuation v3 */
.ai-chat-dialog.ai-chat-v3,
.ai-chat-dialog.ai-chat-expanded {
  width: min(1180px, 98vw);
  max-width: 1180px;
}

.ai-chat-dialog.ai-chat-v3 .ai-chat-body,
.ai-chat-dialog.ai-chat-expanded .ai-chat-body {
  min-height: min(92vh, 980px);
}

.ai-chat-dialog.ai-chat-v3 .ai-chat-messages,
.ai-chat-dialog.ai-chat-expanded .ai-chat-messages {
  min-height: 58vh;
  max-height: 68vh;
}

.ai-chat-dialog.ai-chat-v3 .ai-chat-composer textarea,
.ai-chat-dialog.ai-chat-expanded .ai-chat-composer textarea {
  min-height: 48px;
  max-height: 42vh;
}

.ai-chat-troubleshooter {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  margin: 8px 0 10px;
  background: rgba(255, 255, 255, 0.045);
}

.ai-chat-troubleshooter summary {
  cursor: pointer;
  font-weight: 700;
}

.planet-sign-lab-dialog {
  width: min(1220px, 97vw);
  max-width: 1220px;
}

.planet-lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 14px;
}

.planet-lab-panel,
.planet-lab-result,
.evidence-layer,
.planet-atlas-card,
.sign-atlas-card,
.planet-result-card,
.v3-mixer-evidence,
.v3-inventory-evidence {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  padding: 13px;
  box-shadow: var(--shadow-soft);
}

.planet-lab-output,
.planet-atlas,
.sign-atlas {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.planet-lab-result ul {
  margin: 8px 0 0;
  padding-left: 1.15rem;
}

.planet-lab-result li {
  margin: 6px 0;
}

.evidence-layer {
  margin-bottom: 9px;
}

.evidence-layer span,
.sign-atlas-card span {
  display: inline-block;
  margin-left: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.planet-atlas {
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.sign-atlas {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.planet-lab-output .pill.tiny {
  font-size: 0.7rem;
  padding: 2px 6px;
  margin-left: 4px;
}

.v3-mixer-evidence,
.v3-inventory-evidence {
  margin-top: 12px;
}

.v3-inventory-evidence {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

@media (max-width: 860px) {
  .planet-lab-grid,
  .v3-inventory-evidence {
    grid-template-columns: 1fr;
  }
  .ai-chat-dialog.ai-chat-v3,
  .ai-chat-dialog.ai-chat-expanded {
    width: 100vw;
    max-width: 100vw;
  }
  .ai-chat-dialog.ai-chat-v3 .ai-chat-body,
  .ai-chat-dialog.ai-chat-expanded .ai-chat-body {
    min-height: 96vh;
  }
}

/* Feature continuation v4 */
.stack-lab-dialog .dialog-body,
.evidence-board-dialog .dialog-body {
  max-width: min(1180px, 96vw);
  width: min(1180px, 96vw);
}
.stack-lab-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  margin-bottom: 12px;
}
.stack-lab-output,
.evidence-board-output {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}
.stack-lab-grid,
.evidence-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.stack-lab-card,
.evidence-summary-grid article,
.stack-lab-section,
.evidence-row,
.evidence-method-note,
.tarot-library-card {
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.stack-lab-card.primary {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}
.stack-lab-card h3,
.stack-lab-section h3,
.evidence-row strong,
.tarot-library-card strong {
  margin-top: 0;
}
.stack-lab-items,
.tarot-library-results {
  display: grid;
  gap: 10px;
}
.stack-lab-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border-soft, var(--border));
  border-radius: 14px;
  padding: 10px;
  background: color-mix(in srgb, var(--bg) 35%, transparent);
}
.warning-text {
  color: var(--danger, #ff8c8c);
}
.evidence-summary-grid article strong {
  display: block;
  font-size: 1.3rem;
}
.evidence-summary-grid article span {
  color: var(--muted);
  font-size: 0.86rem;
}
.evidence-row p {
  margin-bottom: 0;
}
.v4-owned-spell-output {
  margin-top: 10px;
}
.tarot-library-results {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin-top: 10px;
  max-height: 340px;
  overflow: auto;
}
.ai-chat-v4.ai-chat-expanded .dialog-body,
.ai-chat-v4.ai-chat-fullscreen .dialog-body {
  width: min(1180px, 96vw);
  max-width: min(1180px, 96vw);
}
.ai-chat-v4.ai-chat-fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  border-radius: 0;
}
.ai-chat-v4.ai-chat-fullscreen .dialog-body {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.ai-chat-v4.ai-chat-fullscreen .ai-chat-messages,
.ai-chat-v4.ai-chat-expanded .ai-chat-messages {
  min-height: 58vh;
}
.ai-chat-v4.ai-chat-fullscreen .ai-chat-input-wrap textarea,
.ai-chat-v4.ai-chat-expanded .ai-chat-input-wrap textarea {
  min-height: 72px;
}
@media (max-width: 760px) {
  .stack-lab-inputs {
    grid-template-columns: 1fr;
  }
  .stack-lab-dialog .dialog-body,
  .evidence-board-dialog .dialog-body {
    width: 96vw;
  }
}

/* Feature continuation V5: feasibility, substitutions, oil intake, tarot planning, AI context inspector */
.v5-feasibility-dialog,
.v5-oil-intake-dialog {
  width: min(1120px, calc(100vw - 28px));
}

.v5-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.v5-output {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.v5-result-hero {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255,255,255,0.045);
  display: grid;
  gap: 10px;
}

.v5-result-hero strong {
  display: block;
  font-size: 1.05rem;
}

.v5-meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.v5-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.v5-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.v5-grid article,
.v5-card,
.v5-sub-row,
.v5-materials-planner,
.ai-context-preview {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
}

.v5-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.v5-card strong,
.v5-sub-row strong {
  display: block;
  margin-bottom: 4px;
}

.v5-sub-row p {
  margin: 8px 0 0;
}

.warning-panel {
  border: 1px solid rgba(255, 191, 105, 0.35);
  background: rgba(255, 191, 105, 0.08);
  border-radius: 16px;
  padding: 12px;
}

.v5-materials-planner {
  margin: 14px 0;
}

.ai-chat-v5 .ai-chat-input,
.ai-chat-v5 textarea,
.ai-chat-v5 #aiChatInput {
  min-height: 72px;
  max-height: 240px;
}

.ai-chat-v5.ai-chat-fullscreen .dialog-body,
.ai-chat-v5 .dialog-body {
  min-height: min(74vh, 760px);
}

.ai-context-preview pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 8px 0 0;
}

.choice.compact {
  align-items: center;
}

@media (max-width: 720px) {
  .v5-feasibility-dialog,
  .v5-oil-intake-dialog {
    width: calc(100vw - 12px);
  }
  .v5-card-grid,
  .v5-grid {
    grid-template-columns: 1fr;
  }
}

/* v32 silent runtime hardening fixes */
.image-load-failed {
  display: grid !important;
  place-items: center;
  border: 1px dashed rgba(255,255,255,.22);
  background: rgba(255,255,255,.045);
  object-fit: contain !important;
}
.image-load-failed::after { content: "Image unavailable"; }
.field-invalid,
.has-invalid-fields input:invalid,
.has-invalid-fields textarea:invalid,
.has-invalid-fields select:invalid {
  outline: 2px solid rgba(255, 107, 107, .72) !important;
  outline-offset: 2px;
}
body.layout-overflow-guard { overflow-x: hidden; }
body.layout-overflow-guard .app,
body.layout-overflow-guard .detail,
body.layout-overflow-guard .sidebar { max-width: 100vw; }
