/* =============================================================
   Fullscreen Text Display — style.css
   Mobile-first. CSS variables for theming. Flexbox + Grid layout.
   ============================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* Palette (light default) */
  --bg:            #fafafa;
  --bg-elev:       #ffffff;
  --bg-elev-2:     #f2f2f5;
  --fg:            #111114;
  --fg-muted:      #55555d;
  --border:        #e3e3e8;
  --accent:        #4f46e5;
  --accent-fg:     #ffffff;
  --danger:        #dc2626;
  --shadow:        0 6px 24px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --radius:        12px;
  --radius-sm:     8px;

  /* Display palette — mirrors app palette by default */
  --display-bg:    var(--bg);
  --display-fg:    var(--fg);

  /* Typography */
  --ff-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ff-sans:   "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ff-serif:  Georgia, "Times New Roman", Times, serif;
  --ff-mono:   ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ff-rounded: "SF Pro Rounded", "Nunito", "Quicksand", system-ui, sans-serif;
  --ff-display: "Impact", "Oswald", "Bebas Neue", Arial Black, sans-serif;

  /* Motion */
  --dur-fast: 120ms;
  --dur-med:  220ms;
  --ease:     cubic-bezier(.2,.7,.2,1);
}

/* Dark theme */
[data-theme="dark"] {
  --bg:        #0b0b0f;
  --bg-elev:   #14141b;
  --bg-elev-2: #1c1c26;
  --fg:        #f2f2f5;
  --fg-muted:  #a0a0ad;
  --border:    #262633;
  --accent:    #818cf8;
  --accent-fg: #0b0b0f;
  --shadow:    0 10px 40px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --display-bg: var(--bg);
  --display-fg: var(--fg);
}

/* Color themes — modify display surface only, so the editor stays neutral */
[data-color="mono"]    { --display-bg:#000000; --display-fg:#ffffff; }
[data-color="paper"]   { --display-bg:#faf7f0; --display-fg:#111114; }
[data-color="amber"]   { --display-bg:#0d0700; --display-fg:#ffb648; }
[data-color="matrix"]  { --display-bg:#02120a; --display-fg:#39ff8b; }
[data-color="ocean"]   { --display-bg:#031628; --display-fg:#7bdcff; }
[data-color="sunset"]  { --display-bg:#2a0a1e; --display-fg:#ffd166; }
[data-color="rose"]    { --display-bg:#1a0410; --display-fg:#ff86b3; }
[data-color="highviz"] { --display-bg:#ffd000; --display-fg:#000000; }

/* High-contrast preference / toggle */
[data-contrast="high"] {
  --display-bg: #000000;
  --display-fg: #ffffff;
  --fg: #ffffff;
  --bg: #000000;
  --bg-elev: #000000;
  --border: #ffffff;
  --accent: #ffff00;
  --accent-fg: #000000;
}
@media (prefers-contrast: more) {
  :root { --border: #000; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ff-system);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select, button { font-family: inherit; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--accent); color: var(--accent-fg);
  padding: 8px 12px; border-radius: var(--radius-sm);
  z-index: 100; text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* ---------- Layout ---------- */
.editor-view {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 96px;
  display: grid;
  gap: 20px;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  background: var(--accent); color: var(--accent-fg);
  border-radius: 10px; font-weight: 800;
}
.brand__title { margin: 0; font-size: 1.1rem; letter-spacing: -.01em; }
.app-header__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.app-footer {
  color: var(--fg-muted);
  font-size: .85rem;
  text-align: center;
  padding-top: 12px;
}
kbd {
  display: inline-block;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0 6px;
  background: var(--bg-elev);
  font-family: var(--ff-mono);
  font-size: .8em;
}

/* ---------- Editor block ---------- */
.editor {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid; gap: 12px;
}
.editor__head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.editor__label { font-weight: 600; }
.editor__meta { color: var(--fg-muted); font-size: .9rem; }
.editor__sep { margin: 0 4px; }
.editor__textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  padding: 14px 16px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 1rem;
  line-height: 1.55;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.editor__textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent);
}
.editor__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  --_bg: var(--bg-elev-2);
  --_fg: var(--fg);
  --_bd: var(--border);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--_bg);
  color: var(--_fg);
  border: 1px solid var(--_bd);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: transform var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.btn:hover  { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: 3px solid color-mix(in oklab, var(--accent) 50%, transparent);
  outline-offset: 2px;
}
.btn--primary { --_bg: var(--accent); --_fg: var(--accent-fg); --_bd: var(--accent); }
.btn--ghost   { --_bg: transparent; }
.btn--small   { padding: 6px 10px; font-size: .9rem; }
.btn__icon    { font-size: 1.05em; line-height: 1; }

/* ---------- Panel ---------- */
.panel {
  display: grid; gap: 12px;
}
.panel__group {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel__summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}
.panel__summary::-webkit-details-marker { display: none; }
.panel__summary::after {
  content: "▸";
  transition: transform var(--dur-fast) var(--ease);
  color: var(--fg-muted);
}
.panel__group[open] .panel__summary::after { transform: rotate(90deg); }
.panel__body {
  padding: 4px 16px 16px;
  display: grid; gap: 14px;
}

/* ---------- Fields ---------- */
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: .95rem; display: flex; justify-content: space-between; }
.field__val { color: var(--fg-muted); font-weight: 500; }
.field__help { color: var(--fg-muted); }
.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent);
}
input[type="range"] {
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elev);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elev);
  cursor: pointer;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .input { flex: 1 1 200px; min-width: 0; }

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-flex;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.segmented__btn {
  padding: 6px 12px;
  background: transparent; color: var(--fg);
  border: 0; border-radius: 6px;
  font-weight: 600;
}
.segmented__btn.is-active { background: var(--accent); color: var(--accent-fg); }

/* ---------- Switch ---------- */
.switch {
  display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none;
}
.switch--inline { margin-left: auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__ui {
  width: 40px; height: 22px; border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background var(--dur-fast) var(--ease);
}
.switch__ui::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--fg);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.switch input:checked + .switch__ui { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__ui::after { transform: translateX(18px); background: var(--accent-fg); }
.switch input:focus-visible + .switch__ui {
  outline: 3px solid color-mix(in oklab, var(--accent) 50%, transparent);
  outline-offset: 2px;
}

/* ---------- Share ---------- */
.share { display: grid; gap: 8px; margin-top: 8px; }
.share__actions { display: flex; gap: 8px; }
.qr {
  padding: 12px; background: #fff; border-radius: var(--radius-sm);
  display: grid; place-items: center;
}

/* ---------- Recent list ---------- */
.recent { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.recent__item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.recent__preview {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--fg);
}
.recent__time { color: var(--fg-muted); font-size: .85rem; }
.recent__del {
  background: transparent; border: 0; color: var(--fg-muted);
  padding: 4px 6px; border-radius: 6px;
}
.recent__del:hover { color: var(--danger); }

/* ---------- Display (fullscreen) ---------- */
.display {
  position: fixed; inset: 0;
  background: var(--display-bg);
  color: var(--display-fg);
  display: grid; place-items: center;
  overflow: hidden;
  z-index: 50;
}
.display[hidden] { display: none; }

.display__content {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  padding: 4vmin;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-align: center;
  font-family: var(--ff-system);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
  transition: opacity var(--dur-med) var(--ease);
  will-change: font-size, transform;
}
.display--bold    .display__content { font-weight: 900; }
.display--upper   .display__content { text-transform: uppercase; }
.display--outline .display__content {
  text-shadow:
    0 0 2px rgba(0,0,0,.85),
    0 3px 12px rgba(0,0,0,.45),
    0 0 24px rgba(0,0,0,.35);
}
.display--mirror  .display__content { transform: scaleX(-1); }

/* Font families for the display */
.display[data-ff="system"]  .display__content { font-family: var(--ff-system); }
.display[data-ff="sans"]    .display__content { font-family: var(--ff-sans); }
.display[data-ff="serif"]   .display__content { font-family: var(--ff-serif); }
.display[data-ff="mono"]    .display__content { font-family: var(--ff-mono); }
.display[data-ff="rounded"] .display__content { font-family: var(--ff-rounded); }
.display[data-ff="display"] .display__content { font-family: var(--ff-display); }

.display__toolbar {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center;
  padding: 6px;
  background: color-mix(in oklab, var(--display-bg) 70%, transparent);
  color: var(--display-fg);
  border: 1px solid color-mix(in oklab, var(--display-fg) 30%, transparent);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity var(--dur-med) var(--ease), transform var(--dur-med) var(--ease);
  z-index: 51;
}
.display__toolbar .btn {
  --_bg: transparent;
  --_fg: var(--display-fg);
  --_bd: color-mix(in oklab, var(--display-fg) 30%, transparent);
}
.display--controls-hidden .display__toolbar {
  opacity: 0;
  transform: translate(-50%, 20px);
  pointer-events: none;
}
.display__timer {
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* Auto-scroll animation surface */
.display--autoscroll .display__content { align-items: flex-start; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 10px 16px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease), transform var(--dur-med) var(--ease);
  z-index: 100;
  font-weight: 600;
}
.toast.is-shown {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive breakpoints ---------- */
@media (min-width: 720px) {
  .editor-view { padding: 32px 24px 96px; gap: 24px; }
  .panel { grid-template-columns: 1fr 1fr; }
  .panel__group:first-child { grid-column: 1 / -1; }
  .editor__textarea { min-height: 220px; font-size: 1.05rem; }
}
@media (min-width: 1024px) {
  .editor-view { padding: 40px 32px 120px; }
  .panel { grid-template-columns: repeat(3, 1fr); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .editor-view { padding: 12px 12px 60px; gap: 12px; }
  .editor__textarea { min-height: 120px; }
}

/* ---------- Print mode ---------- */
@media print {
  body { background: #fff; color: #000; }
  .app-header, .editor__actions, .panel, .app-footer, .display__toolbar, .toast { display: none !important; }
  .editor { border: 0; box-shadow: none; padding: 0; }
  .editor__textarea {
    border: 0; background: transparent; color: #000;
    font-size: 2rem; line-height: 1.4; min-height: auto;
    white-space: pre-wrap;
  }
}

/* ---------- Native fullscreen fallback styling ---------- */
:fullscreen .display,
:fullscreen #display-view { background: var(--display-bg); }
.display:fullscreen { width: 100vw; height: 100vh; }
