/* ============================================================
   Ask My Articles — Substack editorial theme, v2
   Key changes: better mobile layout, less "AI-generated" feel,
   tighter spacing, improved typography, responsive sidebar.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Playfair+Display:ital,wght@0,600;0,700;1,600;1,700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #ffffff;
  --bg-soft: #faf9f7;
  --bg-soft-2: #f2efe8;
  --ink: #1a1a1a;
  --ink-soft: #6b6761;
  --ink-faint: #a09c96;
  --border: #e6e2da;
  --border-strong: #1a1a1a;
  --accent: #ff6719;
  --accent-soft: #fff2ea;
  --accent-ink: #c44e0d;

  --serif: "DM Serif Display", Georgia, serif;
  --sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Fira Code", ui-monospace, SFMono-Regular, monospace;

  --radius: 4px;
  --max-width: 680px;
  --sidebar-w: 250px;
}

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

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ============================================================
   Shell / layout
   ============================================================ */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Sidebar (history)
   ============================================================ */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink-soft);
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  transition: all 0.15s;
}

.sidebar-toggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
  transition: background 0.1s, color 0.1s;
}

.history-item:hover {
  background: var(--bg-soft-2);
  color: var(--ink);
}

.history-item span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.setting-note {
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.5;
}

/* Hamburger expand button — shown when sidebar is hidden */
.sidebar-expand {
  position: fixed;
  top: 14px;
  left: 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  padding: 7px 9px;
  cursor: pointer;
  z-index: 100;
  transition: all 0.15s;
}

.sidebar-expand:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* ============================================================
   Topbar
   ============================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 36px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
}

body.sidebar-collapsed .topbar {
  padding-left: 64px;
}

.wordmark {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.wordmark-accent {
  color: var(--accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--ink);
  background: var(--bg);
  transition: all 0.15s;
}

.entry-pill:hover {
  background: var(--ink);
  color: var(--bg);
}

/* ============================================================
   Main content area
   ============================================================ */

main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px 100px;
}

/* ============================================================
   Hero
   ============================================================ */

.hero {
  margin-bottom: 32px;
}

.hero h1 {
  font-family: var(--sans);
  font-weight: 800;
  font-style: normal;
  font-size: 56px;
  line-height: 1.0;
  margin: 0 0 10px;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.hero-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

/* ============================================================
   Ask box
   ============================================================ */

.ask-box {
  margin-bottom: 18px;
}

#ask-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 5px 6px 5px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#ask-form:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.06);
}

.ask-mark {
  color: var(--accent);
  font-size: 15px;
  flex-shrink: 0;
}

#query {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  padding: 10px 0;
  outline: none;
  min-width: 0;
}

#query::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

#ask-form button {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.03em;
  background: var(--ink);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  white-space: nowrap;
}

#ask-form button:hover {
  background: var(--accent);
}

/* ============================================================
   Quick prompts
   ============================================================ */

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 40px;
}

.quick-btn {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.quick-btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.quick-btn-dice {
  font-size: 14px;
  background: var(--bg);
  color: var(--ink-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.12s;
}

.quick-btn-dice:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Answer cards (tickets)
   ============================================================ */

#tickets {
  display: flex;
  flex-direction: column;
}

.ticket {
  padding: 24px 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: 70px;
}

.ticket:first-child {
  border-top: 2px solid var(--border-strong);
}

.ticket.loading .ticket-answer {
  color: var(--ink-faint);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.ticket-serial {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin-bottom: 7px;
}

.ticket-serial-api {
  color: var(--accent-ink);
}

.ticket-question {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 700;
  font-style: normal;
  line-height: 1.3;
  margin: 0 0 14px;
  color: var(--ink);
}

.ticket-answer {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
}

.ticket-answer p {
  margin: 0 0 12px;
}

.ticket-answer p:last-child {
  margin-bottom: 0;
}

.ticket-answer ul,
.ticket-answer ol {
  margin: 0 0 12px;
  padding-left: 22px;
}

.ticket-answer li {
  margin-bottom: 5px;
}

.ticket-answer strong {
  font-weight: 700;
}

.ticket-answer em {
  font-style: italic;
}

.ticket-footer {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Source stamps */
.stamp {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-soft);
}

.stamp::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.stamp.kb {
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-color: transparent;
}

.stamp.cache {
  color: #2b6a52;
  background: #e8f4ed;
  border-color: transparent;
}

.stamp.api {
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-color: transparent;
}

/* Read article button */
.article-link-btn {
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  background: var(--ink);
  border: none;
  border-radius: 999px;
  color: var(--bg);
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}

.article-link-btn:hover {
  background: var(--accent);
  color: #fff;
}

.article-link-btn::after {
  content: " →";
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--ink-soft);
}

.ticket-icon {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 12px;
}

.empty-state p {
  margin: 0 0 6px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-transform: uppercase;
}

.empty-sub {
  font-size: 13.5px !important;
  font-weight: 400 !important;
  letter-spacing: normal !important;
  text-transform: none !important;
  color: var(--ink-faint) !important;
  max-width: 340px;
  margin: 0 auto !important;
  line-height: 1.6;
}

.history-nudge {
  margin-top: 16px;
  background: none;
  border: none;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s;
}

.history-nudge:hover {
  color: var(--accent);
}

/* ============================================================
   Terminal (insights panel)
   ============================================================ */

.terminal-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 17px;
  cursor: pointer;
  z-index: 30;
  transition: background 0.15s, transform 0.15s;
  box-shadow: 0 2px 12px rgba(255, 103, 25, 0.35);
}

.terminal-fab:hover {
  background: var(--accent-ink);
  transform: scale(1.05);
}

.terminal-panel {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 320px;
  background: #17140f;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 30;
  border: 1px solid #2a251c;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.terminal-header {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  background: #201c15;
  border-bottom: 1px solid #2a251c;
  gap: 8px;
}

.terminal-dots {
  display: flex;
  gap: 5px;
}

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

.dot-red {
  background: #ff5f56;
}

.dot-yellow {
  background: #ffbd2e;
}

.dot-green {
  background: #27c93f;
}

.terminal-title {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: #7a7261;
}

.terminal-close {
  background: none;
  border: none;
  color: #7a7261;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.1s;
}

.terminal-close:hover {
  color: #fff;
}

.terminal-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: #d8d0c2;
}

.terminal-line {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 3px;
}

.terminal-query {
  color: #fff;
  font-weight: 500;
}

.terminal-cache {
  color: #6fd39a;
}

.terminal-api {
  color: var(--accent);
}

.terminal-muted {
  color: #6a6253;
}

/* ============================================================
   Mobile overlay backdrop for sidebar
   ============================================================ */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 39;
}

.sidebar-backdrop.visible {
  display: block;
}

/* ============================================================
   Responsive — tablet / phone
   ============================================================ */

@media (max-width: 820px) {

  /* Sidebar becomes a slide-in overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }

  .sidebar-expand {
    display: flex;
  }

  .topbar {
    padding: 14px 16px;
    padding-left: 56px;
  }

  main {
    padding: 32px 16px 80px;
  }

  .hero h1 {
    font-size: 38px;
  }

  .hero-sub {
    font-size: 10px;
  }

  #ask-form button {
    padding: 10px 14px;
    font-size: 12px;
  }

  .ticket-question {
    font-size: 18px;
  }

  .wordmark {
    font-size: 15px;
  }

  .entry-pill span {
    display: none;
  }

  /* hide label text, keep icon on mobile */

  .terminal-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 72px;
  }

  .terminal-fab {
    right: 16px;
    bottom: 16px;
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 32px;
  }

  .quick-btn {
    font-size: 10.5px;
    padding: 5px 11px;
  }

  .topbar-right {
    gap: 6px;
  }
}