:root {
  color-scheme: dark light;
  --bg: #10130f;
  --surface: #171c15;
  --surface-strong: #20271d;
  --card: #f2ead0;
  --card-text: #171914;
  --text: #f5f1e5;
  --muted: #aeb6a7;
  --line: rgba(245, 241, 229, 0.12);
  --primary: #d3ff63;
  --primary-text: #11150f;
  --accent: #e6c06d;
  --danger: #ff786d;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --topbar-h: 68px;
  --bottom-h: 86px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f4ee;
    --surface: #ffffff;
    --surface-strong: #ebe7dc;
    --card: #151812;
    --card-text: #f8f3df;
    --text: #151812;
    --muted: #68705f;
    --line: rgba(21, 24, 18, 0.12);
    --shadow: 0 24px 60px rgba(45, 40, 24, 0.12);
  }
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

body {
  height: 100dvh;
  touch-action: pan-y;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--bottom-h);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--bg) 0 9px, transparent 10px),
    conic-gradient(from 24deg, var(--primary), var(--accent), #f5ead1, var(--primary));
  box-shadow: inset 0 0 0 1px var(--line);
  flex: 0 0 auto;
}

.brand__text {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.brand strong {
  font-size: 18px;
  line-height: 1;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-switch {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.mode-switch__item {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  color: var(--muted);
  background: transparent;
  min-width: 76px;
}

.mode-switch__item.is-active {
  color: var(--primary-text);
  background: var(--primary);
}

.account-chip {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-chip__balance,
.account-chip__cabinet {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  min-height: 0;
}

.view.is-active {
  display: block;
}

.auth-panel {
  padding: 24px;
}

.auth-panel__inner {
  max-width: 480px;
  margin: 8vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.auth-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.interest-input {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form input,
.interest-input textarea,
.discussion-composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
  font-size: 16px;
}

.auth-form input:focus,
.interest-input textarea:focus,
.discussion-composer textarea:focus {
  border-color: color-mix(in srgb, var(--primary) 70%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.auth-form button,
.primary-action {
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  padding: 14px 18px;
  font-weight: 800;
}

.ghost-button,
.icon-action {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
}

.inline-error {
  color: var(--danger);
}

.feed-stage {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 14px 16px;
}

.roll-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.roll-status__main {
  color: var(--text);
  font-weight: 700;
}

.feed-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(280px, 38vw);
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  padding: 2px 0 16px;
  min-height: 0;
}

.news-card--empty {
  max-width: 520px;
}

.news-card {
  scroll-snap-align: center;
  align-self: stretch;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--card-text);
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.news-card__meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: color-mix(in srgb, var(--card-text) 70%, transparent);
  font-size: 12px;
}

.news-card h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.08;
}

.news-card p {
  margin: 0;
  line-height: 1.42;
}

.news-card details {
  min-height: 0;
  overflow: auto;
}

.news-card summary {
  font-weight: 800;
  cursor: pointer;
  margin-bottom: 10px;
}

.news-card__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.news-card__actions button,
.news-card__actions a {
  border: 1px solid color-mix(in srgb, var(--card-text) 22%, transparent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--card-text);
  padding: 11px;
  text-align: center;
  text-decoration: none;
  font-weight: 700;
}

.discussion-layout,
.interests-layout {
  height: 100%;
  overflow: auto;
  padding: 16px;
}

.discussion-layout {
  display: grid;
  grid-template-columns: minmax(260px, 380px) minmax(0, 1fr);
  gap: 14px;
}

.selected-card,
.discussion-thread,
.interest-columns section,
.strictness {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
}

.selected-card h2 {
  margin: 6px 0 10px;
}

.selected-card__eyebrow,
.message__meta {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.discussion-thread {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.message {
  max-width: 760px;
  border-radius: var(--radius);
  padding: 13px 14px;
  background: var(--surface-strong);
  white-space: pre-wrap;
  line-height: 1.45;
}

.message--user {
  justify-self: end;
  background: color-mix(in srgb, var(--primary) 18%, var(--surface-strong));
}

.interests-layout {
  display: grid;
  gap: 14px;
  align-content: start;
  max-width: 1120px;
  margin: 0 auto;
}

.interest-input textarea {
  resize: vertical;
  min-height: 112px;
}

.strictness {
  display: grid;
  gap: 10px;
}

.strictness div {
  display: flex;
  justify-content: space-between;
}

.strictness input {
  width: 100%;
  accent-color: var(--primary);
}

.strictness p {
  margin: 0;
  color: var(--muted);
}

.interest-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.interest-columns[hidden] {
  display: none;
}

.interest-columns h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.chip input {
  margin-right: 6px;
  accent-color: var(--primary);
}

.bottom-panel {
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  z-index: 11;
}

.bottom-panel > div {
  height: 100%;
  display: grid;
  gap: 10px;
  align-items: center;
  max-width: 980px;
  margin: 0 auto;
}

.feed-actions,
.interest-actions {
  grid-template-columns: minmax(0, 1fr);
}

.discuss-actions {
  grid-template-columns: minmax(0, 1fr) auto;
}

.discussion-composer {
  position: relative;
  min-width: 0;
}

.discussion-composer textarea {
  min-height: 48px;
  max-height: 96px;
  resize: none;
  overflow: hidden;
  padding-right: 70px;
}

.composer-thinking {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
}

.primary-action:disabled,
.ghost-button:disabled,
.discussion-composer textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary-action--compact {
  white-space: nowrap;
}

.icon-action {
  width: 48px;
  height: 48px;
  position: relative;
}

.icon-action::before {
  content: "";
  position: absolute;
  inset: 14px 15px 10px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 4px 4px;
}

.icon-action::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 12px;
  width: 2px;
  height: 19px;
  background: currentColor;
  box-shadow: -5px 5px 0 -3px currentColor, 5px 5px 0 -3px currentColor;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-h) + 18px);
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 760px) {
  :root {
    --topbar-h: 104px;
    --bottom-h: 96px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 8px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .account-chip {
    grid-column: 2;
    grid-row: 1;
  }

  .mode-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .mode-switch__item {
    min-width: 0;
    width: 100%;
    padding: 9px 8px;
  }

  .brand small {
    max-width: 150px;
  }

  .account-chip__cabinet {
    width: 42px;
    height: 42px;
    padding: 0;
    overflow: hidden;
    text-indent: 100px;
    position: relative;
  }

  .account-chip__cabinet::before {
    content: "";
    position: absolute;
    inset: 11px;
    border: 2px solid currentColor;
    border-radius: 50% 50% 45% 45%;
  }

  .account-chip__cabinet::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 9px;
    height: 9px;
    border: 2px solid currentColor;
    border-radius: 10px 10px 4px 4px;
    border-top: 0;
  }

  .feed-stage {
    padding: 10px 10px 12px;
  }

  .roll-status {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .feed-track {
    grid-auto-columns: minmax(286px, calc(100vw - 30px));
  }

  .news-card h2 {
    font-size: 21px;
  }

  .discussion-layout {
    grid-template-columns: 1fr;
  }

  .interest-columns {
    grid-template-columns: 1fr;
  }

  .bottom-panel > div {
    max-width: none;
  }

  .discuss-actions {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .primary-action--compact {
    min-width: 112px;
    padding-left: 12px;
    padding-right: 12px;
  }
}
