/* 字讀 TextView — 互動式閱讀體驗區樣式（忠實還原 src/styles.js 與擴充功能實際介面） */

.demo-section {
  padding-top: 0.5rem;
}

.demo-shell {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.browser-chrome {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.72rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chrome-dots {
  display: flex;
  align-items: center;
  gap: 0.42rem;
}

.chrome-dots span {
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 50%;
}
.chrome-dots span:nth-child(1) { background: #ef6f6c; }
.chrome-dots span:nth-child(2) { background: #f2be54; }
.chrome-dots span:nth-child(3) { background: #62c554; }

.chrome-address {
  flex: 1 1 220px;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mode-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  gap: 3px;
}

.mode-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.36rem 0.82rem;
  border-radius: 7px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.mode-switch button[aria-pressed="true"] {
  background: var(--brand-navy);
  color: var(--brand-white);
}

html[data-site-theme="dark"] .mode-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ── Before: Cluttered Webpage Simulation ── */
.cluttered-view {
  background: #f3f4f6;
  color: #1f2937;
  padding: 1rem;
  font-family: system-ui, sans-serif;
}

.cluttered-view[hidden] {
  display: none;
}

.fake-top-ad {
  background: linear-gradient(90deg, #ffedd5, #fef3c7);
  border: 1px dashed #d97706;
  color: #92400e;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.84rem;
  margin-bottom: 0.85rem;
}

.fake-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding: 0.55rem 0.9rem;
  background: #1f2937;
  color: #e5e7eb;
  font-size: 0.78rem;
  border-radius: 6px;
  margin-bottom: 0.9rem;
}

.fake-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 1rem;
  align-items: start;
}

.fake-main {
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 1.15rem 1.25rem;
}

.fake-share-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0.85rem;
}

.fake-chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  background: #e5e7eb;
  color: #4b5563;
}

.fake-main h3 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  line-height: 1.35;
}

.fake-main p {
  font-size: 0.87rem;
  line-height: 1.48;
  color: #374151;
  margin: 0.65rem 0;
}

.fake-inline-ad {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 0.8rem;
  text-align: center;
  margin: 0.8rem 0;
}

.fake-sidebar {
  display: grid;
  gap: 0.75rem;
}

.fake-widget {
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0.8rem;
  font-size: 0.78rem;
  color: #4b5563;
}

.fake-widget strong {
  display: block;
  color: #111827;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
}

.fake-widget ul {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.35rem;
}

.fake-cookie {
  margin-top: 0.85rem;
  background: #111827;
  color: #f9fafb;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.78rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.fake-cta-bar {
  margin-top: 0.9rem;
  text-align: center;
}

/* ── After: Authentic TextView Reader (matches src/styles.js) ── */
.tv-demo {
  --brand-navy: #13243b;
  --brand-mint: #76e2c1;
  --brand-white: #f8fafc;
  --tv-canvas: #edf2f7;
  --tv-surface: var(--brand-white);
  --tv-ink: var(--brand-navy);
  --tv-muted: #4b6178;
  --tv-border: #cbd7e3;
  --tv-hover: #e1f5ee;
  --tv-accent: var(--brand-mint);
  --tv-accent-ink: var(--brand-navy);
  --tv-focus: #206653;
  --rail-width: 53.6px;

  --zh-font: 'Microsoft JhengHei', 'PingFang TC', sans-serif;
  --zh-size: 18px;
  --zh-spacing: 0.02em;
  --zh-height: 32.4px;

  --en-font: Arial, sans-serif;
  --en-size: 17px;
  --en-spacing: 0em;
  --en-height: 28.05px;

  --reader-width: 75ch;

  position: relative;
  display: flex;
  flex-direction: column;
  height: 670px;
  background: var(--tv-canvas);
  color: var(--tv-ink);
  font: 16px/1.5 system-ui, 'Noto Sans TC', sans-serif;
  overflow: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.tv-demo:fullscreen {
  height: 100dvh;
}

.tv-demo[hidden] {
  display: none;
}

.tv-demo[data-theme="sepia"] {
  --tv-canvas: #e7dbc5;
  --tv-surface: #f2e8d5;
  --tv-ink: #342a20;
  --tv-muted: #635342;
  --tv-border: #cbb99a;
  --tv-hover: #eaddc6;
  --tv-accent: #c4e6d7;
  --tv-accent-ink: #1e3d35;
  --tv-focus: #235c50;
}

.tv-demo[data-theme="dark"] {
  color-scheme: dark;
  --tv-canvas: #0d192a;
  --tv-surface: var(--brand-navy);
  --tv-ink: #ecf3fb;
  --tv-muted: #afbed0;
  --tv-border: #37485c;
  --tv-hover: #25394d;
  --tv-accent: var(--brand-mint);
  --tv-accent-ink: var(--brand-navy);
  --tv-focus: var(--brand-mint);
}

.tv-demo[data-toolbar="bottom"] { flex-direction: column-reverse; }
.tv-demo[data-toolbar="left"] { flex-direction: row; }
.tv-demo[data-toolbar="right"] { flex-direction: row-reverse; }

/* ── Toolbar Header ── */
.tv-header {
  position: relative;
  flex: none;
  z-index: 4;
  background: var(--tv-surface);
  border-bottom: 1px solid var(--tv-border);
}

.tv-demo[data-toolbar="bottom"] .tv-header {
  border-bottom: 0;
  border-top: 1px solid var(--tv-border);
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-header {
  width: var(--rail-width);
  overflow: auto;
  scrollbar-width: none;
  border-bottom: 0;
}

.tv-demo[data-toolbar="left"] .tv-header { border-inline-end: 1px solid var(--tv-border); }
.tv-demo[data-toolbar="right"] .tv-header { border-inline-start: 1px solid var(--tv-border); }

.tv-toolbar {
  max-width: 1248px;
  margin: auto;
  padding: 10px clamp(10px, 2vw, 22px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.tv-brand {
  display: inline-flex;
  align-items: center;
  gap: 8.8px;
  margin-right: auto;
  font-size: 16px;
  font-weight: 750;
  white-space: nowrap;
}

.tv-brand-mark {
  display: block;
  width: 29.6px;
  height: 29.6px;
  flex: none;
}

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

.tv-controls,
.tv-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5.6px;
}

.tv-toolbar-section {
  display: contents;
}

.tv-demo button,
.tv-demo summary {
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--tv-ink);
  cursor: pointer;
  padding: 6.4px 10.4px;
  line-height: 1.4;
  font-size: 14px;
  min-height: 35.2px;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.tv-demo button:hover,
.tv-demo summary:hover {
  background: var(--tv-hover);
}

.tv-demo button:focus-visible,
.tv-demo summary:focus-visible,
.tv-demo input:focus-visible,
.tv-demo select:focus-visible {
  outline: 2px solid var(--tv-focus);
  outline-offset: 2px;
}

.tv-demo .tv-toolbar button[aria-pressed="true"] {
  background: var(--tv-hover);
  border-color: var(--tv-border);
}

.tv-rail-icon {
  display: none;
  width: 18.4px;
  height: 18.4px;
  flex: none;
}

.tv-control-chevron {
  width: 13.6px;
  height: 13.6px;
  vertical-align: middle;
  margin-inline-start: 4px;
  transition: transform 0.2s ease;
  flex: none;
}

.tv-export[open] .tv-control-chevron,
.tv-preferences-toggle[aria-expanded="true"] .tv-control-chevron {
  transform: rotate(180deg);
}

/* Line height quick controls */
.tv-line-height-controls {
  display: inline-flex;
  gap: 2.4px;
}

.tv-line-height-controls button {
  display: grid;
  place-items: center;
  width: 34.4px;
  padding: 5.6px;
}

.tv-line-height-controls .tv-rail-icon {
  display: block;
}

.tv-line-height-controls .tv-icon-label {
  display: none;
}

/* Width picker */
.tv-layout-picker {
  display: inline-flex;
  flex: none;
  padding: 2.4px;
  gap: 1.6px;
  border: 1px solid var(--tv-border);
  border-radius: 9.6px;
}

.tv-layout-picker button {
  white-space: nowrap;
  min-height: 30.4px;
  padding: 4px 8px;
}

.tv-layout-picker button[aria-pressed="true"] {
  background: var(--tv-accent) !important;
  color: var(--tv-accent-ink);
  border-color: transparent !important;
  font-weight: 600;
}

/* Theme swatches (matching Screenshot 1) */
.tv-theme-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline: 4px;
}

.tv-theme-picker .tv-theme-swatch {
  flex: none;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 9.6px;
  border: 1px solid var(--tv-muted);
  background: var(--swatch);
}

.tv-theme-swatch[data-demo-theme="light"] { --swatch: #ffffff; }
.tv-theme-swatch[data-demo-theme="sepia"] { --swatch: #f2e8d5; }
.tv-theme-swatch[data-demo-theme="dark"] { --swatch: var(--brand-navy); }

.tv-theme-picker .tv-theme-swatch[aria-pressed="true"] {
  background: var(--swatch);
  border-color: var(--tv-muted);
  outline: 2px solid var(--tv-focus);
  outline-offset: 2px;
}

/* Preferences toggle, capture, export, close */
.tv-demo:is([data-toolbar="top"], [data-toolbar="bottom"]) :is(.tv-actions > button, .tv-actions summary, .tv-preferences-toggle) {
  display: inline-flex;
  align-items: center;
  height: 36px;
  min-height: 0;
  padding-block: 0;
}

.tv-preferences-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.tv-preferences-toggle[aria-expanded="true"] {
  background: var(--tv-hover);
  border-color: var(--tv-border);
}

.tv-capture-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-color: var(--tv-border) !important;
}

.tv-capture-trigger .tv-rail-icon {
  display: block;
}

.tv-close-btn {
  border-color: var(--tv-border) !important;
}

.tv-export {
  position: relative;
}

.tv-export summary {
  list-style: none;
  background: var(--tv-accent);
  color: var(--tv-accent-ink);
  font-weight: 700;
  border-color: var(--tv-accent);
}

.tv-export summary:hover {
  filter: brightness(0.95);
  background: var(--tv-accent);
}

.tv-export summary::-webkit-details-marker {
  display: none;
}

.tv-export-menu {
  position: absolute;
  inset-block-start: calc(100% + 7.2px);
  inset-inline-end: 0;
  display: grid;
  width: min(192px, calc(100vw - 32px));
  padding: 5.6px;
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 10.4px;
  box-shadow: 0 10.4px 25.6px rgba(16, 29, 48, 0.22);
  z-index: 20;
}

.tv-demo[data-toolbar="bottom"] .tv-export-menu {
  inset-block-start: auto;
  inset-block-end: calc(100% + 7.2px);
}

.tv-export-menu button {
  text-align: start;
  min-height: 34px;
  padding: 5px 10px;
}

/* ── Left / Right Vertical Icon Rail Mode ── */
.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) :is(.tv-toolbar, .tv-controls, .tv-actions) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 4px;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-toolbar {
  padding: 8.8px 3.2px;
  gap: 7.2px;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-brand {
  margin: 0;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) :is(.tv-brand-name, .tv-brand-meta, .tv-control-chevron, .tv-icon-label) {
  display: none;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-toolbar-section {
  display: grid;
  justify-items: center;
  gap: 2.4px;
  padding-top: 4.8px;
  border-top: 1px solid var(--tv-border);
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-rail-icon {
  display: block;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) [data-rail-icon] {
  display: grid;
  place-items: center;
  width: 36px;
  height: 32px;
  min-height: 0;
  padding: 0;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) :is(.tv-theme-picker, .tv-layout-picker, .tv-line-height-controls) {
  display: grid;
  justify-items: center;
  padding: 1.6px;
  border: 0;
  gap: 3.2px;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-theme-picker {
  gap: 8.8px;
  padding: 4.8px 2.4px;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-actions {
  border-top: 1px solid var(--tv-border);
  padding-top: 4.8px;
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-actions :is(.tv-close-btn, .tv-capture-trigger, summary) {
  background: transparent;
  border-color: transparent !important;
  color: var(--tv-ink);
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-actions :is(.tv-close-btn, .tv-capture-trigger, summary):hover {
  background: var(--tv-hover);
}

.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-actions .tv-export[open] summary,
.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) .tv-preferences-toggle[aria-expanded="true"],
.tv-demo:is([data-toolbar="left"], [data-toolbar="right"]) #demo-toggle-images[aria-pressed="true"] {
  background: var(--tv-accent);
  color: var(--tv-accent-ink);
}

.tv-demo[data-toolbar="left"] .tv-export-menu {
  inset-block-start: auto;
  inset-block-end: 0;
  inset-inline-start: calc(var(--rail-width) + 7.2px);
  inset-inline-end: auto;
}

.tv-demo[data-toolbar="right"] .tv-export-menu {
  inset-block-start: auto;
  inset-block-end: 0;
  inset-inline-start: auto;
  inset-inline-end: calc(var(--rail-width) + 7.2px);
}

/* ── Reader Article Canvas ── */
.tv-reader-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: clamp(16px, 3.2vw, 36px) clamp(12px, 3vw, 28px);
}

.tv-article-card {
  box-sizing: content-box;
  max-width: var(--reader-width, 75ch);
  margin: 0 auto;
  padding: clamp(18px, 3.8vw, 40px);
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 16px;
  overflow-wrap: anywhere;
  transition: max-width 0.25s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.tv-article-card ::selection {
  background: var(--tv-accent);
  color: var(--tv-accent-ink);
}

.tv-article-card h1 {
  --text-scale: 1.65;
  margin: 0 0 8.8px;
  font-weight: 760;
  line-height: 1.3;
}

.tv-article-card .tv-lead {
  margin: 8.8px 0 12.8px;
  color: var(--tv-muted);
}

.tv-article-card > small {
  display: block;
  color: var(--tv-muted);
  margin-bottom: 24px;
  font-size: 13.5px;
}

.tv-article-card p {
  margin: 0.85em 0;
}

.tv-article-card blockquote {
  margin: 1.4em 0;
  padding: 0.2em 0.9em;
  border-inline-start: 3px solid var(--tv-focus);
  color: var(--tv-ink);
}

.tv-article-card ul {
  margin: 0.9em 0;
  padding-inline-start: 1.4em;
}

.tv-article-card ul ul {
  margin: 0.35em 0;
}

.tv-article-card li {
  margin: 0.35em 0;
}

.tv-article-card .zh,
.tv-article-card .en {
  font-family: var(--font);
  font-size: calc(var(--size) * var(--text-scale, 1));
  letter-spacing: var(--spacing);
}

.tv-article-card .zh {
  --font: var(--zh-font);
  --size: var(--zh-size);
  --spacing: var(--zh-spacing);
}

.tv-article-card .en {
  --font: var(--en-font);
  --size: var(--en-size);
  --spacing: var(--en-spacing);
}

.tv-article-card [data-lang="zh"] { line-height: var(--zh-height); }
.tv-article-card [data-lang="en"] { line-height: var(--en-height); }
.tv-article-card [data-lang="mixed"] { line-height: max(var(--zh-height), var(--en-height)); }
.tv-article-card h1[data-lang] { line-height: 1.3; }

.tv-figure {
  margin: 1.4em 0;
}

.tv-figure[hidden] {
  display: none;
}

.tv-figure-box {
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--tv-canvas);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tv-spec-card {
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  padding: 10px 12px;
}

.tv-spec-card span {
  display: block;
  font-size: 12px;
  color: var(--tv-muted);
}

.tv-spec-card strong {
  font-size: 14.5px;
  color: var(--tv-ink);
}

.tv-figure figcaption {
  --text-scale: 0.84;
  margin: 6px 0 0;
  color: var(--tv-muted);
}

/* ── Floating「排版設定」Panel (matches Screenshots 2 & 3 and src/styles.js) ── */
.tv-preferences-panel {
  position: absolute;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.2s ease, visibility 0.2s;
}

.tv-demo:is([data-toolbar="top"], [data-toolbar="bottom"]) .tv-preferences-panel {
  left: var(--preferences-left, auto);
  right: auto;
  top: var(--preferences-edge, 64px);
  width: min(432px, calc(100% - 24px));
  transform: translateY(-4.8px);
}

.tv-demo[data-toolbar="bottom"] .tv-preferences-panel {
  top: auto;
  bottom: var(--preferences-edge, 64px);
  transform: translateY(4.8px);
}

.tv-demo[data-toolbar="left"] .tv-preferences-panel {
  inset-block: 10px;
  inset-inline-start: calc(var(--rail-width) + 10px);
  width: min(432px, calc(100% - var(--rail-width) - 20px));
  transform: translateX(-6.4px);
}

.tv-demo[data-toolbar="right"] .tv-preferences-panel {
  inset-block: 10px;
  inset-inline-end: calc(var(--rail-width) + 10px);
  width: min(432px, calc(100% - var(--rail-width) - 20px));
  transform: translateX(6.4px);
}

.tv-preferences-panel[data-open] {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: none;
}

.tv-preferences-clip {
  max-height: calc(100% - 8px);
  overflow: auto;
  background: var(--tv-surface);
  border: 1px solid var(--tv-border);
  border-radius: 13.6px;
  box-shadow: 0 10.4px 25.6px rgba(16, 29, 48, 0.22);
}

.tv-demo:is([data-toolbar="top"], [data-toolbar="bottom"]) .tv-preferences-clip {
  max-height: var(--preferences-available, 580px);
}

.tv-preferences-panel-top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--tv-surface);
  border-bottom: 1px solid var(--tv-border);
}

.tv-preferences-panel-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6.4px;
  padding: 10px 13.6px;
  font-weight: 700;
  font-size: 15.5px;
}

.tv-preferences-panel-heading .tv-scope-switch {
  margin-inline-start: auto;
}

.tv-preferences-panel-heading > button {
  min-height: 32px;
  padding: 4px 10px;
}

.tv-segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--tv-border);
  border-radius: 8.8px;
  background: var(--tv-canvas);
}

.tv-segmented button {
  min-height: 28px !important;
  padding: 1.6px 10.4px;
  border: 0 !important;
  border-radius: 6.4px;
  background: transparent;
  font-size: 12.8px !important;
  font-weight: 550;
  color: var(--tv-muted);
}

.tv-segmented button[aria-pressed="true"] {
  background: var(--tv-accent) !important;
  color: var(--tv-accent-ink);
  font-weight: 700;
}

.tv-preferences {
  display: flex;
  flex-direction: column;
  padding: 0 13.6px 8px;
}

.tv-pref-section {
  display: grid;
  gap: 8.8px;
  padding: 12.8px 0;
  border-bottom: 1px solid var(--tv-border);
}

.tv-pref-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tv-pref-title {
  margin: 0;
  font-size: 14.4px;
  font-weight: 700;
}

.tv-pref-block {
  display: grid;
  gap: 8px;
}

.tv-pref-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 9.6px;
}

.tv-pref-label {
  color: var(--tv-muted);
  font-size: 13.12px;
}

.tv-pref-note {
  margin: 0;
  color: var(--tv-muted);
  font-size: 12.48px;
  overflow-wrap: anywhere;
}

.tv-pref-note:empty,
.tv-pref-note[hidden] {
  display: none;
}

.tv-preferences input,
.tv-preferences select {
  box-sizing: border-box;
  border: 1px solid var(--tv-border);
  border-radius: 6.4px;
  background: var(--tv-canvas);
  color: var(--tv-ink);
  padding: 5.5px 8px;
  font: inherit;
  font-size: 13.6px;
}

.tv-preferences select {
  width: 100%;
}

.tv-size-control {
  display: flex;
  align-items: center;
  gap: 5.6px;
  min-width: 0;
}

.tv-size-control button,
.tv-stepper button {
  min-width: 32px;
  min-height: 32px;
  padding: 2.4px 6.4px;
  border-color: var(--tv-border) !important;
  display: inline-grid;
  place-items: center;
}

.tv-size-control button svg,
.tv-stepper button svg {
  width: 16px;
  height: 16px;
}

.tv-size-control input[type="range"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 64px;
  padding: 0;
  border: 0;
  background: none;
  accent-color: var(--brand-mint);
  cursor: pointer;
}

.tv-size-control output {
  min-width: 3.4em;
  text-align: end;
  font-size: 13.6px;
  font-variant-numeric: tabular-nums;
}

.tv-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4.8px;
}

.tv-stepper input {
  width: 4.8em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tv-pref-link {
  min-height: 0 !important;
  padding: 2.4px 3.2px;
  border: 0 !important;
  background: none !important;
  color: var(--tv-focus) !important;
  font-size: 12.8px !important;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  justify-self: end;
}

.tv-pref-primary {
  background: var(--tv-accent) !important;
  color: var(--tv-accent-ink) !important;
  font-weight: 700;
  border-color: transparent !important;
}

.tv-pref-primary:hover:not(:disabled) {
  filter: brightness(0.95);
}

.tv-preferences button:disabled {
  opacity: 0.45;
  cursor: default;
}

.tv-preset-row {
  display: flex;
  align-items: center;
  gap: 7.2px;
}

.tv-preset-row select {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.tv-preset-row button {
  flex: none;
  white-space: nowrap;
}

.tv-preset-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7.2px;
}

.tv-pref-secondary {
  border-color: var(--tv-border) !important;
  background: var(--tv-canvas) !important;
  font-weight: 600;
  white-space: nowrap;
}

.tv-pref-secondary:hover,
.tv-pref-secondary[aria-expanded="true"] {
  background: var(--tv-hover) !important;
}

.tv-preset-save {
  display: flex;
  gap: 7.2px;
}

.tv-preset-save[hidden] {
  display: none;
}

.tv-preset-save input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.tv-preset-save button {
  flex: none;
}

.tv-pref-more {
  display: grid;
  gap: 8.8px;
  padding: 11.2px 0 3.2px;
}

.tv-pref-more summary {
  width: fit-content;
  min-height: 0;
  padding: 2px 4px;
  cursor: pointer;
  font-size: 13.12px;
  color: var(--tv-muted);
  font-weight: 650;
}

.tv-pref-more[open] summary {
  margin-bottom: 4px;
}

/* Status toast (matches src/styles.js .status) */
.tv-toast {
  position: absolute;
  z-index: 15;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(512px, calc(100% - 32px));
  padding: 8.8px 15.2px;
  border-radius: 10.4px;
  background: var(--tv-ink);
  color: var(--tv-surface);
  font-size: 13.6px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 8px 22.4px rgba(16, 29, 48, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tv-toast.visible {
  opacity: 1;
}

/* ── Export Preview Dialog ── */
.export-dialog {
  width: min(680px, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.export-dialog::backdrop {
  background: rgba(13, 25, 42, 0.55);
  backdrop-filter: blur(4px);
}

.export-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.export-dialog-head h3 {
  margin: 0;
  font-size: 1rem;
}

.export-dialog-body {
  padding: 1rem 1.25rem;
}

.export-dialog pre {
  margin: 0;
  padding: 1rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.export-dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

@media (max-width: 960px) {
  .fake-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .tv-demo {
    height: 620px;
  }
  .tv-brand-meta {
    display: none;
  }
  .tv-figure-box {
    grid-template-columns: 1fr;
  }
  .tv-demo:is([data-toolbar="top"], [data-toolbar="bottom"]) .tv-preferences-panel {
    width: calc(100% - 16px);
  }
}
