/* ============================================================
   SUNOGEN — App
   Palette: warm near-black + electric amber
   Type: Space Grotesk + Space Mono
   ============================================================ */

:root {
  --bg:         #0c0b09;
  --bg2:        #131210;
  --bg3:        #1a1814;
  --border:     #2a2720;
  --border2:    #3a3530;
  --amber:      #f59e0b;
  --amber-dim:  #b45309;
  --amber-glow: rgba(245,158,11,.12);
  --amber-soft: rgba(245,158,11,.06);
  --text:       #f0ebe2;
  --muted:      #7a7468;
  --muted2:     #4a4640;
  --error:      #ef4444;
  --success:    #22c55e;
  --mono:       'Space Mono', monospace;
  --sans:       'Space Grotesk', sans-serif;
  --sidebar-w:  220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
button { font-family: var(--sans); cursor: pointer; }

.hidden { display: none !important; }

/* ── SCREENS ─────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── AUTH ────────────────────────────────────────────────── */
#screen-auth {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.auth-wrap {
  display: flex;
  width: 100%;
  max-width: 860px;
  min-height: 500px;
  border: 1px solid var(--border);
  background: var(--bg2);
}

.auth-brand {
  flex: 1;
  padding: 3rem 2.5rem;
  background: var(--bg3);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-logo {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--text);
  margin-bottom: 1.5rem;
}
.auth-logo span { color: var(--amber); }

.auth-tagline {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 2.5rem;
}

.auth-ticker {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}
.ticker-item {
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--muted);
  font-style: italic;
}

.auth-panel {
  flex: 1;
  padding: 3rem 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .06em;
  padding: .6rem 1.25rem .6rem 0;
  margin-right: 1.5rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .2s;
}
.auth-tab.active { color: var(--amber); border-bottom-color: var(--amber); }
.auth-tab:hover { color: var(--text); }

.auth-form {
  display: none;
  flex-direction: column;
  gap: 1rem;
}
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: .4rem; }
.field label {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.opt { font-family: var(--sans); text-transform: none; letter-spacing: 0; font-size: .75rem; }

input[type="text"], input[type="email"], input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: .95rem;
  padding: .65rem 1rem;
  border-radius: 3px;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}
input:focus { border-color: var(--amber-dim); }
input::placeholder { color: var(--muted2); }

.btn-main {
  font-family: var(--mono);
  font-size: .8rem;
  letter-spacing: .06em;
  background: var(--amber);
  color: var(--bg);
  border: none;
  padding: .75rem 1.75rem;
  border-radius: 3px;
  font-weight: 700;
  transition: opacity .2s;
  display: inline-block;
}
.btn-main:hover { opacity: .85; }

.auth-error {
  font-size: .82rem;
  color: var(--error);
  min-height: 1.2em;
  margin-top: .25rem;
}

/* ── APP LAYOUT ──────────────────────────────────────────── */
html, body { height: 100%; }

#screen-main { flex-direction: row; height: 100vh; overflow: hidden; }

.app-layout {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-logo {
  font-family: var(--mono);
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--text);
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: block;
}
.sidebar-logo span { color: var(--amber); }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.snav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem 1.25rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: .875rem;
  transition: all .15s;
  text-align: left;
  position: relative;
  width: 100%;
  border-radius: 0;
}
.snav-item:hover { color: var(--text); background: var(--bg3); }
.snav-item.active { color: var(--text); background: var(--bg3); }
.snav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--amber);
}

.snav-icon { font-size: .9rem; width: 1.25rem; text-align: center; }
.snav-label { flex: 1; }

.pro-tag {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .06em;
  padding: .1rem .4rem;
  border: 1px solid var(--amber-dim);
  color: var(--amber);
  border-radius: 2px;
}

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: .75rem 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .5rem 1.25rem;
}
.user-dot {
  width: 6px; height: 6px;
  background: var(--success);
  border-radius: 50%;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#user-name-label {
  font-size: .8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sub-badge {
  font-family: var(--mono);
  font-size: .65rem;
  color: var(--amber);
  letter-spacing: .06em;
}

.snav-logout { color: var(--muted2); }
.snav-logout:hover { color: var(--error); }

/* ── CONTENT ─────────────────────────────────────────────── */
.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.mode { display: none; min-height: 0; }
.mode.active { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }

.mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  z-index: 10;
}

.mode-label {
  font-family: var(--mono);
  font-size: .65rem;
  letter-spacing: .18em;
  color: var(--amber);
  display: block;
  margin-bottom: .3rem;
}

.mode-title h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
}

.btn-generate {
  white-space: nowrap;
  font-size: .8rem;
  padding: .65rem 1.5rem;
}

/* ── BUILDER LAYOUT ──────────────────────────────────────── */
.builder-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.builder-params {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
}

/* ── PARAM SECTIONS ──────────────────────────────────────── */
/* ── ACCORDION SECTIONS ──────────────────────────────────── */
.param-section {
  border-bottom: 1px solid var(--border);
}
.param-section:last-child { border-bottom: none; }

.param-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 0;
  cursor: pointer;
  user-select: none;
  transition: opacity .15s;
}
.param-head:hover { opacity: .85; }

.param-label {
  font-family: var(--mono);
  font-size: .67rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--amber);
  flex-shrink: 0;
}

.param-badge {
  font-family: var(--mono);
  font-size: .6rem;
  background: var(--amber-glow);
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  padding: .1rem .45rem;
  border-radius: 2px;
  display: none;
}
.param-badge.visible { display: inline; }

.param-preview {
  font-family: var(--mono);
  font-size: .65rem;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param-arrow {
  font-size: .6rem;
  color: var(--muted2);
  transition: transform .2s;
  flex-shrink: 0;
  margin-left: auto;
}
.param-section.open .param-arrow { transform: rotate(90deg); }

.param-body {
  display: none;
  padding-bottom: 1rem;
}
.param-section.open .param-body { display: block; }

.param-hint {
  font-size: .75rem;
  color: var(--muted2);
  margin-bottom: .6rem;
}

.multi-hint {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .06em;
  color: var(--muted2);
  border: 1px solid var(--border);
  padding: .1rem .4rem;
  border-radius: 2px;
}

/* ── CHIPS ───────────────────────────────────────────────── */
.chip-group { display: flex; flex-wrap: wrap; gap: .35rem; }

.chip {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .02em;
  padding: .3rem .7rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 3px;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.chip:hover { border-color: var(--border2); color: var(--text); }
.chip.selected {
  background: var(--amber-glow);
  border-color: var(--amber-dim);
  color: var(--amber);
}
.chip-group.negative .chip.selected {
  background: rgba(239,68,68,.08);
  border-color: rgba(239,68,68,.4);
  color: #f87171;
}

/* ── BPM SLIDER ──────────────────────────────────────────── */
.bpm-row {
  margin-top: 1rem;
}
.bpm-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.bpm-value {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--amber);
  font-weight: 700;
}
.bpm-slider {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.bpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--amber);
  border-radius: 50%;
  cursor: pointer;
}
.bpm-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--amber);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.bpm-scale {
  display: flex;
  justify-content: space-between;
  margin-top: .3rem;
  font-family: var(--mono);
  font-size: .6rem;
  color: var(--muted2);
}
.bpm-clear {
  background: transparent;
  border: none;
  color: var(--muted2);
  font-family: var(--mono);
  font-size: .65rem;
  letter-spacing: .06em;
  margin-top: .6rem;
  padding: 0;
  cursor: pointer;
  transition: color .15s;
}
.bpm-clear:hover { color: var(--muted); }

/* ── THEME TEXTAREA ──────────────────────────────────────── */
.theme-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: .9rem;
  padding: .75rem 1rem;
  border-radius: 3px;
  resize: vertical;
  outline: none;
  transition: border-color .2s;
  line-height: 1.6;
}
.theme-input:focus { border-color: var(--amber-dim); }
.theme-input::placeholder { color: var(--muted2); }

/* ── RESULT PANEL ────────────────────────────────────────── */
.result-panel {
  padding: 1.5rem;
  height: 100%;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2rem;
}

.result-empty {
  text-align: center;
  color: var(--muted2);
  width: 100%;
}
.result-empty-icon {
  font-size: 2rem;
  margin-bottom: 1rem;
  opacity: .4;
}
.result-empty p {
  font-size: .875rem;
  line-height: 1.7;
}
.result-empty strong { color: var(--muted); }

.result-content {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem;
  align-self: flex-start;
  margin-top: 0;
}

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

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: .3rem .5rem;
  font-size: .9rem;
  border-radius: 3px;
  transition: all .15s;
  line-height: 1;
}
.btn-icon:hover { border-color: var(--amber-dim); color: var(--amber); }

.result-text--exclude {
  color: #ef4444 !important;
  border-bottom: 1px solid rgba(239,68,68,.2) !important;
}

.result-text {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--amber);
  line-height: 1.7;
  letter-spacing: .01em;
  word-break: break-word;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  min-height: 3rem;
}

.result-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}

.btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .04em;
  padding: .35rem .75rem;
  border-radius: 3px;
  transition: all .15s;
}
.btn-ghost-sm:hover { border-color: var(--border2); color: var(--text); }

.result-loading {
  text-align: center;
  color: var(--muted);
}
.result-loading p { font-size: .85rem; margin-top: .75rem; }

.loading-dots {
  display: inline-flex;
  gap: .4rem;
  align-items: center;
}
.loading-dots span {
  width: 6px; height: 6px;
  background: var(--amber);
  border-radius: 50%;
  animation: blink 1.2s infinite both;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .2; }
  40% { opacity: 1; }
}

/* ── GATE ────────────────────────────────────────────────── */
.gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  max-width: 480px;
  margin: 0 auto;
  min-height: 0;
  overflow-y: auto;
}
.gate-icon {
  font-size: 2.5rem;
  margin-bottom: 1.25rem;
  opacity: .7;
}
.gate h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: .75rem;
  letter-spacing: -.01em;
}
.gate p {
  font-size: .9rem;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 2rem;
}

/* ── CHAT ────────────────────────────────────────────────── */
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 2rem;
  min-height: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding-bottom: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  min-height: 0;
}

.chat-msg {
  max-width: 70%;
  padding: .75rem 1rem;
  line-height: 1.55;
  font-size: .9rem;
  border-radius: 2px;
}
.chat-msg.user {
  background: var(--amber-glow);
  border: 1px solid var(--amber-dim);
  color: var(--text);
  align-self: flex-end;
  border-bottom-right-radius: 0;
}
.chat-msg.ai {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 0;
}

.extracted-prompt {
  margin-top: .75rem;
  padding: .6rem .8rem;
  background: var(--amber-soft);
  border-left: 2px solid var(--amber-dim);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--amber);
  line-height: 1.6;
}

.chat-input-wrap {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--sans);
  font-size: .9rem;
  padding: .65rem 1rem;
  border-radius: 3px;
  resize: none;
  outline: none;
  transition: border-color .2s;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
}
.chat-input:focus { border-color: var(--amber-dim); }
.chat-input::placeholder { color: var(--muted2); }

.chat-send {
  background: var(--amber);
  color: var(--bg);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 3px;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: opacity .2s;
}
.chat-send:hover { opacity: .85; }

/* ── HISTORY ─────────────────────────────────────────────── */
#history-content {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.history-list { display: flex; flex-direction: column; gap: .6rem; }

.history-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  transition: background .15s;
}
.history-item:hover { background: var(--bg3); }

.history-prompt {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--amber);
  flex: 1;
  line-height: 1.6;
}

.history-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .4rem;
  white-space: nowrap;
}
.history-date {
  font-family: var(--mono);
  font-size: .65rem;
  color: var(--muted2);
}
.history-mode {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .06em;
  color: var(--muted2);
  border: 1px solid var(--border);
  padding: .1rem .35rem;
  border-radius: 2px;
}
.history-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .65rem;
  padding: .2rem .5rem;
  border-radius: 2px;
  cursor: pointer;
  transition: all .15s;
}
.history-copy:hover { border-color: var(--amber-dim); color: var(--amber); }

/* ── PERSONA MODAL ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 2rem;
  width: 100%;
  max-width: 460px;
  border-radius: 2px;
}

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

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: .9rem;
  padding: .2rem;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-sub {
  font-size: .875rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.persona-grid {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.persona-option {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s;
  border-radius: 2px;
}
.persona-option:hover { border-color: var(--border2); background: var(--bg3); }
.persona-option.active {
  border-color: var(--amber-dim);
  background: var(--amber-glow);
}
.persona-icon { font-size: 1.25rem; flex-shrink: 0; margin-top: .1rem; }
.persona-name {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: .2rem;
}
.persona-desc { font-size: .8rem; color: var(--muted); line-height: 1.5; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .builder-layout { grid-template-columns: 1fr; }
  .result-panel { position: static; height: auto; border-top: 1px solid var(--border); }
  .result-content { align-self: auto; }
}

@media (max-width: 680px) {
  .auth-wrap { flex-direction: column; }
  .auth-brand { border-right: none; border-bottom: 1px solid var(--border); padding: 2rem 1.5rem; }
  .auth-ticker { display: none; }
  .auth-panel { padding: 2rem 1.5rem; }
  .sidebar { width: 56px; }
  .snav-label, .pro-tag, .sidebar-logo span, .user-info, .sidebar-user .user-dot { display: none; }
  .sidebar-logo { font-size: .75rem; padding: 1rem .75rem; letter-spacing: .05em; }
  .snav-item { padding: .65rem 0; justify-content: center; }
  .snav-icon { width: auto; font-size: 1rem; }
  .builder-params { padding: 1rem; }
  .mode-header { padding: 1rem; }
  .chat-wrap { padding: 1rem; }
}
