:root {
  --bg: #010409;
  --terminal-bg: #0d1117;
  --titlebar-bg: #161b22;
  --border: #30363d;
  --panel: #21262d;
  --text: #c9d1d9;
  --text-strong: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --blue: #58a6ff;
  --blue-soft: #79c0ff;
  --green: #3fb950;
  --purple: #bc8cff;
  --accent: #bc8cff;
  --red: #f85149;
  --kb-offset: 0px;
}

body.light-mode {
  --bg: #f6f7fb;
  --terminal-bg: #fcfcfd;
  --titlebar-bg: #eef2f7;
  --border: #cbd5e1;
  --panel: #e2e8f0;
  --text: #334155;
  --text-strong: #0f172a;
  --text-muted: #64748b;
  --text-dim: #748094;
  --blue: #4f46e5;
  --blue-soft: #4338ca;
  --green: #15803d;
  --purple: #4338ca;
  --accent: #312e81;
  --red: #b91c1c;
}

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

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  min-height: 100vh;
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden;
  transition: background 0.2s ease;
}

.page-topbar {
  position: fixed;
  top: 14px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 1200;
}

.theme-toggle {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 40px;
  border-radius: 999px;
  border: 0.5px solid var(--border);
  background: var(--titlebar-bg);
  color: var(--text-strong);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
  position: relative;
}

.theme-toggle:hover {
  background: var(--panel);
}

.theme-toggle:active {
  transform: translateY(1px);
}

.theme-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-sun,
.theme-moon {
  opacity: 0;
  transition: opacity 0.18s ease;
}

body:not(.light-mode) .theme-sun {
  opacity: 1;
}

body.light-mode .theme-moon {
  opacity: 1;
}

.page-footer {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  z-index: 1100;
  pointer-events: none;
}

.app-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.terminal-wrap {
  position: absolute;
  width: 860px;
  height: 720px;
  background: var(--terminal-bg);
  border-radius: 12px;
  border: 0.5px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition:
    border-radius 0.2s ease,
    transform 0.15s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

.terminal-wrap.is-normal {
  border-radius: 12px;
}

.terminal-wrap.is-normal .output-area {
  min-height: 0;
  max-height: none;
  height: auto;
  flex: 1 1 auto;
}

.terminal-wrap.is-minimized {
  width: 248px !important;
  height: auto !important;
  border-radius: 12px;
}

.terminal-wrap.is-minimized .output-area,
.terminal-wrap.is-minimized .input-row,
.terminal-wrap.is-minimized .ac-box,
.terminal-wrap.is-minimized .palette-overlay,
.terminal-wrap.is-minimized .help-btn,
.terminal-wrap.is-minimized .resize-handle {
  display: none;
}

.terminal-wrap.is-minimized .titlebar {
  border-bottom: none;
  padding: 16px 18px;
  cursor: move;
}

.terminal-wrap.is-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw !important;
  height: 100vh !important;
  border-radius: 0;
  border: none;
  z-index: 999;
}

.terminal-wrap.is-fullscreen .output-area {
  min-height: 0;
  max-height: none;
  height: auto;
  flex: 1 1 auto;
}

.terminal-wrap.is-fullscreen .resize-handle {
  display: none;
}

.terminal-wrap.is-hidden {
  display: none;
}

body.terminal-fullscreen .page-topbar,
body.terminal-fullscreen .page-footer {
  display: none;
}

.reopen-btn {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--titlebar-bg);
  border: 0.5px solid var(--border);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  z-index: 1000;
}

.reopen-btn:hover {
  background: var(--panel);
}

.mac-btn {
  border: none;
  padding: 0;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  user-select: none;
  background: transparent;
}

.dots {
  display: flex;
  gap: 7px;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  cursor: default;
}

.dot.red    { background: #ff5f57; }
.dot.yellow { background: #ffbd2e; }
.dot.green  { background: #28c840; }

.dot-glyph {
  font-size: 9px;
  line-height: 1;
  color: rgba(0, 0, 0, 0.65);
  opacity: 0;
  transform: translateY(-0.2px);
  transition: opacity 0.12s ease;
  pointer-events: none;
  font-family: sans-serif;
  position: absolute;
}

.dots:hover .dot-glyph,
.mac-btn:hover .dot-glyph {
  opacity: 1;
}

.titlebar {
  background: var(--titlebar-bg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  cursor: move;
  user-select: none;
}

.mac-btn,
.help-btn,
.palette-close,
.reopen-btn,
.clickable-cmd,
.link-inline {
  user-select: none;
}

.resize-handle {
  position: absolute;
  z-index: 30;
}

.resize-handle.top,
.resize-handle.bottom {
  left: 10px;
  right: 10px;
  height: 10px;
}

.resize-handle.left,
.resize-handle.right {
  top: 10px;
  bottom: 10px;
  width: 10px;
}

.resize-handle.top    { top: -5px; cursor: ns-resize; }
.resize-handle.bottom { bottom: -5px; cursor: ns-resize; }
.resize-handle.left   { left: -5px; cursor: ew-resize; }
.resize-handle.right  { right: -5px; cursor: ew-resize; }

.resize-handle.top-left,
.resize-handle.top-right,
.resize-handle.bottom-left,
.resize-handle.bottom-right {
  width: 14px;
  height: 14px;
}

.resize-handle.top-left {
  top: -7px;
  left: -7px;
  cursor: nwse-resize;
}

.resize-handle.top-right {
  top: -7px;
  right: -7px;
  cursor: nesw-resize;
}

.resize-handle.bottom-left {
  bottom: -7px;
  left: -7px;
  cursor: nesw-resize;
}

.resize-handle.bottom-right {
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}

.title-text {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.help-btn {
  background: var(--panel);
  border: 0.5px solid var(--border);
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.help-btn:hover {
  background: var(--border);
  color: var(--text-strong);
}

.output-area {
  padding: 16px 20px 8px 28px;
  overflow-y: auto;
  min-height: 420px;
  max-height: 560px;
  flex: 1;
  cursor: text;
  background: var(--terminal-bg);
}

.line {
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
}

.line.prompt-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
}

.prompt-cmd {
  color: var(--text-strong);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.prompt-user { color: var(--blue); }
.prompt-sym  { color: var(--text-muted); }
.prompt-host { color: var(--green); }
.prompt-path { color: var(--blue-soft); }
.prompt-cmd  { color: var(--text-strong); }

.line.output        { color: var(--text-muted); }
.line.output.white  { color: var(--text); }
.line.output.green  { color: var(--green); }
.line.output.blue   { color: var(--blue); }
.line.output.dim    { color: var(--text-dim); }
.line.output.accent { color: var(--accent); }
.line.output.bold   { font-weight: 700; color: var(--text-strong); }
.line.output.red    { color: var(--red); }

.clickable-cmd {
  display: inline-block;
  background: var(--panel);
  border: 0.5px solid var(--border);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  margin-right: 6px;
}

.clickable-cmd:hover {
  background: var(--panel);
  color: var(--blue-soft);
  border-color: var(--blue);
}

body.light-mode .clickable-cmd:hover {
  background: var(--panel);
  color: var(--purple);
  border-color: var(--purple);
}

.tag {
  display: inline-block;
  background: rgba(63, 185, 80, 0.06);
  border: 0.5px solid rgba(63, 185, 80, 0.25);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--green);
  margin: 2px;
}

.input-row {
  display: flex;
  align-items: baseline;
  padding: 10px 20px 12px 28px;
  border-top: 0.5px solid var(--panel);
  background: var(--terminal-bg);
  flex-shrink: 0;
  position: relative;
  cursor: text;
  gap: 0;
}

.prompt-prefix {
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  line-height: 1;
}

.typed-text {
  font-size: 13px;
  color: var(--text-strong);
  font-family: 'JetBrains Mono', monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
  line-height: 1;
}

.cursor {
  display: inline-flex;
  width: 8px;
  height: 13px;
  background: var(--text-strong);
  margin-left: 1px;
  position: relative;
  top: 1px;
  line-height: 1;
  animation: blink 1s step-end infinite;
}

.cursor.typing {
  animation: none;
  opacity: 1;
}

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

.hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.hint-text {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  margin-left: auto;
  padding-left: 16px;
  flex-shrink: 0;
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
}

.ac-box {
  position: absolute;
  bottom: 50px;
  left: 28px;
  right: 20px;
  background: var(--titlebar-bg);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: none;
  z-index: 10;
}

.ac-box.visible {
  display: block;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 12px;
}

.ac-item:hover,
.ac-item.active {
  background: var(--panel);
}

.ac-cmd {
  color: var(--blue);
  min-width: 80px;
}

.ac-desc {
  color: var(--text-dim);
}

.palette-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: flex-end;
  border-radius: 12px;
  z-index: 20;
  padding: 16px;
}

.palette-overlay.visible {
  display: flex;
}

.palette-panel {
  background: var(--titlebar-bg);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  width: 100%;
  padding: 16px;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.palette-title {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.palette-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  font-family: 'JetBrains Mono', monospace;
}

.palette-close:hover {
  color: var(--text-strong);
}

.cmd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.palette-cmd {
  background: var(--panel);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  text-align: left;
}

.palette-cmd:hover {
  background: var(--blue);
  border-color: var(--blue);
}

.palette-cmd:hover .pcmd-name {
  color: #fff;
}

.palette-cmd:hover .pcmd-desc {
  color: rgba(255, 255, 255, 0.8);
}

.pcmd-name {
  font-size: 12px;
  color: var(--blue);
  display: block;
  margin-bottom: 2px;
}

.pcmd-desc {
  font-size: 10px;
  color: var(--text-dim);
  display: block;
}

.fade-in {
  animation: fi 0.18s ease both;
}

@keyframes fi {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

.ascii-line {
  white-space: pre;
  line-height: 1.35;
  letter-spacing: 0;
}

.link-inline {
  color: var(--blue);
  text-decoration: none;
  transition: color 0.12s;
}

.link-inline:hover {
  color: var(--blue-soft);
  text-decoration: underline;
}

body.light-mode .title-text {
  color: #4b5563;
}

body.light-mode .link-inline,
body.light-mode .ac-cmd,
body.light-mode .prompt-user {
  color: var(--blue);
}

body.light-mode .line.output.accent {
  color: var(--accent);
}

@media (max-width: 700px) {
  .hint-text {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .page-topbar {
    display: none;
  }

  .page-footer {
    display: none;
  }

  .app-shell {
    padding: 0;
  }

  .terminal-wrap,
  .terminal-wrap.is-normal {
    position: relative;
    inset: auto;
    width: 100% !important;
    height: calc(100dvh - 70px) !important;
    min-height: 0;
    max-height: none;
    border-radius: 14px;
    left: 0 !important;
    top: 0 !important;
  }

  .terminal-wrap.is-fullscreen {
    inset: 0;
    width: 100vw !important;
    height: 100dvh !important;
    border-radius: 0;
  }

  .titlebar {
    padding: 12px;
    gap: 8px;
    cursor: default;
    justify-content: flex-start;
  }

  .title-text {
    flex: 1 1 auto;
    font-size: 11px;
    text-align: left;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theme-toggle {
    width: 38px;
    height: 30px;
    margin-left: auto;
    margin-right: 0;
    flex: 0 0 auto;
    order: 2;
  }

  .help-btn {
    padding: 6px 8px;
    font-size: 10px;
    flex: 0 0 auto;
    order: 3;
  }

  .output-area {
    min-height: 0;
    max-height: none;
    padding: 14px 14px 8px 14px;
    -webkit-overflow-scrolling: touch;
  }

  .line {
    font-size: 12px;
    line-height: 1.6;
  }

  .input-row {
    padding: 10px 14px 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    column-gap: 0;
    row-gap: 4px;
  }

  .prompt-prefix,
  .typed-text,
  .cursor {
    font-size: 12px;
    position: static !important;
  }

  .typed-text {
    min-width: 1px;
    flex: 0 1 auto;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .cursor {
    display: inline-block;
    width: 8px;
    height: 1.05em;
    margin-left: 1px !important;
    vertical-align: text-bottom;
    flex: 0 0 auto;
    right: auto !important;
    left: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
  }

  .hint-text {
    display: none;
  }

  .ac-box {
    left: 12px;
    right: 12px;
    bottom: 54px;
  }

  .ac-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .ac-cmd {
    min-width: 0;
  }

  .palette-overlay {
    padding: 10px;
    border-radius: 14px;
    align-items: stretch;
  }

  .palette-panel {
    padding: 14px;
    border-radius: 12px;
    max-height: 100%;
    overflow: auto;
  }

  .cmd-grid {
    grid-template-columns: 1fr;
  }

  .resize-handle {
    display: none !important;
  }

  body.keyboard-open .input-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--kb-offset);
    z-index: 2000;
    background: var(--terminal-bg);
    border-top: 0.5px solid var(--border);
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  }

  body.keyboard-open .ac-box {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--kb-offset) + 56px);
    z-index: 2100;
  }

  body.keyboard-open .output-area {
    padding-bottom: 84px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 0;
  }

  .terminal-wrap,
  .terminal-wrap.is-normal {
    height: 100dvh !important;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0;
  }

  .titlebar {
    padding: 10px 12px;
    gap: 6px;
  }

  .dots {
    gap: 6px;
  }

  .dot {
    width: 12px;
    height: 12px;
  }

  .theme-toggle {
    width: 34px;
    height: 28px;
  }

  .help-btn {
    padding: 5px 7px;
    font-size: 10px;
  }

  .output-area {
    padding: 12px 10px 8px 10px;
  }

  .line {
    font-size: 11px;
  }

  .clickable-cmd {
    margin-bottom: 6px;
  }

  .cursor {
  width: 7px;
  height: 1em;
}
}