:root {
  color-scheme: light;
  --plane: #f9f9f9;
  --surface-1: #ffffff;
  --text-primary: #191919;
  --text-secondary: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.05);
  --series-1: #257de0;
  --series-2: #f47230;
  --up: #006c10;
  --down: #c4302b;
  --radius: 14px;
  --tabbar: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane: #0b0b0b;
    --surface-1: #191919;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.08);
    --series-1: #338ced;
    --series-2: #e76624;
    --up: #53c556;
    --down: #eb6263;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p,
ol,
ul {
  margin: 0;
}

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) max(16px, env(safe-area-inset-right))
    calc(var(--tabbar) + env(safe-area-inset-bottom) + 28px) max(16px, env(safe-area-inset-left));
}

.view > * + *,
#dash > * + * {
  margin-top: 16px;
}

.page-title,
.empty h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.muted,
.status {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Cards */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card > * + * {
  margin-top: 12px;
}

.card h2 {
  font-size: 17px;
  font-weight: 600;
}

/* Hero figure */

.hero-label {
  color: var(--text-secondary);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-value {
  font-size: 48px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.hero-cents {
  font-size: 24px;
  color: var(--text-secondary);
  letter-spacing: 0;
}

.delta {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.delta strong,
.tile-value.up,
.tile-value.down {
  font-weight: 600;
}

.up {
  color: var(--up);
}

.down {
  color: var(--down);
}

.badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}

/* Time range */

.ranges {
  display: flex;
  gap: 6px;
}

.ranges button {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.ranges button:hover {
  background: var(--wash);
}

.ranges button[aria-pressed="true"] {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--surface-1);
}

/* Chart */

.chart-card {
  padding: 14px 8px 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend > * {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
}

.legend button {
  border: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.legend button:hover {
  background: var(--wash);
}

.legend button[aria-pressed="false"] .key {
  background: var(--axis);
}

.key {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  flex: none;
}

.key.s1 {
  background: var(--series-1);
}

.key.s2 {
  background: var(--series-2);
}

.chart {
  position: relative;
  min-height: 264px;
}

.chart-svg {
  display: block;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
  outline: none;
  border-radius: 8px;
}

.chart-svg:focus-visible {
  box-shadow: 0 0 0 2px var(--series-1);
}

.chart-grid line {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart-axis {
  fill: var(--text-secondary);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-line.s1 {
  stroke: var(--series-1);
}

.chart-line.s2 {
  stroke: var(--series-2);
}

.chart-dot {
  stroke: var(--surface-1);
  stroke-width: 2;
}

.chart-dot.s1 {
  fill: var(--series-1);
}

.chart-dot.s2 {
  fill: var(--series-2);
}

.chart-crosshair {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart-end-label {
  fill: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
}

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.tip-date {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 2px;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.tip-name {
  color: var(--text-secondary);
}

/* Table view */

.table-view,
.help {
  font-size: 14px;
}

.table-view {
  padding: 0 8px;
}

summary {
  cursor: pointer;
  color: var(--text-secondary);
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

details[open] > summary::before {
  transform: rotate(45deg);
}

.table-scroll {
  max-height: 320px;
  overflow: auto;
  margin: 4px 0 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

th,
td {
  text-align: right;
  padding: 6px 4px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-weight: 500;
}

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

/* Stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}

.tile:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.tile-label {
  color: var(--text-secondary);
  font-size: 13px;
}

.tile-value {
  font-size: 20px;
  font-weight: 600;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.tile-note {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 2px;
}

/* Holdings */

.holding {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}

.holding:first-child {
  border-top: 0;
  padding-top: 0;
}

.holding:last-child {
  padding-bottom: 0;
}

.holding > :last-child {
  text-align: right;
  flex: none;
}

.holding strong {
  display: block;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.holding span {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Status line */

.status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.link {
  border: 0;
  background: none;
  padding: 6px 0;
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  flex: none;
}

/* Buttons and forms */

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

.btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--wash);
}

.btn.primary {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--surface-1);
}

.btn.primary:hover {
  opacity: 0.88;
}

.btn.danger {
  color: var(--down);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

:is(.btn, .link, .ranges button, .legend button, .tabbar a, summary, input):focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--axis);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.field-row {
  display: flex;
  gap: 8px;
}

.field-row input {
  flex: 1;
  min-width: 0;
}

.edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 6px 0;
}

.edit-row label {
  margin: 0;
  font-weight: 600;
}

.edit-row input {
  text-align: right;
}

.edit-row input.symbol {
  text-align: left;
  text-transform: uppercase;
}

.notice {
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--wash);
}

.issues {
  list-style: none;
  padding: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.issues:empty {
  display: none;
}

.issues li + li {
  margin-top: 4px;
}

.help ol,
.steps {
  padding-left: 20px;
  color: var(--text-secondary);
}

.help li + li,
.steps li + li {
  margin-top: 6px;
}

.steps {
  color: var(--text-primary);
}

.empty {
  padding-top: 24px;
}

.empty > * + * {
  margin-top: 16px;
}

/* Tab bar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 0 1 180px;
  height: var(--tabbar);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
}

.tabbar a[aria-current="page"] {
  color: var(--text-primary);
}

.tabbar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 600px) {
  .tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tile:last-child:nth-child(odd) {
    grid-column: auto;
  }

  .ranges {
    max-width: 360px;
  }
}

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