:root {
  color-scheme: light dark;
  /* page */
  --paper: #f7f5ef;
  --ink: #1c1c1c;
  --ink-dim: #4a4a4a;
  --ink-faint: #b5b0a4;
  /* Liquid Glass chrome: translucent, blurred, with a bright rim */
  --glass: rgba(255, 255, 255, 0.64);
  --glass-strong: rgba(248, 247, 243, 0.8);
  --glass-head: rgba(248, 247, 243, 0.94);
  --glass-rim: rgba(255, 255, 255, 0.85);
  --glass-shadow: 0 10px 30px rgba(30, 28, 22, 0.16), 0 1px 3px rgba(30, 28, 22, 0.08);
  --glass-blur: blur(22px) saturate(180%);
  --chrome: #f2f1ec;
  --border: rgba(0, 0, 0, 0.09);
  --text: #1d1d1f;
  --dim: #6e6e73;
  --accent: #b86e12;
  --accent-soft: rgba(184, 110, 18, 0.12);
  --accent-line: rgba(184, 110, 18, 0.4);
  --on-accent: #fff;
  --chip-bg: rgba(255, 255, 255, 0.55);
  --press: rgba(0, 0, 0, 0.07);
  --warn: #a8640a;
  --danger: #d23b3b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #131418;
    --ink: #e9e6de;
    --ink-dim: #b3afa6;
    --ink-faint: #5d5a54;
    --glass: rgba(40, 44, 54, 0.66);
    --glass-strong: rgba(26, 28, 34, 0.78);
    --glass-head: rgba(26, 28, 34, 0.94);
    --glass-rim: rgba(255, 255, 255, 0.16);
    --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
    --chrome: #16191f;
    --border: rgba(255, 255, 255, 0.1);
    --text: #ece9e2;
    --dim: #9aa0ab;
    --accent: #e0a458;
    --accent-soft: rgba(224, 164, 88, 0.14);
    --accent-line: var(--accent-line);
    --on-accent: #1a1408;
    --chip-bg: rgba(255, 255, 255, 0.08);
    --press: rgba(255, 255, 255, 0.12);
    --warn: #f0b45e;
    --danger: #ff6b6b;
  }
}

/* ---------- chosen themes (Settings → Appearance) ---------- */
:root[data-theme="night"] {
  color-scheme: dark;
  --paper: #131418;
  --ink: #e9e6de;
  --ink-dim: #b3afa6;
  --ink-faint: #5d5a54;
  --glass: rgba(40, 44, 54, 0.66);
  --glass-strong: rgba(26, 28, 34, 0.78);
  --glass-head: rgba(26, 28, 34, 0.94);
  --glass-rim: rgba(255, 255, 255, 0.16);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  --chrome: #16191f;
  --border: rgba(255, 255, 255, 0.1);
  --text: #ece9e2;
  --dim: #9aa0ab;
  --accent: #e0a458;
  --accent-soft: rgba(224, 164, 88, 0.14);
  --accent-line: var(--accent-line);
  --on-accent: #1a1408;
  --chip-bg: rgba(255, 255, 255, 0.08);
  --press: rgba(255, 255, 255, 0.12);
  --warn: #f0b45e;
  --danger: #ff6b6b;
}

:root[data-theme="paper"] { color-scheme: light; }

:root[data-theme="sepia"] {
  color-scheme: light;
  --paper: #f1e7d0;
  --ink: #3b2f22;
  --ink-dim: #6b5a45;
  --ink-faint: #b9a585;
  --glass: rgba(250, 243, 228, 0.64);
  --glass-strong: rgba(244, 235, 214, 0.84);
  --glass-head: rgba(244, 235, 214, 0.95);
  --glass-rim: rgba(255, 255, 255, 0.7);
  --glass-shadow: 0 10px 30px rgba(70, 50, 20, 0.18), 0 1px 3px rgba(70, 50, 20, 0.1);
  --chrome: #efe4cc;
  --border: rgba(59, 47, 34, 0.14);
  --text: #3b2f22;
  --dim: #7a6650;
  --accent: #9a5b1e;
  --accent-soft: rgba(154, 91, 30, 0.12);
  --accent-line: rgba(154, 91, 30, 0.4);
  --on-accent: #fff;
  --chip-bg: rgba(255, 250, 240, 0.55);
  --press: rgba(59, 47, 34, 0.08);
  --warn: #9a5b1e;
  --danger: #b3362f;
}

:root[data-theme="midnight"] {
  color-scheme: dark;
  --paper: #0d1424;
  --ink: #dbe6f5;
  --ink-dim: #9fb1c9;
  --ink-faint: #4a5a75;
  --glass: rgba(28, 40, 66, 0.64);
  --glass-strong: rgba(16, 24, 42, 0.8);
  --glass-head: rgba(16, 24, 42, 0.95);
  --glass-rim: rgba(160, 200, 255, 0.18);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.3);
  --chrome: #0f1729;
  --border: rgba(160, 200, 255, 0.12);
  --text: #e3ecf8;
  --dim: #8a9bb5;
  --accent: #8fd0ff;
  --accent-soft: rgba(143, 208, 255, 0.14);
  --accent-line: rgba(143, 208, 255, 0.45);
  --on-accent: #0a1220;
  --chip-bg: rgba(160, 200, 255, 0.08);
  --press: rgba(160, 200, 255, 0.16);
  --warn: #f3c06b;
  --danger: #ff7b7b;
}

/* High contrast: solid surfaces, black on white, no translucency. */
:root[data-theme="contrast"] {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #000000;
  --ink-dim: #222222;
  --ink-faint: #767676;
  --glass: #ffffff;
  --glass-strong: #ffffff;
  --glass-head: #ffffff;
  --glass-rim: #ffffff;
  --glass-shadow: 0 0 0 1px #000000;
  --glass-blur: none;
  --chrome: #ffffff;
  --border: #000000;
  --text: #000000;
  --dim: #333333;
  --accent: #0040c8;
  --accent-soft: rgba(0, 64, 200, 0.12);
  --accent-line: #0040c8;
  --on-accent: #ffffff;
  --chip-bg: #ffffff;
  --press: rgba(0, 0, 0, 0.12);
  --warn: #8a4b00;
  --danger: #c00000;
}

/* The shared Liquid Glass material: frosted fill, specular top rim,
   soft drop shadow. Applied to the floating bars and chips. */
.glass {
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 var(--glass-rim), inset 0 -1px 0 rgba(255, 255, 255, 0.06), var(--glass-shadow);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  touch-action: manipulation;
}

/* ---------- top bar ---------- */
#topbar {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: calc(env(safe-area-inset-top) + 8px) 10px 0;
  padding: 7px 8px 7px 7px;
  border-radius: 24px;
  color: var(--text);
}

.topbtn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 17px;
  width: 38px;
  height: 34px;
  box-shadow: inset 0 1px 0 var(--glass-rim);
  font-size: 17px;
  line-height: 1;
  padding: 0;
}

.topbtn:active, .chip:active { background: var(--press); transform: scale(0.96); }

.topbtn-count {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--dim);
  white-space: nowrap;
}

.topbtn-count #pageCount { color: var(--text); }

#title {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 0;
}

#title::placeholder { color: var(--dim); }

/* ---------- script page ---------- */
#page {
  min-height: 80vh;
  padding: 18px 5% calc(200px + env(safe-area-inset-bottom));
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 16px;
  line-height: 1.45;
  cursor: text;
}

.el {
  min-height: 1.45em;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 2px 4px;
  border-radius: 4px;
}

.el.active { background: var(--accent-soft); }

.el-scene { text-transform: uppercase; font-weight: 700; margin-top: 1em; }
.el-action { margin-top: 0.6em; }
.el-character { text-transform: uppercase; margin: 1em 0 0 22%; }
.el-dialogue { margin: 0 8% 0 12%; }
.el-paren { margin: 0 20% 0 17%; color: var(--ink-dim); }
.el-transition { text-transform: uppercase; text-align: right; margin-top: 1em; }
.el-marker { text-transform: uppercase; text-align: center; font-weight: 700; text-decoration: underline; margin: 1.4em 0 0.6em; letter-spacing: 0.05em; }

#blockInput {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  font: inherit;
  line-height: inherit;
  color: inherit;
  text-transform: inherit;
  text-align: inherit;
}

#blockInput::placeholder { color: var(--ink-faint); text-transform: none; }

/* ---------- quick bar ---------- */
#quickbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 8px calc(8px + env(safe-area-inset-bottom));
  padding: 6px;
  border-radius: 26px;
  will-change: transform;
}

/* Keyboard up: hug the keyboard instead of clearing the home indicator. */
#quickbar.kb-open { margin-bottom: 6px; }

.qb-row { display: flex; align-items: center; gap: 6px; min-height: 36px; }

.qb-chips {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
  touch-action: pan-x;
  scrollbar-width: none;
}

.qb-chips::-webkit-scrollbar { display: none; }

/* Soften whichever edge has more chips beyond it, instead of a hard cut
   against the fixed buttons. quickbar.js toggles the classes on scroll. */
.qb-chips {
  --fade-start: 0px;
  --fade-end: 0px;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fade-start), #000 calc(100% - var(--fade-end)), transparent);
  mask-image: linear-gradient(to right, transparent, #000 var(--fade-start), #000 calc(100% - var(--fade-end)), transparent);
}
.qb-chips.fade-start { --fade-start: 20px; }
.qb-chips.fade-end { --fade-end: 32px; }

.qb-empty { color: var(--dim); font-size: 13px; padding: 0 8px; align-self: center; white-space: nowrap; }

/* Keyboard can't be detected (e.g. the app is embedded in another page's
   frame): dock the quick bar under the title bar, out of the keyboard's way. */
body.qb-top #quickbar {
  top: calc(env(safe-area-inset-top) + 70px);
  bottom: auto;
  margin-bottom: 0;
  transform: none !important;
}
body.qb-top #page { padding-top: 112px; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 18px;
  padding: 9px 14px;
  box-shadow: inset 0 1px 0 var(--glass-rim);
  transition: transform 0.12s ease, background 0.12s ease;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
}

.chip-char { color: var(--accent); border-color: var(--accent-line); }

/* Autocomplete completion: leading chip that fills in a learned name. */
.chip-suggest {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.chip-tool {
  border-radius: 18px;
  padding: 9px 8px;
  color: var(--dim);
}

.chip-tool:disabled { opacity: 0.32; }

#cycleType { min-width: 0; font-size: 13px; color: var(--text); }

.qb-fixed { display: flex; gap: 4px; }

/* ---------- sheets (settings + scripts + outline + export + profile) ---------- */
#settingsSheet, #scriptsSheet, #outlineSheet, #exportSheet, #profileSheet, #snippetSheet, #reviewSheet {
  position: fixed;
  inset: calc(env(safe-area-inset-top) + 10px) 0 0;
  z-index: 30;
  background: var(--glass-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 24px 24px 0 0;
  box-shadow: inset 0 1px 0 var(--glass-rim), 0 -10px 40px rgba(0, 0, 0, 0.18);
  color: var(--text);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
  padding: 16px 16px 12px;
  background: var(--glass-head);
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 { margin: 0; font-size: 17px; }

.btn-done {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  padding: 4px 2px;
}

.sheet-body { padding: 16px; }

.hint { color: var(--dim); font-size: 14px; margin: 0 0 12px; }

.seg {
  display: flex;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.seg button {
  flex: 1;
  border: none;
  background: none;
  color: var(--dim);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 6px;
  border-radius: 9px;
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

#manualLists section { margin-top: 22px; }

#manualLists h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

#manualLists ul { list-style: none; margin: 0; padding: 0; }

#manualLists li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 15px;
}

#manualLists li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

#manualLists li button {
  border: none;
  background: none;
  color: var(--dim);
  font-size: 16px;
  padding: 4px 8px;
}

#manualLists form { display: flex; gap: 8px; margin-top: 8px; }

#manualLists input {
  flex: 1;
  min-width: 0;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
}

#manualLists form button {
  border: 1px solid var(--accent-line);
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  padding: 0 16px;
}

/* ---------- scripts sheet ---------- */
.btn-primary {
  display: block;
  box-shadow: inset 0 1px 0 var(--glass-rim);
  width: 100%;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px;
  padding: 13px;
  margin-bottom: 16px;
}

.btn-primary:active { background: var(--press); }

.btn-secondary {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}

.btn-secondary:active { background: var(--press); }

/* ---------- export sheet ---------- */
.export-formats { display: flex; flex-direction: column; gap: 10px; }

.export-fmt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
}

.export-fmt b { font-size: 16px; }
.export-fmt span { font-size: 13px; color: var(--dim); line-height: 1.4; }
.export-fmt:active { background: var(--press); }
.export-fmt:disabled { opacity: 0.45; }

.script-list { list-style: none; margin: 0; padding: 0; }

.script-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
}

.script-row.current { border-color: var(--accent-line); }

.script-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
}

.script-title {
  font-size: 16px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.script-actions { display: flex; align-items: center; padding-right: 6px; gap: 2px; }

.script-act {
  border: none;
  background: none;
  color: var(--dim);
  font-size: 15px;
  padding: 8px 8px;
  border-radius: 8px;
}

.script-act.armed { color: var(--danger); font-weight: 700; font-size: 13px; }

.script-rename {
  flex: 1;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  align-items: center;
}

.script-rename input {
  flex: 1;
  min-width: 0;
  background: var(--chrome);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  padding: 8px 10px;
  outline: none;
}

.script-rename button {
  border: 1px solid var(--accent-line);
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
  padding: 0 14px;
}

/* ---------- outline sheet ---------- */
.outline-stats {
  color: var(--dim);
  font-size: 13px;
  margin: 0 0 14px;
  letter-spacing: 0.02em;
}

.scene-list { margin: 0; padding: 0; counter-reset: scene; list-style: none; }

.scene-list li { margin-bottom: 8px; }

.scene-jump {
  counter-increment: scene;
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 15px;
  text-transform: uppercase;
}

.scene-jump::before {
  content: counter(scene);
  flex: 0 0 auto;
  color: var(--accent);
  font-weight: 700;
  min-width: 1.4em;
}

.scene-jump:active { background: var(--press); }

.scene-empty { color: var(--dim); font-size: 14px; }

.act-list { list-style: none; margin: 0 0 4px; padding: 0; }

.act-row {
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 13px;
  color: var(--text);
  padding: 7px 12px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 5px;
}

.act-row.act-total { font-weight: 700; }
.act-row.warn { color: var(--warn); border-color: var(--warn); }

/* ---------- character profile (Personae Dramatis) ---------- */
.profile-name {
  margin: 0;
  font-size: 17px;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  text-transform: uppercase;
  color: var(--accent);
}

.profile-stats {
  color: var(--dim);
  font-size: 13px;
  margin: 0 0 16px;
}

.profile-field {
  display: block;
  margin-bottom: 12px;
}

.profile-field > span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 5px;
}

.profile-field input,
.profile-field textarea {
  width: 100%;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
  resize: vertical;
}

.profile-field textarea { min-height: 60px; line-height: 1.4; }

.profile-sub {
  margin: 22px 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.appearance-list { list-style: none; margin: 0; padding: 0; }

.appearance-list li { margin-bottom: 8px; }

.appearance-jump {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 11px 13px;
}

.appearance-scene {
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--accent);
}

.appearance-line {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appearance-jump:active { background: var(--press); }

/* ---------- import & backup ---------- */
.btn-row { display: flex; gap: 8px; }
.btn-row .btn-secondary { flex: 1; margin-bottom: 10px; padding: 12px 6px; font-size: 14px; }

/* ---------- scene snippet ---------- */
.scene-row { display: flex; gap: 8px; align-items: stretch; }
.scene-row .scene-jump { flex: 1; min-width: 0; }

.scene-share {
  flex: 0 0 auto;
  width: 46px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--accent);
  border-radius: 10px;
  font-size: 18px;
}

.scene-share:active { background: var(--press); }

.snip-controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.snip-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.snip-preview canvas {
  max-width: 100%;
  max-height: 56vh;
  height: auto;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--glass-shadow);
}

.snip-count { font-style: normal; font-weight: 500; letter-spacing: 0; text-transform: none; margin-left: 6px; }

a.btn-secondary { text-align: center; text-decoration: none; }

/* ---------- settings: appearance ---------- */
.set-section { margin-bottom: 26px; }
.set-section > h3 { margin-top: 0; }

.theme-grid, .icon-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.theme-opt, .icon-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 6px;
  font-size: 13px;
  font-weight: 600;
}

.theme-opt[aria-pressed="true"], .icon-opt[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-line);
}

.theme-swatch {
  width: 44px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.theme-swatch i {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.icon-opt img { width: 52px; height: 52px; border-radius: 12px; }

.install-card {
  border: 1px solid var(--border);
  background: var(--chip-bg);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.45;
}

.install-card ol { margin: 6px 0 0; padding-left: 20px; }

/* ---------- review comments ---------- */
.topbtn-review { position: relative; display: grid; place-items: center; }

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

/* Margin marker on a line with open comments (tap to open its thread).
   Positioned against #page with no top offset, so it keeps its static
   vertical position — level with the first row of its line — while every
   marker lines up in the right-hand gutter whatever the line's indent. */
#page { position: relative; }

.note-pin {
  position: absolute;
  right: 1px;
  margin-top: 0.15em;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px 9px 9px 2px;
  background: var(--accent);
  color: var(--on-accent);
  font: 800 11px/18px -apple-system, system-ui, sans-serif;
  text-align: center;
  text-transform: none;
  text-decoration: none;
  letter-spacing: 0;
  cursor: pointer;
}

.rv-compose {
  border: 1px solid var(--border);
  background: var(--chip-bg);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 16px;
}

.rv-on { margin: 0 0 8px; font-size: 13px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-on span { color: var(--text); font-family: 'Courier Prime', 'Courier New', Courier, monospace; }

.rv-compose textarea, .rv-replyform input {
  width: 100%;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
  resize: vertical;
}

.rv-compose .btn-primary { margin: 10px 0 0; padding: 11px; }

.rv-focus { margin-top: 12px; }
.rv-link { border: none; background: none; color: var(--accent); font: inherit; font-weight: 700; padding: 0; }

.rv-list { list-style: none; margin: 14px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.rv-thread {
  border: 1px solid var(--border);
  background: var(--chip-bg);
  border-radius: 14px;
  padding: 10px 12px;
}

.rv-thread.resolved { opacity: 0.62; }

.rv-quote {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 4px 8px 8px 4px;
  padding: 6px 9px;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rv-entry { margin-top: 8px; }
.rv-reply { margin-left: 14px; padding-left: 10px; border-left: 2px solid var(--border); }
.rv-meta { font-size: 12px; color: var(--dim); }
.rv-meta b { color: var(--text); }
.rv-text { margin: 2px 0 0; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }

.rv-actions { display: flex; gap: 4px; margin-top: 8px; }
.rv-act { border: none; background: none; color: var(--accent); font-size: 14px; font-weight: 700; padding: 6px 8px; border-radius: 8px; }
.rv-act:active { background: var(--press); }
.rv-del { color: var(--dim); margin-left: auto; }
.rv-del.armed { color: var(--danger); }

.rv-replyform { display: flex; gap: 8px; margin-top: 8px; }
.rv-replyform button {
  border: 1px solid var(--accent-line);
  background: none;
  color: var(--accent);
  font-weight: 700;
  border-radius: 10px;
  padding: 0 14px;
}

/* ---------- web / desktop ---------- */

/* Wide windows: the script sits on a page about as wide as a printed one
   (60 columns of Courier plus margins) instead of stretching edge to edge,
   with the bars matched to it and sheets as centred panels. */
@media (min-width: 760px) {
  :root { --col: 780px; }

  #topbar {
    max-width: var(--col);
    margin-left: auto;
    margin-right: auto;
  }

  #page {
    max-width: var(--col);
    min-height: calc(100vh - 230px);
    margin: 20px auto 150px;
    padding: 32px 64px 96px;
    background: var(--chip-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--glass-shadow);
  }

  #quickbar {
    width: min(var(--col), calc(100% - 16px));
    margin-left: auto;
    margin-right: auto;
  }

  #settingsSheet, #scriptsSheet, #outlineSheet, #exportSheet, #profileSheet, #snippetSheet, #reviewSheet {
    inset: 6vh 0 auto;
    width: min(620px, calc(100% - 32px));
    max-height: 88vh;
    margin: 0 auto;
    border-radius: 24px;
    padding-bottom: 16px;
    /* The last shadow is a spread-only scrim that dims the page behind. */
    box-shadow: inset 0 1px 0 var(--glass-rim), 0 24px 80px rgba(0, 0, 0, 0.28), 0 0 0 100vmax rgba(0, 0, 0, 0.22);
  }
}

/* Mouse and trackpad: hover feedback and pointer cursors. The overlay
   shadow darkens whatever background a control already has. */
@media (hover: hover) and (pointer: fine) {
  button:not(:disabled), .script-row, .export-fmt { cursor: pointer; }
  .chip:not(:disabled):hover,
  .topbtn:hover,
  .btn-secondary:hover,
  .btn-primary:hover,
  .export-fmt:hover {
    box-shadow: inset 0 0 0 100vmax var(--press);
  }
  .btn-done:hover { opacity: 0.75; }
  .el:not(.active):hover { background: var(--press); }
}
