:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2230;
  --muted: #666d7c;
  --line: #e3dfd5;
  --accent: #e8573c;
  --good: #2a9d8f;
  --good-soft: #cfe9e5;
  --neutral: #d9d5cb;
  --median: #3d5a98;
  --mean: #8e5bb5;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 8px 30px rgba(20, 20, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1b2029;
    --ink: #eceef2;
    --muted: #9aa2b1;
    --line: #2c3340;
    --accent: #ff7a59;
    --good: #43c2b1;
    --good-soft: #1f3b3a;
    --neutral: #353c4a;
    --median: #7f9ddf;
    --mean: #c294e6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); letter-spacing: -.02em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.1rem; margin-top: 1.5em; }
a { color: var(--median); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.hero { padding: 56px 0 28px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 700; color: var(--accent); margin: 0 0 .6em; }
.subtitle { font-size: clamp(1.2rem, 2.6vw, 1.6rem); font-weight: 600; color: var(--muted); margin: -.2em 0 .8em; }
.lead { font-size: 1.12rem; max-width: 60ch; }
.counter { color: var(--muted); font-size: .9rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 24px;
}
.card.error { border-color: var(--accent); color: var(--accent); }

/* Form */
.amount-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
label > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.amount { flex: 1 1 260px; }
.amount input {
  width: 100%; font-size: 2rem; font-weight: 700; padding: 10px 16px;
  border: 2px solid var(--line); border-radius: 14px; background: transparent; color: var(--ink);
}
.amount input:focus, select:focus, .inline input:focus { outline: none; border-color: var(--accent); }
.toggle { border: 0; padding: 4px; margin: 0; display: flex; background: var(--bg); border-radius: 12px; }
.toggle label { cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { display: block; padding: 10px 14px; border-radius: 9px; font-weight: 600; margin: 0; color: var(--muted); }
.toggle input:checked + span { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); }
.hint { color: var(--muted); font-size: .9rem; margin: 18px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.grid .wide { grid-column: 1 / -1; }
select {
  width: 100%; max-width: 100%; padding: 10px 12px; font-size: .95rem;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
.btn {
  margin-top: 22px; width: 100%; padding: 16px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.1rem; font-weight: 700;
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.spinner { display: none; width: 16px; height: 16px; margin-left: 8px; vertical-align: -2px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.htmx-request .spinner, .htmx-request.spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.privacy { font-size: .8rem; color: var(--muted); text-align: center; margin: 10px 0 0; }

/* Result */
.result { animation: rise .5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.headline { font-size: clamp(1.4rem, 3.5vw, 2rem); font-weight: 600; }
.mega { display: block; font-size: clamp(4rem, 14vw, 7.5rem); font-weight: 800; color: var(--good); letter-spacing: -.04em; line-height: 1; margin: 8px 0; font-variant-numeric: tabular-nums; }
.verdict { font-size: 1.05rem; padding: 14px 18px; background: var(--bg); border-left: 4px solid var(--accent); border-radius: 8px; }

.people { margin: 24px 0; }
.people-grid { display: grid; grid-template-columns: repeat(20, 1fr); gap: 6px; max-width: 560px; }
@media (max-width: 520px) { .people-grid { grid-template-columns: repeat(10, 1fr); } }
.person {
  aspect-ratio: 1; border-radius: 50%; background: var(--neutral);
  animation: pop .35s ease both; animation-delay: calc(var(--i) * 12ms);
}
.person.below { animation: pop .35s ease both, fill .4s ease forwards; animation-delay: calc(var(--i) * 12ms), calc(400ms + var(--i) * 18ms); }
@keyframes pop { from { transform: scale(0); } }
@keyframes fill { to { background: var(--good); } }

.hist { margin: 24px 0 8px; }
.hist svg { width: 100%; height: auto; display: block; overflow: visible; }
.bar { fill: var(--neutral); transform-box: fill-box; transform-origin: bottom; animation: grow .6s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--d); }
.bar.below { fill: var(--good); }
@keyframes grow { from { transform: scaleY(0); } }
.marker line { stroke-width: 2; stroke-dasharray: 4 3; }
.marker text { font-size: 12px; font-weight: 700; }
.marker.median line { stroke: var(--median); } .marker.median text { fill: var(--median); }
.marker.mean line { stroke: var(--mean); } .marker.mean text { fill: var(--mean); }
.marker.you line { stroke: var(--accent); stroke-width: 3; stroke-dasharray: none; } .marker.you text { fill: var(--accent); font-size: 14px; }
.marker { animation: fade .5s ease both; animation-delay: .9s; }
@keyframes fade { from { opacity: 0; } }
.tick { font-size: 11px; fill: var(--muted); }
figcaption { font-size: .85rem; margin-top: 6px; }

.groups { display: grid; gap: 18px; }
.group-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.group-title { font-weight: 600; }
.group-title em { font-style: normal; font-weight: 400; color: var(--muted); }
.group-pct { font-weight: 800; font-size: 1.3rem; color: var(--good); font-variant-numeric: tabular-nums; }
.bar-track { position: relative; height: 12px; background: var(--neutral); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar-fill { height: 100%; width: var(--w); background: linear-gradient(90deg, var(--good), #57c4b3); border-radius: 99px; animation: widen 1.2s cubic-bezier(.2,.8,.2,1) both; animation-delay: .3s; }
@keyframes widen { from { width: 0; } }
.bar-median { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .35; }
.group-meta { font-size: .85rem; color: var(--muted); }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; font-size: .75rem; background: var(--bg); border: 1px solid var(--line); cursor: help; }
.badge.exact { color: var(--good); border-color: var(--good); }

/* Wealth */
.field {
  width: 100%; font-size: 1.3rem; font-weight: 700; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 12px; background: transparent; color: var(--ink);
}
.field:focus { outline: none; border-color: var(--accent); }
#majatek-wynik:not(:empty) { margin-top: 24px; }
.wealth-result { border-top: 1px solid var(--line); padding-top: 20px; }
.wealth-result .error, #majatek-wynik .error { margin: 0; }
.wealth-block + .wealth-block { margin-top: 28px; }
.wealth-block .headline { font-size: clamp(1.2rem, 3vw, 1.6rem); }
.housing { margin: 16px 0 8px; }
.housing-bar { position: relative; display: flex; height: 44px; border-radius: 12px; overflow: visible; margin-top: 28px; }
.seg {
  width: var(--w); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .9rem;
  animation: widen .9s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--d); overflow: hidden; white-space: nowrap;
}
.seg:first-child { border-radius: 12px 0 0 12px; }
.seg:nth-last-child(2) { border-radius: 0 12px 12px 0; }
.seg-none { background: #9aa2b1; }
.seg-one { background: var(--median); }
.seg-more { background: var(--mean); }
.seg.mine { box-shadow: inset 0 0 0 3px var(--accent); }
.housing-marker { position: absolute; left: var(--x); top: -26px; bottom: -6px; width: 3px; margin-left: -1.5px; background: var(--accent); animation: fade .5s ease both; animation-delay: 1.1s; }
.housing-marker span { position: absolute; top: -2px; left: 6px; color: var(--accent); font-weight: 800; font-size: .9rem; }
.housing-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.housing-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.housing-legend .seg-none i { background: #9aa2b1; } .housing-legend .seg-one i { background: var(--median); } .housing-legend .seg-more i { background: var(--mean); }
.housing-legend span { background: none; }

/* Reality section */
.reality { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 18px 0; }
.reality-card { padding: 18px; border-radius: 14px; background: var(--bg); text-align: center; }
.reality-amount { font-weight: 700; font-size: 1.15rem; }
.reality-amount small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.reality-share { font-size: 2.4rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.reality-label { font-size: .85rem; color: var(--muted); }
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; }
.tool h3 { margin-top: .5em; }
.inline { display: flex; align-items: center; gap: 10px; }
.inline input { width: 160px; font-size: 1.2rem; font-weight: 700; padding: 8px 12px; border: 2px solid var(--line); border-radius: 10px; background: transparent; color: var(--ink); }
.inline span { margin: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.big { font-size: 1.6rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; }
.fact-num { font-size: 1.8rem; font-weight: 800; }
.fact-label { color: var(--muted); font-size: .9rem; }
.trend-svg { width: 100%; height: auto; display: block; }
.trend-area { fill: var(--good-soft); }
.trend-line { fill: none; stroke: var(--good); stroke-width: 3; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 2s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.trend-dot { fill: var(--accent); }

.sources ul { padding-left: 1.2em; }
.sources li { margin-bottom: .4em; }
.footer { color: var(--muted); font-size: .85rem; padding-bottom: 40px; }

@media (max-width: 520px) {
  .card { padding: 20px; }
  .hero { padding-top: 32px; }
}
/* Cookie consent */
.cookie-banner {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 10; max-width: 760px; margin: 0 auto;
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(20, 20, 40, .18); padding: 16px 20px; animation: rise .35s ease both;
}
.cookie-text { flex: 1 1 360px; font-size: .9rem; }
.cookie-text p { margin: 4px 0 0; color: var(--muted); }
.cookie-actions { display: flex; gap: 10px; flex: 0 0 auto; }
.cookie-actions .btn-secondary { min-width: 120px; padding: 10px 16px; }
body:has(.cookie-banner) { padding-bottom: 170px; }
.linklike { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
@media (max-width: 520px) { .cookie-actions { width: 100%; } .cookie-actions .btn-secondary { flex: 1; } }

/* Admin */
.admin .wrap.narrow { max-width: 440px; padding-top: 80px; }
.admin .wrap.wide { max-width: 1200px; }
.admin-title { font-size: 1.8rem; }
.login-card form { display: grid; gap: 4px; }
.admin-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; max-width: 1200px; padding-top: 32px; padding-bottom: 16px; }
.btn-secondary { padding: 8px 16px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; cursor: pointer; }
.btn-secondary:hover { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.stat-num { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }
.daily { width: 100%; height: auto; display: block; }
.d-visits { fill: var(--neutral); color: var(--neutral); }
.d-compares { fill: var(--accent); color: var(--accent); }
.legend.admin-legend { display: flex; }
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.admin-table td { white-space: nowrap; }
.admin-table td.details { white-space: normal; min-width: 280px; color: var(--muted); }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.more-row td { text-align: center; border-bottom: 0; padding-top: 14px; }

.admin-tabs { display: flex; gap: 6px; margin-top: 4px; }
.admin-tabs a { padding: 6px 14px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 700; font-size: 1.05rem; }
.admin-tabs a:hover { color: var(--ink); }
.admin-tabs a.active { background: var(--card); color: var(--ink); border: 1px solid var(--line); }

/* DB explorer */
.db-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 800px) { .db-layout { grid-template-columns: 1fr; } }
.db-tables { padding: 18px; position: sticky; top: 16px; }
.db-tables h2 { font-size: 1.1rem; }
.db-tables ul { list-style: none; margin: 0; padding: 0; }
.db-tables a { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.db-tables a small { color: var(--muted); font-family: system-ui, sans-serif; }
.db-tables a:hover { background: var(--bg); }
.db-tables a.active { background: var(--accent); color: #fff; }
.db-tables a.active small { color: rgba(255,255,255,.85); }
.db-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.db-head h2 { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0; }
.db-head .btn-secondary, .db-pager .btn-secondary { text-decoration: none; font-size: .85rem; display: inline-block; }
.db-schema { margin: 14px 0; }
.db-schema summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.db-schema table { margin-top: 8px; max-width: 560px; }
.db-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 10px 0; }
.small-field { font-size: .95rem; font-weight: 400; padding: 8px 12px; max-width: 360px; }
.db-grid { max-height: 70vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.db-grid .admin-table { font-size: .8rem; }
.db-grid .admin-table th { position: sticky; top: 0; background: var(--card); z-index: 1; }
.db-grid .admin-table th a { color: var(--ink); text-decoration: none; }
.db-grid .admin-table td { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.admin-table td.null { color: var(--muted); font-style: italic; }
.db-pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 14px; }
.db-console textarea.sql {
  width: 100%; font: .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); resize: vertical;
}
.db-console textarea.sql:focus { outline: none; border-color: var(--accent); }
.db-console-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; }
.btn-secondary.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.spinner.dark { border-color: rgba(255,255,255,.4); border-top-color: #fff; }
kbd { font: .75rem ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; }
#db-query .error, #db-view .error { margin: 10px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition: none !important; }
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: .85rem; }
.legend li::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; background: currentColor; }
.legend .you { color: var(--accent); font-weight: 700; }
.legend .median { color: var(--median); }
.legend .mean { color: var(--mean); }
@media (min-width: 601px) { .legend { display: none; } }
@media (max-width: 600px) {
  .marker text { display: none; }
  .tick { font-size: 22px; }
}
