:root {
  color-scheme: dark;
  --bg: #101412;
  --ink: #f1f7f2;
  --muted: #b8c7be;
  --soft: #2a3832;
  --line: #3b4d45;
  --panel: #17201c;
  --panel-2: #202b26;
  --field: #0e1412;
  --accent: #78dcc7;
  --accent-2: #f0a15f;
  --good: #8bdc9b;
  --bad: #ff9589;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f8f4;
  --ink: #18201d;
  --muted: #626d67;
  --soft: #e7ece4;
  --line: #d3dbd0;
  --panel: #ffffff;
  --panel-2: #eef3eb;
  --field: #ffffff;
  --accent: #0a7068;
  --accent-2: #b85c38;
  --good: #1d7d45;
  --bad: #a33a2f;
  --shadow: 0 14px 40px rgba(24, 32, 29, 0.08);
}

body[data-theme="contrast"] {
  color-scheme: dark;
  --bg: #000000;
  --ink: #ffffff;
  --muted: #d4d4d4;
  --soft: #3a3a3a;
  --line: #ffffff;
  --panel: #090909;
  --panel-2: #151515;
  --field: #000000;
  --accent: #8ee8ff;
  --accent-2: #ffe16b;
  --good: #9fff9f;
  --bad: #ff9c9c;
  --shadow: none;
}

body[data-theme="amber"] {
  color-scheme: dark;
  --bg: #11110f;
  --ink: #fff5d4;
  --muted: #dccb9f;
  --soft: #3a3426;
  --line: #5a4d32;
  --panel: #1b1a15;
  --panel-2: #272216;
  --field: #10100d;
  --accent: #ffd166;
  --accent-2: #7cd5d0;
  --good: #a7e27d;
  --bad: #ff9c76;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: Atkinson Hyperlegible Next, Atkinson Hyperlegible, Lexend, Noto Sans, OpenDyslexic, -apple-system, BlinkMacSystemFont, Segoe UI, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

body.comfort-text {
  font-family: Atkinson Hyperlegible Next, Atkinson Hyperlegible, Lexend, Noto Sans, OpenDyslexic, Verdana, -apple-system, BlinkMacSystemFont, Segoe UI, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.62;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 52px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 58px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  flex: 0 0 auto;
}

.brand svg,
.icon-button svg,
.mini-button svg,
.market-focus svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: 16px;
  line-height: 1.15;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.mini-button,
.toggle-button,
.segmented button,
.market-focus {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--ink) 4%);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-button {
  display: grid;
  grid-template-columns: 24px;
  place-items: center;
  width: 42px;
  height: 42px;
}

.icon-button span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.icon-button:hover,
.mini-button:hover,
.toggle-button:hover,
.segmented button:hover,
.market-focus:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.icon-button.is-active,
.toggle-button.is-active,
.segmented button.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  color: var(--accent);
}

.native-only {
  display: none;
}

.native-shell .native-only {
  display: grid;
}

main {
  display: grid;
  gap: 18px;
}

.settings-band {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button,
.toggle-button {
  min-height: 38px;
  padding: 0 13px;
  font-weight: 700;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 26px;
  align-items: end;
  padding: 44px 0 18px;
}

.hero h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(38px, 6.6vw, 70px);
  line-height: 1.02;
  letter-spacing: 0;
}

.hero p {
  max-width: 720px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.52;
}

.privacy-panel,
.panel,
.controls,
.status-strip,
.source-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
}

.privacy-panel {
  display: grid;
  gap: 8px;
  padding: 20px;
}

.privacy-panel strong {
  font-size: 20px;
}

.privacy-panel span,
.source-panel p,
.selected-signal p {
  color: var(--muted);
  line-height: 1.48;
}

.controls {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 16px;
}

label,
.status-label,
dt {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topic-form,
.ask-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.topic-form input,
.ask-form input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
}

.topic-form button,
.ask-form button {
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-weight: 800;
}

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

.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 7px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
}

.topic-chip button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.topic-chip button:hover {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  color: var(--ink);
}

.status-strip {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 1px;
  overflow: hidden;
}

.status-strip > div {
  padding: 16px;
  background: color-mix(in srgb, var(--panel) 76%, var(--bg));
  min-width: 0;
}

.status-strip strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.source-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 18px;
  padding: 18px;
}

.source-panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.source-panel p {
  margin: 0;
}

.source-panel dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.source-panel dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.grid.two,
.focus-grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.focus-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.nav-pair {
  display: flex;
  gap: 6px;
}

.mini-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
}

.mini-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.selected-signal {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.selected-signal h3 {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.selected-signal p {
  margin: 8px 0 0;
}

.selected-price {
  min-width: 110px;
  text-align: right;
}

.selected-price strong {
  display: block;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.selected-price span,
.selected-price small {
  display: block;
  margin-top: 7px;
  color: var(--accent-2);
}

.selected-price small {
  color: var(--muted);
}

.chat-transcript,
.memory-list,
.market-list,
.topic-windows {
  display: grid;
  gap: 10px;
}

.chat-transcript {
  margin-top: 12px;
  max-height: 340px;
  overflow: auto;
  padding-right: 4px;
}

.chat-entry,
.memory-row {
  display: grid;
  gap: 6px;
  padding: 13px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 80%, var(--bg));
}

.chat-entry strong,
.memory-row strong {
  overflow-wrap: anywhere;
}

.chat-entry p {
  margin: 0;
  color: var(--muted);
  line-height: 1.48;
}

.chat-entry span,
.memory-row span,
.memory-row small {
  color: var(--muted);
  font-size: 12px;
}

.market-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

.market-row.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
}

.market-title {
  display: inline-block;
  max-width: 100%;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.market-title:hover {
  color: var(--accent);
}

.market-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.market-synopsis {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.market-price {
  min-width: 98px;
  text-align: right;
}

.market-price strong {
  display: block;
  color: var(--accent);
  font-size: 27px;
  line-height: 1;
}

.market-price span {
  display: block;
  margin-top: 6px;
  color: var(--accent-2);
  font-size: 13px;
}

.market-focus {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
}

.market-focus svg {
  width: 18px;
  height: 18px;
}

.topic-window {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 86%, var(--bg));
}

.topic-window h3 {
  margin: 0;
  font-size: 17px;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .hero,
  .controls,
  .grid.two,
  .status-strip,
  .source-panel,
  .focus-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 22px, 1180px);
    padding-top: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    align-items: start;
  }

  .brand > span:last-child {
    min-width: 0;
  }

  .brand small {
    white-space: normal;
  }

  .top-actions {
    gap: 6px;
    justify-content: start;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .hero {
    padding-top: 26px;
  }

  .hero h1 {
    max-width: 100%;
    font-size: clamp(31px, 8vw, 36px);
    line-height: 1.08;
    overflow-wrap: normal;
  }

  .hero p {
    font-size: 16px;
  }

  .privacy-panel,
  .panel,
  .controls,
  .status-strip,
  .source-panel {
    max-width: 100%;
    overflow: hidden;
  }

  .panel-head {
    display: grid;
    gap: 8px;
  }

  .market-row,
  .selected-signal {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .market-price,
  .selected-price {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: 368px;
    max-width: calc(100vw - 22px);
    margin-left: 11px;
    margin-right: 0;
  }

  .settings-band {
    display: grid;
    justify-content: stretch;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
