/* ---------- Warm editorial tokens ---------- */
:root {
  --bg: #f7f4ef;
  --bg-2: #f1ece3;
  --surface: #fffdfa;
  --surface-2: #fbf7f1;
  --text: #241f1a;
  --muted: #7a7168;
  --muted-2: #9a9086;
  --line: #ece5da;
  --line-strong: #ddd4c6;

  --accent: #c25b3a;        /* terracotta */
  --accent-ink: #9c4426;
  --accent-weak: #f6e8e1;
  --indigo: #3d4a8a;
  --indigo-weak: #e7e9f5;

  --green: #2f8f5b;
  --green-weak: #e3f1e8;
  --red: #c0453b;
  --red-weak: #f7e5e2;
  --amber: #b8801f;
  --amber-weak: #f5ecd8;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(60,40,20,.05), 0 2px 6px rgba(60,40,20,.05);
  --shadow-h: 0 8px 22px rgba(60,40,20,.12);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  padding-bottom: 76px; /* room for tab bar */
}

.app { max-width: 520px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0 10px;
}
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand .site {
  font-family: var(--serif);
  font-size: 21px; font-weight: 600; letter-spacing: -.01em;
}
.brand .sub { font-size: 12px; color: var(--muted); letter-spacing: .01em; }

.lang {
  display: inline-flex; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.lang button {
  border: 0; background: transparent; color: var(--muted);
  font: 600 12px/1 var(--sans); padding: 6px 10px; border-radius: 999px;
  cursor: pointer; transition: color .15s, background .15s;
}
.lang button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Segmented period switch ---------- */
.segmented {
  display: flex; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px; margin: 6px 0 18px;
}
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font: 600 13px/1 var(--sans); padding: 9px 8px; border-radius: 999px;
  cursor: pointer; transition: color .15s, background .15s, box-shadow .15s;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- KPI grid ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 14px 12px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted-2);
}
.kpi .value {
  font-family: var(--serif); font-size: 30px; font-weight: 600;
  letter-spacing: -.02em; margin-top: 4px; line-height: 1.05;
}
.kpi .value .unit { font-size: 16px; color: var(--muted); font-weight: 500; }
.delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11.5px; font-weight: 700; border-radius: 999px;
  padding: 3px 7px; margin-top: 6px;
}
.delta.up { color: var(--green); background: var(--green-weak); }
.delta.down { color: var(--red); background: var(--red-weak); }
.delta.flat { color: var(--muted); background: var(--bg-2); }
/* position: lower is better, so invert semantics visually handled in JS */
.kpi .spark { position: absolute; right: 12px; top: 14px; width: 58px; height: 26px; opacity: .9; }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-top: 16px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 {
  font-family: var(--serif); font-size: 17px; font-weight: 600; letter-spacing: -.01em;
}
.card-head .hint { font-size: 11.5px; color: var(--muted-2); }

/* ---------- Trend chart ---------- */
.chart-legend { display: flex; gap: 14px; margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 999px; }
.dot.clicks { background: var(--accent); }
.dot.impr { background: var(--indigo); }
.chart { width: 100%; height: 132px; display: block; }
.chart .area { opacity: 0; animation: fadein .7s .35s ease forwards; }
.chart .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.05s .12s cubic-bezier(.4,.1,.2,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fadein { to { opacity: 1; } }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted-2); font: 10px var(--sans); }

/* ---------- Ranked list (queries/pages) ---------- */
.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row .name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .metric { font-size: 13px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.row .barwrap { grid-column: 1 / -1; height: 5px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.row .bar { height: 100%; background: var(--accent); border-radius: 999px; width: 0; transition: width .8s cubic-bezier(.2,.7,.2,1); }
.row .meta { grid-column: 1 / -1; font-size: 11px; color: var(--muted-2); display: flex; gap: 12px; }

/* ---------- Sources ---------- */
.source {
  display: flex; align-items: center; gap: 12px; padding: 14px 0;
  border-top: 1px solid var(--line);
}
.source:first-child { border-top: 0; }
.source .ic {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-size: 20px; background: var(--surface-2); border: 1px solid var(--line); flex: none;
}
.source .info { flex: 1; min-width: 0; }
.source .info .n { font-size: 14px; font-weight: 600; }
.source .info .s { font-size: 12px; color: var(--muted); }
.chip {
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  letter-spacing: .02em; flex: none;
}
.chip.ok { color: var(--green); background: var(--green-weak); }
.chip.off { color: var(--amber); background: var(--amber-weak); }

/* ---------- Settings ---------- */
.field { margin-top: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field .desc { font-size: 11.5px; color: var(--muted-2); margin-bottom: 8px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 13px var(--sans);
  padding: 10px 12px; resize: vertical;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.btn {
  border: 0; border-radius: var(--radius-sm); background: var(--accent); color: #fff;
  font: 700 14px var(--sans); padding: 12px 16px; width: 100%; margin-top: 18px;
  cursor: pointer; transition: background .15s, transform .1s;
}
.btn:hover { background: var(--accent-ink); }
.btn:active { transform: translateY(1px); }

/* ---------- Tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: rgba(255,253,250,.9); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted-2); font: 600 10.5px var(--sans); padding: 4px;
  transition: color .15s;
}
.tabs button .ti { font-size: 19px; line-height: 1; filter: grayscale(1) opacity(.6); transition: filter .15s; }
.tabs button.on { color: var(--accent); }
.tabs button.on .ti { filter: none; }

/* ---------- Screens & motion ---------- */
.screen { display: none; }
.screen.active { display: block; }
.fade { opacity: 0; transform: translateY(12px); animation: fadeUp .5s cubic-bezier(.2,.7,.2,1) forwards; }
@keyframes fadeUp { to { opacity: 1; transform: none; } }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.empty .t { font-family: var(--serif); font-size: 17px; color: var(--text); margin-bottom: 4px; }
.empty .d { font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  .fade { animation: none; opacity: 1; transform: none; }
  .chart .area { animation: none; opacity: 1; }
  .chart .draw { animation: none; stroke-dasharray: none; stroke-dashoffset: 0; }
  * { transition: none !important; }
}
