:root {
  color-scheme: light;
  --display-scale: 1;
  --content-max: 1120px;
  --sidebar-width: 320px;
  --control-height: 42px;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --sidebar-bg: #fbf8f0;
  --panel-alt: #edf4ee;
  --ink: #1f2522;
  --muted: #66716c;
  --line: #d9d4c8;
  --accent: #2e6f58;
  --accent-strong: #1f352e;
  --warn: #9c5a2e;
  --shadow: 0 16px 40px rgba(41, 37, 28, 0.12);
  --surface-raised: #fffdf8;
  --focus-ring: var(--accent);
  --selection-bg: #cfe8da;
  --selection-ink: var(--ink);
  --control-radius: 0px;
  --panel-radius: 0px;
  --card-accent: var(--line);
  --card-accent-width: 1px;
  --theme-pattern: none;
  --theme-pattern-size: auto;
  --heading-font: Inter, ui-sans-serif, system-ui, sans-serif;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="night-watch"] {
  color-scheme: dark;
  --bg: #141816;
  --panel: #202722;
  --sidebar-bg: #181f1b;
  --panel-alt: #26382f;
  --ink: #eef4ec;
  --muted: #a7b6ac;
  --line: #3c4b42;
  --accent: #78c59e;
  --accent-strong: #a7e0bd;
  --warn: #e0a06d;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
  --surface-raised: #252d28;
  --selection-bg: #315f49;
}

body[data-theme="crt-green"] {
  color-scheme: dark;
  --bg: #08120b;
  --panel: #102016;
  --sidebar-bg: #0b170f;
  --panel-alt: #163821;
  --ink: #d7ffd8;
  --muted: #89b58d;
  --line: #245331;
  --accent: #50d46d;
  --accent-strong: #a5ffad;
  --warn: #e6d36a;
  --shadow: 0 0 0 1px rgba(80, 212, 109, 0.08), 0 18px 46px rgba(0, 0, 0, 0.35);
  --surface-raised: #13291a;
  --focus-ring: #e6d36a;
  --selection-bg: #245331;
  --theme-pattern: repeating-linear-gradient(0deg, transparent 0 3px, rgba(80, 212, 109, 0.018) 3px 4px);
  --theme-pattern-size: 100% 4px;
}

body[data-theme="lcd-blue"] {
  --bg: #e8f0f4;
  --panel: #fbfdff;
  --sidebar-bg: #dce8ee;
  --panel-alt: #e4f2f8;
  --ink: #16222b;
  --muted: #5d6c76;
  --line: #bccbd3;
  --accent: #2e789b;
  --accent-strong: #174b64;
  --warn: #9c5d2e;
  --shadow: 0 14px 34px rgba(22, 34, 43, 0.13);
  --surface-raised: #ffffff;
  --selection-bg: #c3e5f3;
}

body[data-theme="cartridge-pop"] {
  --bg: #eef1f3;
  --panel: #fffefb;
  --sidebar-bg: #e4e9eb;
  --panel-alt: #dff3ed;
  --ink: #182633;
  --muted: #59666f;
  --line: #9baab1;
  --accent: #d94b55;
  --accent-strong: #8f2330;
  --warn: #b77700;
  --shadow: 6px 6px 0 rgba(24, 38, 51, 0.12);
  --surface-raised: #ffffff;
  --focus-ring: #176b87;
  --selection-bg: #f7d34b;
  --selection-ink: #182633;
  --control-radius: 4px;
  --panel-radius: 4px;
  --card-accent: #f0b82d;
  --card-accent-width: 4px;
  --theme-pattern: linear-gradient(rgba(24, 38, 51, 0.025) 1px, transparent 1px), linear-gradient(90deg, rgba(24, 38, 51, 0.025) 1px, transparent 1px);
  --theme-pattern-size: 24px 24px;
  --heading-font: "Trebuchet MS", Inter, ui-sans-serif, system-ui, sans-serif;
}

body[data-theme="arcade-neon"] {
  color-scheme: dark;
  --bg: #0d0f13;
  --panel: #171b22;
  --sidebar-bg: #101419;
  --panel-alt: #202b2c;
  --ink: #f5f7f2;
  --muted: #a5b0ad;
  --line: #364248;
  --accent: #36e1d0;
  --accent-strong: #8cfff2;
  --warn: #ff6b7c;
  --shadow: 0 0 0 1px rgba(54, 225, 208, 0.1), 0 18px 48px rgba(0, 0, 0, 0.42);
  --surface-raised: #1d222b;
  --focus-ring: #ffd43b;
  --selection-bg: #245b61;
  --selection-ink: #ffffff;
  --control-radius: 3px;
  --panel-radius: 3px;
  --card-accent: #ff4fa3;
  --card-accent-width: 3px;
  --theme-pattern: linear-gradient(rgba(54, 225, 208, 0.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 79, 163, 0.02) 1px, transparent 1px);
  --theme-pattern-size: 32px 32px;
  --heading-font: "Arial Narrow", "Trebuchet MS", Inter, ui-sans-serif, sans-serif;
}

body[data-theme="mono-deck"] {
  --bg: #f1f1ef;
  --panel: #ffffff;
  --sidebar-bg: #e6e6e2;
  --panel-alt: #eceff5;
  --ink: #101114;
  --muted: #5b5d63;
  --line: #a8aaaf;
  --accent: #245eea;
  --accent-strong: #123b9b;
  --warn: #a34b00;
  --shadow: 0 8px 0 rgba(16, 17, 20, 0.12);
  --surface-raised: #ffffff;
  --focus-ring: #ffb800;
  --selection-bg: #ffcf33;
  --selection-ink: #101114;
  --control-radius: 2px;
  --panel-radius: 2px;
  --card-accent: #101114;
  --card-accent-width: 4px;
  --theme-pattern: radial-gradient(rgba(16, 17, 20, 0.07) 0.7px, transparent 0.7px);
  --theme-pattern-size: 8px 8px;
  --heading-font: "Arial Narrow", Inter, ui-sans-serif, system-ui, sans-serif;
}

body[data-display="desktop"] {
  --display-scale: 1;
  --content-max: 1180px;
  --sidebar-width: 320px;
  --control-height: 42px;
}

body[data-display="tablet"] {
  --display-scale: 1.05;
  --content-max: 980px;
  --sidebar-width: 292px;
  --control-height: 46px;
}

body[data-display="phone"] {
  --display-scale: 1.02;
  --content-max: 680px;
  --sidebar-width: 100%;
  --control-height: 46px;
}

body[data-display="handheld-wide"] {
  --display-scale: 0.94;
  --content-max: 980px;
  --sidebar-width: 270px;
  --control-height: 40px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--theme-pattern);
  background-size: var(--theme-pattern-size);
  color: var(--ink);
  font-size: calc(16px * var(--display-scale));
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-ink);
}

h1,
h2,
h3,
h4 {
  font-family: var(--heading-font);
}

button,
input,
select {
  font: inherit;
}

svg.lucide {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  stroke-width: 2;
}

.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;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  padding: 24px;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-copy {
  min-width: 0;
}

.sidebar-toggle {
  margin-left: auto;
}

.brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  overflow: hidden;
  border-radius: 8px;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand h1,
.topbar h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.25rem;
}

.brand p,
.eyebrow,
.offline-panel span,
.meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.field-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.select,
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.select {
  min-width: 0;
  min-height: var(--control-height);
  padding: 8px 10px;
}

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

#gameControls,
#guideControls,
.guide-spoiler-control {
  display: grid;
  gap: 8px;
}

#guideControls {
  gap: 12px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 3px;
}

.mode-button {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
}

.mode-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-button.active {
  background: var(--panel-alt);
  color: var(--accent-strong);
}

.bookmarks-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  padding: 7px 10px;
  font: inherit;
  text-align: left;
}

.settings-launch-button {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
}
.settings-launch-button svg { width: 16px; height: 16px; color: var(--accent-strong); }

.bookmarks-button span { flex: 1; font-weight: 700; }
.bookmarks-button strong { min-width: 24px; color: var(--ink); text-align: right; }
.bookmarks-button.has-bookmarks { color: var(--accent-strong); }

.manage-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.file-button,
.text-button {
  display: grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9rem;
}

.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.settings-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
}

.settings-panel summary {
  display: flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
}

.settings-panel[open] summary {
  margin-bottom: 2px;
}

.settings-grid {
  display: grid;
  gap: 10px;
}

.settings-grid label {
  display: grid;
  gap: 6px;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.shortcut-grid span {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--panel-alt) 50%, transparent);
  padding: 5px 7px;
}

.section-nav {
  display: grid;
  gap: 8px;
}

.nav-button,
.icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.nav-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px 10px calc(12px + (var(--section-level, 0) * 18px));
  text-align: left;
}

.nav-button span:first-child,
.studio-section-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-section-nav {
  position: relative;
  user-select: none;
}

.studio-section-title {
  display: block;
  outline: none;
  cursor: text;
}

.studio-section-title:focus {
  color: var(--accent-strong);
}

.studio-section-nav[data-drop-level="main"] {
  box-shadow: inset 3px 0 0 var(--accent);
}

.studio-section-nav[data-drop-level="child"] {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-alt));
  box-shadow: inset 18px 0 0 color-mix(in srgb, var(--accent) 22%, transparent);
}

.nav-button:hover,
.nav-button.active {
  border-color: var(--line);
  background: var(--panel-alt);
}

.nav-button.active::before {
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 0;
  width: 3px;
  background: var(--accent);
  content: "";
}

.offline-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
}

.offline-panel strong,
.offline-panel span {
  display: block;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-color: var(--line);
  background: var(--panel-alt);
  font-size: 1.1rem;
}

.workspace {
  min-width: 0;
  max-width: var(--content-max);
  width: 100%;
  padding: 28px clamp(22px, 3vw, 36px);
  margin: 0 auto;
}

body[data-mode="studio"] {
  --content-max: 1680px;
}

body[data-mode="studio"] .workspace {
  margin: 0;
}

.primary-button,
.studio-toolbar .text-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: var(--panel);
}

.studio-shell {
  min-width: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.studio-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.studio-pack-fields,
.studio-actions,
.studio-status,
.studio-canvas-bar,
.studio-tool-groups,
.studio-add-menu,
.studio-section-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.studio-actions,
.studio-canvas-bar,
.studio-tool-groups,
.studio-add-menu,
.studio-section-tools {
  flex-wrap: wrap;
}

.studio-pack-fields {
  min-width: 0;
  flex: 1;
}

.studio-pack-fields label:first-child {
  width: min(360px, 55%);
}

.studio-pack-fields label:last-child {
  width: min(260px, 40%);
}

.studio-toolbar label,
.property-fields label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.studio-toolbar input,
.property-fields input,
.property-fields select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink);
  padding: 7px 9px;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 680px;
}

.studio-panel-heading {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.studio-section-list,
.studio-resource-tray {
  display: grid;
  gap: 5px;
}

.studio-section-button {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  padding: 8px 6px;
  cursor: pointer;
  text-align: left;
}

.studio-section-button:hover,
.studio-section-button.active {
  border-color: var(--line);
  background: var(--panel-alt);
}

.studio-section-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-section-button small {
  color: var(--muted);
}

.studio-dropzone {
  display: grid;
  min-height: 116px;
  place-items: center;
  align-content: center;
  gap: 4px;
  margin: 16px 0 10px;
  border: 1px dashed var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.studio-dropzone.dragging {
  border-style: solid;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
}

.studio-dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.studio-dropzone svg {
  color: var(--accent-strong);
  font-size: 1.4rem;
}

.studio-dropzone span,
.studio-resource-tray p {
  color: var(--muted);
  font-size: 0.75rem;
}

.studio-link-resource {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.studio-resource-tray {
  max-height: 300px;
  overflow-y: auto;
}

.studio-resource-tray button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px;
  cursor: pointer;
  text-align: left;
}

.studio-resource-tray img,
.studio-resource-tray button > svg {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: var(--panel-alt);
  padding: 4px;
}

.studio-resource-tray span,
.studio-resource-tray small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-resource-tray small {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.7rem;
}

.studio-canvas {
  min-width: 0;
  background: transparent;
  padding: 14px 0;
}

.studio-canvas-bar {
  justify-content: space-between;
  width: min(var(--content-max), 100%);
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 12px;
  box-shadow: 0 8px 22px rgba(20, 28, 24, 0.08);
}

.studio-preview-switch {
  min-width: 220px;
  max-width: 260px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.studio-tool-groups {
  margin-left: auto;
  justify-content: flex-end;
}

.studio-section-tools {
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.studio-card-density {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 4px 7px;
  color: var(--muted);
}

.studio-card-density select {
  width: 86px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
}

.studio-check {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 5px 9px;
  font-size: 0.78rem;
}

.danger-button {
  color: #a33e35;
}

.studio-page {
  width: min(var(--content-max), 100%);
  min-height: 610px;
  margin: 0 auto;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.studio-preview {
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.studio-page [contenteditable="true"] {
  border: 1px solid transparent;
  outline: none;
}

.studio-page [contenteditable="true"]:hover,
.studio-page [contenteditable="true"]:focus {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.studio-page [contenteditable="true"]:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
}

.studio-page > h3 {
  margin: 4px 0 8px;
  padding: 4px;
  font-size: 1.55rem;
}

.studio-summary {
  min-height: 38px;
  margin: 0 0 12px;
  padding: 5px;
  color: var(--muted);
  line-height: 1.5;
}

.tag-add {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  padding: 3px 7px;
  cursor: pointer;
}

.studio-blocks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--reference-card-min, 220px), 1fr));
  gap: 12px;
  margin-top: 18px;
}

.studio-block {
  position: relative;
  display: grid;
  min-width: 0;
  align-content: start;
  border: 0;
  background: transparent;
  padding: 0;
}

.studio-block-callouts,
.studio-block-steps {
  grid-column: 1 / -1;
}

.studio-block-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.studio-block-tools .icon-button {
  width: 28px;
  height: 28px;
}

.studio-block-tools .icon-button:first-of-type {
  margin-left: auto;
}

.studio-block-preview {
  min-width: 0;
}

.studio-block-preview .reference-grid,
.studio-block-preview .callout-stack,
.studio-block-preview .steps {
  margin: 0;
}

.studio-block [contenteditable="true"] {
  border-radius: 3px;
  outline: 1px solid transparent;
  outline-offset: 2px;
}

.studio-block [contenteditable="true"]:hover,
.studio-block [contenteditable="true"]:focus {
  outline-color: color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.studio-block [contenteditable="true"]:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
}

.studio-document-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.studio-document-badges span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 4px 7px;
  font-size: 0.74rem;
  font-weight: 700;
}

.studio-block-preview,
.studio-block-preview .reference-grid,
.studio-block-preview .reference-grid > article {
  height: 100%;
}

.studio-block-image {
  width: 100%;
  max-height: 260px;
  margin-bottom: 8px;
  object-fit: contain;
  background: var(--panel-alt);
}

.studio-empty,
.studio-empty-add {
  display: grid;
  min-height: 120px;
  place-items: center;
  align-content: center;
  gap: 5px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  text-align: center;
}

.studio-empty-add {
  width: 100%;
  min-height: 48px;
  grid-template-columns: auto auto;
  margin-top: 10px;
  cursor: pointer;
}

.studio-status {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 5px 9px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.studio-status.valid { color: var(--accent-strong); }
.studio-status.invalid { color: #a33e35; }

.annotation-dialog {
  width: min(1240px, 96vw);
  max-width: none;
  height: min(94vh, 980px);
  max-height: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
}

.annotation-dialog::backdrop {
  background: rgba(8, 12, 10, 0.82);
}

.resource-dialog,
.property-dialog,
.block-dialog {
  width: min(900px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.resource-dialog::backdrop,
.property-dialog::backdrop,
.block-dialog::backdrop {
  background: rgba(8, 12, 10, 0.56);
}

.resource-modal,
.property-modal,
.block-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: inherit;
}

.resource-modal > header,
.resource-modal > footer,
.property-modal > header,
.property-modal > footer,
.block-modal > header,
.block-modal > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.resource-modal > footer,
.property-modal > footer,
.block-modal > footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.resource-modal h2,
.property-modal h2,
.block-modal h2 {
  margin: 2px 0 3px;
  font-size: 1.35rem;
}

.resource-modal header span,
.resource-library .studio-panel-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.resource-body {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  min-height: 0;
}

.resource-import,
.resource-library {
  min-width: 0;
  padding: 14px;
}

.resource-import {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--sidebar-bg) 70%, var(--panel));
}

.resource-library {
  overflow-y: auto;
}

.resource-library .studio-panel-heading > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.resource-search {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 0 10px;
}

.resource-search:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.resource-search svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.resource-search input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.resource-filter-empty {
  margin-top: 8px;
}

.resource-dialog .studio-dropzone {
  margin-top: 0;
}

.resource-dialog .studio-resource-tray {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  max-height: none;
}

.property-dialog {
  width: min(620px, calc(100vw - 28px));
}

.block-dialog {
  width: min(720px, calc(100vw - 28px));
}

.property-fields,
.block-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 16px;
}

.property-fields label:first-child,
.block-fields .wide {
  grid-column: 1 / -1;
}

.block-fields label,
.block-fields .wide {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.block-fields input,
.block-fields select,
.block-fields textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink);
  padding: 7px 9px;
  font: inherit;
}

.block-fields textarea {
  min-height: 96px;
  resize: vertical;
}

.block-resource-controls {
  display: grid;
  gap: 8px;
}

.block-resource-controls > div {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 8px;
}

.block-resource-controls span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.block-resource-controls strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annotation-editor {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100%;
}

.annotation-editor > header,
.annotation-editor > footer,
.annotation-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}

.annotation-editor h2 { margin: 2px 0 0; font-size: 1rem; }
.annotation-editor > footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.annotation-pager { justify-content: center; }
.annotation-pager label { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 0.78rem; }
.annotation-pager input { width: 68px; min-height: 32px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 6px; }

.annotation-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  min-height: 0;
}

.annotation-page {
  position: relative;
  align-self: start;
  justify-self: center;
  margin: 16px;
  box-shadow: var(--shadow);
}

.annotation-page canvas { display: block; max-width: 100%; height: auto; background: white; }
.annotation-overlay { position: absolute; inset: 0; cursor: crosshair; }
.annotation-mark { position: absolute; border: 2px solid #b17a00; background: rgba(255, 210, 45, 0.32); pointer-events: none; }

.annotation-workspace > aside {
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 14px;
}

.annotation-workspace > aside > p { color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.annotation-list-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding: 8px 0; }
.annotation-list-item > div { display: grid; min-width: 0; flex: 1; gap: 4px; }
.annotation-list-item input,
.annotation-list-item textarea { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 6px; font: inherit; }
.annotation-list-item textarea { min-height: 58px; resize: vertical; }
.annotation-list-item small { color: var(--muted); }

@media (max-width: 1200px) {
  .studio-layout { grid-template-columns: 1fr; }
}

@media (max-width: 1360px) and (min-width: 841px) {
  body[data-mode="guide"] .topbar {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  body[data-mode="guide"] .search-box {
    order: -1;
  }
}

@media (max-width: 840px) {
  .studio-toolbar { align-items: stretch; flex-direction: column; }
  .studio-pack-fields { width: 100%; }
  .studio-actions { justify-content: flex-end; }
  .studio-layout { grid-template-columns: 1fr; }
  .studio-tool-groups { justify-content: flex-start; margin-left: 0; }
  .studio-section-tools { border-left: 0; padding-left: 0; }
  .studio-dropzone { min-height: 80px; }
  .studio-resource-tray { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); max-height: none; }
  .resource-body { grid-template-columns: 1fr; }
  .resource-import { border-right: 0; border-bottom: 1px solid var(--line); }
  .property-fields,
  .block-fields { grid-template-columns: 1fr; }
  .annotation-workspace { grid-template-columns: 1fr; overflow-y: auto; }
  .annotation-workspace > aside { border-top: 1px solid var(--line); border-left: 0; }
}

.topbar {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(240px, 440px);
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
}

body:not([data-mode="guide"]) .topbar {
  grid-template-columns: minmax(0, 1fr);
}

body:not([data-mode="guide"]) .search-box {
  display: none;
}

.title-cluster {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 13px;
}

.title-artwork {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--accent-strong);
}

.title-artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-artwork.box-art {
  width: clamp(42px, calc(64px * var(--media-ratio, 0.75)), 96px);
  height: 64px;
  aspect-ratio: var(--media-aspect, 3 / 4);
  flex-basis: clamp(42px, calc(64px * var(--media-ratio, 0.75)), 96px);
  padding: 2px;
  background: #101312;
}

.title-artwork.box-art img {
  object-fit: contain;
}

.title-artwork svg {
  width: 25px;
  height: 25px;
}

.title-copy {
  min-width: 0;
}

.breadcrumbs {
  display: flex;
  min-height: 20px;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  overflow: hidden;
  text-transform: uppercase;
}

.breadcrumbs button,
.breadcrumbs span {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumbs button {
  min-height: 28px;
  padding: 4px 3px;
  cursor: pointer;
}

.breadcrumbs button:hover {
  color: var(--accent-strong);
}

.breadcrumbs svg {
  width: 0.85em;
  height: 0.85em;
  opacity: 0.7;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.header-meta > span,
.header-meta .entity-link {
  min-height: 30px;
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
}

.header-meta .entity-link {
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  color: var(--accent-strong);
  padding: 3px 7px;
  text-decoration: none;
}

.header-meta .entity-link:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--panel));
  text-decoration: none;
}

.header-meta .entity-link svg:last-child {
  width: 0.9em;
  height: 0.9em;
  opacity: 0.82;
}

.topbar h2 {
  font-size: clamp(1.6rem, 2.1vw, 2rem);
  line-height: 1.12;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 12px;
  box-shadow: var(--shadow);
}

.search-box input {
  min-width: 0;
  flex: 1;
  min-height: 46px;
  border: 0;
  outline: none;
}

.search-clear {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
}

.search-clear:hover {
  background: var(--panel-alt);
}

.search-box:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, rgba(0, 0, 0, 0.18));
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

body[data-loading="true"] .loading-overlay {
  opacity: 1;
  pointer-events: auto;
}

.loading-card {
  display: flex;
  width: min(420px, calc(100vw - 32px));
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 18px;
  box-shadow: var(--shadow);
}

.loading-card strong,
.loading-card span {
  display: block;
}

.loading-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: loading-spin 800ms linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.content,
.search-results {
  display: grid;
  gap: 14px;
}

.content.hidden,
.search-results.hidden {
  display: none;
}

.section-pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.section-pager-button {
  display: flex;
  min-width: 0;
  min-height: 52px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
}

.section-pager-button:hover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.section-pager-button span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.section-pager-button small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.section-pager-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-pager-next {
  flex-direction: row-reverse;
  grid-column: 3;
  text-align: right;
}

.section-pager-position {
  display: grid;
  min-width: 58px;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.section-pager-spacer:first-child { grid-column: 1; }

.sidebar-scrim {
  display: none;
}

.game-profile {
  display: grid;
  gap: 22px;
}

.game-overview {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.game-overview-copy {
  display: grid;
  gap: 20px;
}

.game-box-art {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #101312;
  box-shadow: var(--shadow);
}

.game-box-art img {
  display: block;
  width: 100%;
  aspect-ratio: var(--media-aspect, 5 / 7);
  object-fit: contain;
}

.game-box-art figcaption {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 9px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.game-artwork,
.section-media,
.reference-media,
.entity-game-art {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-alt);
}

.game-artwork img,
.section-media img,
.reference-media img {
  display: block;
  width: 100%;
  object-fit: var(--media-object-fit, cover);
  image-rendering: var(--media-rendering, auto);
}

.game-artwork img {
  aspect-ratio: 3 / 1;
}

.section-media img {
  aspect-ratio: 16 / 7;
}

.reference-media img {
  aspect-ratio: 16 / 9;
  max-height: 220px;
  image-rendering: pixelated;
  image-rendering: var(--media-rendering, crisp-edges);
}

.reference-media.sprite-media {
  display: grid;
  min-height: 112px;
  place-items: center;
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line) 35%, transparent) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--line) 35%, transparent) 1px, transparent 1px),
    var(--panel-alt);
  background-size: 12px 12px;
}

.reference-media.sprite-media img {
  width: 96px;
  height: 96px;
  aspect-ratio: 1;
  object-fit: var(--media-object-fit, contain);
  image-rendering: pixelated;
  image-rendering: var(--media-rendering, crisp-edges);
}

.reference-media.sprite-media figcaption {
  width: 100%;
}

.entity-game-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #101312;
}

.game-artwork figcaption,
.section-media figcaption,
.reference-media figcaption {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 7px 10px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.section-media {
  margin-top: 16px;
}

.reference-media {
  margin-bottom: 12px;
}

.game-description {
  max-width: 76ch;
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.65;
}

.fact-grid,
.time-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 0;
}

.game-overview .fact-grid {
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
}

.fact-grid > div,
.time-grid > div {
  border-left: 3px solid var(--accent);
  padding: 7px 10px;
}

.fact-grid dt,
.time-grid dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.fact-grid dd,
.time-grid dd {
  margin: 4px 0 0;
  font-weight: 700;
}

.profile-section {
  display: grid;
  gap: 12px;
}

.profile-section h3 {
  margin: 0;
  font-size: 1rem;
}

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

.provider-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.provider-scope-badge {
  border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  color: var(--accent-strong);
  padding: 3px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.provider-card {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.provider-card p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.provider-card .provider-note {
  border-left: 2px solid var(--line);
  padding-left: 9px;
  color: var(--ink);
}

.provider-card a {
  color: var(--accent-strong);
  font-weight: 700;
}

.provider-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.provider-score {
  display: block;
  margin: 6px 0 10px;
  color: var(--accent-strong);
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.release-profile,
.release-data {
  margin: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.release-heading,
.release-data {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.release-heading h4,
.release-data h4 {
  margin: 2px 0 0;
}

.release-heading > span,
.release-data > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.provider-unavailable {
  background: color-mix(in srgb, var(--panel) 65%, var(--panel-alt));
}

.platform-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.platform-list .entity-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink);
  padding: 7px 9px;
  cursor: pointer;
  font-size: 0.82rem;
  text-align: left;
}

.platform-list .entity-link:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

.platform-list small,
.platform-list b {
  color: var(--muted);
  font-weight: 400;
}

.spoiler-text {
  display: inline;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0 2px;
}

body[data-spoilers="blur"] .spoiler-text:not(.revealed) {
  background: color-mix(in srgb, var(--ink) 12%, var(--panel));
}

body[data-spoilers="blur"] .spoiler-text:not(.revealed) .spoiler-content {
  filter: blur(0.38em);
  user-select: none;
}

.spoiler-text.revealed,
body[data-spoilers="reveal"] .spoiler-text {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.result,
.reference-grid > article,
.studio-block-preview > article {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
}

.search-summary {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
}

.search-summary strong {
  color: var(--ink);
}

.section {
  min-width: 0;
}

.section > .reference-grid,
.section > .steps {
  margin-top: 16px;
}

.section h3,
.result h3,
.reference-grid h4,
.studio-block-preview > article h4 {
  margin: 0 0 8px;
  letter-spacing: 0;
}

.section h3 {
  font-size: 1.2rem;
}

.section p,
.result p,
.reference-grid p,
.studio-block-preview > article p {
  margin: 0 0 10px;
  line-height: 1.55;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.tag {
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--accent-strong);
  padding: 3px 8px;
  font-size: 0.78rem;
}

.steps,
.compact-list {
  margin: 10px 0 0;
  padding-left: 1.3rem;
}

.steps li,
.compact-list li {
  margin: 6px 0;
  line-height: 1.45;
}

.checklist {
  padding: 0;
  list-style: none;
}

.checklist li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 12px 4px;
}

.checklist input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.checklist input:checked + div {
  color: var(--muted);
}

.nav-progress {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.reference-grid {
  --reference-grid-gap: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(max(var(--reference-card-min, 220px), var(--reference-card-max-basis, var(--reference-card-min, 220px))), 1fr));
  gap: var(--reference-grid-gap);
  align-items: start;
}

.reference-grid.equal-height-rows {
  align-items: stretch;
}

.reference-grid.reference-grid-group.center-partial-rows {
  grid-template-columns: repeat(auto-fit, minmax(var(--reference-card-min, 220px), var(--reference-card-max-basis, 1fr)));
  justify-content: center;
}

.section > .reference-grid.reference-grid-group + .reference-grid.reference-grid-group {
  margin-top: 12px;
}

.reference-grid > article,
.studio-block-preview > article {
  --reference-card-padding: 18px;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: var(--reference-card-padding);
  box-shadow: none;
  background: color-mix(in srgb, var(--panel-alt) 45%, var(--panel));
}

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

.reference-grid > article > h4,
.studio-block-preview > article > h4 {
  margin-bottom: 10px;
}

.entry-type {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.reference-card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 32px;
  align-items: stretch;
  gap: 0;
  margin: auto calc(var(--reference-card-padding) * -1) calc(var(--reference-card-padding) * -1);
  border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  background: color-mix(in srgb, var(--panel-alt) 72%, var(--panel));
  padding-left: var(--reference-card-padding);
}

.reference-card-links {
  display: flex;
  min-width: 0;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 5px 8px 5px 0;
}

.reference-card-actions {
  display: flex;
  align-self: stretch;
  justify-self: end;
}

.reference-actions-menu {
  justify-self: end;
}

.reference-card-footer > .reference-card-actions > .reference-detail-button,
.reference-card-footer > .reference-actions-menu > summary {
  height: 100%;
  min-height: 31px;
  border: 0;
  border-left: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 0;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-alt));
  padding: 0 12px;
}

.reference-card-footer .guide-link-row,
.reference-card-footer .guide-link,
.reference-card-footer .reference-detail-button {
  margin: 0;
}

.reference-actions-menu {
  position: relative;
}

.reference-actions-menu summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel-alt) 82%, transparent);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  list-style: none;
  padding: 5px 8px;
}

.reference-actions-menu summary::-webkit-details-marker {
  display: none;
}

.reference-actions-menu[open] summary,
.reference-actions-menu summary:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.reference-actions-list {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 20;
  display: grid;
  min-width: 180px;
  gap: 6px;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 8px;
}

.reference-actions-list .guide-link,
.reference-actions-list .reference-detail-button {
  width: 100%;
  justify-content: flex-start;
}

.guide-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.guide-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel-alt) 82%, transparent);
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  padding: 5px 8px;
}

.guide-link:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

.reference-detail-button {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 8px;
}

.reference-detail-button.compact {
  min-height: 26px;
  margin: 0;
  padding: 3px 7px;
  white-space: nowrap;
}

.reference-detail-button:hover,
.reference-detail-button:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
  outline: none;
}

.reference-detail-button svg {
  width: 0.95em;
  height: 0.95em;
}

.guide-link svg {
  width: 15px;
  height: 15px;
}

.callout-stack {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.callout {
  border-left: 4px solid var(--accent);
  background: var(--panel-alt);
  padding: 11px 13px;
}

.callout p {
  margin: 3px 0 0;
}

.document-ref-list {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.document-link,
.document-preview {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.document-link {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 20px;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
}

.document-link span,
.document-preview > span:not(.document-preview-image) {
  display: grid;
  gap: 3px;
}

.document-link small,
.document-preview small,
.document-preview em {
  color: var(--muted);
  font-size: 0.75rem;
  font-style: normal;
}

.document-link:hover,
.document-preview:hover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.document-preview {
  display: grid;
  grid-template-columns: minmax(110px, 180px) minmax(0, 1fr) 24px;
  gap: 14px;
  align-items: center;
  padding: 0 14px 0 0;
  overflow: hidden;
}

.document-thumbnail {
  margin: 0;
  border: 0;
  border-right: 1px solid var(--line);
  background: white;
}

.document-thumbnail img {
  display: block;
  width: 100%;
  aspect-ratio: 8.5 / 11;
  object-fit: cover;
  object-position: top;
}

.document-thumbnail figcaption {
  display: none;
}

.document-dialog {
  width: min(1100px, 96vw);
  max-width: none;
  height: min(92vh, 980px);
  max-height: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.document-dialog::backdrop {
  background: rgba(10, 14, 12, 0.78);
}

.reference-dialog {
  width: min(1020px, calc(100vw - 28px));
  max-height: min(92vh, 980px);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.reference-dialog::backdrop {
  background: rgba(10, 14, 12, 0.68);
}

.reference-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: inherit;
}

.reference-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  position: sticky;
  top: 0;
  z-index: 3;
}

.reference-modal-header h2 {
  margin: 2px 0 0;
  font-size: 1.25rem;
}

.reference-modal-body {
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.bookmarks-dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(88vh, 820px);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.bookmarks-dialog::backdrop { background: rgba(10, 14, 12, 0.68); }

.repository-dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: min(90vh, 860px);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}
.repository-dialog::backdrop { background: rgba(10, 14, 12, 0.72); }
.repository-modal { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: inherit; }
.repository-modal > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 14px 16px; }
.repository-modal h2, .repository-modal h3 { margin: 0; }
.repository-modal-body { display: grid; grid-template-columns: minmax(260px, 0.8fr) minmax(360px, 1.2fr); min-height: 0; overflow-y: auto; }
.repository-list-panel { min-width: 0; border-right: 1px solid var(--line); padding: 16px; }
.repository-section-heading, .repository-form-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.repository-section-heading .text-button, .repository-form footer button { display: inline-flex; align-items: center; gap: 6px; }
.repository-list { display: grid; gap: 8px; }
.repository-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--panel-alt); padding: 10px; }
.repository-row > div:first-child { display: grid; min-width: 0; gap: 3px; }
.repository-row span { overflow: hidden; color: var(--muted); font-size: 0.74rem; text-overflow: ellipsis; white-space: nowrap; }
.repository-row small { color: var(--accent-strong); font-size: 0.68rem; }
.repository-row-actions { display: flex; gap: 4px; }
.repository-row-actions .icon-button { width: 32px; min-height: 32px; }
.repository-empty { min-height: 120px; }
.repository-form { min-width: 0; padding: 16px; }
.repository-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.repository-field { display: grid; min-width: 0; gap: 5px; }
.repository-field > span, .repository-check > span { color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
.repository-field input, .repository-field select { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 0; background: var(--panel-alt); color: var(--ink); padding: 7px 9px; font: inherit; }
.repository-field-wide { grid-column: 1 / -1; }
.repository-check { display: flex; align-items: center; gap: 8px; align-self: end; min-height: 38px; }
.repository-form footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
#repositoryFormStatus { color: var(--accent-strong); font-size: 0.75rem; }
#repositoryFormStatus[data-error="true"] { color: var(--warning); }

@media (max-width: 720px) {
  .repository-modal-body { grid-template-columns: 1fr; }
  .repository-list-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .repository-form-grid { grid-template-columns: 1fr; }
  .repository-field-wide { grid-column: auto; }
}

.bookmarks-modal { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: inherit; }
.bookmarks-modal > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 14px 16px; }
.bookmarks-modal h2 { margin: 2px 0 0; font-size: 1.25rem; }
.bookmarks-body { display: grid; gap: 18px; min-height: 0; overflow-y: auto; padding: 16px; }
.bookmark-group { display: grid; gap: 8px; }
.bookmark-group > h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.92rem; }
.bookmark-group > h3 span { flex: 1; }
.bookmark-group > h3 small { color: var(--muted); }
.bookmark-list { display: grid; border: 1px solid var(--line); }
.bookmark-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 10px 12px; }
.bookmark-row:last-child { border-bottom: 0; }
.bookmark-row > div:first-child { display: grid; gap: 2px; min-width: 0; }
.bookmark-row > div:first-child span,
.bookmark-row > div:first-child small { color: var(--muted); font-size: 0.72rem; }
.bookmark-row strong { overflow-wrap: anywhere; }
.bookmark-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.bookmark-actions .text-button { display: flex; gap: 6px; padding: 6px 9px; }
.bookmark-empty { display: grid; justify-items: center; gap: 8px; text-align: center; }

.controller-selected {
  outline: 3px solid var(--accent-strong) !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 20%, transparent), var(--shadow) !important;
}

[data-bookmarked="true"] .reference-card-head::after {
  content: "Saved";
  margin-left: auto;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
  color: var(--accent-strong);
  padding: 2px 5px;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
}

.reference-table tr[data-bookmarked="true"] { box-shadow: inset 3px 0 var(--accent-strong); }

.controller-status {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 36px));
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.controller-status.visible { opacity: 1; transform: translateY(0); }

.reference-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  gap: 16px;
}

.reference-detail-layout.no-media {
  grid-template-columns: minmax(0, 1fr);
}

.reference-detail-layout .reference-detail-media {
  align-self: start;
  margin: 0;
}

.reference-detail-main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.reference-detail-main section,
.reference-detail-main .stat-grid,
.reference-detail-main .meta,
.reference-detail-main .document-ref-list {
  margin: 0;
}

.reference-detail-main h3 {
  margin: 0 0 5px;
  font-size: 0.9rem;
}

.reference-detail-main p {
  margin: 0;
  line-height: 1.55;
}

.reference-template-detail {
  display: grid;
  gap: 20px;
}

.reference-template-header {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(0, 1fr) minmax(160px, 200px);
  gap: 24px;
  align-items: center;
}

.reference-template-header.no-media {
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
}

.reference-template-portrait {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 188px;
  background: color-mix(in srgb, var(--panel-alt) 74%, var(--panel));
  padding: 18px;
}

.reference-template-portrait figure {
  width: 100%;
  margin: 0;
}

.reference-template-portrait img {
  width: 100%;
  height: 132px;
  object-fit: contain;
  image-rendering: pixelated;
}

.reference-template-portrait figcaption {
  display: none;
}

.reference-template-title-block {
  display: grid;
  align-content: start;
  gap: 8px;
}

.reference-template-title-block h3 {
  margin: 0;
  font-size: 1.75rem;
}

.reference-template-title-block p {
  margin: 0;
  line-height: 1.55;
}

.reference-template-summary-grid,
.reference-template-panel dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.reference-template-summary-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-alt) 58%, var(--panel));
  padding: 8px 16px;
}

.reference-template-summary-grid div,
.reference-template-panel dl div {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) minmax(0, 1.2fr);
  gap: 8px;
}

.reference-template-summary-grid div {
  align-items: center;
  min-height: 46px;
  border-bottom: 1px solid var(--line);
}

.reference-template-summary-grid div:last-child {
  border-bottom: 0;
}

.reference-template-summary-grid dt,
.reference-template-panel dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.reference-template-summary-grid dd,
.reference-template-panel dd {
  margin: 0;
  font-weight: 700;
}

.reference-template-summary-grid dd {
  font-size: 1.02rem;
  text-align: right;
}

.reference-template-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reference-template-badge {
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  background: color-mix(in srgb, var(--accent) 11%, var(--panel));
  color: var(--accent-strong);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.reference-template-badge .reference-template-icon {
  width: 18px;
  height: 18px;
}

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

.reference-template-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-alt) 44%, var(--panel));
  padding: 16px;
}

.reference-template-panel h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.92rem;
  text-transform: uppercase;
}

.reference-template-panel h4 > i,
.reference-template-panel h4 > svg,
.reference-template-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.reference-template-data-list > div {
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

.reference-template-data-list > div:last-child {
  border-bottom: 0;
}

.reference-template-wide {
  grid-column: 1 / -1;
}

.reference-template-stat-row {
  display: grid;
  grid-template-columns: 78px 36px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
}

.reference-template-stat-row span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.reference-template-stat-row meter {
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

.reference-template-stat-total {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 8px;
}

.reference-template-value-grid,
.reference-template-item-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.reference-template-value-grid span,
.reference-template-item-list span {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 68%, transparent);
  padding: 7px 9px;
}

.reference-template-value-grid > span {
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.reference-template-value-grid .reference-template-icon {
  width: 20px;
  height: 20px;
}

.reference-template-value-grid em {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
}

.reference-template-value-grid em,
.reference-template-item-list em,
.reference-template-item-list small,
.reference-template-linked-list small {
  color: var(--muted);
  font-style: normal;
  font-size: 0.72rem;
}

.reference-template-linked-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.reference-template-linked-stage {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 68%, transparent);
  padding: 8px;
}

.reference-template-linked-stage-link {
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.reference-template-linked-stage-link:hover,
.reference-template-linked-stage-link:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.reference-template-linked-stage > span:last-child {
  display: grid;
  gap: 2px;
}

.reference-template-linked-portrait {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
}

.reference-template-linked-media,
.reference-template-linked-media img {
  width: 44px;
  height: 44px;
  margin: 0;
  object-fit: contain;
  image-rendering: pixelated;
}

.reference-template-note-list > div {
  grid-template-columns: 92px minmax(0, 1fr) !important;
  align-items: start;
}

.reference-template-item-list > span {
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.reference-template-item-list > span > span {
  display: grid;
  gap: 2px;
}

.reference-template-item-list .reference-template-icon {
  width: 22px;
  height: 22px;
}

.reference-template-item-list small {
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  color: var(--ink);
  padding: 3px 6px;
  font-weight: 700;
}

.reference-template-panel-grid > .guide-link-row,
.reference-template-panel-grid > .tag-row,
.reference-template-panel-grid > .document-ref-list {
  grid-column: 1 / -1;
}

@media (max-width: 700px) {
  .reference-dialog {
    width: 100vw;
    max-width: 100vw !important;
    max-height: 100dvh;
    height: 100dvh;
    margin: 0;
    border: 0;
  }

  .reference-detail-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .reference-template-header,
  .reference-template-panel-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .reference-template-wide {
    grid-column: auto;
  }

  .bookmark-row { align-items: stretch; flex-direction: column; }
  .bookmark-actions { justify-content: flex-end; }
}

.document-modal {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  height: 100%;
}

.document-toolbar,
.document-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.document-toolbar h2 {
  margin: 2px 0 0;
  font-size: 1.15rem;
}

.document-actions,
.document-pager {
  display: flex;
  align-items: center;
}

.document-actions {
  gap: 8px;
}

.document-pager {
  justify-content: center;
  padding: 7px 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.document-status {
  min-height: 0;
  margin: 0;
  padding: 0 16px;
  color: var(--muted);
  text-align: center;
}

.document-status:not(:empty) {
  padding: 14px 16px;
}

.document-stage {
  display: grid;
  min-height: 0;
  overflow: auto;
  align-items: start;
  background: #4a504d;
  padding: 16px;
}

.document-stage canvas,
.document-highlights {
  grid-area: 1 / 1;
  justify-self: center;
}

.document-stage canvas {
  display: block;
  max-width: none;
  background: white;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.document-highlights {
  position: relative;
  pointer-events: none;
}

.pdf-highlight {
  position: absolute;
  border: 2px solid #e3a714;
  background: rgba(255, 214, 64, 0.3);
  cursor: help;
  pointer-events: auto;
}

.pdf-highlight:hover,
.pdf-highlight:focus-visible {
  background: rgba(255, 214, 64, 0.5);
  outline: 3px solid #fff;
}

.document-annotation {
  border-top: 1px solid var(--line);
  background: var(--panel-alt);
  padding: 12px 16px;
}

.document-annotation p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

body[data-sidebar="collapsed"] .app-shell {
  grid-template-columns: 78px minmax(0, 1fr);
}

body[data-sidebar="collapsed"] .sidebar {
  gap: 14px;
  padding: 14px 10px;
  overflow: hidden;
}

body[data-sidebar="collapsed"] .brand {
  flex-direction: column;
}

body[data-sidebar="collapsed"] .brand-copy,
body[data-sidebar="collapsed"] #gameControls,
body[data-sidebar="collapsed"] #guideControls,
body[data-sidebar="collapsed"] .settings-panel,
body[data-sidebar="collapsed"] .section-nav,
body[data-sidebar="collapsed"] .offline-panel,
body[data-sidebar="collapsed"] .sidebar .mode-button span {
  display: none !important;
}

body[data-sidebar="collapsed"] .bookmarks-button span,
body[data-sidebar="collapsed"] .bookmarks-button strong { display: none; }

body[data-sidebar="collapsed"] .bookmarks-button { justify-content: center; padding: 6px; }

body[data-sidebar="collapsed"] .sidebar-toggle {
  margin-left: 0;
}

body[data-sidebar="collapsed"] .sidebar .mode-switch {
  grid-template-columns: 1fr;
}

.callout-warning,
.callout-danger {
  border-left-color: var(--warn);
}

.table-scroll {
  width: 100%;
  margin-top: 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 0.9rem;
}

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

.reference-table th {
  position: sticky;
  top: 0;
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.reference-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--panel-alt) 38%, transparent);
}

.reference-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
}

.reference-table tbody tr:last-child td {
  border-bottom: 0;
}

.jump-target {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.priority {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  padding: 2px 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.entity-link {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  padding: 0;
  font-weight: 700;
}

.entity-link:hover {
  text-decoration: underline;
}

.fact-grid .entity-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.entity-browser {
  display: grid;
  gap: 10px;
}

.entity-game {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 20px;
  min-height: 76px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px 8px 8px;
  text-align: left;
}

.entity-game:hover {
  border-color: var(--accent);
  background: var(--panel-alt);
}

.entity-game-art,
.media-placeholder {
  display: grid;
  width: 76px;
  height: 58px;
  place-items: center;
}

.media-placeholder {
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--muted);
}

.entity-game > span {
  display: grid;
  gap: 4px;
}

.entity-game small {
  color: var(--muted);
}

.priority-essential,
.priority-recommended {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.priority-skip,
.priority-warning {
  border-color: var(--warn);
  color: var(--warn);
}

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

.stat-grid.configured-columns {
  grid-template-columns: repeat(var(--stat-columns), minmax(0, 1fr));
}

.stat-grid > .stat-full-width {
  grid-column: 1 / -1;
}

.stat-grid div {
  border-left: 2px solid var(--line);
  padding-left: 8px;
}

.stat-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.stat-grid dd {
  margin: 2px 0 0;
  font-weight: 700;
}

.source-panel {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.source-panel summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
}

.source-panel[open] summary {
  margin-bottom: 10px;
}

.source-panel p {
  line-height: 1.5;
}

.source-panel ul {
  padding-left: 1.2rem;
}

.source-panel a {
  color: var(--accent-strong);
}

.empty {
  border: 1px dashed var(--line);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  padding: 24px;
  color: var(--muted);
}

mark {
  background: color-mix(in srgb, var(--warn) 42%, white);
  color: var(--ink);
}

body[data-display="handheld-wide"] .app-shell {
  grid-template-columns: minmax(220px, 28vw) minmax(0, 1fr);
}

body[data-display="handheld-wide"] .sidebar {
  gap: 12px;
  padding: 14px;
}

body[data-display="handheld-wide"] .workspace {
  padding: 14px;
}

body[data-display="handheld-wide"] .topbar {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

body[data-display="handheld-wide"] .search-box {
  position: sticky;
  top: 8px;
  z-index: 5;
  order: 1;
}

body[data-display="handheld-wide"] .title-cluster {
  order: 2;
}

body[data-display="handheld-wide"] .title-artwork {
  width: 46px;
  height: 46px;
  flex-basis: 46px;
}

body[data-display="handheld-wide"] .title-artwork.box-art {
  width: clamp(38px, calc(56px * var(--media-ratio, 0.75)), 84px);
  height: 56px;
  flex-basis: clamp(38px, calc(56px * var(--media-ratio, 0.75)), 84px);
}

body[data-display="handheld-wide"] .title-copy {
  display: grid;
  gap: 3px;
}

body[data-display="handheld-wide"] .topbar h2,
body[data-display="phone"] .topbar h2 {
  font-size: 1.35rem;
  line-height: 1.12;
}

body[data-display="handheld-wide"] .header-meta {
  margin-top: 0;
  gap: 4px 9px;
  font-size: 0.72rem;
}

body[data-display="handheld-wide"][data-sidebar="collapsed"] .app-shell {
  grid-template-columns: 68px minmax(0, 1fr);
}

body[data-display="handheld-wide"][data-sidebar="collapsed"] .sidebar {
  padding: 12px 8px;
}

body[data-display="handheld-wide"] .result,
body[data-display="handheld-wide"] .reference-grid > article,
body[data-display="handheld-wide"] .studio-block-preview > article {
  --reference-card-padding: 13px;
  padding: 13px;
}

body[data-display="handheld-wide"] .reference-grid {
  --reference-grid-gap: 10px;
}

body[data-display="handheld-wide"] .section > .reference-grid,
body[data-display="handheld-wide"] .section > .steps,
body[data-display="handheld-wide"] .table-scroll,
body[data-display="handheld-wide"] .callout-stack {
  margin-top: 12px;
}

body[data-display="handheld-wide"] .shortcut-grid,
body[data-display="handheld-wide"] .source-panel {
  font-size: 0.72rem;
}

body[data-display="phone"] .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body[data-display="phone"] .sidebar {
  position: static;
  height: auto;
  overflow: visible;
  border-right: 0;
  border-bottom: 1px solid var(--line);
}

body[data-display="phone"][data-sidebar="expanded"] .sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 31;
  width: min(380px, 100vw);
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: var(--shadow);
}

body[data-display="phone"][data-sidebar="expanded"] .sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: block;
  border: 0;
  background: rgba(10, 14, 12, 0.56);
}

body[data-display="phone"] .topbar {
  grid-template-columns: 1fr;
}

body[data-display="phone"] .game-artwork img {
  aspect-ratio: 16 / 7;
}

body[data-display="phone"] .game-overview {
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
}

body[data-display="phone"] .game-overview-copy {
  gap: 12px;
}

body[data-display="phone"] .game-description {
  font-size: 0.92rem;
  line-height: 1.5;
}

body[data-display="phone"] .header-meta {
  gap: 5px 9px;
}

body[data-display="phone"] .section-nav {
  display: flex;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

body[data-display="phone"] .section-nav .nav-button {
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}

body[data-display="phone"] .reference-grid {
  --reference-card-max-basis: 100%;
  grid-template-columns: minmax(0, 1fr);
}

body[data-display="phone"][data-sidebar="collapsed"] .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body[data-display="phone"][data-sidebar="collapsed"] .sidebar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 10px 14px;
}

body[data-display="phone"][data-sidebar="collapsed"] .brand {
  width: 100%;
  flex-direction: row;
}

body[data-display="phone"][data-sidebar="collapsed"] .sidebar .mode-switch {
  display: none;
}

body[data-pointer="coarse"] .source-panel summary {
  min-height: 42px;
  padding: 10px 0;
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    height: auto;
    overflow: visible;
  }

  body[data-sidebar="expanded"] .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 31;
    width: min(380px, 100vw);
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: var(--shadow);
  }

  body[data-sidebar="expanded"] .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    border: 0;
    background: rgba(10, 14, 12, 0.56);
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 18px;
  }

  .section-nav {
    display: flex;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .section-nav .nav-button {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .reference-table th,
  .reference-table td {
    min-width: 110px;
  }

  .provider-grid {
    grid-template-columns: 1fr;
  }

  .game-overview {
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 16px;
  }

  body[data-sidebar="collapsed"] .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-sidebar="collapsed"] .sidebar {
    position: sticky;
    top: 0;
    z-index: 12;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
  }

  body[data-sidebar="collapsed"] .brand {
    width: 100%;
    flex-direction: row;
  }

  body[data-sidebar="collapsed"] .sidebar .mode-switch {
    display: none;
  }

  .release-heading,
  .release-data {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-preview {
    grid-template-columns: 100px minmax(0, 1fr) 20px;
  }

  .document-dialog {
    width: 100vw;
    height: 100dvh;
    border: 0;
  }
}

@media (max-width: 520px) {
  .section-pager {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .section-pager-position {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .section-pager-next { grid-column: 2; }

  .game-overview {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 12px;
  }

  .game-overview .fact-grid {
    grid-template-columns: 1fr;
  }
}

/* Theme contract: these treatments stay generic so guide packs only supply content. */
.select-with-palette {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 6px;
  align-items: stretch;
}

.theme-palette {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  min-height: var(--control-height);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--panel);
  padding: 3px;
}

.theme-palette span:first-child { border-radius: max(0px, calc(var(--control-radius) - 2px)) 0 0 0; }
.theme-palette span:nth-child(2) { border-radius: 0 max(0px, calc(var(--control-radius) - 2px)) 0 0; }
.theme-palette span:nth-child(3) { border-radius: 0 0 0 max(0px, calc(var(--control-radius) - 2px)); }
.theme-palette span:last-child { border-radius: 0 0 max(0px, calc(var(--control-radius) - 2px)) 0; }

:where(
  .select,
  .search-box,
  .mode-switch,
  .bookmarks-button,
  .settings-launch-button,
  .file-button,
  .text-button,
  .settings-panel,
  .icon-button,
  .primary-button,
  .studio-card-density,
  .studio-check,
  .guide-link,
  .reference-detail-button
) {
  border-radius: var(--control-radius);
}

:where(
  .studio-toolbar,
  .studio-canvas-bar,
  .offline-panel,
  .provider-card,
  .result,
  .reference-grid > article,
  .studio-block-preview > article,
  .document-dialog,
  .reference-dialog,
  .bookmarks-dialog,
  .repository-dialog,
  .resource-dialog,
  .property-dialog,
  .block-dialog
) {
  border-radius: var(--panel-radius);
}

:where(
  .search-box,
  .studio-toolbar,
  .studio-canvas-bar,
  .document-dialog,
  .reference-dialog,
  .bookmarks-dialog,
  .repository-dialog,
  .resource-dialog,
  .property-dialog,
  .block-dialog
) {
  background-color: var(--surface-raised);
}

:where(
  .provider-card,
  .result,
  .reference-grid > article,
  .studio-block-preview > article
) {
  border-top-color: var(--card-accent);
  border-top-width: var(--card-accent-width);
}

/* These component selectors intentionally outrank their base border declarations. */
.provider-card,
.result,
.reference-grid > article,
.studio-block-preview > article {
  border-top-color: var(--card-accent);
  border-top-width: var(--card-accent-width);
}

.search-box,
.studio-toolbar,
.studio-canvas-bar,
.document-dialog,
.reference-dialog,
.bookmarks-dialog,
.repository-dialog,
.resource-dialog,
.property-dialog,
.block-dialog {
  background-color: var(--surface-raised);
}

.search-box:focus-within {
  outline-color: var(--focus-ring);
}

body[data-theme="cartridge-pop"] .brand-mark {
  box-shadow: 3px 3px 0 var(--accent);
}

body[data-theme="cartridge-pop"] .mode-button.active {
  box-shadow: inset 0 -3px var(--accent);
}

body[data-theme="cartridge-pop"] .primary-button {
  border-color: var(--ink);
  background: var(--accent);
  color: #fffefb;
  box-shadow: 3px 3px 0 rgba(24, 38, 51, 0.18);
}

body[data-theme="arcade-neon"] .brand-mark {
  box-shadow: 0 0 18px rgba(54, 225, 208, 0.28);
}

body[data-theme="arcade-neon"] .mode-button.active,
body[data-theme="arcade-neon"] .nav-button.active {
  box-shadow: inset 0 -2px var(--accent), 0 0 14px rgba(54, 225, 208, 0.09);
}

body[data-theme="arcade-neon"] .tag:nth-child(3n + 2) {
  border-color: color-mix(in srgb, #ff4fa3 45%, var(--line));
  color: #ff9dcb;
}

body[data-theme="arcade-neon"] .primary-button {
  border-color: var(--accent);
  background: #143d3e;
  color: var(--accent-strong);
  box-shadow: 0 0 16px rgba(54, 225, 208, 0.16);
}

body[data-theme="mono-deck"] .brand-mark {
  box-shadow: 0 0 0 1px var(--ink);
}

body[data-theme="mono-deck"] .nav-button.active::before {
  width: 5px;
}

body[data-theme="mono-deck"] .mode-button.active,
body[data-theme="mono-deck"] .primary-button {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
}

body[data-theme="mono-deck"] .tag {
  border-color: var(--ink);
  background: #ffffff;
  color: var(--ink);
}
