/* =========================================================================
   GianOS — Terminal app styles
   Committed dark in-fiction palette (this app only; not global dark mode).
   Deep phosphor terminal aesthetic: green/amber on near-black, Geist Mono.
   All colors OKLCH only. Scoped under .app-screen[data-app=terminal] and
   body[data-app=terminal] overrides for statusbar + app-head.

   Contrast: --term-text on --term-bg ≥ 4.5:1 (verified: ~7.8:1 at these
   oklch values). --term-amber on --term-bg ≥ 4.5:1 (~5.1:1).

   These tokens are fixed — they do not follow --seed (Terminal's art direction
   is deliberately immune to the theme toy, per plan).
   ========================================================================= */

/* ---- dark statusbar override when Terminal is the active app ------------ */
body[data-app="terminal"] {
  --statusbar-ink: oklch(0.88 0.08 150);   /* phosphor green, light enough to read */
  --statusbar-bg:  oklch(0.14 0.02 150 / 0.92);
}

/* ---- app-head dark variant -------------------------------------------- */
/* iOS: translucent dark glass. Android: dark tonal surface.
   Both override the shared .app-head which inherits the warm-paper theme. */
.app-screen[data-app="terminal"] .app-head {
  background: oklch(0.16 0.025 150 / 0.96);
  border-bottom-color: oklch(0.30 0.06 150 / 0.4);
  backdrop-filter: blur(16px) saturate(1.2);
  color: oklch(0.85 0.08 150);
}
.app-screen[data-app="terminal"] .app-head__back {
  color: oklch(0.70 0.12 150);
}
.app-screen[data-app="terminal"] .app-head__back:hover {
  color: oklch(0.88 0.10 150);
}
.app-screen[data-app="terminal"] .app-head__title {
  color: oklch(0.88 0.08 150);
}

/* Android tonal variant */
body[data-os="android"] .app-screen[data-app="terminal"] .app-head {
  background: oklch(0.18 0.025 150 / 0.98);
  border-bottom-color: oklch(0.28 0.06 150 / 0.5);
}

/* ---- Terminal screen surface ------------------------------------------ */
.app-screen[data-app="terminal"] {
  /* scoped token palette — immune to --seed */
  --term-bg:        oklch(0.18 0.02 150);   /* deep green-black */
  --term-surface:   oklch(0.22 0.025 150);  /* slightly lighter for UI elements */
  --term-text:      oklch(0.82 0.10 150);   /* phosphor green — main text */
  --term-text-dim:  oklch(0.60 0.07 150);   /* dimmer for secondary info */
  --term-amber:     oklch(0.78 0.14 85);    /* amber for emphasis / dirs */
  --term-prompt:    oklch(0.72 0.12 150);   /* prompt prefix */
  --term-line:      oklch(0.28 0.04 150 / 0.6);
  --term-chip-bg:   oklch(0.24 0.03 150);
  --term-chip-border: oklch(0.38 0.07 150 / 0.7);
  --term-selection: oklch(0.40 0.09 150 / 0.5);
}

.app-screen[data-app="terminal"] .app-body {
  background: var(--term-bg);
  color: var(--term-text);
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
}

/* selection */
.app-screen[data-app="terminal"] ::selection {
  background: var(--term-selection);
  color: var(--term-text);
}

/* ---- scrollback log ---------------------------------------------------- */
.term-scrollback {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  font-size: 0.84rem;
  line-height: 1.6;
  /* smooth scroll unless reduced motion */
  scroll-behavior: smooth;
  /* extra bottom padding so last line never hides behind prompt bar */
  padding-bottom: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .term-scrollback { scroll-behavior: auto; }
}

/* ---- output lines ------------------------------------------------------ */
.term-line {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  color: var(--term-text);
  min-height: 1.1em;   /* blank lines have height */
}

/* dimmed decorative lines (e.g. separators, hints) */
.term-line--dim { color: var(--term-text-dim); }

/* amber tinted lines: directories, emphasis */
.term-line--amber { color: var(--term-amber); }

/* error / not-found lines */
.term-line--err { color: oklch(0.72 0.18 30); }

/* command echo (what the user "typed") */
.term-line--cmd {
  color: var(--term-prompt);
  font-weight: 500;
}

/* key: value alignment helper — spans inside .term-line */
.term-kv {
  display: inline-grid;
  grid-template-columns: 10ch 1fr;
  gap: 0 0.5ch;
  width: 100%;
}
.term-kv__k { color: var(--term-amber); }
.term-kv__v { color: var(--term-text); }

/* spacer between command blocks */
.term-spacer { display: block; height: 0.6em; }

/* ---- prompt row -------------------------------------------------------- */
.term-prompt-row {
  position: relative;   /* anchors the transparent .term-input overlay */
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.55rem 1rem 0.5rem;
  border-top: 1px solid var(--term-line);
  background: var(--term-bg);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 500;
  /* sticky bottom; safe-area respected */
  padding-bottom: max(0.55rem, env(safe-area-inset-bottom));
}

/* Focus cue: when the real input has focus, the whole prompt line reads as
   the active field (the block cursor already signals "here"; this adds an
   AT/keyboard-visible ring around the row without disturbing the phosphor look). */
.term-prompt-row:focus-within {
  outline: 1px solid var(--term-amber);
  outline-offset: 2px;
  border-radius: 2px;
}

.term-prompt-prefix {
  color: var(--term-prompt);
  white-space: nowrap;
  flex: 0 0 auto;
  margin-right: 0.5ch;
  user-select: none;
}

.term-input-buffer {
  flex: 1 1 auto;
  color: var(--term-text);
  font-family: inherit;
  font-size: inherit;
  white-space: pre;
  letter-spacing: inherit;
  min-width: 0;
  /* visual mirror of the real input; the block cursor renders the caret */
}

/* The real, focusable input home. Laid over the prompt row and made fully
   transparent (text, caret, background, border) so the visible affordance
   stays the phosphor display span + block cursor. It still receives focus,
   clicks, and physical keys, and carries the accessible label. Its own
   selection/caret never show; the display span above renders the text. */
.term-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;          /* hide the input's own glyphs */
  caret-color: transparent;    /* hide the native caret; block cursor stands in */
  font: inherit;
  letter-spacing: inherit;
  outline: none;               /* focus is shown on .term-prompt-row:focus-within */
  /* keep native selection invisible so only the display span reads */
  -webkit-text-fill-color: transparent;
}
.term-input::selection { background: transparent; }
.term-input::-moz-selection { background: transparent; }

/* blinking block cursor — reuses the stream-cursor concept */
.term-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  vertical-align: text-bottom;
  background: var(--term-text);
  margin-left: 0.05em;
  animation: term-blink 1.1s step-start infinite;
}

@keyframes term-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .term-cursor { animation: none; opacity: 1; }
}

/* ---- suggested command chips ------------------------------------------- */
.term-chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0.5rem;
  /* extra right padding parks a partial chip under the fade: the row visibly
     half-cuts the last chip so the h-scroll affordance reads as honest, not
     clipped mid-word by accident (same idiom as Messages' .suggest). */
  padding: 0.5rem 2.6rem calc(1.5rem + max(0.3rem, env(safe-area-inset-bottom))) 1rem;
  scroll-padding-inline: 1rem 2.6rem;
  border-top: 1px solid var(--term-line);
  background: var(--term-surface);
  /* hide scrollbar but keep scrollable */
  scrollbar-width: none;
  /* stronger end fade so the cut chip reads as "more to scroll" */
  -webkit-mask-image: linear-gradient(to right, transparent, #000 0.6rem, #000 calc(100% - 2.8rem), transparent);
          mask-image: linear-gradient(to right, transparent, #000 0.6rem, #000 calc(100% - 2.8rem), transparent);
}
.term-chips::-webkit-scrollbar { display: none; }

.term-chip {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--term-text);
  background: var(--term-chip-bg);
  border: 1px solid var(--term-chip-border);
  border-radius: 0.35rem;
  padding: 0.28rem 0.65rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease), transform 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.term-chip:hover {
  background: oklch(0.28 0.05 150);
  border-color: oklch(0.50 0.10 150 / 0.8);
  color: oklch(0.90 0.10 150);
}
.term-chip:active { transform: scale(0.96); }
.term-chip:focus-visible {
  outline: 2px solid var(--term-amber);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .term-chip { transition: none; }
}

/* ---- app-head typing indicator (optional) ------------------------------ */
/* reuse the existing .stream-cursor CSS pattern; no new keyframe needed */

/* phone tier: the tablet scaffold is inert. .term-main is display:contents so
   scrollback + prompt row sit directly in the .app-body column flow exactly
   as before this wrapper existed; the info pane is hidden outright. */
.term-main { display: contents; }
.term-info { display: none; }

/* =========================================================================
   TABLET TIER — @container device (min-width: 700px)
   tmux-style split: scrollback (capped ~80-90ch, left) beside a static
   framed kv panel (~18-20rem, right) that reads like a pinned session pane,
   not a duplicate of the streamed `gian --stack` output. Phone stays
   pixel-identical below the threshold — this block only adds rules.
   ========================================================================= */
@container device (min-width: 700px) {
  .app-screen[data-app="terminal"] .app-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 20rem);
    grid-template-rows: 1fr auto;
    align-items: stretch;
    height: 100%;
  }

  .term-main {
    display: flex;
    flex-direction: column;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--term-line);
  }

  /* cap scrollback measure so long lines stay readable, left-aligned in the
     freed column rather than stretching edge to edge */
  .term-scrollback {
    max-width: 88ch;
    width: 100%;
  }
  .term-prompt-row { max-width: 88ch; }

  .term-chips {
    grid-column: 1 / -1;
    grid-row: 2;
    /* room freed by the split lets suggestions wrap into rows instead of
       scrolling — no more half-cut chip, so the phone-only fade backs off */
    flex-wrap: wrap;
    overflow-x: visible;
    padding: 0.6rem 1.2rem calc(1.3rem + max(0.3rem, env(safe-area-inset-bottom)));
    -webkit-mask-image: none;
            mask-image: none;
  }

  /* ---- info pane: tmux-style framed session summary --------------------- */
  .term-info {
    display: flex;
    flex-direction: column;
    grid-column: 2;
    grid-row: 1;
    min-height: 0;
    padding: 1rem 1.1rem;
    background: var(--term-surface);
    border-left: 1px solid var(--term-line);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.5;
    overflow-y: auto;
  }

  .term-info__head {
    color: var(--term-text-dim);
    text-transform: lowercase;
    letter-spacing: 0.02em;
    padding-bottom: 0.5rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--term-line);
  }

  .term-info__kv {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.7ch;
    row-gap: 0.5rem;
    margin: 0;
  }
  .term-info__k {
    color: var(--term-amber);
    white-space: nowrap;
  }
  .term-info__k::after { content: ":"; }
  .term-info__v {
    margin: 0;
    color: var(--term-text);
    overflow-wrap: break-word;
  }

  .term-info__note {
    margin-top: 0.9rem;
    padding-top: 0.7rem;
    border-top: 1px solid var(--term-line);
    color: var(--term-text-dim);
  }
}
