:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --raised: #eaf1f2;
  --text: #102633;
  --muted: #536a75;
  --border: #82969e;
  --teal: #006d69;
  --gold: #76520c;
  --positive: #08734c;
  --warning: #8a4d0c;
  --danger: #a32236;
  --disabled-bg: #e5eaec;
  --disabled-text: #52656e;
  --disabled-border: #82969e;
  --nav: #ffffff;
  --shadow: 0 8px 24px rgba(5, 31, 41, .08);
  --focus: #006d69;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071521;
  --surface: #0d2230;
  --raised: #143342;
  --text: #f5fafb;
  --muted: #b3c4ca;
  --border: #587786;
  --teal: #58ddd3;
  --gold: #f1ca67;
  --positive: #65dda8;
  --warning: #ffc16c;
  --danger: #ff8994;
  --disabled-bg: #18313d;
  --disabled-text: #b4c2c8;
  --disabled-border: #587786;
  --nav: #0a1d29;
  --shadow: none;
  --focus: #72e9df;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-width: 0;
  min-height: 100%;
  background: var(--bg);
}

html { text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }

body {
  color: var(--text);
  font: 1rem/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open { overflow: hidden; }

body, button, a, summary, p, span, strong, h1, h2, h3, time {
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}

.quote-meta {
  color: var(--muted);
  font-size: .78rem;
  margin: .2rem 0 .35rem;
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }
h1, h2, h3, p, figure { margin: 0; }
h1 { font-size: 1.125rem; line-height: 1.35; font-weight: 720; }
h2 { font-size: 1rem; line-height: 1.4; font-weight: 720; }
h3 { margin-top: 1rem; font-size: .875rem; line-height: 1.4; color: var(--muted); }

#app {
  width: 100%;
  max-width: 32.5rem;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

.shell {
  min-height: 100dvh;
  padding: 1rem 1rem calc(7rem + env(safe-area-inset-bottom));
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .625rem;
}

.brand {
  display: flex;
  align-items: center;
  flex: 1 1 12rem;
  min-width: 0;
  gap: .625rem;
}

.brand img {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: .75rem;
  object-fit: contain;
}

.brand-copy { min-width: 0; }

.eyebrow {
  display: block;
  color: var(--gold);
  font-size: .6875rem;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: .01em;
}

.theme,
.back,
.filter,
.control,
summary,
.term,
.nav-item {
  min-height: 2.75rem;
  min-width: 2.75rem;
}

.theme {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .5rem .75rem;
  background: var(--raised);
  color: var(--teal);
  font-size: .75rem;
  line-height: 1.25;
  font-weight: 700;
  cursor: pointer;
}

.back {
  display: inline-flex;
  align-items: center;
  margin: 0 0 .75rem;
  padding: 0 .25rem;
  color: var(--teal);
  font-weight: 700;
  text-decoration: none;
}

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: .75rem;
}

.card {
  width: 100%;
  min-width: 0;
  padding: clamp(12px, .875rem, 15px);
  border: 1px solid var(--border);
  border-radius: 1.125rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.notice {
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
  background: var(--raised);
  color: var(--muted);
}

.virtual-warning {
  color: var(--gold);
  font-weight: 720;
  text-align: center;
}

.summary-head,
.system-card-head,
.operation-head,
.decision-heading,
.section-label,
.time-row,
.status-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
  gap: .75rem;
  flex-wrap: wrap;
}

.system-card-head h2 { flex: 1 1 auto; min-width: max-content; }
.operation-head h2,
.decision-heading h2 { flex: 1 1 auto; min-width: 0; }

.label,
.muted { color: var(--muted); }

.label { font-size: .8125rem; line-height: 1.4; font-weight: 600; }

.badge,
.side-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 1.75rem;
  padding: .3125rem .5625rem;
  border-radius: 999px;
  background: var(--raised);
  color: var(--gold);
  font-size: .6875rem;
  line-height: 1.3;
  font-weight: 750;
  white-space: normal;
}

.badge.teal { color: var(--teal); }
.side-badge { color: var(--text); }

.value {
  margin: .5rem 0 .25rem;
  font-size: clamp(1.5rem, 8vw, 2.25rem);
  line-height: 1.2;
  font-weight: 780;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.positive { color: var(--positive); }
.warning { color: var(--warning); }
.danger { color: var(--danger); }
.supporting, .disclosure { margin-top: .5rem; color: var(--muted); }
.operation-head { font-size: .875rem; }

.compact-empty {
  margin-top: .75rem;
  padding: .625rem .75rem;
  border-radius: .75rem;
  background: var(--raised);
  color: var(--muted);
  font-size: .8125rem;
}

.system-card {
  display: block;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, border-color .12s ease, background-color .12s ease;
}

.system-card:active { transform: scale(.985); background: var(--raised); }

.account-summary,
.metrics,
.status-list,
.operation-fields,
.decision-facts {
  display: grid;
  gap: .625rem;
  margin-top: .75rem;
}

.account-summary,
.metrics,
.status-list,
.operation-fields,
.limits,
.controls { font-size: .875rem; }
.decision-facts { font-size: .8125rem; }

.metric,
.operation-line,
.decision-facts > div,
.technical-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
  gap: .875rem;
  flex-wrap: wrap;
}

.metric > :first-child,
.operation-line > :first-child,
.decision-facts span,
.technical-row > :first-child { color: var(--muted); }

.metric > :last-child,
.operation-line > :last-child { text-align: right; }
.metric > *,
.operation-line > *,
.status-row > *,
.time-row > * { max-width: 100%; }

.card-action {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 2.75rem;
  margin-top: .25rem;
  color: var(--teal);
  font-weight: 750;
}

.chart-empty {
  margin-top: .75rem;
  padding: .625rem .75rem;
  border-radius: .75rem;
  background: var(--raised);
  color: var(--muted);
  font-size: .8125rem;
  text-align: center;
}

.chart-figure { margin-top: .75rem; }
.chart-figure figcaption { margin-bottom: .5rem; font-weight: 700; }
.chart { width: 100%; height: 4.5rem; border-radius: .75rem; background: var(--raised); overflow: hidden; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart + .label { margin-top: .375rem; }

.decision-action { margin-top: .5rem; color: var(--teal); font-weight: 750; }
.decision-facts > div { flex-direction: column; gap: .125rem; }
.decision-facts strong { font-weight: 650; }
.confidence { margin-top: .75rem; color: var(--muted); }
.time-row { margin-top: .75rem; color: var(--muted); font-size: .8125rem; }
.time-row time { text-align: right; }

.operation-fields { padding-top: .25rem; }
.cash-flow { color: var(--text); }
.cash-flow > :first-child { color: var(--text); }

details {
  margin-top: .75rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

summary {
  display: flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  color: var(--teal);
  font-weight: 700;
  cursor: pointer;
}

details[open] summary { margin-bottom: .5rem; }
.detail-copy { color: var(--muted); }

.adviser,
.journal-item {
  padding: .75rem 0;
  border-top: 1px solid var(--border);
}

.adviser:first-of-type,
.journal-item:first-of-type { border-top: 0; }
.adviser p { margin-top: .25rem; color: var(--muted); }

.research-card { border-color: var(--teal); }
.research-card .system-card-head h2 { min-width: 0; }
.research-empty p + p { margin-top: .75rem; }
.why-content { font-size: .75rem; }
.why-content .system-card-head h2 { min-width: 0; }
.why-content .why-list { font-size: .875em; padding-left: 1rem; }
.why-list { display: grid; gap: .625rem; margin: .625rem 0 0; padding-left: 1.25rem; }
.why-list li { padding-left: .125rem; }
.factor-code { display: block; margin-top: .125rem; color: var(--muted); font-size: .75rem; }
.audit-details { border-top: 1px solid var(--border); }
.audit-details code { overflow-wrap: anywhere; word-break: break-all; }

.status-row { padding: .25rem 0; }
.status-row strong { text-align: right; }
.status-notice { margin-top: .75rem; font-size: .75rem; }

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: .5rem;
  margin-top: .75rem;
}

.control {
  padding: .625rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
  background: var(--raised);
  font-weight: 720;
  cursor: pointer;
}

.control.primary { border-color: var(--teal); background: var(--teal); color: #ffffff; }
[data-theme="dark"] .control.primary { color: #071521; }
.control.danger-control { color: var(--danger); }
.control:disabled {
  border-color: var(--disabled-border);
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.control.primary:disabled {
  border-color: var(--disabled-border);
  background: var(--disabled-bg);
  color: var(--disabled-text);
}

.limits {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: .5rem;
  margin-top: 1rem;
}

.limits > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: .25rem;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: .75rem;
  background: var(--raised);
}

.limits span { color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 5.5rem), 1fr));
  gap: .5rem;
  padding: .625rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
}

.filter {
  padding: .5rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--raised);
  color: var(--gold);
  font-weight: 700;
  cursor: pointer;
}

.filter.active { border-color: var(--teal); color: var(--teal); }

.journal-main,
.journal-meta { display: grid; gap: .25rem; }
.journal-main span { color: var(--text); }
.journal-meta { margin-top: .375rem; color: var(--muted); font-size: .8125rem; }

.technical { display: grid; gap: .5rem; }
.technical code {
  min-width: 0;
  color: var(--text);
  font-size: .75rem;
  text-align: right;
  overflow-wrap: break-word;
  word-break: break-word;
}

.term {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  border-bottom: 1px dotted currentColor;
  background: transparent;
  color: inherit;
  cursor: help;
}
.tooltip-anchor { display: none; }

.tooltip {
  position: fixed;
  z-index: 40;
  left: 1rem;
  right: 1rem;
  bottom: calc(5.25rem + env(safe-area-inset-bottom));
  max-width: 30.5rem;
  margin: auto;
  padding: .75rem .875rem;
  border: 1px solid var(--border);
  border-radius: .875rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

.bottom-nav {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 4.5rem), 1fr));
  width: min(100%, 32.5rem);
  min-height: calc(4.25rem + env(safe-area-inset-bottom));
  padding: .375rem .5rem calc(.5rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--nav);
}

.nav-item {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .125rem;
  padding: .25rem .125rem;
  color: var(--muted);
  font-size: .6875rem;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
}

.nav-item.active { color: var(--teal); font-weight: 750; }
.nav-item .dot { line-height: 1; }

.end-sentinel { width: 100%; height: 1px; margin-top: 1rem; scroll-margin-bottom: calc(7rem + env(safe-area-inset-bottom)); }

.boot,
.gate {
  display: grid;
  min-height: 100dvh;
  place-content: center;
  justify-items: center;
  gap: .875rem;
  padding: 1.5rem;
  color: var(--muted);
  text-align: center;
}

.boot img,
.gate img { width: 3.625rem; height: 3.625rem; border-radius: .875rem; }

.modal-wrap {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 1rem;
  background: rgba(3, 15, 22, .72);
}

.modal {
  width: min(100%, 30.5rem);
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  background: var(--surface);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .24);
}

.modal h2 { font-size: 1.25rem; }
.modal p { margin: .5rem 0 1rem; color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); gap: .5rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

h1[tabindex="-1"]:focus { outline: none; }

@media (max-width: 23.5rem) {
  .shell { padding-inline: .75rem; }
  .system-card-head,
  .operation-head,
  .decision-heading,
  .summary-head,
  .time-row,
  .status-row,
  .metric,
  .operation-line,
  .technical-row {
    flex-direction: column;
    align-items: flex-start;
    gap: .1875rem;
  }
  .metric > :last-child,
  .operation-line > :last-child,
  .time-row time,
  .status-row strong,
  .technical code { text-align: left; }
  .controls,
  .limits { grid-template-columns: 1fr; }
  .brand { flex-basis: 100%; }
  .theme { margin-left: auto; }
}

@media (min-width: 32.5625rem) { #app { border-inline: 1px solid var(--border); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
