/* ══════════════════════════════════════════════════════════════════════════
   ArkPrompt — "Obsidian Velvet" theme
   Matte dark slate base, glassmorphism panels, "Digital Mint" cyan accents.

   ZERO-WOBBLE RULE (critical regression prevention):
   Horizontal scrolling is forbidden. Every flex child gets min-width: 0 and
   box-sizing: border-box so long token strings wrap aggressively and can never
   push a container past the viewport horizon.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Palette */
  --obsidian:        #0B0F19;  /* base matte slate            */
  --obsidian-raise:  #111726;  /* slightly raised surface     */
  --glass:           rgba(20, 28, 44, 0.55);
  --glass-border:    rgba(0, 245, 212, 0.18);
  --glass-border-hi: rgba(0, 245, 212, 0.45);
  --mint:            #00F5D4;  /* Digital Mint accent         */
  --mint-soft:       rgba(0, 245, 212, 0.12);
  --mint-glow:       rgba(0, 245, 212, 0.35);
  --ink:             #E8EEF5;  /* primary text                */
  --ink-dim:         #8A97AD;  /* secondary text              */
  --ink-faint:       #51607a;  /* tertiary / placeholders     */
  --danger:          #ff5d73;

  /* Live transcription ink opacities */
  --ink-spoken:      rgba(232, 238, 245, 0.40); /* 0.4 as spoken */
  --ink-locked:      rgba(255, 255, 255, 1.0);  /* 1.0 when locked */

  --radius:          16px;
  --radius-sm:       10px;
  --gap:             16px;
  --panel-pad:       18px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Reset / global encapsulation ──────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;     /* zero-wobble: predictable widths everywhere   */
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;          /* zero-wobble: never allow horizontal scroll   */
  background: var(--obsidian);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient mint aurora behind everything */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(60% 50% at 50% -10%, rgba(0, 245, 212, 0.10), transparent 70%),
    radial-gradient(40% 40% at 100% 100%, rgba(0, 245, 212, 0.06), transparent 70%);
  pointer-events: none;
}

/* Any element that holds text must be allowed to wrap hard. */
p, span, div, li, h1, h2, h3, label, button, input, textarea {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ─── Buttons & form primitives ─────────────────────────────────────────── */
button {
  font-family: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .05s ease;
}
button:hover  { border-color: var(--glass-border-hi); background: var(--mint-soft); }
button:active { transform: translateY(1px); }

.btn-primary {
  background: var(--mint);
  color: #04231f;
  border-color: var(--mint);
  font-weight: 600;
  box-shadow: 0 0 24px var(--mint-glow);
}
.btn-primary:hover { background: #2afbe0; }

input, textarea, select {
  font-family: inherit;
  color: var(--ink);
  background: rgba(8, 12, 20, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  max-width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--mint);
  box-shadow: 0 0 0 2px var(--mint-soft);
}
::placeholder { color: var(--ink-faint); }

/* ─── Glass panel ───────────────────────────────────────────────────────── */
.panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  padding: var(--panel-pad);
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;            /* clip, never scroll sideways */
}

.panel-title {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mint);
  margin: 0 0 12px;
  opacity: 0.9;
}

/* ══════════════════════════════════════════════════════════════════════════
   PASSCODE GATE — entrance portal
   ══════════════════════════════════════════════════════════════════════════ */
#gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(80% 80% at 50% 40%, #0d1320, var(--obsidian));
}
#gate.hidden { display: none; }

.gate-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  gap: 14px;
}
.gate-brand {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--ink);
  margin-bottom: 2px;
}
.gate-brand .accent { color: var(--mint); text-shadow: 0 0 18px var(--mint-glow); }
.gate-sub {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 18px;
}
.gate-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 4px;
}

/* ══════════════════════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════════════════════ */
#app {
  position: relative;
  z-index: 1;
  height: 100dvh;              /* account for iOS Safari UI shifts */
  max-height: 100dvh;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#app.hidden { display: none; }

/* ─── Top bar ───────────────────────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 14px 18px;
  border-bottom: 1px solid var(--glass-border);
}
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.34em;
  color: var(--ink);
}
.brand .accent { color: var(--mint); text-shadow: 0 0 16px var(--mint-glow); }
.topbar-actions {
  position: absolute;
  right: 14px;
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}

/* ─── Desktop: 3-column "Split-Screen Horizon" ──────────────────────────── */
.workspace {
  flex: 1 1 auto;
  min-height: 0;               /* zero-wobble: let children shrink */
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 300px;
  gap: var(--gap);
  padding: var(--gap);
  overflow: hidden;
}
.col { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: var(--gap); overflow: hidden; }
.col-left   { }
.col-center { }
.col-right  { }

/* Scrollable region inside a panel (vertical only) */
.scroll-y {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ─── Persona row ───────────────────────────────────────────────────────── */
.row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.row > select { flex: 1 1 auto; }
.row > .icon-btn { flex: 0 0 auto; }

/* ─── Tone slider ───────────────────────────────────────────────────────── */
.tone-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  padding: 0;
  background: linear-gradient(90deg, var(--mint), rgba(0,245,212,0.2));
  border: none;
  border-radius: 999px;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 14px var(--mint-glow);
  cursor: pointer;
}
input[type='range']::-moz-range-thumb {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: var(--mint); box-shadow: 0 0 14px var(--mint-glow); cursor: pointer;
}

/* ─── Voice capture ─────────────────────────────────────────────────────── */
.capture-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}
.mic-btn {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 1px solid var(--glass-border-hi);
  background: radial-gradient(circle at 50% 40%, rgba(0,245,212,0.18), rgba(8,12,20,0.7));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 28px var(--mint-glow);
}
.mic-btn svg { width: 30px; height: 30px; stroke: var(--mint); }
.mic-hint { font-size: 12px; color: var(--ink-dim); }

/* Live waveform canvas (shown during active capture) */
.waveform {
  width: 100%;
  height: 84px;
  display: none;               /* toggled on during capture */
}
.capturing .waveform { display: block; }
.capturing .mic-idle { display: none; }

.transcript {
  width: 100%;
  min-height: 96px;
  resize: vertical;
}
/* Live transcription ink: spoken text faint, locked text full white */
.ink-spoken { color: var(--ink-spoken); }
.ink-locked { color: var(--ink-locked); }

/* ─── Sign-off toggle switch ────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-dim);
}
.switch {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 999px;
  background: rgba(8, 12, 20, 0.85);
  border: 1px solid var(--glass-border);
  position: relative;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.switch:checked {
  background: var(--mint);
  border-color: var(--mint);
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform .15s ease, background .15s ease;
}
.switch:checked::after {
  transform: translateX(20px);
  background: #04231f;
}

/* ─── Context drop zone ─────────────────────────────────────────────────── */
.dropzone {
  border: 1px dashed var(--glass-border-hi);
  border-radius: var(--radius-sm);
  padding: 18px 12px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 13px;
  transition: background .15s ease, border-color .15s ease;
}
.dropzone.dragover {
  background: var(--mint-soft);
  border-color: var(--mint);
  color: var(--ink);
}

/* ─── Generated output ──────────────────────────────────────────────────── */
.output {
  flex: 1 1 auto;
  min-height: 0;
  white-space: pre-wrap;       /* preserve structure, still wrap */
  overflow-wrap: anywhere;
  font-size: 14px;
}
.output-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.output-actions .btn-primary { flex: 1 1 auto; }
.statusline {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 8px;
}
.statusline .dot { color: var(--mint); }

/* ─── Favorites binder ──────────────────────────────────────────────────── */
.fav-list { display: flex; flex-direction: column; gap: 8px; }
.fav-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: rgba(8, 12, 20, 0.4);
  min-width: 0;
}
.fav-item .fav-body { flex: 1 1 auto; min-width: 0; }
.fav-title { font-size: 13px; font-weight: 600; }
.fav-tag {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mint);
  background: var(--mint-soft);
  border-radius: 6px;
  padding: 2px 6px;
  margin-bottom: 4px;
}
.fav-star { flex: 0 0 auto; color: var(--mint); }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE — fixed baseline + "Bottom Slide-Up Tray" (Apple Maps style)
   ══════════════════════════════════════════════════════════════════════════ */
.tray { display: none; }       /* desktop: hidden */

@media (max-width: 760px) {
  /* On mobile the whole page scrolls naturally; panels stack as plain blocks
     so they can neither crop their own content nor overlap each other. */
  html, body { height: auto; min-height: 100dvh; overflow-x: hidden; }
  #app { height: auto; min-height: 100dvh; max-height: none; overflow: visible; }

  .workspace {
    display: block;          /* simple top-to-bottom flow, no flex shrinking */
    height: auto;
    min-height: 0;
    overflow: visible;
    padding: 12px;
    padding-bottom: 96px;    /* clearance for the tray handle               */
  }
  .col, .col-left, .col-center {
    display: block;
    overflow: visible;
    height: auto;
    min-height: 0;
  }
  .col > .panel { margin-bottom: var(--gap); }  /* replaces the flex gap       */
  .panel { overflow: visible; }                 /* never clip panel content    */
  .scroll-y { overflow: visible; max-height: none; }

  /* On mobile the right column (favourites) moves into the slide-up tray. */
  .col-right { display: none; }

  /* Mobile capture goes big and centred, per reference_mobile_layout. */
  .mic-btn { width: 104px; height: 104px; }
  .mic-btn svg { width: 40px; height: 40px; }

  /* Bottom slide-up tray holding outputs / favourites */
  .tray {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    max-height: 82dvh;
    transform: translateY(calc(100% - 64px)); /* peek the handle by default */
    transition: transform .28s cubic-bezier(.22, 1, .36, 1);
    will-change: transform;                    /* hardware-accelerated */
    background: var(--glass);
    border-top: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
    backdrop-filter: blur(18px) saturate(120%);
    -webkit-backdrop-filter: blur(18px) saturate(120%);
    padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .tray.open { transform: translateY(0); }
  .tray-handle {
    flex: 0 0 auto;
    align-self: center;
    width: 44px; height: 5px;
    border-radius: 999px;
    background: var(--ink-faint);
    margin: 6px 0 12px;
    border: none;
    padding: 0;
  }
  .tray .scroll-y { max-height: 70dvh; }
}

/* ─── Live transcription ink overlay ────────────────────────────────────── */
.ink-overlay {
  width: 100%;
  min-height: 28px;
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.ink-overlay:empty { display: none; }

/* ─── Sharpen diff highlight ─────────────────────────────────────────────── */
.diff-add {
  background: var(--mint-soft);
  color: var(--mint);
  border-radius: 3px;
  padding: 0 2px;
}

/* ─── Modal (QR / settings) ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 7, 12, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal.open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
  align-items: center;
}
.modal-card canvas { max-width: 100%; height: auto; border-radius: 8px; }

/* ─── Dim theme toggle ──────────────────────────────────────────────────── */
body.dim { filter: brightness(0.82); }

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