.hidden { display: none !important; }

:root {
  --bg: #0d0d0d;
  --bg2: #141414;
  --bg3: #1c1c1c;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text2: #909090;
  --text3: #585858;
  --accent: #4f8ef7;
  --accent-dim: #1e3a6e;
  --success: #3db36a;
  --danger: #e05555;
  --user-bubble: #1a2a4a;
  --claude-bubble: #171717;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SF Mono", "Fira Code", monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── NAV ── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; color: var(--text); letter-spacing: 0.05em; }
.nav-links { display: flex; gap: 8px; }
.nav-link {
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--text2);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover, .nav-link.active { background: var(--bg3); color: var(--text); text-decoration: none; }

/* ── MAIN ── */
.main { padding: 0; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

/* ── INPUTS ── */
.input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }

/* ── LOGIN ── */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 48px);
  padding: 24px;
}
.login-title { font-size: 28px; margin-bottom: 24px; letter-spacing: 0.1em; }
.login-form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px; }
.error { color: var(--danger); font-size: 13px; }

/* ── LANDING ── */
.landing { max-width: 700px; margin: 0 auto; padding: 48px 20px; }
.landing-hero { margin-bottom: 48px; }
.landing-hero h1 { font-size: 36px; margin-bottom: 8px; }
.landing-sub { color: var(--text2); margin-bottom: 24px; }
.landing-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.landing-latest { border-top: 1px solid var(--border); padding-top: 32px; }
.latest-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text3); margin-bottom: 8px; }
.latest-title { font-size: 22px; margin-bottom: 4px; }
.latest-date { color: var(--text2); font-size: 13px; margin-bottom: 16px; }
.read-more { font-size: 14px; color: var(--accent); }

/* ── PLAY OUTER ── */
.play-outer {
  position: fixed;
  inset: 48px 0 0 0;
  display: flex;
  flex-direction: row;
}
.play-tabs { display: none; }
.play-tab {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.play-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.play-outer .chat-layout { flex: 1; min-width: 0; height: 100%; }

/* ── DASHBOARD PANEL ── */
.dashboard-panel {
  width: 360px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
  border-right: 1px solid var(--border);
}
.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dashboard-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
}
.dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── DASHBOARD CONTENT COMPONENTS ── */
.dash-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 4px 2px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.dash-turn { font-size: 13px; font-weight: 600; color: var(--text); }
.dash-date { font-size: 12px; color: var(--accent); }
.dash-phase { font-size: 11px; color: var(--text2); }
.dash-section-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin: 10px 0 4px;
}
.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.dash-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text3);
  font-weight: 500;
  padding: 3px 4px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.dash-table td {
  padding: 4px 4px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.dash-table tr:last-child td { border-bottom: none; }
.dash-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.dash-stat {
  background: var(--bg3);
  border-radius: 6px;
  padding: 6px 8px;
  text-align: center;
}
.dash-stat-val { font-size: 18px; font-weight: 600; color: var(--text); line-height: 1.2; }
.dash-stat-val small { font-size: 11px; color: var(--text2); font-weight: 400; }
.dash-stat-lbl { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; }
.dash-colony {
  background: var(--bg3);
  border-radius: 6px;
  padding: 7px 9px;
  margin-bottom: 4px;
  font-size: 12px;
}
.dash-colony-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-weight: 500;
}
.dash-tier {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg2);
  border-radius: 4px;
  padding: 1px 5px;
}
.dash-colony-stats {
  display: flex;
  gap: 8px;
  color: var(--text2);
  font-size: 11px;
  flex-wrap: wrap;
}
.dash-colony-note { font-size: 11px; color: var(--accent); margin-top: 3px; }
.dash-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 5px;
  overflow: hidden;
}
.dash-progress-bar div { height: 100%; background: var(--accent); border-radius: 2px; }
.dash-watch-list { display: flex; flex-direction: column; gap: 3px; }
.dash-watch {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 0;
}
.dash-watch-p { font-size: 10px; font-weight: 700; width: 20px; flex-shrink: 0; }
.dash-watch-status { margin-left: auto; font-size: 10px; color: var(--text3); text-transform: uppercase; }

/* ── TERMINAL LAYOUT (play page) ── */
.terminal-layout {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d0d0d;
}
.terminal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.terminal-container {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  /* no padding — xterm.js manages its own internal spacing */
}
.terminal-container .xterm { height: 100%; }
.terminal-container .xterm-viewport { overflow-y: auto !important; }

/* ── CHAT LAYOUT (manage draft page) ── */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: min(680px, 90%);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}
.bubble-user {
  background: var(--user-bubble);
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.bubble-claude {
  background: var(--claude-bubble);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.bubble-claude.streaming { border-color: var(--accent-dim); }
.bubble-info {
  align-self: center;
  color: var(--text3);
  font-size: 12px;
  background: none;
  padding: 4px 0;
}
.bubble-pre {
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  margin: 0;
}

/* ── PERMISSION PROMPT ── */
.permission-prompt {
  background: #2a1f0a;
  border: 1px solid #6b4c1a;
  border-radius: var(--radius);
  padding: 12px 14px;
  align-self: flex-start;
  max-width: min(680px, 90%);
}
.permission-prompt.resolved { opacity: 0.5; pointer-events: none; }
.perm-text { font-family: var(--mono); font-size: 12px; margin-bottom: 10px; color: #e0c080; }
.perm-btns { display: flex; gap: 8px; }

/* ── CHAT BAR ── */
.chat-bar {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  position: relative;
}
.chat-input-wrap { display: flex; gap: 8px; align-items: flex-end; }
.chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 9px 12px;
  outline: none;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
  -webkit-overflow-scrolling: touch;
}
.chat-input:focus { border-color: var(--accent); }
.send-btn {
  width: 40px; height: 40px;
  background: var(--accent);
  border: none; border-radius: 10px;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--mono);
  transition: border-color 0.15s, color 0.15s;
}
.action-btn:hover { border-color: var(--accent); color: var(--text); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── STATUS DOT ── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}
.status-dot.ready { background: var(--success); }
.status-dot.thinking { background: var(--accent); animation: pulse 1s infinite; }
.status-dot.connecting { background: #888; animation: pulse 1.5s infinite; }
.status-dot.disconnected { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── MANAGE ── */
.manage-layout { max-width: 900px; margin: 0 auto; padding: 28px 20px; }
.manage-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; flex-wrap: wrap; gap: 12px; }
.manage-section { margin-bottom: 36px; }
.manage-section h2 { font-size: 16px; color: var(--text2); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.draft-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.draft-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.draft-item.published { opacity: 0.7; }
.draft-meta { display: flex; flex-direction: column; gap: 2px; }
.draft-title { font-weight: 500; }
.draft-date { font-size: 13px; color: var(--accent); }
.draft-created { font-size: 12px; color: var(--text3); }
.draft-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── DRAFT EDITOR LAYOUT ── */
/* ── Draft page: fixed three-panel layout ── */
.draft-tabs { display: none; }

.draft-outer {
  position: fixed;
  inset: 48px 0 0 0;
  display: flex;
  flex-direction: row;
}

/* Left: metadata panel */
.draft-meta-panel {
  width: 220px;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}
.draft-action-btns { display: flex; flex-wrap: wrap; gap: 6px; }

/* Centre: edit / preview */
.draft-content-panel {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.draft-mode-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.draft-mode-btn {
  padding: 8px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  transition: color 0.15s;
}
.draft-mode-btn.active {
  color: var(--text1);
  border-bottom-color: var(--accent);
}
.draft-edit-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.draft-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  resize: none;
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg1);
  color: var(--text1);
  border: none;
  padding: 16px;
  outline: none;
  box-sizing: border-box;
}
.draft-preview-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  font-size: 15px;
  line-height: 1.7;
}
.draft-preview-area h1 { font-size: 22px; margin: 0 0 12px; }
.draft-preview-area h2 { font-size: 18px; margin: 20px 0 8px; color: var(--text1); }
.draft-preview-area h3 { font-size: 15px; margin: 16px 0 6px; color: var(--text2); }
.draft-preview-area p  { margin: 0 0 12px; }
.draft-preview-area blockquote { border-left: 3px solid var(--border); margin: 0 0 12px 0; padding-left: 12px; color: var(--text2); }
.draft-preview-area hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Right: chat panel */
.draft-chat-panel {
  width: 300px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.draft-chat-panel .chat-messages { flex: 1; overflow-y: auto; padding: 12px; }
.draft-mobile-actions { display: none; }

/* Legacy — keep for other uses */
.draft-meta-form { display: flex; flex-direction: column; gap: 10px; }
.draft-form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.field-label { font-size: 12px; color: var(--text2); }
.info-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* ── NEW DRAFT ── */
.new-draft-form { display: flex; flex-direction: column; gap: 10px; max-width: 520px; margin-top: 20px; }
.field-hint { font-size: 12px; color: var(--text3); }

/* ── READ ── */
.read-layout { max-width: 760px; margin: 0 auto; padding: 40px 20px; }
.read-layout h1 { font-size: 28px; margin-bottom: 36px; }
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: "";
  position: absolute;
  left: 7px; top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 40px; }
.timeline-dot {
  position: absolute;
  left: -20px; top: 6px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.timeline-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.timeline-date { font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.timeline-title { font-size: 20px; margin: 4px 0 12px; }
.timeline-title a { color: var(--text); }

/* ── POST ── */
.post-layout { max-width: 720px; margin: 0 auto; padding: 40px 20px; }
.post-header { margin-bottom: 32px; }
.post-date { font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; display: block; margin: 8px 0; }
.post-title { font-size: 30px; line-height: 1.2; }

/* ── PROSE ── */
.prose { color: var(--text); line-height: 1.7; }
.prose.preview { -webkit-line-clamp: 4; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; }
.prose h1,.prose h2,.prose h3 { margin: 1.4em 0 0.5em; line-height: 1.2; }
.prose h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.prose p { margin: 0 0 1em; }
.prose ul,.prose ol { margin: 0 0 1em 1.5em; }
.prose li { margin: 0.2em 0; }
.prose code { font-family: var(--mono); font-size: 0.88em; background: var(--bg3); padding: 1px 5px; border-radius: 4px; }
.prose pre { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 14px; overflow-x: auto; margin: 0 0 1em; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 3px solid var(--border); padding-left: 16px; color: var(--text2); margin: 0 0 1em; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.prose table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
.prose th,.prose td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg3); }

/* ── COMMENTS ── */
.comments { border-top: 1px solid var(--border); margin-top: 48px; padding-top: 32px; }
.comments h2 { font-size: 18px; margin-bottom: 20px; }
.comment-list { display: flex; flex-direction: column; gap: 16px; margin-bottom: 32px; }
.comment {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.comment-meta { display: flex; gap: 12px; margin-bottom: 8px; }
.comment-author { font-weight: 500; font-size: 14px; }
.comment-date { font-size: 12px; color: var(--text3); }
.comment-body { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.comment-form { display: flex; flex-direction: column; gap: 10px; max-width: 540px; }
.comment-form h3 { font-size: 16px; margin-bottom: 4px; }

/* ── MISC ── */
.back-link { font-size: 14px; color: var(--text2); display: inline-block; margin-bottom: 16px; }
.empty-state { color: var(--text3); font-size: 14px; }

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  /* Draft page mobile: tab-based */
  .draft-tabs {
    display: flex;
    height: 40px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: fixed;
    top: 48px;
    left: 0; right: 0;
    z-index: 10;
  }
  .draft-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
  }
  .draft-tab.active { color: var(--text1); border-bottom-color: var(--accent); }

  .draft-outer {
    inset: 88px 0 0 0;
    flex-direction: column;
  }
  /* Each panel fills the full outer when it's the only visible one */
  .draft-meta-panel,
  .draft-content-panel,
  .draft-chat-panel {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-right: none;
    border-bottom: none;
  }
  /* Hide the inner Edit/Preview toggle — mobile tabs replace it */
  .draft-mode-bar { display: none; }
  /* Give the edit/preview areas full height without the mode bar */
  .draft-edit-area, .draft-preview-area { flex: 1; min-height: 0; }
  /* Show compact action strip on mobile */
  .draft-mobile-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
  }
  .hidden-mobile { display: none !important; }
  .timeline { padding-left: 16px; }
  .post-title { font-size: 24px; }

  /* Play page: tab-based on mobile */
  .play-outer {
    position: fixed;
    inset: 48px 0 0 0;
    flex-direction: column;
  }
  .play-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0;
    height: 40px;
  }
  .dashboard-panel {
    width: 100%;
    height: 0;
    display: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .dashboard-panel.active {
    display: flex;
    height: auto;
    flex: 1;
  }
  .terminal-layout { height: auto; flex: 1; }
  .terminal-layout.hidden { display: none; }
}
