/* ============================================================
   NAGI — Stylesheet
   ------------------------------------------------------------
   Single responsibility: visual layer only.
   No HTML structure, no app logic.
   ============================================================ */

/* ------------------------------------------------------------
   SPLASH SCREEN
   ------------------------------------------------------------ */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #070B16; text-align: center;
  transition: opacity .4s ease-out, visibility .4s;
}
.splash.hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.splash-icon {
  width: 96px; height: 96px;
  animation: splashPulse 1.8s ease-in-out infinite;
}
.splash-title {
  font-family: 'Georgia', serif;
  font-size: 32px; font-weight: 700; font-style: italic;
  color: #F0C96A; margin-top: 20px; letter-spacing: 0.5px;
}
.splash-kanji {
  font-style: normal; font-weight: 400;
  font-size: 28px; opacity: 0.7; margin-left: 2px;
  vertical-align: baseline;
}
.splash-tagline {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; color: rgba(255,255,255,0.45);
  margin-top: 8px; letter-spacing: 0.3px;
}
@keyframes splashPulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.04); }
}

/* ------------------------------------------------------------
   THEME SYSTEM — Dark only (indigo + seigaiha + gold)
   ------------------------------------------------------------ */
:root {
  --bg: #070B16;
  --surface: #101827;
  --surface-2: #17243A;
  --surface-3: #1E3050;
  --border: #2D3A55;
  --text: #F6F1E7;
  --text-muted: #AAB3C5;
  --accent: #D6A84F;
  --accent-hover: #F0C96A;
  --accent-dim: rgba(214, 168, 79, 0.14);
  --indigo: #1E3A8A;
  --indigo-bright: #2A4D91;
  --gold: #D6A84F;
  --moon-gold: #F0C96A;
  --paper: #F6F1E7;
  --green: #6FBF9F;
  --green-dim: rgba(111, 191, 159, 0.14);
  --amber: #D6A84F;
  --amber-dim: rgba(214, 168, 79, 0.16);
  --red: #D96C5F;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

/* ------------------------------------------------------------
   RESET & BASE
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font); color: var(--text);
  line-height: 1.6; height: 100dvh; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  /* ── Seigaiha (青海波) wave pattern ──
     Inline SVG with 5 concentric arcs per wave, offset rows.
     Rendered as a tiling background directly on body. */
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='28'%3E%3Cg fill='none' stroke='%23a0b8d0' stroke-width='0.6' opacity='0.18'%3E%3Ccircle cx='28' cy='28' r='4'/%3E%3Ccircle cx='28' cy='28' r='7'/%3E%3Ccircle cx='28' cy='28' r='10'/%3E%3Ccircle cx='28' cy='28' r='13'/%3E%3Ccircle cx='28' cy='28' r='16'/%3E%3Ccircle cx='0' cy='28' r='4'/%3E%3Ccircle cx='0' cy='28' r='7'/%3E%3Ccircle cx='0' cy='28' r='10'/%3E%3Ccircle cx='0' cy='28' r='13'/%3E%3Ccircle cx='0' cy='28' r='16'/%3E%3Ccircle cx='56' cy='28' r='4'/%3E%3Ccircle cx='56' cy='28' r='7'/%3E%3Ccircle cx='56' cy='28' r='10'/%3E%3Ccircle cx='56' cy='28' r='13'/%3E%3Ccircle cx='56' cy='28' r='16'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 56px 28px;
}
.container {
  max-width: 1520px; margin: 0 auto;
  padding: 24px;
  padding-left:  max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  padding-top:   max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  height: 100%; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Custom scrollbars — thin, theme-matched */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ------------------------------------------------------------
   HEADER
   ------------------------------------------------------------ */
.header {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px;
  flex-wrap: wrap;
}
.header .brand-mark {
  width: 44px; height: 44px; border-radius: 10px;
  display: block; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(214,168,79,.15), 0 0 0 1px rgba(255,255,255,.04);
}
.header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.header h1 em { font-style: normal; color: var(--accent); }
.header-kanji { font-size: 22px; font-weight: 400; opacity: 0.6; margin-left: 1px; }
.header .tagline { color: var(--text-muted); font-size: 14px; }
.theme-toggle {
  margin-left: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  transition: border-color .2s, background .2s; color: var(--text);
}
.theme-toggle:hover { border-color: var(--accent); }

/* ------------------------------------------------------------
   VALUE BLURB
   ------------------------------------------------------------ */
.value-blurb {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
  font-size: 13px; line-height: 1.65; color: var(--text-muted);
}
.value-blurb strong { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------
   TIER SELECTOR
   ------------------------------------------------------------ */
.tier-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 14px; }
.tier-btn {
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  transition: all .2s; text-align: left; color: var(--text);
}
.tier-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.tier-btn.active { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent); }
.tier-btn .tier-name { font-weight: 600; font-size: 15px; display: block; margin-bottom: 2px; }
.tier-btn .tier-desc { font-size: 13px; color: var(--text-muted); display: block; }
.tier-indicator {
  font-size: 12px; color: var(--text-muted); margin-bottom: 18px;
  display: flex; align-items: center; gap: 6px;
}
.tier-indicator strong { color: var(--accent); font-weight: 600; text-transform: capitalize; }
.builder-mode-header {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); margin-bottom: 10px;
}
.builder-mode .tier-indicator { margin-bottom: 0; }

/* ------------------------------------------------------------
   MAIN GRID — Input | Preview | Signals
   ------------------------------------------------------------ */
.main-grid {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.main-grid.visible { display: grid; }
.input-col, .preview-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ------------------------------------------------------------
   CARDS
   ------------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-weight: 600; font-size: 14px; gap: 8px;
}
.card-header .badge {
  font-size: 11px; font-weight: 500; padding: 2px 8px;
  border-radius: 12px; background: var(--accent-dim); color: var(--accent);
  white-space: nowrap;
}

/* ------------------------------------------------------------
   FORM FIELDS
   ------------------------------------------------------------ */
.field-group { margin-bottom: 10px; }
.field-group:last-child { margin-bottom: 0; }
.field-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 4px;
}
.field-group textarea,
.field-group input,
.field-group select {
  width: 100%; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 13px;
  transition: border-color .15s;
}
.field-group textarea {
  resize: none; overflow: hidden; min-height: 38px; line-height: 1.4;
}
.field-group textarea:focus,
.field-group input:focus,
.field-group select:focus { outline: none; border-color: var(--accent); }
.field-group textarea::placeholder,
.field-group input::placeholder { color: var(--text-muted); }
.field-group select { appearance: none; cursor: pointer; }
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; display: block; }

/* Checkbox groups */
.checkbox-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px;
  margin-top: 4px;
}
.checkbox-grid label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text); font-weight: 400;
  cursor: pointer; padding: 4px 0;
}
.checkbox-grid input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }

/* ------------------------------------------------------------
   INTENT TEMPLATE CHIPS (flat + categorized)
   ------------------------------------------------------------ */
.intent-template-row,
.prompt-library-row {
  display: flex; flex-direction: column; gap: 10px; margin-top: 12px;
}
.intent-template-row.categorized,
.prompt-library-row.categorized {
  flex-direction: column; flex-wrap: nowrap; gap: 10px;
}
.intent-category,
.prompt-library-group { display: flex; flex-direction: column; gap: 6px; }
.intent-category-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted);
  padding-left: 2px;
}
.prompt-library-group-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted); padding-left: 2px;
}
.intent-category-chips,
.prompt-library-group-chips {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
}

.intent-subsection {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.intent-subsection-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 8px; font-size: 12px; font-weight: 600;
}
.intent-subsection-header .badge {
  font-size: 11px; font-weight: 500; padding: 2px 8px;
  border-radius: 12px; background: var(--accent-dim); color: var(--accent);
  white-space: nowrap;
}

/* ------------------------------------------------------------
   PROMPT LIBRARY
   ------------------------------------------------------------ */
.prompt-library-intro {
  font-size: 12px; color: var(--text-muted); line-height: 1.6;
}
.prompt-library-summary {
  min-height: 0; margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.prompt-library-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--accent-dim); border: 1px solid var(--accent);
  color: var(--accent); font-size: 12px; font-weight: 600;
}
.prompt-library-clear {
  background: none; border: none; padding: 2px 0;
  color: var(--text-muted); cursor: pointer; font-size: 12px;
  text-decoration: underline;
}
.prompt-library-clear:hover { color: var(--accent); }
.template-option-card {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; transition: all .15s;
  font-size: 12px; line-height: 1.35; text-align: left; width: 100%;
}
.template-option-card:hover {
  border-color: var(--accent); color: var(--accent); background: var(--accent-dim);
}
.template-option-card.active {
  border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent);
}
.template-option-card strong {
  display: block; font-size: 12px; font-weight: 700; color: inherit;
}
.template-option-card span {
  display: block; color: var(--text-muted); font-size: 11px;
}

/* ------------------------------------------------------------
   SUPPORTING MATERIAL (collapsible)
   ------------------------------------------------------------ */
.supporting-toggle {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; padding: 6px 0 4px;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font); font-weight: 500;
}
.supporting-toggle:hover { text-decoration: underline; }
.supporting-toggle .caret { display: inline-block; transition: transform .15s; }
.supporting-toggle.open .caret { transform: rotate(90deg); }
.supporting-body { display: none; margin-top: 8px; }
.supporting-body.open { display: block; }

/* ------------------------------------------------------------
   DATA SOURCE PICKER
   ------------------------------------------------------------ */
.source-summary {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
  min-height: 0;
}
.source-chip {
  font-size: 12px; padding: 4px 10px; border-radius: 14px;
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono);
}
.source-chip.registry { background: var(--green-dim); color: var(--green); border: 1px solid var(--green-dim); }
.source-chip.custom   { background: var(--amber-dim); color: var(--amber); border: 1px solid var(--amber-dim); }
.source-chip .x {
  cursor: pointer; opacity: .6; font-weight: 700;
  display: inline-flex; width: 14px; height: 14px;
  align-items: center; justify-content: center;
  border-radius: 50%;
}
.source-chip .x:hover { opacity: 1; }
.source-clear {
  background: none; border: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; padding: 2px 6px;
  text-decoration: underline;
}
.source-clear:hover { color: var(--accent); }

.source-browse-toggle {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; padding: 4px 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500;
}
.source-browse-toggle:hover { text-decoration: underline; }
.source-browse-toggle .caret { display: inline-block; transition: transform .15s; }
.source-browse-toggle.open .caret { transform: rotate(90deg); }

.source-grid {
  display: none; flex-wrap: wrap; gap: 6px;
  margin: 8px 0; padding: 10px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.source-grid.open { display: flex; }
.source-grid-chip {
  font-size: 12px; padding: 4px 10px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; transition: all .15s;
  font-family: var(--mono); user-select: none;
}
.source-grid-chip:hover { border-color: var(--green); color: var(--green); }
.source-grid-chip.selected {
  background: var(--green-dim); border-color: var(--green); color: var(--green);
}

.source-custom-row {
  display: flex; gap: 6px; margin-top: 6px; align-items: stretch;
}
.source-custom-row input { flex: 1; }
.source-custom-row button {
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; border: none;
  font-weight: 600; font-size: 12px; cursor: pointer;
}
.source-custom-row button:hover { background: var(--accent-hover); }

/* ------------------------------------------------------------
   SIGNAL TILES
   ------------------------------------------------------------ */
.signal-group { margin-bottom: 12px; }
.signal-group:last-child { margin-bottom: 0; }
.signal-group-label {
  font-size: 10px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px;
}
.signal-tile-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.signal-tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2);
  transition: all .15s; user-select: none; min-width: 0; text-align: center;
  flex: 1 1 auto;
}
.signal-tile:hover { border-color: var(--accent); background: var(--accent-dim); }
.signal-tile.active { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent); }
.signal-tile-label {
  font-size: 11px; font-family: var(--mono); font-weight: 600;
  color: var(--text); line-height: 1;
}
.signal-tile.active .signal-tile-label { color: var(--accent); }
.signal-tile-brief {
  font-size: 10px; color: var(--text-muted); line-height: 1.2; white-space: nowrap;
}
.signal-preview {
  margin-top: 8px; font-size: 12px; font-family: var(--mono);
  color: var(--accent); min-height: 18px; word-break: break-all;
}
.signal-info-link {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 10px;
  font-size: 11px; color: var(--accent); cursor: pointer; border: none;
  background: none; padding: 2px 0; user-select: none;
}
.signal-info-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------
   SIGNAL DETAIL DRAWER
   ------------------------------------------------------------ */
.signal-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 999; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.signal-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.signal-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 1000; transform: translateX(100%); transition: transform .3s ease;
  overflow-y: auto; padding: 24px;
}
.signal-drawer.open { transform: translateX(0); }
.signal-drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.signal-drawer-header h3 { font-size: 16px; font-weight: 700; }
.signal-drawer-close {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  transition: border-color .15s;
}
.signal-drawer-close:hover { border-color: var(--accent); }
.signal-drawer-group { margin-bottom: 18px; }
.signal-drawer-group:last-child { margin-bottom: 0; }
.signal-drawer-group-label {
  font-size: 11px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;
}
.signal-drawer-item { margin-bottom: 12px; }
.signal-drawer-item:last-child { margin-bottom: 0; }
.signal-drawer-item-label {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--text); margin-bottom: 2px;
}
.signal-drawer-item-desc {
  font-size: 12px; color: var(--text-muted); line-height: 1.55;
}

/* ------------------------------------------------------------
   CONDITIONAL SECTIONS
   ------------------------------------------------------------ */
.conditional-section { display: none; }
.conditional-section.visible { display: block; }

/* ------------------------------------------------------------
   CHECKPOINT ROADMAP — wrapping pills
   ------------------------------------------------------------ */
.checkpoint-roadmap {
  display: flex; flex-wrap: wrap; gap: 8px; row-gap: 8px;
  align-items: center; padding: 4px 0;
}
.cp-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 20px;
  background: var(--accent-dim); border: 1px solid var(--accent);
  font-size: 12px; color: var(--accent); font-weight: 500;
  white-space: normal; line-height: 1.3;
}
.cp-pill .cp-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}

/* ------------------------------------------------------------
   PREVIEW
   ------------------------------------------------------------ */
.preview-area {
  background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 16px; font-family: var(--mono); font-size: 12px;
  line-height: 1.7; white-space: pre-wrap; word-wrap: break-word;
  max-height: calc(100dvh - 240px); overflow-y: auto; min-height: 420px;
  color: var(--text); resize: none; width: 100%;
  transition: border-color .15s;
}
.preview-area:focus { outline: none; border-color: var(--accent); }

/* ------------------------------------------------------------
   ACTION BAR
   ------------------------------------------------------------ */
.action-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.action-btn {
  padding: 10px 20px; border-radius: var(--radius);
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: all .15s; border: none;
}
.action-btn.primary { background: var(--accent); color: #fff; }
.action-btn.primary:hover { background: var(--accent-hover); }
.action-btn.accent {
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--accent); font-weight: 700;
}
.action-btn.accent:hover { background: var(--accent-dim); }
.action-btn.secondary {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.action-btn.secondary:hover { border-color: var(--accent); }
.copy-feedback {
  font-size: 12px; color: var(--green); opacity: 0;
  transition: opacity .3s;
}
.copy-feedback.visible { opacity: 1; }

.example-link {
  color: var(--accent); font-size: .75rem; text-decoration: none;
  opacity: .75; transition: opacity .2s; cursor: pointer;
  background: none; border: none; padding: 2px 0; font-family: var(--font);
}
.example-link:hover { opacity: 1; text-decoration: underline; }

/* ------------------------------------------------------------
   IDENTITY BUTTON (header)
   ------------------------------------------------------------ */
.identity-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .2s, background .2s; color: var(--text);
  flex-shrink: 0;
}
.identity-btn:hover,
.identity-btn.active { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.identity-btn svg { width: 18px; height: 18px; }

/* ------------------------------------------------------------
   IDENTITY DRAWER
   ------------------------------------------------------------ */
.identity-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 999; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.identity-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.identity-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 1000; transform: translateX(100%); transition: transform .3s ease;
  overflow-y: auto; padding: 24px;
}
.identity-drawer.open { transform: translateX(0); }
.identity-drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.identity-drawer-header h3 { font-size: 16px; font-weight: 700; }
.identity-drawer-close {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  transition: border-color .15s;
}
.identity-drawer-close:hover { border-color: var(--accent); }
.identity-enabled-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 16px; gap: 12px;
}
.identity-enabled-row label { font-size: 13px; font-weight: 600; cursor: pointer; }
.identity-enabled-row input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent); }
.identity-field { margin-bottom: 14px; }
.identity-field:last-child { margin-bottom: 0; }
.identity-field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 4px;
}
.identity-field textarea {
  width: 100%; padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font); font-size: 13px;
  resize: none; line-height: 1.5; transition: border-color .15s;
  overflow: hidden; min-height: 38px;
}
.identity-field textarea:focus { outline: none; border-color: var(--accent); }
.identity-field textarea::placeholder { color: var(--text-muted); }
.identity-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--accent); margin: 18px 0 10px;
}

/* ------------------------------------------------------------
   QUICK CAPTURE (primary entry for all screen sizes)
   ------------------------------------------------------------ */
.quick-capture { display: block; max-width: 860px; margin: 0 auto; padding-top: 24px; }

/* Result view toggle — works at all screen sizes */
body.state-result .quick-capture { display: none; }
body.state-result .main-grid { display: none !important; }
body.state-result .value-blurb { display: none !important; }
body.state-result .result-view { display: block !important; max-width: 860px; margin: 0 auto; }
.quick-capture-title {
  font-size: 28px; font-weight: 700; margin-bottom: 6px; color: var(--text);
  letter-spacing: -0.5px; line-height: 1.15;
}
.quick-capture-helper {
  font-size: 15px; color: var(--text-muted); line-height: 1.5;
  margin-bottom: 20px;
}
.quick-capture textarea {
  width: 100%; padding: 14px; min-height: 120px; max-height: 40vh;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.5;
  resize: none; transition: border-color .15s;
  overflow-y: auto;
}
.quick-capture textarea:focus { outline: none; border-color: var(--accent); }
.quick-capture textarea::placeholder { color: var(--text-muted); }
.storm-input-wrap { position: relative; }
.storm-mic-btn {
  position: absolute; bottom: 10px; right: 10px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; transition: all .15s;
}
.storm-mic-btn:active { border-color: var(--accent); color: var(--accent); }
.storm-mic-btn.recording {
  border-color: var(--red); color: var(--red);
  background: rgba(217,108,95,0.1);
  animation: micPulse 1.2s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217,108,95,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(217,108,95,0); }
}

/* Template starter chips */
.template-chips {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px;
}
.tmpl-chip {
  padding: 8px 14px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 13px; font-family: var(--font);
  cursor: pointer; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.tmpl-chip:hover { border-color: var(--accent); color: var(--accent); }
.tmpl-chip:active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.tmpl-chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.tmpl-chip-prd { border-color: rgba(240, 201, 106, 0.35); color: rgba(240, 201, 106, 0.8); }
.tmpl-chip-prd:hover { border-color: rgba(240, 201, 106, 0.6); color: rgba(240, 201, 106, 1); }
.tmpl-chip-prd:active, .tmpl-chip-prd.active {
  border-color: rgba(240, 201, 106, 0.8); color: rgba(240, 201, 106, 1);
  background: rgba(240, 201, 106, 0.1);
}
.tmpl-chip-dev { border-color: rgba(168, 130, 255, 0.35); color: rgba(168, 130, 255, 0.8); }
.tmpl-chip-dev:hover { border-color: rgba(168, 130, 255, 0.6); color: rgba(168, 130, 255, 1); }
.tmpl-chip-dev:active, .tmpl-chip-dev.active {
  border-color: rgba(168, 130, 255, 0.8); color: rgba(168, 130, 255, 1);
  background: rgba(168, 130, 255, 0.1);
}

/* Mode selector — compact single-line */
.mode-selector { margin: 14px 0 16px; display: inline-block; margin-right: 8px; }
.mode-target-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 16px; flex-wrap: wrap; }
.mode-target-row .mode-selector,
.mode-target-row .target-selector { margin: 0; }
.mode-selector-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; cursor: pointer;
  transition: border-color .15s; font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.mode-selector-btn:active { border-color: var(--accent); }
.mode-selector-label { color: var(--text-muted); font-weight: 400; }
.mode-selector-value { font-weight: 600; color: var(--accent); }
.mode-selector-btn svg { color: var(--text-muted); }

/* Target selector — mirrors mode selector */
.target-selector { margin: 0 0 16px; }
.target-selector-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; cursor: pointer;
  transition: border-color .15s; font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.target-selector-btn:active { border-color: var(--accent); }
.target-selector-label { color: var(--text-muted); font-weight: 400; }
.target-selector-value { font-weight: 600; color: var(--accent); }
.target-selector-btn svg { color: var(--text-muted); }

/* Audit feedback */
.audit-feedback {
  background: rgba(251, 191, 36, 0.08); border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  animation: auditSlideIn .3s ease-out;
}
@keyframes auditSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.audit-feedback-header {
  font-size: 14px; font-weight: 700; color: #fbbf24; margin-bottom: 8px;
}
.audit-feedback-list {
  margin: 0 0 10px 0; padding-left: 18px; list-style: disc;
  font-size: 13px; line-height: 1.6; color: var(--text-muted);
}
.audit-feedback-list li { margin-bottom: 4px; }
.audit-feedback-hint {
  font-size: 12px; color: var(--text-muted); margin: 0; font-style: italic;
}

/* CTA */
.quick-capture-cta {
  width: 100%; padding: 16px; border: none;
  border-radius: var(--radius); background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: background .15s, transform 60ms ease-out, opacity .15s;
  min-height: 48px; margin-bottom: 8px;
  -webkit-tap-highlight-color: transparent;
}
.quick-capture-cta:hover:not(:disabled) { background: var(--accent-hover); }
.quick-capture-cta:active:not(:disabled) { transform: scale(0.97); }
.quick-capture-cta:disabled { opacity: 0.4; cursor: default; }
.quick-capture-cta.processing { pointer-events: none; opacity: 0.7; }
.quick-capture-cta.success { background: var(--green); pointer-events: none; }
/* Secondary actions — Save for later | Clear */
.capture-secondary {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; padding: 8px 0 4px;
}
.capture-secondary-btn {
  background: none; border: none; font-size: 14px;
  cursor: pointer; font-family: var(--font); padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.capture-secondary-btn.save-btn { color: var(--accent); font-weight: 500; }
.capture-secondary-btn.save-btn:active { opacity: 0.7; }
.capture-secondary-btn.clear-btn { color: var(--text-muted); }
.capture-secondary-btn.clear-btn:active { color: var(--red); }
.capture-secondary-sep {
  width: 1px; height: 14px; background: var(--border);
}
.quick-capture-toggle {
  width: 100%; padding: 10px; border: none;
  background: none; color: var(--text-muted); font-size: 13px;
  cursor: pointer; font-family: var(--font);
}
.quick-capture-toggle:hover { color: var(--accent); }

/* Old quick chips — hidden in new mobile, kept for desktop */
.quick-action-chips { display: none; }

/* History section */
.history-section {
  margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px;
}
.history-section:empty, .history-section.empty { display: none; }
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.history-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
}
.history-clear-all {
  background: none; border: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; font-family: var(--font);
  padding: 4px 8px; -webkit-tap-highlight-color: transparent;
}
.history-clear-all:active { color: var(--red); }
.history-list {
  display: flex; flex-direction: column; gap: 6px;
}
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s;
}
.history-item:active { border-color: var(--accent); }
.history-item-content { flex: 1; min-width: 0; }
.history-item-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item-meta {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.history-item-delete {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px; -webkit-tap-highlight-color: transparent;
}
.history-item-delete:active { color: var(--red); }

/* Saved prompts button (mobile) */
.saved-btn {
  margin-left: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .2s; color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
}
.saved-btn:active { border-color: var(--accent); color: var(--accent); }

/* Settings button (mobile) */
.settings-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .2s; color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
}
.settings-btn:active { border-color: var(--accent); }

/* ------------------------------------------------------------
   MOBILE RESULT VIEW
   ------------------------------------------------------------ */
.result-view {
  padding: 0; animation: resultFadeIn 250ms ease-out;
  padding-top: max(8px, env(safe-area-inset-top));
}
.result-top-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; gap: 8px;
}
.result-header {
  font-size: 18px; font-weight: 700; color: var(--accent);
}
.result-top-actions {
  display: flex; gap: 6px; flex-shrink: 0;
}
.result-top-actions .action-btn {
  padding: 8px 14px; min-height: 36px; font-size: 13px;
}
.result-body-actions {
  display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 6px;
}
.result-body-action {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; transition: all .15s;
}
.result-body-action:active { border-color: var(--accent); color: var(--accent); }
.result-body-action.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.result-body {
  width: 100%; max-height: 50vh; min-height: 120px; padding: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  resize: none; margin-bottom: 12px; overflow-y: auto;
}
.result-body:focus { outline: none; border-color: var(--accent); }

/* Completeness score bar */
#completenessContainer { padding: 0 0 8px; }
.completeness-bar { margin-bottom: 10px; }
.completeness-label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.completeness-label strong { color: var(--text); }
.completeness-track {
  height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden;
}
.completeness-fill {
  height: 100%; border-radius: 2px; transition: width 300ms ease;
}
.completeness-missing {
  font-size: 11px; color: var(--text-dim); margin-top: 4px; line-height: 1.4;
}

/* Template card */
.template-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.template-card-header {
  font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 8px;
}
.template-card-fields { display: flex; flex-direction: column; gap: 6px; }
.template-field { padding: 6px 8px; border-radius: 6px; background: var(--bg); }
.template-field.filled { border-left: 2px solid var(--accent); }
.template-field-label {
  font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.3px; margin-bottom: 2px;
}
.template-req { color: var(--accent); }
.template-field-value { font-size: 13px; color: var(--text); }
.template-field-placeholder { font-size: 12px; color: var(--text-dim); opacity: 0.6; font-style: italic; }
.template-apply-btn {
  width: 100%; margin-top: 10px; padding: 10px; border: 1px solid var(--accent);
  border-radius: var(--radius); background: transparent; color: var(--accent);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.template-apply-btn:active { background: var(--accent-dim); }

/* Template Editor View — fixed full-screen overlay (like reader/history) */
.template-editor {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: var(--bg); flex-direction: column;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='28'%3E%3Cg fill='none' stroke='%23a0b8d0' stroke-width='0.6' opacity='0.18'%3E%3Ccircle cx='28' cy='28' r='4'/%3E%3Ccircle cx='28' cy='28' r='7'/%3E%3Ccircle cx='28' cy='28' r='10'/%3E%3Ccircle cx='28' cy='28' r='13'/%3E%3Ccircle cx='28' cy='28' r='16'/%3E%3Ccircle cx='0' cy='28' r='4'/%3E%3Ccircle cx='0' cy='28' r='7'/%3E%3Ccircle cx='0' cy='28' r='10'/%3E%3Ccircle cx='0' cy='28' r='13'/%3E%3Ccircle cx='0' cy='28' r='16'/%3E%3Ccircle cx='56' cy='28' r='4'/%3E%3Ccircle cx='56' cy='28' r='7'/%3E%3Ccircle cx='56' cy='28' r='10'/%3E%3Ccircle cx='56' cy='28' r='13'/%3E%3Ccircle cx='56' cy='28' r='16'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 56px 28px;
}
.template-editor.open { display: flex; animation: resultFadeIn 200ms ease-out; }
.te-header {
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  background: var(--bg);
  padding: max(16px, env(safe-area-inset-top)) 16px 14px;
}
.te-back {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; flex-shrink: 0;
}
.te-back:active { border-color: var(--accent); color: var(--accent); }
.te-title {
  font-size: 20px; font-weight: 700; color: var(--accent);
  letter-spacing: -0.3px;
}
.te-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  max-width: 860px; margin: 0 auto; width: 100%;
}
.te-fields { display: flex; flex-direction: column; gap: 16px; padding-bottom: 16px; }
.te-field {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  transition: border-color .15s;
  -webkit-user-select: text; user-select: text;
  touch-action: auto;
}
.te-field:focus-within { border-color: var(--accent); }
.te-field-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-muted); margin-bottom: 6px;
}
.te-field-label .te-req { color: var(--accent); margin-left: 2px; }
.te-field-input {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 15px;
  line-height: 1.5; resize: none; min-height: 44px;
  -webkit-user-select: text; user-select: text;
  touch-action: auto;
}
.te-field-input::placeholder { color: var(--text-muted); opacity: 0.7; font-size: 14px; }

/* Pill selector within template fields */
.te-pill-wrap {
  -webkit-user-select: text; user-select: text;
  touch-action: auto;
}
.te-pill-options {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px;
}
.te-pill {
  padding: 8px 14px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 14px; font-family: var(--font);
  cursor: pointer; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.te-pill:active { transform: scale(0.96); }
.te-pill.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}
.te-pill-custom {
  width: 100%; padding: 10px 0; border: none; border-top: 1px solid var(--border);
  background: transparent; color: var(--text); font-family: var(--font);
  font-size: 14px; outline: none; min-height: 44px;
  -webkit-user-select: text; user-select: text;
}
.te-pill-custom::placeholder { color: var(--text-muted); opacity: 0.6; }
.te-transform-btn {
  width: 100%; padding: 16px; border: none;
  border-radius: var(--radius); background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: background .15s, transform 60ms ease-out;
  min-height: 48px; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.te-transform-btn:active { transform: scale(0.97); }

.reader-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: var(--bg); flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)) 16px;
}
.reader-overlay.open { display: flex; animation: resultFadeIn 200ms ease-out; }
.reader-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; flex-shrink: 0;
}
.reader-actions { display: flex; align-items: center; gap: 8px; }
.reader-action-btn { padding: 8px 16px !important; min-height: 36px !important; font-size: 14px !important; }
.reader-close {
  background: none; border: none; color: var(--accent);
  font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: var(--font); padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.reader-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  font-family: var(--mono); font-size: 15px; line-height: 1.7;
  color: var(--text); white-space: pre-wrap; word-wrap: break-word;
  -webkit-user-select: text; user-select: text;
  border-radius: var(--radius-sm); padding: 4px;
  transition: background .15s, border-color .15s;
  border: 1px solid transparent;
}
.reader-body[contenteditable="true"] {
  background: var(--surface-2); border-color: var(--accent);
  outline: none; padding: 12px;
}
.toast {
  position: fixed; bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--green); color: #111; font-weight: 600;
  font-size: 14px; padding: 10px 24px; border-radius: 20px;
  opacity: 0; pointer-events: none; z-index: 9999;
  transition: opacity .25s, transform .25s;
  font-family: var(--font);
}
.toast.visible {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
.refine-strip {
  margin-bottom: 16px; padding: 12px 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.refine-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
}
.refine-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.refine-chip {
  padding: 6px 12px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s; font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.refine-chip:active { transform: scale(0.96); }
.refine-chip.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}
.refine-context-toggle {
  margin-top: 4px; border-style: dashed;
}
.refine-context {
  margin-top: 8px;
}
.refine-context textarea {
  width: 100%; padding: 10px; min-height: 60px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 13px; line-height: 1.5;
  resize: vertical; margin-bottom: 8px;
}
.refine-context textarea:focus { outline: none; border-color: var(--accent); }
.refine-recompile-btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  background: var(--accent); border: none; color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); -webkit-tap-highlight-color: transparent;
}
.refine-recompile-btn:active { opacity: 0.8; }
.result-secondary-actions {
  display: flex; gap: 12px; justify-content: center;
  padding: 8px 0;
}
.result-secondary-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; cursor: pointer; font-family: var(--font);
  padding: 8px 4px; -webkit-tap-highlight-color: transparent;
}
.result-secondary-btn:active { color: var(--accent); }
@keyframes resultFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------
   BOTTOM SHEETS (mode selector, settings)
   ------------------------------------------------------------ */
.mode-sheet-backdrop, .settings-sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 500; opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.mode-sheet-backdrop.open, .settings-sheet-backdrop.open {
  opacity: 1; pointer-events: auto;
}
.mode-sheet, .settings-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; z-index: 501;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .25s ease-out;
  max-height: 70vh; overflow-y: auto;
}
.mode-sheet.open, .settings-sheet.open { transform: translateY(0); }
.mode-sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 4px auto 12px;
}
.mode-sheet-title {
  font-size: 14px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.mode-sheet-option {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; padding: 14px 12px; border: none;
  background: none; color: var(--text); font-size: 16px;
  font-weight: 600; text-align: left; cursor: pointer;
  border-radius: var(--radius-sm); font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.mode-sheet-option:active { background: var(--accent-dim); }
.mode-sheet-option.active { color: var(--accent); background: var(--accent-dim); }
.mode-sheet-desc {
  font-size: 13px; font-weight: 400; color: var(--text-muted);
}

/* ------------------------------------------------------------
   REDUCED MOTION — respect user preference
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------
   CONTEXT TYPE CHIPS (inside Context Inbox)
   ------------------------------------------------------------ */
.context-type-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px;
}
.ctx-chip {
  padding: 4px 10px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; cursor: pointer;
  transition: all .15s; font-family: var(--font);
}
.ctx-chip:hover { border-color: var(--accent); color: var(--accent); }

/* Mobile/desktop action visibility */
.mobile-action { display: none; }
.desktop-action { display: inline-flex; }

/* ------------------------------------------------------------
   PROMPT LENGTH CONTROL
   ------------------------------------------------------------ */
.prompt-length-control {
  display: flex; gap: 6px; margin: 10px 0;
}
.length-chip {
  flex: 1; padding: 8px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s; text-align: center;
  font-family: var(--font);
}
.length-chip:hover { border-color: var(--accent); color: var(--accent); }
.length-chip.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}

/* ------------------------------------------------------------
   MOBILE TAB BAR (hidden on desktop)
   ------------------------------------------------------------ */
.mobile-tab-bar {
  display: none; /* shown only on ≤820px via media query */
}

/* ------------------------------------------------------------
   RESPONSIVE
   ------------------------------------------------------------ */
/* Desktop enhancements — larger storm input, centered layout */
@media (min-width: 821px) {
  .quick-capture textarea { min-height: 160px; font-size: 15px; }
  .quick-capture-title { font-size: 32px; }
  .quick-capture-cta { max-width: 320px; margin-left: auto; margin-right: auto; }
  .quick-capture-toggle { max-width: 320px; margin-left: auto; margin-right: auto; }
  .template-chips { justify-content: center; }
  .mode-selector { display: flex; justify-content: center; }
  .mode-target-row { justify-content: center; }
  .capture-secondary { justify-content: center; }
}

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

@media (max-width: 820px) {
  /* --- Layout: single screen, no tabs --- */
  .main-grid { display: none !important; }

  /* --- Quick Capture visible on mobile --- */
  .quick-capture { display: block; padding-top: 16px; }

  /* Hide value blurb on mobile */
  .value-blurb { display: none !important; }

  /* Hide capture + header when showing result */
  body.state-result .quick-capture { display: none; }
  body.state-result .header { display: none !important; }
  body.state-result .result-view { display: block !important; }

  /* --- Mobile/desktop action visibility --- */
  .mobile-action { display: inline-flex; }
  .desktop-action { display: none; }

  /* --- No mobile tab bar in v1 --- */
  .mobile-tab-bar { display: none !important; }

  /* --- Container padding (header handles safe-area-top) --- */
  .container {
    padding: 16px;
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-top:   0;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  }

  /* --- Header (sticky, flush to top) --- */
  .header {
    position: sticky; top: 0; z-index: 100;
    background: var(--bg);
    margin: -16px -16px 0 -16px;
    padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  }
  .header h1 { font-size: 22px; }
  .header .tagline { display: none; }
  .header .brand-mark { width: 36px; height: 36px; }

  /* --- Prevent iOS zoom on input focus (must be >= 16px) --- */
  textarea, input, select { font-size: 16px !important; }

  /* --- Native app feel --- */
  body { -webkit-user-select: none; user-select: none; }
  textarea, input, .result-body, .preview-area { -webkit-user-select: text; user-select: text; }

  /* --- Tier bar --- */
  .tier-bar { grid-template-columns: repeat(2, 1fr); }
  .tier-btn { padding: 12px 14px; }
  .tier-btn .tier-desc { font-size: 12px; }

  .intent-subsection-header {
    flex-direction: column; align-items: flex-start;
  }

  /* --- Form fields --- */
  .checkbox-grid { grid-template-columns: 1fr; }

  /* Touch targets — Apple HIG 44pt minimum */
  .action-btn { padding: 12px 18px; min-height: 44px; font-size: 14px; }
  .template-option-card { width: 100%; min-height: 64px; }
  .signal-tile { min-height: 44px; padding: 8px 10px; }
  .theme-toggle { width: 40px; height: 40px; }
  .source-grid-chip { padding: 6px 12px; min-height: 32px; }
  .checkbox-grid input[type="checkbox"] { width: 18px; height: 18px; }
  .checkbox-grid label { padding: 8px 0; font-size: 13px; }
  .supporting-toggle, .source-browse-toggle { padding: 10px 0; }

  .field-group textarea,
  .field-group input,
  .field-group select { font-size: 16px; }

  .preview-area { max-height: none; min-height: 300px; border: none; }

  .preview-col .action-bar {
    position: sticky;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    margin-top: -2px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    background: var(--surface);
    box-shadow: 0 10px 24px rgba(0,0,0,.18);
  }

}

@media (max-width: 480px) {
  .tier-bar { grid-template-columns: 1fr; gap: 8px; }
  .intent-category-chips,
  .prompt-library-group-chips { grid-template-columns: 1fr; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .action-bar .action-btn { width: 100%; }
  .header { gap: 10px; }
  .header h1 { font-size: 20px; }
}

/* ------------------------------------------------------------
   TIPS OVERLAY (prompt best practices — tapping Nagi icon)
   ------------------------------------------------------------ */
.tips-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: var(--bg); flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)) 16px;
}
.tips-overlay.open { display: flex; animation: resultFadeIn 200ms ease-out; }
.tips-overlay-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-shrink: 0;
}
.tips-overlay-title {
  font-size: 20px; font-weight: 700; color: var(--accent);
  letter-spacing: -0.3px;
}
.tips-overlay-close {
  background: none; border: none; color: var(--accent);
  font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: var(--font); padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.tips-overlay-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.tips-section {
  padding: 16px 0; border-bottom: 1px solid var(--border);
}
.tips-section:last-child { border-bottom: none; }
.tips-section-title {
  font-size: 15px; font-weight: 700; color: var(--text);
  margin-bottom: 8px;
}
.tips-text {
  font-size: 14px; color: var(--text-muted); line-height: 1.6;
  margin-bottom: 6px;
}
.tips-text:last-child { margin-bottom: 0; }
.tips-text strong { color: var(--accent); font-weight: 600; }
.tips-text.tips-bad {
  color: var(--red); opacity: 0.8; font-style: italic;
}
.brand-mark { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ------------------------------------------------------------
   HISTORY OVERLAY (full-screen prompt library)
   ------------------------------------------------------------ */
.history-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: var(--bg); flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)) 16px;
}
.history-overlay.open { display: flex; animation: resultFadeIn 200ms ease-out; }
.history-overlay-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-shrink: 0;
}
.history-overlay-title {
  font-size: 18px; font-weight: 700; color: var(--text);
}
.history-overlay-close {
  background: none; border: none; color: var(--accent);
  font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: var(--font); padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.history-overlay-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 14px; text-align: center;
  padding: 40px 20px; line-height: 1.6;
}
.history-overlay-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 8px;
}
.history-overlay-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s;
}
.history-overlay-item:active { border-color: var(--accent); }
.history-overlay-item-content { flex: 1; min-width: 0; }
.history-overlay-item-title {
  font-size: 15px; font-weight: 600; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.4;
}
.history-overlay-item-meta {
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
  display: flex; gap: 8px; align-items: center;
}
.history-overlay-item-badge {
  font-size: 10px; font-weight: 600; padding: 2px 6px;
  border-radius: 8px; background: var(--accent-dim); color: var(--accent);
}
.history-overlay-item-delete {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 8px;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 18px; -webkit-tap-highlight-color: transparent;
}
.history-overlay-item-delete:active { color: var(--red); }
.history-overlay-actions {
  flex-shrink: 0; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; justify-content: center;
}
.history-overlay-clear-all {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; cursor: pointer; font-family: var(--font);
  padding: 10px 16px; -webkit-tap-highlight-color: transparent;
}
.history-overlay-clear-all:active { color: var(--red); }
