:root {
  --bg:#0c0c0e; --panel:#17171a; --panel-2:#202024; --border:#2c2c31;
  --text:#f4f4f6; --text-dim:#a2a2ab; --text-faint:#6e6e77;
  --accent:#d09e52; --on-accent:#2f2410; --danger:#c06a3e; --sage:#b9b98f;
  --radius:14px;
  --s0:#d09e52; --s1:#b9b98f; --s2:#8fb0c9; --s3:#c9908f; --s4:#a390c9;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  letter-spacing: 0;
  color-scheme: dark;
  --header-h: 60px;
  --bottom-chrome-h: calc(72px + env(safe-area-inset-bottom));
  --chrome-ease: cubic-bezier(0.32,0.72,0,1);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
}

button,
a,
input[type="range"],
summary {
  -webkit-tap-highlight-color: transparent;
}

button,
.pressable {
  transition: transform 160ms var(--chrome-ease), background-color 160ms var(--chrome-ease), border-color 160ms var(--chrome-ease), color 160ms var(--chrome-ease);
}

button:active,
.pressable:active {
  transform: scale(0.97);
}

a {
  color: inherit;
  text-decoration: none;
}

#app {
  min-height: 100svh;
}

.app-header {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  line-height: 1;
  letter-spacing: 0;
  color: var(--text);
}

.screens {
  min-height: 100svh;
  padding-top: calc(var(--header-h) + env(safe-area-inset-top));
}

.screen {
  display: none;
  width: 100%;
  min-height: calc(100svh - var(--header-h));
  padding: 14px 14px var(--bottom-chrome-h);
}

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

section[id] {
  scroll-margin-top: calc(var(--header-h) + env(safe-area-inset-top) + 12px);
}

.tabbar {
  position: fixed;
  z-index: 30;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  height: 52px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.34);
}

.tab {
  min-width: 0;
  height: 40px;
  padding: 0 8px;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.tab.is-active,
.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.profile-card,
.panel,
.chart-panel,
.value-card,
.accordion-item,
.rank-row,
.play-step,
.gives-back-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.profile-card,
.panel,
.chart-panel,
.play-step,
.gives-back-card {
  padding: 14px;
}

.loading-hint {
  margin: 0;
  color: var(--text-dim);
}

.profile-card {
  display: grid;
  gap: 12px;
}

.profile-card.is-collapsed .profile-fields {
  display: none;
}

.profile-header,
.section-head,
.row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kicker,
.label,
label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 650;
}

.dim,
.hint,
.subtle {
  color: var(--text-faint);
}

.profile-fields,
.control-grid,
.sim-controls {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  font-size: 16px;
}

input:focus,
select:focus,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button,
.save-button,
.sheet-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 750;
  cursor: pointer;
}

.ghost-button,
.icon-button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.segment {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer;
}

.segment.is-active,
.segment[aria-pressed="true"] {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

.city-chips,
.legend,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.city-chip,
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-dim);
}

.city-chip {
  cursor: pointer;
}

.city-chip.is-selected,
.city-chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
}

.city-chip.is-pinned {
  border-color: var(--sage);
}

.legend-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: currentColor;
}

[data-slot="0"] { color: var(--s0); }
[data-slot="1"] { color: var(--s1); }
[data-slot="2"] { color: var(--s2); }
[data-slot="3"] { color: var(--s3); }
[data-slot="4"] { color: var(--s4); }

.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(52px, auto);
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-value {
  min-width: 52px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.chart-panel {
  margin-top: 12px;
  aspect-ratio: 16 / 10;
  min-height: 240px;
  overflow: hidden;
}

.chart-panel canvas,
#sim-chart {
  display: block;
  width: 100%;
  height: 100%;
}

.value-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.value-card {
  display: grid;
  gap: 7px;
  min-height: 118px;
  padding: 12px;
}

.value-card .city {
  color: var(--text-dim);
  font-weight: 750;
}

.value-card .value {
  color: var(--text);
  font-size: clamp(24px, 8vw, 38px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.value-card .delta {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  width: 100%;
  margin-top: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
}

.compare-picker,
.rank-strip,
.ranked-table,
.play-list,
.notes-list {
  display: grid;
  gap: 10px;
}

.rank-strip {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.rank-card {
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.ranked-table {
  margin-top: 12px;
}

.rank-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  overflow: hidden;
}

.rank-row.is-berlin {
  border-color: var(--accent);
}

.rank-row .bar {
  position: absolute;
  inset: auto auto 0 0;
  z-index: 0;
  width: 0;
  height: 3px;
  background: var(--accent);
}

.rank-row > * {
  position: relative;
  z-index: 1;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-meta {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 12px;
}

.rank-value {
  color: var(--text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.rank-row details {
  grid-column: 1 / -1;
}

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

.accordion-item {
  overflow: hidden;
}

.accordion-item summary {
  min-height: 48px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 750;
  list-style: none;
}

.accordion-item summary::-webkit-details-marker {
  display: none;
}

.accordion-body {
  padding: 0 14px 14px;
  color: var(--text-dim);
}

.play-list {
  counter-reset: play;
}

.play-step {
  display: grid;
  gap: 8px;
  counter-increment: play;
}

.play-step::before {
  content: counter(play);
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
}

.play-title,
.card-title {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.2;
}

.play-body,
.card-body {
  margin: 0;
  color: var(--text-dim);
}

.worth-line {
  color: var(--sage);
  font-weight: 750;
}

.scrim {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: rgba(0,0,0,0.58);
  opacity: 0;
  transition: opacity 200ms var(--chrome-ease);
}

.scrim.is-open {
  opacity: 1;
}

.sheet {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(82svh, 680px);
  overflow: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(100%);
  transition: transform 200ms var(--chrome-ease);
}

.sheet.is-open {
  transform: translateY(0);
}

[hidden] {
  display: none !important;
}

@media (min-width: 720px) {
  html {
    --header-h: 64px;
    --bottom-chrome-h: 84px;
  }

  .app-header {
    padding-left: 24px;
    padding-right: 24px;
  }

  .screen {
    max-width: 1040px;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
  }

  .tabbar {
    left: 50%;
    right: auto;
    width: min(520px, calc(100vw - 32px));
    transform: translateX(-50%);
  }

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

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

  button:active,
  .pressable:active {
    transform: none;
  }
}

/* integration fixes (architect) */
.dim-accent { color: var(--accent); opacity: 0.75; font-size: 12px; }

/* compare screen vocabulary (integration, architect) */
.compare-picker { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.compare-picker::-webkit-scrollbar { display: none; }
.compare-picker-btn { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px;
  background: var(--panel-2); color: var(--text-dim); border: 1px solid var(--border);
  font-size: 13px; white-space: nowrap; transition: transform 160ms ease-out; }
.compare-picker-btn:active { transform: scale(0.97); }
.compare-picker-btn.is-active { background: var(--accent); color: var(--on-accent);
  border-color: var(--accent); }
.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-table th { text-align: left; color: var(--text-faint); font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 8px 6px; border-bottom: 1px solid var(--border); }
.compare-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.compare-table .rank-col { width: 26px; color: var(--text-faint); }
.compare-table .value-col { font-variant-numeric: tabular-nums; }
.compare-table .keep-col .chip { background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 8px; font-size: 11px; color: var(--sage); }
.compare-table .bar-col { width: 26%; }
.compare-table .bar { height: 6px; border-radius: 3px; background: var(--accent);
  opacity: 0.75; min-width: 2px; }
.compare-table tr.is-berlin td { color: var(--accent); }
.compare-table tr.is-berlin .bar { background: var(--sage); opacity: 1; }
.compare-table .detail-row td { background: var(--panel); font-size: 12px;
  color: var(--text-dim); }
.structure-name { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.structure-why { color: var(--text-dim); }
#compare-ranks { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px; margin: 12px 0 16px; }
.rank-chip { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column;
  gap: 3px; }
.rank-num { color: var(--accent); font-weight: 700; font-size: 13px; }
.rank-scenario { color: var(--text); font-size: 12px; }
.rank-why { color: var(--text-faint); font-size: 11px; line-height: 1.35; }

/* playbook + notes vocabulary (integration, architect) */
.play-step .step-num { display: none; } /* CSS counter chip already renders the number */
.step-title { margin: 0; color: var(--text); font-size: 16px; font-weight: 700; }
.step-body { margin: 0; color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.note-item { background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.note-header { display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; padding: 13px 14px; background: none; border: 0;
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; }
.note-header:active { transform: scale(0.99); }
.note-chevron { color: var(--text-faint); transition: transform 200ms cubic-bezier(0.32,0.72,0,1); }
.note-item.is-open .note-chevron { transform: rotate(180deg); }
.note-body { padding: 0 14px 13px; color: var(--text-dim); font-size: 13px; line-height: 1.55; }
.note-item:not(.is-open) .note-body { display: none; }
@media (prefers-reduced-motion: reduce) { .note-chevron { transition: none; } }
