:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-alt: #efede6;
  --text: #1d1d1b;
  --text-2: #5f5e5a;
  --text-3: #8c8b85;
  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.2);
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --good: #0f6e56;
  --good-bg: #e1f5ee;
  --bad: #a32d2d;
  --bad-bg: #fcebeb;
  --warn: #854f0b;
  --warn-bg: #faeeda;
  --c1: #1d9e75; --c2: #378add; --c3: #ba7517; --c4: #7f77dd; --c5: #d85a30; --c6: #888780;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b19;
    --surface: #252523;
    --surface-alt: #2e2e2b;
    --text: #f1efe8;
    --text-2: #b4b2a9;
    --text-3: #888780;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.22);
    --accent: #85b7eb;
    --accent-bg: #0c447c;
    --good: #5dcaa5;
    --good-bg: #085041;
    --bad: #f09595;
    --bad-bg: #791f1f;
    --warn: #fac775;
    --warn-bg: #633806;
    --c1: #5dcaa5; --c2: #85b7eb; --c3: #ef9f27; --c4: #afa9ec; --c5: #f0997b; --c6: #b4b2a9;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); font-size: 13px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; flex-shrink: 1; }
@media (max-width: 640px) { .brand { max-width: 100%; text-align: center; } }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 14px;
}
.tabs a:hover { background: var(--surface-alt); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

.container { max-width: 980px; margin: 0 auto; padding: 20px 16px 64px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--text-3); }

button.tile-link {
  text-align: left; width: 100%; font: inherit; color: inherit; cursor: pointer; position: relative;
  border-radius: var(--radius); padding: 12px 28px 12px 14px; transition: border-color .15s, transform .1s;
}
button.tile-link::after { content: "›"; position: absolute; right: 12px; top: 10px; color: var(--text-3); font-size: 20px; }
button.tile-link:hover { background: var(--surface); border-color: var(--border-strong); }
button.tile-link:active { transform: scale(0.98); }
button.row-link {
  width: 100%; font: inherit; color: inherit; background: none; border: 0; border-bottom: 1px solid var(--border);
  border-radius: 0; padding: 10px 0; cursor: pointer;
}
button.row-link:hover { background: var(--surface-alt); }
button.row-link:last-of-type { border-bottom: 0; }
.share { height: 4px; background: var(--surface-alt); border-radius: 99px; margin-top: 6px; max-width: 220px; }
.share > div { height: 100%; background: var(--c1); border-radius: 99px; }

.video-card { margin-bottom: 16px; border-radius: 14px; overflow: hidden; background: #000; border: 1px solid var(--border); }
.video-facade, .video-frame { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; padding: 0; margin: 0; background: #000; border-radius: 0; }
.video-facade { position: relative; cursor: pointer; }
.video-facade:hover { background: #000; }
.video-facade img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .85; }
.video-play {
  position: absolute; left: 50%; top: 50%; width: 68px; height: 48px; transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, .7); border-radius: 12px;
}
.video-play::after {
  content: ""; position: absolute; left: 27px; top: 14px;
  border-style: solid; border-width: 10px 0 10px 17px; border-color: transparent transparent transparent #fff;
}
.video-facade:hover .video-play { background: #e00; }
.video-caption { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: var(--surface); font-size: 13px; color: var(--text-2); }

.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.hero .big { font-size: 38px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 300px; }

.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-2); vertical-align: 1px;
}
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.accent { background: var(--accent-bg); color: var(--accent); }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 24px 0 10px; flex-wrap: wrap; }
.section-head:first-child { margin-top: 0; }

button, .btn {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--surface-alt); }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.primary:hover { opacity: .88; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
button.danger { color: var(--bad); }
button.small { font-size: 13px; padding: 3px 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { padding: 0; accent-color: var(--accent); }
.form-grid { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.error { color: var(--bad); font-size: 13px; min-height: 1em; margin: 0 0 8px; }

.money-input { position: relative; }
.money-input::before { content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.money-input input { padding-left: 22px; text-align: right; font-variant-numeric: tabular-nums; }

.progress { height: 8px; background: var(--surface-alt); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.progress > div { height: 100%; background: var(--c1); border-radius: 99px; }

.slider-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 12px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.slider-row output { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 32px 16px; }
.empty h2 { margin-bottom: 6px; }

table.preview { width: 100%; border-collapse: collapse; font-size: 13px; }
table.preview td, table.preview th { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
table.preview td.num { text-align: right; }

dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
#modal-body { padding: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.accent { background: var(--accent-bg); color: var(--accent); }

.bottombar { display: none; }
.more-list a { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; padding: 14px 0; border-bottom: 1px solid var(--border); }
.more-list a:last-child { border-bottom: 0; }
.more-list a::after { content: "›"; margin-left: auto; color: var(--text-3); font-size: 20px; }

@media (max-width: 640px) {
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); justify-content: center; }
  .topbar .tabs { display: none; }
  .bottombar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottombar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--text-3); text-decoration: none; padding: 4px 0;
    -webkit-tap-highlight-color: transparent;
  }
  .bottombar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottombar a.active { color: var(--accent); }
  .container { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  input, select, textarea { font-size: 16px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .tile .value { font-size: 19px; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92vh; }
  #modal-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .hero .big { font-size: 32px; }
  .slider-row { grid-template-columns: 1fr 80px; }
  .slider-row input { grid-column: 1 / -1; grid-row: 2; }
  .sub-row { flex-wrap: wrap; }
  .sub-row .grow { flex-basis: calc(100% - 110px); }
  .sub-row select { width: 100% !important; }
}
