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

::selection {
  background: var(--selection);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
}

/* Static landing for crawlers/no-JS */
#static-landing {
  max-width: 600px;
  margin: 80px auto;
  padding: 0 20px;
  color: var(--fg, #d4d4d8);
}

#static-landing h1 {
  color: var(--accent, #fde68a);
  font-size: 1.5em;
  margin-bottom: 16px;
}

#static-landing a {
  color: var(--accent, #fde68a);
}

#static-landing nav {
  margin: 16px 0;
}

/* ─── Three-column layout ─── */
#app-layout {
  display: flex;
  justify-content: center;
  height: 100vh;
  position: relative;
}

/* ─── Left panel (content pane) ─── */
#left-panel {
  width: 400px;
  height: 100vh;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.15s ease, opacity 0.15s ease;
  overflow: hidden;
}

#left-panel.hidden {
  width: 0;
  opacity: 0;
  border-right: none;
  pointer-events: none;
}

#left-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#left-panel-title {
  color: var(--muted);
  font-size: var(--font-size);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#left-panel-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
  flex-shrink: 0;
  line-height: 1;
}

#left-panel-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#left-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#left-panel-content::-webkit-scrollbar {
  width: 6px;
}

#left-panel-content::-webkit-scrollbar-track {
  background: transparent;
}

#left-panel-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Content inside left panel */
#left-panel-content img,
#left-panel-content video {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 4px 0;
}

#left-panel-content .panel-post-header {
  color: var(--accent);
  margin-bottom: 8px;
}

#left-panel-content .panel-post-body {
  white-space: pre-wrap;
  word-break: break-word;
}

#left-panel-content .panel-post-tags span {
  color: var(--accent);
  cursor: pointer;
}

#left-panel-content .panel-reply {
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin-top: 8px;
}

/* ─── Center column — terminal ─── */
#terminal-wrapper {
  display: flex;
  justify-content: center;
  flex: 1;
  min-width: 0;
  height: 100vh;
  position: relative;
}

#terminal {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 12px;
  width: var(--terminal-width, 800px);
  max-width: 100%;
  flex-shrink: 0;
}

/* Resize handles — invisible edge zones */
.resize-handle {
  width: 8px;
  cursor: col-resize;
  flex-shrink: 0;
  user-select: none;
}

/* Media elements must respect container width */
#output img, #output video, #output audio, #output pre {
  max-width: 100%;
}

#output video {
  height: auto;
}

#output {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#output::-webkit-scrollbar {
  width: 6px;
}

#output::-webkit-scrollbar-track {
  background: transparent;
}

#output::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.line {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1em;
}

.line.command { color: var(--fg); }
.line.error { color: var(--error); }
.line.success { color: var(--success); }
.line.muted { color: var(--muted); }
.line.accent { color: var(--accent); }
.line.bold { font-weight: 700; }

#input-line {
  display: flex;
  align-items: center;
  padding: 4px 0;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Top CLI position */
#terminal.cli-top {
  flex-direction: column-reverse;
}

#terminal.cli-top #input-line {
  border-top: none;
  border-bottom: 1px solid var(--border);
}

#terminal.cli-top #output {
  flex-direction: column-reverse;
}

/* Middle CLI position */
#terminal.cli-middle #output {
  flex: 1;
}

#terminal.cli-middle #input-line {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: auto 0;
}

#prompt {
  color: var(--accent);
  white-space: pre;
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  caret-color: var(--accent);
}

#input.waiting {
  caret-color: transparent;
}

#input.masked {
  -webkit-text-security: disc;
  text-security: disc;
}

#block-cursor {
  display: none;
}

#block-cursor.active {
  display: inline-block;
  width: 0.6em;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: cursor-blink-fast 0.4s step-end infinite;
}

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

/* ─── Right panel — sidebar ─── */
#sidebar {
  width: 300px;
  height: 100vh;
  flex-shrink: 0;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: width 0.15s ease, opacity 0.15s ease;
}

#sidebar.hidden {
  width: 0;
  opacity: 0;
  border-left: none;
  pointer-events: none;
  overflow: hidden;
}

#sidebar-content {
  padding: 20px;
  min-width: 280px;
}

#sidebar h2 {
  color: var(--accent);
  font-size: var(--font-size);
  margin-bottom: 4px;
  font-weight: 700;
}

#sidebar .sidebar-tagline {
  color: var(--muted);
  margin-bottom: 12px;
}

#sidebar .sidebar-quicklinks {
  margin-bottom: 16px;
}

#sidebar .sidebar-quicklinks span {
  cursor: pointer;
  color: var(--accent);
  margin-right: 8px;
}

#sidebar .sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.sidebar-section-title {
  color: var(--muted);
  font-size: var(--font-size);
  font-weight: 400;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-category h3 {
  color: var(--muted);
  font-size: var(--font-size);
  font-weight: 400;
  margin-bottom: 4px;
  margin-top: 8px;
}

.sidebar-cmd {
  display: inline-block;
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-family);
  font-size: var(--font-size);
  cursor: pointer;
  padding: 2px 4px;
  margin: 1px 0;
}

.sidebar-cmd:hover {
  text-decoration: underline;
}

.sidebar-doc {
  display: inline-block;
  cursor: pointer;
  color: var(--accent);
  font-family: var(--font-family);
  font-size: var(--font-size);
  padding: 2px 4px;
  margin: 1px 0;
}

.sidebar-doc:hover {
  text-decoration: underline;
}

.sidebar-footer {
  color: var(--muted);
  margin-top: 16px;
}

/* /ask input in sidebar */
#sidebar-ask {
  margin-bottom: 12px;
}

#sidebar-ask-input {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-family);
  font-size: var(--font-size);
  padding: 6px 8px;
  border-radius: 2px;
  outline: none;
}

#sidebar-ask-input:focus {
  border-color: var(--accent);
}

#sidebar-ask-input::placeholder {
  color: var(--muted);
}

#sidebar-ask-output {
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ask-entry {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.ask-question {
  color: var(--accent);
  margin-bottom: 4px;
}

.ask-answer {
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Connection status in sidebar */
.sidebar-connections {
  margin-bottom: 12px;
}

.sidebar-connections .conn-item {
  color: var(--success);
  margin-bottom: 2px;
}

.sidebar-connections .conn-link {
  cursor: pointer;
  color: var(--accent);
}

/* Hamburger button */
#hamburger {
  position: fixed;
  bottom: 12px;
  right: 12px;
  z-index: 20;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 20px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.1s, border-color 0.1s;
  line-height: 1;
  padding: 0;
}

#hamburger:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Responsive ─── */

/* Medium screens: only one side panel at a time */
@media (max-width: 1400px) and (min-width: 801px) {
  #left-panel:not(.hidden) ~ #terminal-wrapper ~ #sidebar:not(.hidden) {
    /* If both open, hide right */
  }
}

/* Mobile */
@media (max-width: 800px) {
  #terminal {
    width: 100% !important;
    padding: 8px;
  }

  .resize-handle {
    display: none;
  }

  /* Panels become full-screen overlays */
  #left-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100vh;
    z-index: 25;
    background: var(--bg);
  }

  #left-panel.hidden {
    width: 0 !important;
  }

  #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 100% !important;
    height: 100vh;
    z-index: 25;
    background: var(--bg);
  }

  #sidebar.hidden {
    width: 0 !important;
  }
}

/* ─── Context menu ─── */
#context-menu {
  position: fixed;
  z-index: 30;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 0;
  min-width: 140px;
}

.ctx-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--fg);
  font-family: var(--font-family);
  font-size: var(--font-size);
  text-align: left;
  padding: 4px 12px;
  cursor: pointer;
}

.ctx-item:hover {
  background: var(--selection);
  color: var(--accent);
}

/* ─── Markdown rendering ─── */
.md-h1 {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1em;
  text-transform: uppercase;
  display: block;
  margin: 4px 0;
}

.md-h2 {
  font-weight: 700;
  color: var(--accent);
  display: block;
  margin: 4px 0;
}

.md-h3 {
  font-weight: 700;
  color: var(--fg);
  display: block;
  margin: 2px 0;
}

.md-bold { font-weight: 700; }
.md-italic { font-style: italic; color: var(--muted); }

.md-code {
  background: var(--border);
  padding: 1px 4px;
  border-radius: 2px;
  color: var(--accent);
}

.md-code-block {
  display: block;
  background: var(--border);
  padding: 0 8px;
  color: var(--fg);
  white-space: pre;
  overflow-x: auto;
}

.md-code-lang {
  display: block;
  color: var(--muted);
  font-size: 0.85em;
}

.md-hr {
  display: block;
  color: var(--border);
  margin: 4px 0;
}

.md-blockquote {
  display: block;
  color: var(--muted);
  padding-left: 8px;
}

.md-list { color: var(--fg); }

.md-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.md-link:hover {
  color: var(--fg);
}

/* ─── Resizing state ─── */
body.resizing {
  cursor: col-resize;
  user-select: none;
}

/* ─── Confirm post modal ─── */
#confirm-modal {
  position: fixed;
  z-index: 999;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px 20px;
  min-width: 300px;
  max-width: 500px;
  font-family: var(--font-family);
  font-size: var(--font-size);
  color: var(--fg);
}

#confirm-modal .confirm-preview {
  color: var(--muted);
  margin-bottom: 12px;
  word-break: break-word;
}

#confirm-modal .confirm-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

#confirm-modal .confirm-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-family);
  font-size: var(--font-size);
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 2px;
}

#confirm-modal .confirm-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#confirm-modal .confirm-check {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--font-size);
}

#confirm-modal .confirm-check input {
  accent-color: var(--accent);
}
