:root {
  --desktop-bg: #05080f;
  --topbar-bg: rgba(13, 17, 23, 0.92);
  --terminal-bg: #0b0f17;
  --hud-bg: rgba(11, 15, 23, 0.78);
  --border-slate: #1e293b;
  --cyan-accent: #38bdf8;
  --green-accent: #4ade80;
  --amber-ember: #F5C76B;
  --electric-cyan: #4FE3E8;
  --sky-zenith: #070B14;
  --river-abyss: #0A1322;
  --text-primary: #e2e8f0;
  --text-muted: #94a3b8;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--desktop-bg);
  color: var(--text-primary);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
}

.desktop-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 20% 0%, #111827 0%, #05080f 65%);
}

/* 1. OS Top Status Bar */
.os-topbar {
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border-slate);
  backdrop-filter: blur(8px);
  font-size: 0.75rem;
  user-select: none;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.topbar-right {
  justify-content: flex-end;
}

.topbar-center {
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
}

.path-user {
  color: var(--green-accent);
  font-weight: 500;
}

.path-sep {
  color: var(--text-muted);
}

.path-dir {
  color: var(--cyan-accent);
}

.workspace-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.32);
  color: var(--cyan-accent);
  font-weight: 500;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-accent);
}

.topbar-tag {
  color: var(--text-muted);
}

.telemetry-badge,
.clock-badge {
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-slate);
  color: var(--text-muted);
  white-space: nowrap;
}

.clock-badge {
  color: var(--text-primary);
  font-weight: 500;
}

/* 2. Terminal Window Frame */
.desktop-workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  padding: 0.65rem;
}

.terminal-window {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--terminal-bg);
  border: 1px solid var(--border-slate);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.window-header {
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.75rem;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid var(--border-slate);
  user-select: none;
}

.window-dots {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-close { background: #ff5f56; }
.dot-min { background: #ffbd2e; }
.dot-max { background: #27c93f; }

.window-title {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.window-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.win-btn {
  appearance: none;
  background: var(--terminal-bg);
  border: 1px solid var(--border-slate);
  border-radius: 4px;
  padding: 0.12rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}

.win-btn:hover,
.win-btn.is-active {
  color: var(--cyan-accent);
  border-color: rgba(56, 189, 248, 0.5);
}

.win-btn:focus-visible,
.flag-btn:focus-visible,
.zsh-action-btn:focus-visible,
.hud-mini-btn:focus-visible {
  outline: 2px solid var(--cyan-accent);
  outline-offset: 2px;
}

/* Main Interactive Canvas Area */
.terminal-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--sky-zenith);
}

.stage-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.stage-canvas.is-sky-hover {
  cursor: crosshair;
}

.stage-canvas.is-river-hover {
  cursor: pointer;
}

.launch-hint {
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  background: rgba(11, 15, 23, 0.65);
  border: 1px solid var(--border-slate);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: calc(100% - 2rem);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: opacity 500ms ease;
}

.launch-hint.is-hidden {
  opacity: 0;
}

/* 4. HUD Overlays */
.hud-panel {
  background: var(--hud-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border-slate);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
}

.hud-logs {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  width: min(360px, calc(100% - 1.5rem));
  min-width: 240px;
  max-width: calc(100% - 1.5rem);
  max-height: 38%;
  min-height: 96px;
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
  resize: both;
  overflow: hidden;
  z-index: 4;
}

.hud-logs.is-expanded {
  width: min(560px, calc(100% - 1.5rem));
  max-height: 68%;
}

.hud-logs.is-hidden {
  display: none;
}

.friend-banner {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  max-width: min(420px, calc(100% - 1.5rem));
  padding: 0.55rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 5;
}

.friend-banner.is-hidden {
  display: none;
}

.friend-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.friend-banner-title {
  font-size: 0.72rem;
  color: var(--amber-ember);
  font-weight: 500;
}

.friend-banner-wish {
  font-size: 0.78rem;
  color: var(--text-primary);
  word-break: break-word;
}

.friend-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.seo-heading {
  margin: 0 0 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--cyan-accent);
}

.hud-panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.35rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-slate);
}

.hud-header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.hud-panel-title {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--cyan-accent);
}

.hud-mini-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border-slate);
  border-radius: 4px;
  padding: 0.08rem 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  cursor: pointer;
}

.hud-mini-btn:hover,
.hud-mini-btn.is-active {
  color: var(--cyan-accent);
  border-color: var(--cyan-accent);
}

.log-list {
  flex: 1 1 auto;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0 0.2rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.72rem;
  line-height: 1.4;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-slate) transparent;
}

.log-item {
  color: var(--text-muted);
  white-space: normal;
  word-break: break-word;
}

.log-time {
  color: #64748b;
  margin-right: 0.35rem;
}

.log-verb {
  color: var(--green-accent);
}

/* 3. Zsh Two-Line Command Input */
.zsh-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem 0.65rem;
  background: var(--terminal-bg);
  border-top: 1px solid var(--border-slate);
}

.zsh-line-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.76rem;
}

.zsh-prompt-top {
  white-space: nowrap;
  user-select: none;
}

.zsh-box {
  color: var(--cyan-accent);
}

.zsh-user {
  color: var(--green-accent);
  font-weight: 500;
}

.zsh-path {
  color: var(--cyan-accent);
  font-weight: 500;
}

.zsh-flags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.flag-sep {
  color: var(--border-slate);
  margin: 0 0.15rem;
}

.flag-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.14rem 0.38rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.flag-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-slate);
}

.flag-btn.is-active {
  color: var(--amber-ember);
  border-color: rgba(245, 199, 107, 0.45);
  background: rgba(245, 199, 107, 0.08);
}

.zsh-line-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.zsh-prompt-symbol {
  flex: 0 0 auto;
  font-size: 0.8rem;
  white-space: nowrap;
  user-select: none;
}

.zsh-hash {
  color: var(--green-accent);
  font-weight: 600;
}

.zsh-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--terminal-bg);
  border: 1px solid var(--border-slate);
  border-radius: 4px;
  padding: 0.36rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.zsh-input::placeholder {
  color: #475569;
}

.zsh-input:focus {
  outline: none;
  border-color: var(--cyan-accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.28);
}

.zsh-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.zsh-action-btn {
  appearance: none;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-slate);
  border-radius: 4px;
  padding: 0.36rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}

.zsh-action-btn:hover {
  border-color: var(--cyan-accent);
  color: var(--cyan-accent);
}

.zsh-action-btn.is-primary {
  border-color: rgba(56, 189, 248, 0.55);
  color: var(--cyan-accent);
  background: rgba(56, 189, 248, 0.1);
}

.zsh-action-btn.is-primary:hover {
  background: rgba(56, 189, 248, 0.2);
}

/* Modal Dialog & Dynamic ASCII <pre> */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(5, 8, 15, 0.68);
  z-index: 20;
}

.modal-backdrop.is-hidden {
  display: none;
}

.modal-dialog {
  width: min(520px, 100%);
  padding: 0.85rem 1rem;
}

.ascii-banner {
  margin: 0.35rem 0 0.75rem;
  padding: 0.55rem 0.7rem;
  background: rgba(5, 8, 15, 0.75);
  border: 1px solid var(--border-slate);
  border-radius: 4px;
  color: var(--cyan-accent);
  font-family: var(--font-mono);
  font-size: clamp(0.48rem, 1.8vw, 0.75rem);
  line-height: 1.2;
  overflow-x: auto;
}

.modal-body {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-desc {
  margin: 0 0 0.65rem;
  color: var(--text-primary);
}

.cmd-help-list {
  margin: 0;
  padding-left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cmd-help-list code {
  color: var(--green-accent);
}

/* 5. Responsive Rules (< 640px) */
@media (max-width: 640px) {
  .os-topbar {
    grid-template-columns: auto 1fr auto;
    padding: 0 0.5rem;
    gap: 0.4rem;
    font-size: 0.68rem;
  }

  .topbar-tag,
  #telemetry-entities {
    display: none;
  }

  .desktop-workspace {
    padding: 0.35rem;
  }

  .window-title {
    font-size: 0.68rem;
  }

  .hud-logs {
    width: calc(100% - 1rem);
    top: 0.5rem;
    left: 0.5rem;
  }

  .zsh-bar {
    padding: 0.45rem 0.55rem 0.55rem;
    gap: 0.4rem;
  }

  .zsh-line-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .zsh-line-input {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .zsh-input {
    flex: 1 1 calc(100% - 2.6rem);
    font-size: 0.78rem;
  }

  .zsh-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .zsh-action-btn {
    flex: 1 1 0;
    text-align: center;
    padding: 0.38rem 0.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .launch-hint,
  .win-btn,
  .flag-btn,
  .zsh-input,
  .zsh-action-btn {
    transition: none;
  }
}
