:root {
  --offwhite: #FBFBFB;
  --charcoal: #1A1A1A;
  --grey-status: #A0A0A0;
  --hairline: #E6E6E6;
}

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

html, body { height: 100%; }

body {
  background: var(--offwhite);
  color: var(--charcoal);
  font-family: 'Inter', sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  align-items: center;
}

.page-container {
  width: 100%;
  max-width: 1400px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 60px;
}

/* TOP NAVIGATION */
.top-nav {
  padding: 30px 0 40px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.logo-box { display: flex; align-items: flex-start; cursor: pointer; }

.k-square {
  border: 4px solid var(--charcoal);
  width: 65px;
  height: 65px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  font-size: 2.5rem;
  margin-right: 20px;
  background: white;
  overflow: hidden;
}
.k-square img { width: 100%; height: 100%; object-fit: contain; }

.brand-info { display: flex; flex-direction: column; }
.brand-name { font-weight: 900; font-size: 2.8rem; text-transform: uppercase; line-height: 0.9; }
.site-description { font-size: 1rem; font-weight: 500; color: var(--grey-status); margin-top: 4px; }

.nav-links { display: flex; gap: 30px; padding-top: 10px; }
.nav-links a {
  text-decoration: none;
  color: var(--charcoal);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
}
.nav-links a:hover { text-decoration: underline; text-underline-offset: 4px; }

/* TIMER DISPLAY */
.header-section { text-align: center; padding-bottom: 25px; width: 100%; }

.timer-label {
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--grey-status);
  margin-bottom: 10px;
}

#timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: min(9.5vw, 133px);
  font-weight: 800;
  line-height: 0.85;
  display: block;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}

.timer-underline { height: 5px; background: var(--charcoal); width: 100%; margin-top: 15px; }

/* MAIN LAYOUT SPLIT */
.main-layout { display: flex; flex: 1; min-height: 0; overflow: hidden; gap: 40px; margin-top: 10px; }

/* LEFT: AUDIT PANEL */
.audit-panel { flex: 1.2; min-width: 0; display: flex; flex-direction: column; position: relative; }

.assignment-slot { height: 60px; margin-bottom: 10px; flex-shrink: 0; }

.assignment-box {
  border: 3px solid var(--charcoal);
  padding: 8px 18px;
  font-weight: 900;
  font-size: 1.1rem;
  text-transform: uppercase;
  display: inline-block;
  animation: stamp 0.25s ease-out;
}
.assignment-box[hidden] { display: none; }

@keyframes stamp {
  from { transform: scale(1.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#chat-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
}
#chat-history::-webkit-scrollbar { display: none; }

.message-block { margin-bottom: 25px; max-width: 90%; }
.kevin-msg { align-self: flex-start; text-align: left; }
.user-msg  { align-self: flex-end;  text-align: right; }

.label {
  font-size: 0.65rem;
  font-weight: 900;
  margin-bottom: 2px;
  display: block;
  text-transform: uppercase;
}

.audit-text {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: pre-line;
}

/* State 0: big arrival prompt */
.intake .audit-text { font-size: 3.5rem; line-height: 0.95; }

.user-msg .audit-text {
  color: var(--grey-status);
  font-weight: 400;
  font-style: italic;
}

.thinking .audit-text::after {
  content: "";
  animation: dots 1s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

.verdict-link {
  display: inline-block;
  margin-top: 12px;
  border: 3px solid var(--charcoal);
  background: var(--charcoal);
  color: var(--offwhite);
  padding: 10px 18px;
  font-weight: 900;
  font-size: 1rem;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
}

/* INPUT COMPONENT & MIGRATION */
.input-wrapper {
  padding: 20px 0;
  border-top: 1px solid var(--hairline);
  flex-shrink: 0;
}
.input-floating { border-top: none; padding-top: 0; margin-top: -10px; }

#user-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--charcoal);
  outline: none;
  text-transform: uppercase;
  border-radius: 0;
}
#user-input::placeholder { color: var(--grey-status); }
#user-input:disabled { opacity: 0.4; }

/* RIGHT: PUBLIC AUDIT LEDGER */
.ledger-panel {
  flex: 0.8;
  min-height: 0;
  border-left: 1px solid var(--hairline);
  padding-left: 30px;
  display: flex;
  flex-direction: column;
  max-width: 450px;
}

.log-header { padding-bottom: 15px; font-weight: 900; font-size: 0.75rem; opacity: 0.4; text-transform: uppercase; }

#ledger-content { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; }
#ledger-content::-webkit-scrollbar { display: none; }

.log-row { margin-bottom: 20px; }
.log-row.fresh { animation: stamp 0.25s ease-out; }
.log-top-line { font-weight: 800; font-size: 1rem; text-transform: uppercase; }
.log-sub-line { font-size: 0.85rem; color: var(--grey-status); display: block; margin-top: 3px; line-height: 1.2; }

/* OVERLAYS */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(251, 251, 251, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 480px;
  width: 100%;
}


.overlay-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 400px; }

.btn {
  display: block;
  text-align: center;
  border: 3px solid var(--charcoal);
  background: transparent;
  color: var(--charcoal);
  padding: 14px 18px;
  font-family: inherit;
  font-weight: 900;
  font-size: 1rem;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
}
.btn-solid { background: var(--charcoal); color: var(--offwhite); }
.btn-quiet { border-color: transparent; color: var(--grey-status); }

.about { align-items: flex-start; }
.about-text { font-size: 1.8rem; font-weight: 900; line-height: 1.05; text-transform: uppercase; }
.about-small { font-size: 1rem; line-height: 1.5; color: #555; }

/* MOBILE */
@media (max-width: 860px) {
  .page-container { padding: 0 16px; }
  .top-nav { padding: 16px 0 18px; }
  .k-square { width: 44px; height: 44px; font-size: 1.6rem; border-width: 3px; margin-right: 12px; }
  .brand-name { font-size: 1.2rem; }
  .site-description { font-size: 0.75rem; }
  .nav-links { gap: 14px; padding-top: 4px; }
  .nav-links a { font-size: 0.75rem; }

  #timer { font-size: 10.5vw; }
  .timer-label { font-size: 0.55rem; margin-bottom: 6px; }
  .timer-underline { height: 4px; margin-top: 10px; }
  .header-section { padding-bottom: 10px; }

  .main-layout { flex-direction: column; gap: 0; margin-top: 4px; }
  .ledger-panel { display: none; }  /* the audit is the whole show on a phone */

  .assignment-slot { height: 46px; margin-bottom: 4px; }
  .assignment-box { font-size: 0.9rem; padding: 6px 12px; }

  .intake .audit-text { font-size: 2rem; }
  .audit-text { font-size: 1.1rem; }
  .message-block { margin-bottom: 18px; }

  #user-input { font-size: 1.2rem; }
  .input-wrapper { padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); }

  .about-text { font-size: 1.4rem; }
}
/* ---- Layout fixes: chat scrolling + text sizing on shorter screens ---- */
.audit-panel { min-height: 0; }
#chat-history { scrollbar-width: thin; }
#chat-history::-webkit-scrollbar { display: block; width: 4px; }
#chat-history::-webkit-scrollbar-thumb { background: var(--grey-status); }
.top-nav { padding: min(30px, 3vh) 0 min(40px, 3vh); }
#timer { font-size: min(9.5vw, 13vh, 133px); }
.intake .audit-text { font-size: clamp(1.6rem, 5.5vh, 3.5rem); }
.audit-text { font-size: clamp(1rem, 2.6vh, 1.4rem); }
@media (max-width: 860px) {
  .intake .audit-text { font-size: clamp(1.4rem, 4.5vh, 2rem); }
  .audit-text { font-size: 1.05rem; }
}

/* ---- Audit card panel ---------------------------------------------------- */
/* Desktop: fixed column widths so the card panel can sit exactly over the ledger */
.main-layout { position: relative; }
.audit-panel { flex: 1 1 0; min-width: 0; }
.ledger-panel { flex: 0 0 min(450px, 40%); max-width: none; }

.card-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(450px, 40%);
  background: var(--offwhite);
  border-left: 1px solid var(--hairline);
  padding: 0 0 12px 30px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  container-type: size;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.45s;
  z-index: 3;
}
.card-panel.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

/* Card keeps its 4:5 shape; buttons always match the card's width */
.card-stack {
  --card-w: min(100cqw, calc((100cqh - 146px) * 0.8));
  width: var(--card-w);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* Two pages side by side; swipe (or click the pills) to move between them */
.card-carousel {
  width: 100%;
  aspect-ratio: 4 / 5;
  max-width: 100%;
  overflow: hidden;
  border: 3px solid var(--charcoal);
  background: #FBFBFB;
  touch-action: pan-y;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.card-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card-track.dragging { transition: none; }
.card-track > canvas {
  flex: 0 0 100%;
  width: 100%;
  height: auto;
  align-self: flex-start;
  display: block;
  pointer-events: none;
}

/* Page 2: the conversation, readable and scrollable */
.convo-page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #FBFBFB;
  color: var(--charcoal);
}
.convo-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 3px solid var(--charcoal);
  flex-shrink: 0;
}
.convo-k {
  width: 34px; height: 34px; flex-shrink: 0;
  border: 3px solid var(--charcoal);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.2rem;
}
.convo-title { font-weight: 900; font-size: 1.05rem; line-height: 1; }
.convo-sub { font-size: 0.72rem; color: var(--grey-status); margin-top: 3px; }
.convo-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  user-select: text;
  -webkit-user-select: text;
  scrollbar-width: thin;
}
.convo-msg { max-width: 92%; }
.convo-msg.you { align-self: flex-end; text-align: right; }
.convo-msg .who { display: block; font-size: 0.62rem; font-weight: 900; margin-bottom: 3px; }
.convo-msg p { font-size: 1.05rem; line-height: 1.22; font-weight: 900; text-transform: uppercase; }
.convo-msg.you p { font-weight: 400; font-style: italic; color: var(--grey-status); }

/* On page 2 the buttons step aside and the conversation takes the space */
.card-stack.convo .card-actions,
.card-stack.convo .card-links { display: none; }
.card-stack.convo .card-carousel { aspect-ratio: auto; height: calc(100cqh - 34px); }
.card-carousel.restamp { animation: restamp 0.5s ease-out; }
.card-dots { display: flex; justify-content: center; gap: 8px; padding: 2px 0; }
.card-dot {
  width: 22px;
  height: 6px;
  border-radius: 3px;
  border: none;
  padding: 0;
  background: var(--hairline);
  cursor: pointer;
  transition: background 0.2s, width 0.2s;
}
.card-dot.active { background: var(--charcoal); width: 34px; }
@keyframes restamp {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.card-actions .btn {
  height: 36px;
  padding: 0 6px;
  font-size: 0.74rem;
  border-width: 2px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Short, wide spaces (laptop windows): card on the left, buttons in a column beside it */
@container (min-aspect-ratio: 17/20) {
  .card-stack {
    --card-w: min(calc(100cqw - 128px), calc((100cqh - 30px) * 0.8));
    width: auto;
    display: grid;
    grid-template-columns: var(--card-w) 120px;
    column-gap: 8px;
    row-gap: 10px;
    align-items: start;
  }
  .card-carousel { width: var(--card-w); grid-column: 1; grid-row: 1; }
  .card-dots { grid-column: 1; grid-row: 2; }
  .card-actions { grid-column: 2; grid-row: 1; }
  .card-links { grid-column: 2; grid-row: 2; }
  .card-stack.convo { grid-template-columns: calc(var(--card-w) + 128px); }
  .card-actions { grid-template-columns: 1fr; }
  .card-actions .btn { height: auto; min-height: 40px; padding: 8px 6px; white-space: normal; }
  .card-links { flex-direction: column; align-items: flex-start; gap: 2px; }
}
.card-links { display: flex; justify-content: center; gap: 18px; }
.link-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-weight: 900;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--grey-status);
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { color: var(--charcoal); }
#keep-talking { display: none; }   /* phone only */

.view-card {
  display: none;
  align-self: flex-start;
  margin: 6px 0 2px;
  border: 2px solid var(--charcoal);
  background: var(--charcoal);
  color: var(--offwhite);
  font-family: inherit;
  font-weight: 900;
  font-size: 0.8rem;
  padding: 8px 14px;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--charcoal);
  color: var(--offwhite);
  font-weight: 900;
  font-size: 0.8rem;
  padding: 10px 16px;
  z-index: 30;
}

/* Edge tabs (phone only) */
.edge-tab { display: none; }
.scrim { display: none; }

/* Phone: the log slides in from the left, the card from the right, each on a folder tab */
@media (max-width: 860px) {
  .ledger-panel,
  .card-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--panel-top, 0px);
    bottom: 0;
    z-index: 20;
    background: var(--offwhite);
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    visibility: visible;
  }
  .ledger-panel {
    left: 0;
    width: min(86vw, 360px);
    max-width: none;
    border-left: none;
    border-right: 3px solid var(--charcoal);
    transform: translateX(-100%);
  }
  .ledger-panel.open { transform: translateX(0); }

  .card-panel {
    right: 0;
    left: auto;
    width: min(86vw, 440px);
    border-left: 3px solid var(--charcoal);
    align-items: center;
    justify-content: center;
    transform: translateX(100%);
  }
  .card-panel.open { transform: translateX(0); }
  body:not(.has-card) .card-panel { display: none; }
  .card-stack { --card-w: min(100cqw, calc((100cqh - 172px) * 0.8)); }

  /* Folder tabs stick out from each panel's outer edge and travel with it */
  .edge-tab {
    display: block;
    position: absolute;
    top: 66.667%;
    transform: translateY(-50%);
    width: 22px;
    background: var(--offwhite);
    color: var(--charcoal);
    border: 2px solid var(--charcoal);
    border-right: none;
    font-family: inherit;
    font-weight: 900;
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    writing-mode: vertical-rl;
    text-align: center;
    padding: 14px 0;
    cursor: pointer;
    border-radius: 6px 0 0 6px;
    transition: opacity 0.2s;
  }
  /* Log tab sticks out to the right of the log; rotated so it reads bottom to top */
  .log-tab { right: -25px; transform: translateY(-50%) rotate(180deg); }
  /* Card tab sticks out to the left of the card */
  .card-tab { left: -25px; }
  .card-tab.nudge { animation: tabNudge 0.5s ease-in-out 3; }
  @keyframes tabNudge {
    0%, 100% { transform: translateY(-50%) translateX(0); }
    50%      { transform: translateY(-50%) translateX(-7px); }
  }

  .scrim {
    display: block;
    position: fixed;
    inset: var(--panel-top, 0px) 0 0 0;
    z-index: 15;
    background: rgba(26, 26, 26, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }
  body.panel-open .scrim { opacity: 1; pointer-events: auto; }

  /* While one panel is open, hide the other panel's tab */
  .ledger-panel.open ~ .card-panel .card-tab,
  body.card-open .log-tab { opacity: 0; pointer-events: none; }

  /* Keep the conversation clear of the tabs */
  .page-container { padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px)); }

  .card-actions .btn { height: auto; min-height: 40px; padding: 6px; white-space: normal; }
  #keep-talking { display: inline-block; color: var(--charcoal); }
  .view-card { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .card-panel, .card-panel.open, .ledger-panel { transition: none; }
  .card-carousel.restamp { animation: none; }
  .card-track { transition: none; }
}


/* ---- Phone menu: STORE and ABOUT tuck behind three lines ---- */
.menu-btn { display: none; }
@media (max-width: 860px) {
  .top-nav { position: relative; }
  .menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 0 8px;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
  }
  .menu-btn span { display: block; height: 3px; background: var(--charcoal); border-radius: 2px; }
  .nav-links {
    display: none;
    position: absolute;
    top: 58px;
    right: 0;
    z-index: 40;
    flex-direction: column;
    gap: 0;
    padding: 0;
    background: var(--offwhite);
    border: 3px solid var(--charcoal);
    min-width: 170px;
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    font-size: 0.95rem;
    padding: 14px 18px;
    border-bottom: 1px solid var(--hairline);
  }
  .nav-links a:last-child { border-bottom: none; }
}


/* ---- Cookie banner ---- */
.cookie-banner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  background: var(--offwhite);
  border-top: 3px solid var(--charcoal);
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}
.cookie-banner[hidden] { display: none; }
.cookie-banner p { font-size: 0.9rem; max-width: 60ch; }
.cookie-banner a { color: var(--charcoal); font-weight: 700; }
.cookie-actions { display: flex; gap: 8px; }
.cookie-actions .btn { padding: 9px 16px; font-size: 0.8rem; border-width: 2px; }
.about-links { font-size: 0.9rem; }
.about-links a { color: var(--charcoal); font-weight: 700; }
.menu-only { display: none; }
@media (max-width: 860px) {
  .nav-links .menu-only { display: block; }
  .cookie-banner { gap: 10px; }
  .cookie-banner p { font-size: 0.82rem; }
}


/* ---- Crisis mode: nothing playful, help in place of the log ---- */
body.crisis .header-section,
body.crisis #store-link,
body.crisis .ledger-panel,
body.crisis .card-panel,
body.crisis .edge-tab,
body.crisis .assignment-slot,
body.crisis .scrim { display: none !important; }
.help-panel {
  flex: 0 0 min(450px, 40%);
  border-left: 1px solid var(--hairline);
  padding-left: 30px;
  overflow-y: auto;
  min-height: 0;
}
.help-panel[hidden] { display: none; }
.help-list { display: flex; flex-direction: column; gap: 10px; }
.help-title { font-weight: 900; font-size: 1.15rem; text-transform: uppercase; line-height: 1.1; }
.help-sub { font-size: 0.9rem; color: #555; margin-bottom: 4px; }
.help-row {
  display: flex; flex-direction: column; gap: 2px;
  border: 2px solid var(--charcoal);
  padding: 10px 14px;
  text-decoration: none;
  color: var(--charcoal);
}
a.help-row:hover { background: var(--charcoal); color: var(--offwhite); }
.help-where { font-size: 0.7rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }
.help-what { font-size: 1.05rem; font-weight: 800; }
.help-note { font-size: 0.8rem; opacity: 0.8; }
.help-inline { display: none; max-width: 100%; width: 100%; }
body.crisis .audit-text { font-size: clamp(1rem, 2.4vh, 1.25rem); }
@media (max-width: 860px) {
  .help-panel { display: none !important; }
  .help-inline { display: block; }
}
