* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
}
body {
  /* Deep Blue: navy with a blue glow top-left, an orange glow bottom-right and a few faint stars. */
  background: var(--bg-stars), var(--bg-glows), var(--bg);
  background-attachment: fixed;
}

/* Document pages (privacy, terms, credits) scroll like normal pages; the app shell above
   locks scrolling, which left the bottom of the legal text unreachable (AUDIT.md P0-6). */
html:has(body.doc-page),
body.doc-page {
  height: auto;
  min-height: 100%;
  overflow: auto;
}

h1,
h2,
h3 {
  font-family: var(--font-ui);
}
.profile-row strong,
.sidebar-meta {
  font-family: var(--font-ui); font-variant-numeric: tabular-nums;
}

/* One paper panel (sidebar, composer, dialogs): hairline plus the card shadow. */
.paper-panel {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}

.app-layout {
  position: relative;
  z-index: 1;
  --side-w: 240px;
  --desk-w: 360px;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--desk-w);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar-backdrop {
  display: none;
}
.sidebar-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--info) 16%, transparent);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-close {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin-left: auto;
  font-size: 14px;
  line-height: 1;
}

/* Sidebar — fixed column, no page scroll */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  top: 0;
  align-self: start;
  padding: 20px 14px;
  border-radius: 0;
  border-top: 0; border-bottom: 0; border-left: 0;
  background: var(--raised);
}

.sidebar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
  position: relative;
}
.sidebar-meta { flex-basis: 100%; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand-logo {
  display: block;
  height: 36px;
  width: auto;
  object-fit: contain;
}
.beta {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: var(--raised);
  color: var(--on-color);
  padding: 3px 7px;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.sidebar-meta {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-top: 10px;
  padding-left: 4px;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}
.nav-item:hover {
  color: var(--ink);
  background: var(--raised);
  border-color: var(--line);
}
.nav-item.active {
  color: var(--ink);
  background: var(--raised);
  border-color: color-mix(in srgb, var(--coin) 25%, transparent);
  box-shadow: var(--shadow);
}

.recent-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 14px 0 12px;
  padding: 0 4px;
}

.recent-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0 8px;
}

.recent-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.recent-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  margin: 0;
}

.recent-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.recent-row:hover {
  background: var(--raised);
  border-color: var(--line);
}

.recent-row:hover .recent-menu-btn {
  opacity: 1;
}

.recent-row.active {
  background: var(--raised);
  border-color: color-mix(in srgb, var(--coin) 25%, transparent);
}

.recent-row.pinned .recent-title {
  color: var(--world-home);
}

.recent-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 6px 10px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.recent-row:hover .recent-open,
.recent-row.active .recent-open {
  color: var(--ink);
}

.recent-menu-btn {
  flex-shrink: 0;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.recent-row.active .recent-menu-btn,
.recent-menu-btn:focus-visible {
  opacity: 1;
}

.recent-menu-btn:hover,
.recent-menu-btn[aria-expanded="true"] {
  opacity: 1;
  background: var(--paper-2);
  color: var(--ink);
}

.recent-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
}

.pin-icon {
  font-size: 10px;
  flex-shrink: 0;
}

.recent-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.recent-time {
  font-size: 10px;
  opacity: 0.7;
}

.chat-context-menu {
  position: fixed;
  z-index: 2000;
  min-width: 168px;
  padding: 6px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}

.chat-menu-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-menu-item:hover {
  background: var(--raised);
}

.chat-menu-item.danger {
  color: var(--action);
}

.chat-menu-item.danger:hover {
  background: color-mix(in srgb, var(--action) 15%, transparent);
}

.finai-toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 3000;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.finai-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (hover: none) {
  .recent-menu-btn {
    opacity: 0.7;
  }
}

.profile-card {
  flex-shrink: 0;
  margin-top: auto;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--raised);
  border: 1px solid var(--line);
  font-size: 12px;
}
.profile-title {
  font-weight: 700;
  margin-bottom: 12px;
  background: none;
  color: var(--ink);
}
.profile-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
}
.profile-row strong { color: var(--ink); }
.profile-user {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.profile-head .profile-title { margin-bottom: 0; }
.profile-edit-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.profile-edit-btn:hover {
  color: var(--ink);
  border-color: var(--info);
  box-shadow: var(--shadow);
}

.profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
}
.profile-overlay[hidden] { display: none; }

.profile-modal {
  width: min(560px, 100%);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
}
.profile-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--line);
}
.profile-modal-head h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}
.profile-close-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.profile-close-btn:hover { color: var(--ink); }

.profile-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
}
.profile-tab {
  flex: 1;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 10px 8px;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.profile-tab.active {
  color: var(--ink);
  background: var(--raised);
  border-color: var(--line);
  border-bottom-color: transparent;
}

.profile-modal-body {
  padding: 16px 22px;
  overflow-y: auto;
  flex: 1;
}
.profile-panel-section { display: flex; flex-direction: column; gap: 12px; }
.profile-panel-section[hidden] { display: none !important; }

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.field-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--scrim);
  color: var(--ink);
  font-size: 14px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}
.field-check input { accent-color: var(--info); }

.profile-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
}
.profile-save-status.error { color: var(--action); }
.btn-primary {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  background: var(--raised);
  box-shadow: var(--shadow);
}
.btn-primary:hover { filter: brightness(1.08); }

.settings-danger-zone {
  margin-top: 20px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--action) 35%, transparent);
  background: color-mix(in srgb, var(--action) 6%, transparent);
}
.settings-danger-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--action);
}
.settings-danger-lead {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.45;
}
.settings-danger-list {
  margin: 0 0 12px 18px;
  padding: 0;
  font-size: 12px;
  line-height: 1.5;
}
.settings-danger-note {
  margin: 0 0 12px;
  font-size: 12px;
}
.btn-danger-outline {
  border: 1px solid color-mix(in srgb, var(--action) 55%, transparent);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--action);
  background: transparent;
}
.btn-danger-outline:hover {
  background: color-mix(in srgb, var(--action) 12%, transparent);
}
.btn-danger {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  background: var(--raised);
  margin-top: 12px;
}
.btn-danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.user-wipe-modal {
  max-width: 480px;
}
.user-wipe-body {
  padding: 0 22px 22px;
  font-size: 14px;
  line-height: 1.5;
}
.user-wipe-body p { margin: 0 0 10px; }
.user-wipe-warning {
  color: var(--action);
  margin: 12px 0 !important;
}
.user-wipe-check {
  margin: 12px 0;
}
body.user-wipe-open { overflow: hidden; }

body.compact-ui .decision-block,
body.compact-ui .dash-card {
  padding: 10px 12px;
}
body.compact-ui .bubble.rich {
  padding: 12px 14px;
}

body.profile-open { overflow: hidden; }

/* Main area — only chat scrolls */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  overflow: hidden;
}

@keyframes pulse { 0%,100%{opacity:1; transform:scale(1)} 50%{opacity:.6; transform:scale(.9)} }

.chat-shell {
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 10px 20px;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.chat {
  grid-row: 1;
  grid-column: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  padding: 8px 4px 8px;
  min-height: 0;
  overscroll-behavior: contain;
  scroll-padding-top: 8px;
  scroll-padding-bottom: 16px;
}

.composer-wrap {
  grid-row: 2;
  grid-column: 1;
  flex-shrink: 0;
  padding: 14px;
  border-radius: var(--radius);
  margin-top: 0;
}

/* Deep Blue type (CANVAS item 1): headlines 800 with slight negative tracking; every number in mono. */
h1, h2, h3 { font-weight: 800; letter-spacing: var(--tracking-head); }
.num, [data-num], .month-num, .pill-xp, .answer-cost strong, .answer-bar strong, .where-row strong, .cal-num,
.payday-day b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
