/* ==========================================================================
   LumiNote — Production Design System (Mobile-First, Scaled & Hardened)
   RodeX Precision x Neo-Mirai Wabi-Sabi x Ancient Sanskrit Acoustics
   ========================================================================== */

:root {
  --font-display: "Chakra Petch", sans-serif;
  --font-sanskrit: "Yatra One", serif;
  --font-body: "Martel", serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  /* Spectral Shared Accents */
  --gold: #d9b64a;
  --gold-deep: #b8952f;
  --amber: #d9a441;
  --red: #e8452c;
  --emerald: #10b981;
}

/* ==========================================================================
   🌙 DARK MODE: "RodeX Obsidian & Brushed Brass"
   ========================================================================== */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg-base: #07090c;
  --bg-ambient: 
    radial-gradient(1000px 500px at 75% -10%, rgba(217, 182, 74, 0.12) 0%, transparent 60%),
    radial-gradient(800px 400px at 15% 95%, rgba(232, 69, 44, 0.06) 0%, transparent 55%),
    repeating-linear-gradient(0deg, transparent 0 24px, rgba(255, 255, 255, 0.015) 24px 25px),
    repeating-linear-gradient(90deg, transparent 0 24px, rgba(255, 255, 255, 0.015) 24px 25px);
  
  --panel-chassis: #0f1217;
  --panel-inner: #080a0e;
  --panel-border: #1f242d;
  --dashed-line: rgba(217, 182, 74, 0.25);

  --ink-primary: #f5f2e9;
  --ink-dim: #8e9588;
  --ink-muted: #565d50;

  --card-shadow: 0 15px 35px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --btn-bg: #15181f;
  --btn-border: #282e38;
  --btn-hover: #1e222a;
  --btn-shadow: 0 2px 8px rgba(0,0,0,0.4);

  --live-ink-bg: rgba(232, 69, 44, 0.16);
  --live-ink-color: #fca5a5;
  --live-ink-border: #e8452c;

  --yantra-opacity: 0.04;
}

/* ==========================================================================
   ☀️ LIGHT MODE: "Wabi-Sabi Silk & Red Lacquer Seal"
   ========================================================================== */
html[data-theme="light"] {
  color-scheme: light;
  --bg-base: #f4efe6;
  --bg-ambient: 
    radial-gradient(circle at 75% 10%, rgba(212, 160, 55, 0.16), transparent 22rem),
    repeating-linear-gradient(0deg, transparent 0 24px, rgba(43, 38, 33, 0.025) 24px 25px),
    repeating-linear-gradient(90deg, transparent 0 24px, rgba(43, 38, 33, 0.025) 24px 25px);

  --panel-chassis: #fbf9f4;
  --panel-inner: #ffffff;
  --panel-border: #2b2621;
  --dashed-line: rgba(43, 38, 33, 0.25);

  --ink-primary: #1c1814;
  --ink-dim: #5c5348;
  --ink-muted: #8c8172;

  --card-shadow: 4px 4px 0px #2b2621;
  --btn-bg: #fdfbf7;
  --btn-border: #2b2621;
  --btn-hover: #eae3d6;
  --btn-shadow: 2px 2px 0px #2b2621;

  --live-ink-bg: rgba(185, 28, 28, 0.1);
  --live-ink-color: #991b1b;
  --live-ink-border: #b91c1c;

  --yantra-opacity: 0.07;
}

/* Reset & Ergonomic Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-base);
  background-image: var(--bg-ambient);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}

.noscript-banner {
  background: var(--red);
  color: #ffffff;
  padding: 0.6rem 1rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
}

/* Dynamic Full-Bleed Container: adapts smoothly to 100% of any screen width and height */
.container {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: clamp(0.5rem, 1.5vw, 1.25rem) clamp(0.75rem, 2.5vw, 2.5rem);
  padding-top: max(clamp(0.5rem, 1.5vw, 1.25rem), env(safe-area-inset-top));
  padding-bottom: max(clamp(0.5rem, 1.5vw, 1.25rem), env(safe-area-inset-bottom));
  padding-left: max(clamp(0.75rem, 2.5vw, 2.5rem), env(safe-area-inset-left));
  padding-right: max(clamp(0.75rem, 2.5vw, 2.5rem), env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  position: relative;
  gap: 0.65rem;
}

/* Sacred Devanagari & Telemetry Side Pillar (Desktop only) */
.sacred-telemetry-pillar {
  position: absolute;
  left: max(0.5rem, env(safe-area-inset-left));
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  color: var(--ink-dim);
  pointer-events: none;
  user-select: none;
  z-index: 10;
  padding: 1.5rem 0;
}

.pillar-top-line {
  flex: 1;
  width: 1px;
  background: repeating-linear-gradient(0deg, var(--panel-border) 0 4px, transparent 4px 8px);
  margin-bottom: 0.5rem;
}

.pillar-bottom-line {
  flex: 1;
  width: 1px;
  background: repeating-linear-gradient(0deg, var(--panel-border) 0 4px, transparent 4px 8px);
  margin-top: 0.5rem;
}

.yantra-hanko-box {
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sanskrit);
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 4px;
  background: var(--panel-inner);
  flex-shrink: 0;
}
.pillar-sanskrit-text {
  font-family: var(--font-sanskrit);
  font-size: 0.95rem;
  writing-mode: vertical-rl;
  letter-spacing: 0.3em;
  color: var(--gold);
  flex-shrink: 0;
}
.pillar-year {
  font-size: 7.5px;
  letter-spacing: 0.12em;
  flex-shrink: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

/* ==========================================================================
   Top Chassis Header
   ========================================================================== */

.chassis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--panel-chassis);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  margin-left: 1.5rem;
  flex-shrink: 0;
  position: relative;
}

.packet-seal {
  position: absolute;
  top: 0;
  right: 0;
  background: linear-gradient(150deg, var(--gold), var(--gold-deep));
  color: #1a1508;
  font-family: var(--font-mono);
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 0.15em;
  padding: 2px 10px 3px;
  border-bottom-left-radius: 6px;
  text-transform: uppercase;
}

.brand-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo-img {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 2px 6px rgba(217, 182, 74, 0.25));
}

.brand-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-primary);
}
.brand-name em {
  font-style: normal;
  color: var(--gold);
}

.fuse-badge {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.12em;
  color: var(--amber);
  border: 1px solid rgba(217, 164, 65, 0.35);
  background: rgba(217, 164, 65, 0.08);
  border-radius: 3px;
  padding: 1px 6px;
}

.header-instruments {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Engine Selector Dropdown */
.engine-switcher-wrap {
  position: relative;
}
.engine-trigger-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 5px;
  padding: 0.35rem 0.75rem;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: all 0.15s ease;
}
.engine-trigger-btn:hover {
  border-color: var(--gold);
}
.engine-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 6px var(--emerald);
}

.chevron-icon {
  color: var(--ink-dim);
  transition: transform 0.2s ease;
}
.engine-switcher-wrap.open .chevron-icon {
  transform: rotate(180deg);
}

.engine-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 290px;
  background: var(--panel-chassis);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all 0.2s var(--ease);
}
.engine-switcher-wrap.open .engine-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.engine-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.engine-opt:hover {
  background: rgba(217, 182, 74, 0.1);
}
.engine-opt.active {
  background: rgba(217, 182, 74, 0.15);
  border: 1px solid var(--gold);
}
.opt-text-group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.opt-title {
  font-size: 0.725rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--ink-primary);
  text-transform: uppercase;
}
.opt-sub {
  font-size: 0.625rem;
  color: var(--ink-dim);
}
.check-mark {
  color: var(--gold);
  font-weight: 800;
  font-size: 0.8rem;
  opacity: 0;
}
.engine-opt.active .check-mark {
  opacity: 1;
}

/* Dual Mode Switch Button */
.mode-switch-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.35rem 0.75rem;
  border-radius: 5px;
  box-shadow: var(--btn-shadow);
  cursor: pointer;
  transition: all 0.15s ease;
}

/* Live link session: emerald icon + dot keep the pairing visible with the
   modal closed, so the session never feels "invisible" (see UX research). */
.mode-switch-btn.link-active {
  border-color: var(--emerald);
}
.mode-switch-btn.link-active .theme-icon-slot {
  color: var(--emerald);
}
.mode-switch-btn.link-active::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 6px var(--emerald);
}

/* Waiting = room open but no peer yet: amber state, never reads as linked. */
.mode-switch-btn.link-waiting {
  border-color: var(--amber);
}
.mode-switch-btn.link-waiting .theme-icon-slot {
  color: var(--amber);
}
.mode-switch-btn.link-waiting::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  animation: link-waiting-pulse 1.6s ease-in-out infinite;
}

@keyframes link-waiting-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 5px var(--amber); }
  50% { opacity: 0.35; box-shadow: 0 0 1px var(--amber); }
}

/* The Link button carries a state label (Link / Waiting / Linked). */
.link-toggle .link-btn-label {
  white-space: nowrap;
}

.theme-icon-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
}
.theme-svg-icon {
  display: block;
}
.mode-switch-btn:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

/* Status Stamp */
.status-stamp {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.15em;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid;
  color: var(--amber);
  border-color: rgba(217, 164, 65, 0.55);
  background: rgba(217, 164, 65, 0.08);
  font-weight: 700;
  text-transform: uppercase;
}
.status-stamp.recording {
  color: var(--red);
  border-color: var(--red);
  background: rgba(232, 69, 44, 0.1);
  animation: pulse-stamp 1.5s infinite;
}
@keyframes pulse-stamp {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* ==========================================================================
   Central Fusion Transcription Workspace
   ========================================================================== */

.fusion-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-left: 1.5rem;
  background: var(--panel-chassis);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
  padding: 0.75rem 1rem;
  position: relative;
  overflow: hidden;
}

/* Background Animated Audio Wave Grid Layer */
.workspace-wave-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.25;
  z-index: 1;
}

/* Sacred Vedic Watermark */
.fusion-workspace::before {
  content: 'ॐ';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-sanskrit);
  font-size: 20rem;
  color: var(--gold);
  opacity: var(--yantra-opacity);
  pointer-events: none;
  user-select: none;
  z-index: 2;
}

.workspace-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--dashed-line);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
  z-index: 5;
}

.telemetry-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

/* Live Web Audio FFT Oscilloscope Canvas (buffer is 2x for retina) */
.fft-oscilloscope {
  display: block;
  width: 140px;
  height: 24px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 3px;
  border: 1px solid var(--panel-border);
}

.live-stream-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--gold);
  font-weight: 700;
}
.badge-bindu-pulse {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
}

/* Live Output Transcription Canvas */
.transcription-output {
  flex: 1;
  margin: 0.5rem 0;
  background: var(--panel-inner);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 1.25rem 1.75rem;
  font-family: var(--font-body);
  font-size: clamp(1.15rem, 1.6vw, 1.35rem);
  line-height: 1.75;
  color: var(--ink-primary);
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
  z-index: 5;
}
.transcription-output:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-dim);
  font-style: italic;
}

/* Live Spoken Turn Inscription */
.live-turn {
  color: var(--live-ink-color);
  background: var(--live-ink-bg);
  border-bottom: 2px solid var(--live-ink-border);
  padding: 0.05rem 0.25rem;
  border-radius: 2px;
  font-style: italic;
  font-weight: 600;
  display: inline-block;
  will-change: opacity, filter;
  animation: ink-flow 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes ink-flow {
  0% { opacity: 0.4; filter: blur(1px); }
  100% { opacity: 1; filter: blur(0); }
}

.workspace-bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--dashed-line);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
  z-index: 5;
}

.dot-sep {
  margin: 0 0.35rem;
}

.cell-tag {
  font-size: 7.5px;
  color: rgba(138, 145, 132, 0.6);
  letter-spacing: 0.15em;
}

.hotkey-hint kbd {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
}

/* ==========================================================================
   Bottom Controls Deck
   ========================================================================== */

.controls-deck {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-left: 1.5rem;
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  gap: 0.45rem;
}
.tool-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.7rem;  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  border-radius: 5px;
  box-shadow: var(--btn-shadow);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tool-btn:hover:not(:disabled) {
  background: var(--btn-hover);
  border-color: var(--gold);
  transform: translateY(-1px);
}
.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.grammar-btn:hover:not(:disabled) {
  color: var(--gold);
  border-color: var(--gold);
}
.grammar-btn.loading svg {
  animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Master Transmit Key */
.master-transmit-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: linear-gradient(135deg, #f5d77f 0%, var(--gold) 45%, var(--gold-deep) 100%);
  border: 1px solid var(--gold);
  color: #121008;
  font-family: var(--font-mono);
  font-size: 0.825rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.65rem 1.85rem;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(217, 182, 74, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: all 0.2s var(--ease);
}
.master-transmit-btn:hover:not(:disabled) {  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 8px 25px rgba(217, 182, 74, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.master-transmit-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(217, 182, 74, 0.3);
}
.master-transmit-btn.recording {
  background: linear-gradient(135deg, #f87171 0%, var(--red) 50%, #991b1b 100%) !important;
  border-color: var(--red);
  color: #ffffff;
  box-shadow: 0 0 25px rgba(232, 69, 44, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: pulse-rec 1.5s infinite;
}
@keyframes pulse-rec {
  0% { box-shadow: 0 0 0 0 rgba(232, 69, 44, 0.7); }
  70% { box-shadow: 0 0 0 14px rgba(232, 69, 44, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 69, 44, 0); }
}

.tally-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #121008;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
}
.master-transmit-btn.recording .tally-dot {
  background: #ffffff;
  box-shadow: 0 0 8px #ffffff;
}

/* The LINKED device is dictating elsewhere: amber, clearly not a local mic. */
.master-transmit-btn.peer-talking {
  background: var(--panel-chassis) !important;
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 14px rgba(217, 164, 65, 0.25);
}
.master-transmit-btn.peer-talking .tally-dot {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: peer-live 1.2s ease-in-out infinite;
}
@keyframes peer-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Output-mode select for Polish AI — visually part of the tool family. */
.tool-select {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.45rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}
.tool-select:focus-visible {
  outline: 1px solid var(--gold, #d9b64a);
}

/* Custom Scrollbar Inside Editor */
.transcription-output::-webkit-scrollbar {
  width: 6px;
}
.transcription-output::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}
.transcription-output::-webkit-scrollbar-thumb {
  background: var(--gold);
  border-radius: 4px;
  opacity: 0.7;
}
.transcription-output::-webkit-scrollbar-thumb:hover {
  background: var(--amber);
}

/* Mid-Rail Toast Notification (Clean, Non-Overlapping) */
.copy-toast {
  position: static;
  background: var(--btn-bg);
  border: 1px solid var(--gold);
  color: var(--ink-primary);
  padding: 0.25rem 0.85rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: all 0.2s var(--ease);
}
.copy-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.toast-indicator-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  display: inline-block;
}

/* App Footer */
.app-footer {
  text-align: center;
  padding-top: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ink-dim);
  border-top: 1px solid var(--panel-border);
  margin-left: 1.5rem;
  flex-shrink: 0;
}

/* The changelog link must read as a link (reported as unstyled text). */
.app-footer a {
  color: var(--gold, #d9b64a);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.app-footer a:hover,
.app-footer a:focus-visible {
  color: var(--gold-deep, #b8952f);
}

/* Accessibility */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   📱 Fluid Responsive & Multi-Screen Adaptation Rules
   ========================================================================== */

/* Large Desktops & 4K Displays: Fill horizontal space comfortably without stretched distortion */
@media (min-width: 1440px) {
  .fusion-workspace {
    padding: 1.5rem 2rem;
  }
  .transcription-output {
    font-size: 1.45rem;
    line-height: 1.9;
  }
}

/* Tablet & Intermediate Screens (768px - 1024px) */
@media (max-width: 1024px) {
  .container {
    padding: 0.65rem 1rem;
  }
  .chassis-header, .fusion-workspace, .controls-deck, .app-footer {
    margin-left: 0;
  }
  .sacred-telemetry-pillar {
    display: none;
  }
  .header-instruments {
    margin-right: 0;
  }
  .packet-seal {
    display: none;
  }
}

/* Mobile Devices (<= 767px) */
@media (max-width: 767px) {
  .container {
    padding: 0.45rem 0.65rem;
    gap: 0.45rem;
  }

  .chassis-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }

  .header-instruments {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    gap: 0.4rem;
  }

  .engine-switcher-wrap {
    flex: 1;
  }
  .engine-trigger-btn {
    width: 100%;
    justify-content: space-between;
    font-size: 0.65rem;
    padding: 0.35rem 0.55rem;
  }
  .engine-dropdown {
    left: 0;
    right: 0;
    width: 100%;
  }

  .mode-switch-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.65rem;
  }
  .status-stamp {
    font-size: 7.5px;
    padding: 2px 6px;
  }

  /* Workspace on Mobile */
  .fusion-workspace {
    padding: 0.6rem 0.75rem;
  }
  .workspace-top-bar {
    font-size: 0.625rem;
    padding-bottom: 0.4rem;
    /* Reported mobile overlap around the live badge: let the bar wrap
       instead of letting items collide on narrow screens. */
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
  }
  /* Touch-target pass (Apple HIG 44px minimum) + no iOS focus zoom. */
  .view-nav a {
    padding: 0.85rem 0.5rem;
  }
  .tool-btn,
  .item-act-btn,
  .library-refresh {
    min-height: 44px;
  }
  .link-join-input,
  .library-search-input {
    font-size: 16px;
  }
  .fft-oscilloscope {
    width: 100px;
    height: 18px;
  }
  .live-stream-badge {
    font-size: 0.625rem;
  }

  .transcription-output {
    padding: 0.85rem 1rem;
    font-size: 1.15rem;
    line-height: 1.65;
  }

  .workspace-bottom-bar {
    font-size: 0.625rem;
    padding-top: 0.4rem;
  }
  .cell-tag, .hotkey-hint {
    display: none;
  }

  /* Controls on Mobile: 2x2 Utility Grid + Full Width Transmit Key */
  .controls-deck {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 0.45rem;
  }

  .tool-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
    gap: 0.35rem;
  }

  .tool-btn {
    justify-content: center;
    padding: 0.55rem 0.4rem;
    font-size: 0.675rem;
  }

  .master-transmit-btn {
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
  }

  .app-footer {
    font-size: 0.6rem;
    padding-top: 0.25rem;
  }
}

/* ==========================================================================
   🔗 LINK MODE: Cross-Device Pairing (v04)
   ========================================================================== */

.link-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(7, 9, 12, 0.72);
  backdrop-filter: blur(6px);
}

html[data-theme="light"] .link-overlay {
  background: rgba(244, 239, 230, 0.8);
}

/* display:flex above overrides the UA [hidden] rule; re-assert it so the
   modal is actually closed until LinkManager.openModal() runs. */
.link-overlay[hidden] {
  display: none;
}

.link-modal {
  width: min(420px, 100%);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  background: var(--panel-chassis);
  border: 1px solid var(--panel-border);
  box-shadow: var(--card-shadow, 0 12px 40px rgba(0, 0, 0, 0.45));
  padding: 1.1rem 1.25rem 1.25rem;
  font-family: var(--font-mono);
}

.link-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px dashed var(--dashed-line);
}

.link-modal-title {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold, #d9b64a);
  margin: 0;
}

html[data-theme="light"] .link-modal-title {
  color: var(--live-ink-color, #b91c1c);
}

.link-close-btn {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: var(--btn-bg, transparent);
  border: 1px solid var(--btn-border, var(--panel-border));
  color: inherit;
  cursor: pointer;
}

.link-close-btn:hover {
  background: var(--btn-hover, rgba(255, 255, 255, 0.06));
}

.link-section + .link-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--dashed-line);
}

.link-hint {
  margin: 0 0 0.7rem;
  font-size: 0.62rem;
  line-height: 1.5;
  letter-spacing: 0.04em;
  color: var(--ink-dim, #8c8172);
}

.link-code-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.link-code {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--gold, #d9b64a);
}

html[data-theme="light"] .link-code {
  color: var(--ink-primary, #1c1814);
}

.link-qr-wrap {
  display: grid;
  place-items: center;
  width: 168px;
  margin: 0 auto;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--panel-border);
}

.link-qr-wrap svg {
  display: block;
  width: 144px;
  height: 144px;
}

/* QR library missing or render failed: show the hint in dim page ink on a
   transparent panel instead of light text on the white QR background. */
.link-qr-wrap.link-qr-fallback {
  width: auto;
  max-width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--ink-dim, #8c8172);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
}

.link-join-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-dim, #8c8172);
}

.link-join-row {
  display: flex;
  gap: 0.5rem;
}

.link-join-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  background: var(--panel-inner);
  border: 1px solid var(--panel-border);
  color: var(--ink-primary, inherit);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.link-join-input:focus-visible,
.link-join-row .tool-btn:focus-visible,
.link-close-btn:focus-visible,
.link-copy-code:focus-visible {
  outline: 2px solid var(--gold, #d9b64a);
  outline-offset: 2px;
}

html[data-theme="light"] .link-join-input:focus-visible {
  outline-color: var(--live-ink-border, #b91c1c);
}

.link-join-hint {
  margin: 0.45rem 0 0;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  color: var(--ink-muted, #8c8172);
}

.link-status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.link-leave-btn {
  margin-left: auto;
}

.link-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-muted, #8c8172);
  flex-shrink: 0;
}

.link-status-dot.linking {
  background: var(--amber, #d9a441);
  animation: link-pulse 1.1s ease-in-out infinite;
}

.link-status-dot.linked {
  background: var(--emerald, #10b981);
}

.link-status-dot.error {
  background: var(--red, #e8452c);
}

@keyframes link-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.link-status-text {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-primary, inherit);
}

.link-devices {
  margin-left: auto;
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim, #8c8172);
}

/* Remote Clipboard Tray */
.clipboard-tray {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 80;
  width: min(340px, calc(100vw - 2.5rem));
  background: var(--panel-chassis);
  border: 1px solid var(--panel-border);
  box-shadow: var(--card-shadow, 0 10px 30px rgba(0, 0, 0, 0.4));
  padding: 0.7rem 0.85rem;
  font-family: var(--font-mono);
}

.clipboard-tray[hidden] {
  display: none;
}

.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.45rem;
}

.tray-title {
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--emerald, #10b981);
}

.tray-text {
  margin: 0 0 0.6rem;
  max-height: 5.5em;
  overflow-y: auto;
  font-family: var(--font-body, inherit);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-primary, inherit);
  overflow-wrap: anywhere;
}

.tray-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 820px) {
  .clipboard-tray {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 4.75rem;
    width: auto;
  }

  .link-modal {
    width: 100%;
  }

  .link-code {
    font-size: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .link-status-dot.linking {
    animation: none;
  }
}

/* Remote dictation interim preview. The zone is permanently reserved in the
   bar (flex-basis) and only its opacity toggles, so the bar height, the
   toast, and the live badge never shift while remote words stream in. */
.remote-interim {
  flex: 0 1 240px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--gold, #d9b64a);
  opacity: 0;
  transition: opacity 0.15s ease;
  contain: layout paint;
}

.remote-interim.show {
  opacity: 1;
}

html[data-theme="light"] .remote-interim {
  color: var(--live-ink-color, #b91c1c);
}

@media (max-width: 640px) {
  .remote-interim {
    flex: 0 1 130px;
    min-width: 60px;
  }
}

/* ==========================================================================
   Authenticator Login (TOTP) inside the Link modal
   ========================================================================== */
.totp-secret {
  display: block;
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--gold, #d9b64a);
  background: rgba(217, 182, 74, 0.06);
  border: 1px dashed var(--panel-border);
  border-radius: 3px;
  user-select: all;
  word-break: break-all;
}

.totp-recovery {
  margin-top: 0.75rem;
}

.totp-recovery-title {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  margin-bottom: 0.4rem;
}

.totp-recovery-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.3rem 0.75rem;
}

.totp-recovery-codes code {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  color: var(--ink-primary);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.25rem 0.4rem;
}

.link-auth-error {
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  color: var(--red, #e8452c);
  min-height: 1em;
}

/* Vocabulary editor (keyterms), one term per line. 16px keeps iOS from
   zoom-jumping the field on focus. */
.vocab-input {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  background: var(--panel-inner, #080a0e);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  color: var(--ink-primary, #f5f2e9);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.7;
  padding: 0.55rem 0.65rem;
}
.vocab-input:focus-visible {
  outline: 1px solid var(--gold, #d9b64a);
}


/* ==========================================================================
   Library Navigation + Saved Library (hash-routed, D1-backed)
   ========================================================================== */
.view-nav {
  display: flex;
  gap: 1.1rem;
  /* Left edge aligned to the editor panel (its 1.5rem offset), tabs to the
     panel's inner content line — reported as drifting too far left. */
  margin-left: 1.5rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px dashed var(--dashed-line);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  position: relative;
  z-index: 5;
}

.view-nav a {
  color: var(--ink-dim);
  text-decoration: none;
  padding: 0.15rem 0.1rem;
  border-bottom: 1px solid transparent;
}

.view-nav a:hover,
.view-nav a:focus-visible {
  color: var(--gold);
}

.view-nav a.active {
  color: var(--gold);
  border-bottom-color: var(--gold-deep);
}

.library-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.75rem 0.2rem 0.5rem;
}

.library-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.7rem;
}

.library-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
}

.library-ghost-btn {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.library-ghost-btn:hover,
.library-ghost-btn:focus-visible {
  color: var(--gold);
  border-color: var(--gold-deep);
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  min-height: 0;
  padding-right: 0.25rem;
}

.library-item {
  background: var(--panel-inner, rgba(0, 0, 0, 0.2));
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.5rem 0.7rem;
}

.library-item.pinned {
  border-left-color: var(--gold);
}

.item-meta {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
}

.item-kind {
  color: var(--amber, #d9a441);
  text-transform: uppercase;
}

.item-source {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.item-act-btn {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 2px;
  padding: 0.12rem 0.4rem;
  cursor: pointer;
}

.item-act-btn:hover,
.item-act-btn:focus-visible {
  color: var(--gold);
  border-color: var(--gold-deep);
}

.item-act-btn.act-delete:hover,
.item-act-btn.act-delete:focus-visible {
  color: var(--red, #e8452c);
  border-color: var(--red, #e8452c);
}

.library-item details {
  margin-top: 0.3rem;
}

.library-item summary {
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-primary);
  list-style: none;
}

.library-item summary::-webkit-details-marker {
  display: none;
}

.library-item .item-body {
  margin-top: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ink-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.library-empty {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  border: 1px dashed var(--panel-border);
  border-radius: 4px;
  padding: 1.25rem;
  text-align: center;
}

@media (max-width: 640px) {
  .view-nav {
    gap: 0.8rem;
    font-size: 0.58rem;
  }
  .item-actions {
    gap: 0.25rem;
  }
}

/* [hidden] re-assertions: .workspace-top-bar, .workspace-bottom-bar,
   .transcription-output, and .library-view all set display, which overrides
   the UA [hidden] rule (same trap as .link-overlay). Without these, the
   hash router cannot hide the studio panels (or the library). */
.workspace-top-bar[hidden],
.workspace-bottom-bar[hidden],
.transcription-output[hidden],
.library-view[hidden] {
  display: none;
}
