:root {
  color-scheme: dark;
  --bg: #090b08;
  --panel: rgba(16, 20, 15, 0.92);
  --panel-strong: rgba(24, 29, 21, 0.96);
  --paper: #f3efe1;
  --paper-ink: #18170f;
  --muted: #9ea58f;
  --line: rgba(237, 242, 209, 0.12);
  --accent: #b7f35a;
  --accent-2: #e5c76b;
  --danger: #ff806d;
  --topbar-h: 74px;
  --bottom-h: 86px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: #eef5dc; }
body { touch-action: manipulation; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--bottom-h);
  background:
    radial-gradient(circle at 20% 0%, rgba(183, 243, 90, 0.16), transparent 32%),
    radial-gradient(circle at 90% 12%, rgba(229, 199, 107, 0.12), transparent 30%),
    var(--bg);
  overflow: hidden;
}

.topbar, .bottom-panel {
  background: linear-gradient(180deg, rgba(15, 18, 13, 0.96), rgba(15, 18, 13, 0.78));
  backdrop-filter: blur(22px);
  border-color: var(--line);
  z-index: 3;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(148px, 1fr) auto minmax(84px, 1fr);
  gap: 12px;
  align-items: center;
  padding: env(safe-area-inset-top) 16px 0;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand__mark { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 24px rgba(183, 243, 90, 0.32); }
.brand__text { display: grid; gap: 2px; min-width: 0; }
.brand strong { font-size: 17px; letter-spacing: 0; }
.brand small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }

.mode-switch { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.mode-switch__item { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 8px 10px; font-size: 14px; }
.mode-switch__item.is-active { background: rgba(183, 243, 90, 0.14); color: #f4ffe0; }

.account-chip { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.account-chip__cabinet, .ghost-button { border: 1px solid var(--line); color: #edf5d8; background: rgba(255,255,255,0.05); border-radius: 8px; padding: 8px 10px; }

.workspace { min-height: 0; overflow: hidden; }
.view { height: 100%; min-height: 0; display: none; }
.view.is-active { display: block; }

.auth-panel { grid-row: 2 / 4; padding: 22px; overflow: auto; }
.auth-panel__inner { max-width: 420px; margin: 6vh auto 0; display: grid; gap: 18px; padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.auth-panel h1 { margin: 0; font-size: 28px; }
.auth-panel p { margin: 0; color: var(--muted); }
.auth-form { display: grid; gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, textarea { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,0.05); color: #f7ffe7; padding: 11px 12px; outline: none; font-size: 16px; resize: vertical; }
input:focus, textarea:focus { border-color: rgba(183, 243, 90, 0.55); box-shadow: 0 0 0 3px rgba(183, 243, 90, 0.1); }
.auth-form button, .primary-action { border: 0; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #d9ff89); color: #101408; font-weight: 750; padding: 13px 16px; min-height: 46px; }
.inline-error { color: var(--danger); min-height: 18px; }

.feed-stage { height: 100%; min-height: 0; display: grid; grid-template-rows: auto 1fr; }
.roll-status { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.roll-status__main { color: #f4ffe0; font-weight: 650; }

.feed-track {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  padding: 14px;
}

.topic-card {
  min-height: var(--feed-card-min-h, 520px);
  scroll-snap-align: start;
  display: grid;
  align-content: start;
  gap: 12px;
  margin: 0 auto 14px;
  max-width: 760px;
  color: var(--paper-ink);
  background: var(--paper);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.28);
}
.topic-card h2 { margin: 0; font-size: 26px; line-height: 1.08; letter-spacing: 0; }
.topic-card p { margin: 0; line-height: 1.42; }
.topic-card__meta { display: flex; gap: 8px; flex-wrap: wrap; color: #5b5a47; font-size: 12px; }
.topic-card__block { display: grid; gap: 5px; }
.topic-card__block strong { font-size: 12px; text-transform: uppercase; color: #68643e; letter-spacing: 0.06em; }
.topic-card ul { margin: 0; padding-left: 18px; }
.topic-card li { margin: 4px 0; }
.topic-card__actions { margin-top: auto; display: flex; gap: 10px; }
.topic-card button { border: 1px solid rgba(24, 23, 15, 0.18); border-radius: 8px; background: #18170f; color: #f7f0cf; padding: 10px 12px; }

.empty-state { max-width: 560px; margin: 12vh auto; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--muted); }
.empty-state h2 { margin: 0 0 8px; color: #f4ffe0; }

.discussion-layout { height: 100%; min-height: 0; display: grid; grid-template-rows: auto 1fr; gap: 12px; padding: 14px; overflow: hidden; }
.selected-card, .discussion-thread, .settings-card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.selected-card { padding: 16px; }
.selected-card__eyebrow { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.selected-card h2 { margin: 6px 0 8px; }
.selected-card p { color: var(--muted); margin: 0; line-height: 1.45; }
.discussion-thread { min-height: 0; overflow: auto; padding: 14px; display: grid; gap: 12px; align-content: start; }
.message { max-width: 780px; padding: 12px; border-radius: 8px; line-height: 1.45; white-space: pre-wrap; }
.message--user { justify-self: end; background: rgba(183, 243, 90, 0.14); }
.message--ai { justify-self: start; background: rgba(255,255,255,0.06); }

.settings-layout { height: 100%; overflow: auto; padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-card { padding: 16px; display: grid; gap: 12px; align-content: start; }
.settings-card h2 { margin: 0; }
.radio-line, .switch-line { grid-template-columns: auto 1fr; align-items: center; color: #edf5d8; }
.radio-line input, .switch-line input { width: 18px; height: 18px; padding: 0; }

.bottom-panel { display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.bottom-panel > div { width: 100%; }
.discuss-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.discussion-composer { position: relative; }
.discussion-composer textarea { min-height: 46px; max-height: 120px; }
.composer-thinking { position: absolute; right: 10px; bottom: 9px; color: var(--accent); font-size: 12px; }
.primary-action--compact { min-width: 108px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 18px); transform: translateX(-50%); max-width: min(92vw, 520px); background: #f3efe1; color: #18170f; padding: 12px 14px; border-radius: 8px; box-shadow: 0 18px 60px rgba(0,0,0,0.35); z-index: 5; }
[hidden] { display: none !important; }

@media (max-width: 720px) {
  :root { --topbar-h: 94px; --bottom-h: 86px; }
  .topbar { grid-template-columns: 1fr auto; grid-template-rows: auto auto; padding-inline: 12px; gap: 8px; }
  .mode-switch { grid-column: 1 / -1; width: 100%; }
  .mode-switch__item { flex: 1; padding: 8px 6px; }
  .account-chip { grid-row: 1; grid-column: 2; }
  .brand small { max-width: 180px; }
  .roll-status { align-items: flex-start; flex-direction: column; gap: 3px; }
  .feed-track { padding: 10px; }
  .topic-card { padding: 15px; }
  .topic-card h2 { font-size: 23px; }
  .settings-layout { grid-template-columns: 1fr; }
  .discuss-actions { grid-template-columns: 1fr; }
}
