/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* ===== DESIGN TOKENS ===== */
:root {
  /* Palette */
  --ink-deep:    #0b0b10;
  --ink:         #111118;
  --ink-light:   #1a1a24;
  --slate:       #2a2a3a;
  --ash:         #6e6e82;
  --smoke:       #a0a0b4;
  --chalk:       #e8e8f0;
  --magenta:     #e8365d;
  --magenta-signal: #FF2E7E;
  --magenta-dim: rgba(232,54,93,0.25);
  --warm-white:  #F2ECE0;
  --cyan:        #3de8c8;
  --amber:       #f0a030;
  --red:         #e04050;

  /* Typography */
  --font-display: 'Fraunces', serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Sizes */
  --top-bar-h: 56px;
  --rail-w:    260px;
  --prompt-h:  72px;
  --transport-h: 56px;
}

/* ===== BASE ===== */
html, body {
  height: 100%;
  background: var(--ink);
  color: var(--chalk);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Film grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.04;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

/* Vignette */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
}

/* ===== APP SHELL — MOBILE FIRST (single column) ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ===== TOP BAR ===== */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--top-bar-h);
  padding: 0 16px;
  background: var(--ink-deep);
  border-bottom: 1px solid var(--slate);
  flex-shrink: 0;
  z-index: 10;
}

#btn-menu {
  background: none;
  border: none;
  color: var(--chalk);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.spiral {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  animation: spiral-breathe 4s ease-in-out infinite;
}
.wordmark-text {
  font-family: var(--font-display);
  font-weight: 900;
  font-style: italic;
  font-size: 26px;
  letter-spacing: -0.025em;
  line-height: 1;
}
.wordmark-text .up      { color: var(--warm-white); }
.wordmark-text .seq     { color: var(--magenta-signal); }

@keyframes spiral-breathe {
  0%, 100% { transform: rotate(0deg);   opacity: 0.9; }
  50%      { transform: rotate(180deg); opacity: 1;   }
}

/* Status pill */
#status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 4px 12px;
  border: 1px solid var(--slate);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  flex-shrink: 0;
}

.pill-dot.ready { background: var(--cyan); }
.pill-dot.working { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.pill-dot.playing { background: var(--magenta); animation: pulse 1.2s ease-in-out infinite; }
.pill-dot.error { background: var(--amber); }
.pill-dot.failed { background: var(--red); }
.pill-dot.reverting { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }

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

.family-crest {
  display: none; /* shown on desktop */
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--ash);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ===== SESSION PANEL / DRAWER ===== */
#panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
  transition: opacity 0.2s;
}
#panel-overlay.hidden { display: none; }

#panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: var(--ink-deep);
  border-right: 1px solid var(--slate);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s ease;
}

#panel.hidden {
  transform: translateX(-100%);
  pointer-events: none;
}

#btn-drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--ash);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  z-index: 1;
}
#btn-drawer-close:hover { color: var(--chalk); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--slate);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ash);
}

#btn-new {
  background: transparent;
  color: var(--magenta);
  border: 1px solid var(--magenta);
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
}
#btn-new:hover {
  background: var(--magenta);
  color: #fff;
}

#session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

/* Custom scrollbar on session list */
#session-list::-webkit-scrollbar { width: 4px; }
#session-list::-webkit-scrollbar-track { background: transparent; }
#session-list::-webkit-scrollbar-thumb { background: var(--slate); border-radius: 2px; }

.session-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(42,42,58,0.5);
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.session-item:hover {
  background: rgba(255,255,255,0.03);
}

.session-item.active {
  background: var(--magenta-dim);
  border-left-color: var(--magenta);
}

.session-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--chalk);
}

.session-meta {
  font-size: 11px;
  color: var(--ash);
  margin-top: 2px;
}

.session-empty {
  padding: 24px 16px;
  color: var(--ash);
  font-size: 13px;
  text-align: center;
}

/* ===== MAIN STAGE ===== */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.stage-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Strudel REPL area */
#iframe-wrap {
  position: relative;
  flex-shrink: 0;
  height: 35vh;
  min-height: 180px;
  min-width: 0;
  overflow: hidden;
  background: var(--ink-deep);
  border-bottom: 1px solid var(--slate);
}

#strudel-editor { display: none; }

#iframe-wrap > div:not(#iframe-placeholder) {
  width: 100%;
  height: 100%;
  overflow: auto;
}

#iframe-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ash);
  font-size: 13px;
  text-align: center;
  padding: 20px;
  font-family: var(--font-mono);
}

#iframe-wrap.loaded #iframe-placeholder { display: none; }

/* Maximize / restore button */
#btn-maximize {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 28px;
  height: 28px;
  background: rgba(11, 11, 16, 0.7);
  border: 1px solid var(--slate);
  border-radius: 4px;
  color: var(--smoke);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
#btn-maximize:hover {
  color: var(--chalk);
  border-color: var(--smoke);
  background: rgba(11, 11, 16, 0.9);
}

/* === MAXIMIZED STATE === */
#app.maximized .top-bar,
#app.maximized #panel,
#app.maximized #panel-overlay,
#app.maximized #chat {
  display: none !important;
}

#app.maximized {
  display: flex !important;
  flex-direction: column !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
}

#app.maximized .stage {
  flex: 1;
  grid-column: auto;
  grid-row: auto;
}

#app.maximized .stage-body {
  flex: 1;
}

#app.maximized #iframe-wrap {
  flex: 1;
  height: auto;
  min-height: 0;
}

#app.maximized .prompt-bar {
  grid-column: auto;
  grid-row: auto;
}

/* Submit edit button */
#btn-submit-edit {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 5;
  background: var(--ink-deep);
  color: var(--magenta);
  border: 1px solid var(--magenta);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  display: none;
  transition: background 0.15s, color 0.15s;
}
#btn-submit-edit:hover {
  background: var(--magenta);
  color: #fff;
}

/* Transport row */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: var(--transport-h);
  background: var(--ink-deep);
  border-top: 1px solid var(--slate);
  flex-shrink: 0;
}

#btn-play, #btn-stop {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}

#btn-play {
  background: var(--magenta);
  color: #fff;
}

.pause-icon {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 14px;
}
.pause-icon::before,
.pause-icon::after {
  content: '';
  display: block;
  width: 3px;
  height: 12px;
  background: #fff;
  border-radius: 1px;
}
#btn-play:hover {
  transform: scale(1.1);
  box-shadow: 0 0 16px var(--magenta-dim);
}

#btn-stop {
  background: var(--ink-light);
  color: var(--smoke);
  border: 1px solid var(--slate);
}
#btn-stop:hover {
  background: var(--slate);
  color: var(--chalk);
}

/* Chat */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb { background: var(--slate); border-radius: 2px; }

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.chat-text {
  flex: 1;
  min-width: 0;
}

.chat-msg .prompt {
  color: var(--chalk);
}

.chat-msg .prompt::before {
  content: "> ";
  color: var(--magenta);
}

.chat-msg .result {
  color: var(--ash);
  font-size: 12px;
  margin-top: 2px;
}

.chat-msg .result.err {
  color: var(--red);
}

/* In-progress spinner (reuses spiral SVG) */
.chat-spinner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--ash);
  font-size: 12px;
}
.chat-spinner .spiral {
  width: 18px;
  height: 18px;
}
.spinner-status {
  color: var(--ash);
  font-size: 11px;
  letter-spacing: 0.06em;
  font-style: italic;
}

.chat-actions {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding-top: 1px;
}

.btn-revert, .btn-undo {
  background: none;
  border: 1px solid var(--slate);
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-revert:hover:not(:disabled) {
  color: var(--chalk);
  border-color: var(--smoke);
}

.btn-revert:disabled, .btn-undo:disabled {
  opacity: 0.3;
  cursor: default;
}

.btn-undo {
  border-color: var(--magenta);
  color: var(--magenta);
}

.btn-undo:hover:not(:disabled) {
  background: var(--magenta-dim);
  color: #fff;
}

/* ===== PROMPT BAR ===== */
.prompt-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--prompt-h);
  background: linear-gradient(180deg, var(--ink-light) 0%, var(--ink-deep) 100%);
  border-top: 1px solid var(--slate);
  flex-shrink: 0;
}

.prompt-caret {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--magenta);
  flex-shrink: 0;
  line-height: 1;
}

.prompt-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.prompt-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ash);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#prompt-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--chalk);
  font-family: var(--font-mono);
  font-size: 15px;
  padding: 4px 0;
  outline: none;
  caret-color: var(--magenta);
}

#prompt-input::placeholder {
  color: var(--ash);
}

#prompt-input:focus {
  outline: none;
}

.enter-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ash);
  flex-shrink: 0;
  white-space: nowrap;
}

.enter-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border: 1px solid var(--slate);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--smoke);
  line-height: 1;
}

/* ===== FOCUS VISIBLE ===== */
:focus-visible {
  outline: 2px solid var(--magenta);
  outline-offset: 2px;
}

#prompt-input:focus-visible {
  outline: none;
}

/* ===== DESKTOP LAYOUT (≥880px) ===== */
@media (min-width: 880px) {
  #app {
    display: grid;
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: var(--top-bar-h) 1fr var(--prompt-h);
    max-width: none;
  }

  /* Top bar spans full width */
  .top-bar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  /* Panel is always visible as rail */
  #panel {
    position: static;
    grid-column: 1;
    grid-row: 2 / 4; /* rail + prompt rows */
    width: auto;
    max-width: none;
    z-index: auto;
    transform: none !important;
    pointer-events: auto !important;
    border-right: 1px solid var(--slate);
    border-top: none;
  }

  #panel.hidden {
    transform: none;
    pointer-events: auto;
  }

  #panel-overlay { display: none !important; }
  #btn-menu { display: none; }
  #btn-drawer-close { display: none; }

  .family-crest { display: block; }

  .stage {
    grid-column: 2;
    grid-row: 2;
  }

  .prompt-bar {
    grid-column: 2;
    grid-row: 3;
  }

  /* Bigger strudel area on desktop */
  #iframe-wrap {
    height: 45vh;
  }

  #prompt-input {
    font-size: 16px;
  }
}

/* ===== MOBILE TWEAKS (<880px) ===== */
@media (max-width: 879px) {
  .family-crest { display: none; }

  /* Compact status pill on mobile */
  #status-pill {
    padding: 3px 8px;
    font-size: 10px;
  }

  .pill-dot {
    width: 6px;
    height: 6px;
  }

  /* Prevent iOS zoom on input focus */
  #prompt-input {
    font-size: 16px;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .pill-dot { animation: none !important; }
  .spiral { animation: none !important; }
  #panel { transition: none; }
}
