/* ==========================================================================
   Zudo Terminal Playground
   A docked terminal: TypeScript editor on top, terminal output below.
   Catppuccin Mocha inside a brutalist frame.
   ========================================================================== */

:root {
  --pg-w: 620px;
  --pg-h: 62vh;
}

/* ---------- launcher ---------- */

.pg-launch {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 70;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  height: 46px;
  padding: 0 1rem 0 0.85rem;
  background: #1E1E2E;
  color: #CDD6F4;
  border: 2px solid #C0392B;
  box-shadow: 4px 4px 0 #C0392B;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.pg-launch:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #C0392B;
}

.pg-launch:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #C0392B;
}

.pg-launch .pg-launch-prompt { color: #A6E3A1; }
.pg-launch .pg-launch-cursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  background: #CDD6F4;
  animation: pg-blink 1s step-end infinite;
}

.pg-launch kbd {
  font-family: inherit;
  font-size: 0.6rem;
  color: #9399B2;
  border: 1px solid #45475A;
  padding: 1px 4px;
  margin-left: 0.25rem;
}

@keyframes pg-blink { 50% { opacity: 0; } }

body.pg-open .pg-launch { display: none; }

@media (max-width: 640px) {
  .pg-launch { right: 16px; bottom: 16px; }
  .pg-launch kbd { display: none; }
}

/* ---------- panel ---------- */

.pg {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 80;
  margin: 0;
  width: min(var(--pg-w), 100vw);
  height: min(var(--pg-h), calc(100vh - var(--z-nav-h, 64px)));
  min-width: 380px;
  min-height: 300px;
  display: none;
  flex-direction: column;
  background: #1E1E2E;
  color: #CDD6F4;
  border-top: 3px solid #C0392B;
  border-left: 3px solid #C0392B;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  box-shadow: -8px -8px 0 rgba(26, 26, 46, 0.18);
}

.pg.is-open { display: flex; }

.pg.is-max {
  width: 100vw;
  height: calc(100vh - var(--z-nav-h, 64px));
  border-left: none;
  box-shadow: none;
}

@media (max-width: 640px) {
  .pg {
    width: 100vw;
    min-width: 0;
    height: 72vh;
    border-left: none;
  }
}

/* resize handles */
.pg-rz {
  position: absolute;
  z-index: 5;
  background: transparent;
}
.pg-rz-t { top: -3px; left: 0; right: 0; height: 8px; cursor: ns-resize; }
.pg-rz-l { top: 0; left: -3px; bottom: 0; width: 8px; cursor: ew-resize; }
.pg-rz-c { top: -3px; left: -3px; width: 16px; height: 16px; cursor: nwse-resize; }
.pg.is-max .pg-rz, body.pg-resizing * { user-select: none; }
.pg.is-max .pg-rz { display: none; }
@media (max-width: 640px) { .pg-rz-l, .pg-rz-c { display: none; } }

/* ---------- title bar ---------- */

.pg-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 42px;
  padding: 0 0.5rem 0 0.75rem;
  background: #181825;
  border-bottom: 2px solid #313244;
  flex-shrink: 0;
}

.pg-dots { display: flex; gap: 5px; margin-right: 0.35rem; }
.pg-dots span { width: 10px; height: 10px; display: block; }
.pg-dots span:nth-child(1) { background: #C0392B; }
.pg-dots span:nth-child(2) { background: #D4AC0D; }
.pg-dots span:nth-child(3) { background: #1E8449; }

.pg-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #A6ADC8;
  white-space: nowrap;
}

.pg-title .pg-file {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: #CDD6F4;
  background: #313244;
  padding: 3px 8px;
  border-left: 2px solid #89B4FA;
}

.pg-title .pg-file.is-dirty::after { content: ' •'; color: #F9E2AF; }

.pg-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.pg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 28px;
  padding: 0 0.6rem;
  background: transparent;
  color: #A6ADC8;
  border: 2px solid #45475A;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}

.pg-btn:hover { background: #45475A; color: #FFFFFF; }
.pg-btn svg { width: 13px; height: 13px; }
.pg-btn--icon { width: 28px; padding: 0; }

.pg-btn--run { border-color: #A6E3A1; color: #A6E3A1; }
.pg-btn--run:hover { background: #A6E3A1; color: #1E1E2E; }
.pg-btn--run[disabled] { opacity: 0.5; cursor: progress; }

.pg-btn--close:hover { background: #F38BA8; border-color: #F38BA8; color: #1E1E2E; }

.pg-select {
  height: 28px;
  padding: 0 1.6rem 0 0.5rem;
  background: #313244 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A6ADC8' stroke-width='3' stroke-linecap='square'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 6px center / 12px;
  color: #CDD6F4;
  border: 2px solid #45475A;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  max-width: 150px;
}

.pg-select:hover { border-color: #6C7086; }

.pg-tools .pg-hide-sm { display: none; }
@media (min-width: 520px) { .pg-tools .pg-hide-sm { display: inline-flex; } }

/* ---------- body: editor + output ---------- */

.pg-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pg.is-side .pg-body { flex-direction: row; }

.pg-editor {
  position: relative;
  flex: 1 1 60%;
  min-height: 0;
  min-width: 0;
  display: flex;
  overflow: hidden;
  background: #1E1E2E;
}

.pg.is-side .pg-editor { border-right: 2px solid #313244; }

.pg-gutter {
  flex-shrink: 0;
  width: 3.2em;
  padding: 12px 0;
  background: #181825;
  color: #45475A;
  font-size: 0.8rem;
  line-height: 1.7;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid #313244;
}

.pg-gutter div { padding-right: 0.8em; }
.pg-gutter div.is-cur { color: #A6ADC8; background: #1E1E2E; }

.pg-code {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.pg-hl,
.pg-ta {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 16px 12px 14px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
  overflow: auto;
  letter-spacing: 0;
}

.pg-hl {
  pointer-events: none;
  color: #CDD6F4;
  overflow: hidden;
}

.pg-hl code { font: inherit; display: block; min-height: 100%; }

.pg-ta {
  background: transparent;
  color: transparent;
  caret-color: #F5E0DC;
  border: none;
  outline: none;
  resize: none;
  -webkit-text-fill-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: #45475A #1E1E2E;
}

.pg-ta::selection { background: rgba(137, 180, 250, 0.3); -webkit-text-fill-color: transparent; }
.pg-ta::placeholder { color: #9399B2; -webkit-text-fill-color: #9399B2; }

/* token colors (Catppuccin Mocha) */
.pg-hl .t-kw  { color: #CBA6F7; }
.pg-hl .t-str { color: #A6E3A1; }
.pg-hl .t-tpl { color: #A6E3A1; }
.pg-hl .t-cmt { color: #9399B2; font-style: italic; }
.pg-hl .t-num { color: #FAB387; }
.pg-hl .t-fn  { color: #89B4FA; }
.pg-hl .t-ty  { color: #89DCEB; }
.pg-hl .t-op  { color: #94E2D5; }
.pg-hl .t-pn  { color: #9399B2; }
.pg-hl .t-cn  { color: #F38BA8; }
.pg-hl .t-dec { color: #F9E2AF; }
.pg-hl .t-prop { color: #B4BEFE; }

/* output */
.pg-out {
  flex: 1 1 40%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-top: 2px solid #313244;
  background: #11111B;
}

.pg.is-side .pg-out { border-top: none; }

.pg-out-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 28px;
  padding: 0 0.5rem 0 0.75rem;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.pg-out-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #9399B2;
}

.pg-out-count {
  font-size: 0.62rem;
  color: #45475A;
}

.pg-out-head .pg-btn { height: 20px; font-size: 0.55rem; padding: 0 0.4rem; border-width: 1px; margin-left: auto; }

.pg-term {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: #45475A #11111B;
}

.pg-line {
  display: flex;
  gap: 0.6rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.pg-line .pg-sig {
  flex-shrink: 0;
  width: 1.2em;
  text-align: center;
  color: #45475A;
  user-select: none;
}

.pg-line-log   { color: #CDD6F4; }
.pg-line-info  { color: #89B4FA; }
.pg-line-info  .pg-sig { color: #89B4FA; }
.pg-line-warn  { color: #F9E2AF; }
.pg-line-warn  .pg-sig { color: #F9E2AF; }
.pg-line-error { color: #F38BA8; }
.pg-line-error .pg-sig { color: #F38BA8; }
.pg-line-debug { color: #9399B2; }
.pg-line-cmd   { color: #A6E3A1; }
.pg-line-cmd   .pg-sig { color: #A6E3A1; }
.pg-line-sys   { color: #9399B2; font-style: italic; }
.pg-line-ok    { color: #A6E3A1; }
.pg-line-ok    .pg-sig { color: #A6E3A1; }
.pg-line-ret   { color: #F5C2E7; }
.pg-line-ret   .pg-sig { color: #F5C2E7; }
.pg-line-stack { color: #9399B2; padding-left: 1.8em; font-size: 0.72rem; }

.pg-line + .pg-line-cmd { margin-top: 0.5rem; }

.pg-table {
  border-collapse: collapse;
  margin: 4px 0 4px 1.8em;
  font-size: 0.72rem;
}
.pg-table th, .pg-table td { border: 1px solid #313244; padding: 2px 8px; text-align: left; }
.pg-table th { background: #181825; color: #A6ADC8; font-weight: 700; }

.pg-empty {
  color: #45475A;
  font-style: italic;
}

/* ---------- status bar ---------- */

.pg-status {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 26px;
  padding: 0 0.75rem;
  background: #181825;
  border-top: 2px solid #313244;
  font-size: 0.62rem;
  color: #9399B2;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
}

.pg-status .pg-lang {
  color: #1E1E2E;
  background: #89B4FA;
  font-weight: 800;
  padding: 1px 5px;
  letter-spacing: 0.05em;
}

.pg-status .pg-state { display: inline-flex; align-items: center; gap: 0.35rem; color: #A6ADC8; }
.pg-status .pg-state::before { content: ''; width: 7px; height: 7px; background: #A6E3A1; }
.pg-status .pg-state[data-state="busy"]::before { background: #F9E2AF; animation: pg-blink 0.6s step-end infinite; }
.pg-status .pg-state[data-state="error"]::before { background: #F38BA8; }

.pg-status .pg-hint { margin-left: auto; display: none; gap: 0.75rem; }
.pg-status .pg-hint kbd { font-family: inherit; color: #A6ADC8; }
@media (min-width: 560px) { .pg-status .pg-hint { display: inline-flex; } }

/* toast */
.pg-toast {
  position: absolute;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  background: #A6E3A1;
  color: #1E1E2E;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border: 2px solid #1E1E2E;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
  z-index: 6;
}
.pg-toast.is-on { opacity: 1; }
