:root {
  --bg: #f4f4f6;
  --card: #ffffff;
  --ink: #1b1c1f;
  --muted: #6b6f76;
  --line: #dcdde1;
  --ring: #ff6464;
  --lvl1: #ffc2c2;
  --lvl2: #ff6464;
  --lvl3: #b91c1c;
  --on-lvl: #1b1c1f;
  --on-lvl-strong: #ffffff;
  --accent: #1b1c1f;
  --on-accent: #ffffff;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #212226;
    --ink: #ececef;
    --muted: #9a9ea6;
    --line: #34363c;
    --ring: #ff7a7a;
    --lvl1: #ffb0b0;
    --lvl2: #ff5a5a;
    --lvl3: #d42a2a;
    --accent: #ececef;
    --on-accent: #16171a;
    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.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
.which { color: var(--ink); }
.section-title { margin: 14px 0 0; color: var(--ink); }

.top { display: flex; flex-direction: column; gap: 8px; }
.when { display: flex; align-items: center; gap: 8px; }
.when label { font-size: 14px; color: var(--muted); }
.when input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}

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

.foot-view { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.foot { fill: var(--ink); }
.foot-label { fill: var(--muted); font-size: 34px; font-weight: 700; }

/* markers */
.marker { cursor: pointer; }
.marker .hit { fill: transparent; }
.marker .dotc { fill: var(--card); fill-opacity: 0.85; stroke: var(--ring); stroke-width: 5; }
.marker text { font-size: 26px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--on-lvl); }
.marker[data-level="1"] .dotc { fill: var(--lvl1); fill-opacity: 1; }
.marker[data-level="2"] .dotc { fill: var(--lvl2); fill-opacity: 1; }
.marker[data-level="3"] .dotc { fill: var(--lvl3); fill-opacity: 1; stroke: var(--lvl3); }
.marker[data-level="3"] text { fill: var(--on-lvl-strong); }
.marker:focus { outline: none; }
.marker:focus-visible .dotc { stroke: var(--ink); }

.legend { list-style: none; margin: 18px 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--on-lvl); }
.swatch.lvl1 { background: var(--lvl1); }
.swatch.lvl2 { background: var(--lvl2); }
.swatch.lvl3 { background: var(--lvl3); color: var(--on-lvl-strong); }

button { font: inherit; cursor: pointer; }

.submit {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
}
.submit:active { transform: scale(0.98); }
.submit-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

.ghost {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
}
.small { font-size: 14px; padding: 7px 12px; }

/* segmented toggle */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
  position: sticky;
  top: 6px;
  z-index: 2;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 9px;
  font-weight: 600;
  position: relative;
}
.seg button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.seg .dot {
  display: none;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--lvl2);
  position: absolute;
  top: 8px; right: 12px;
}
.seg button.has-values .dot { display: block; }

/* history */
.hist-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.hist-head h2 { margin: 0; }
.exports { display: flex; gap: 6px; }
.muted { color: var(--muted); margin: 4px 0; font-size: 14px; }
#hist-list { list-style: none; margin: 0; padding: 0; }
#hist-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
#hist-list li:first-child { border-top: 0; }
.h-body { flex: 1; min-width: 0; }
.h-time { font-weight: 600; font-size: 14px; }
.h-vals { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.h-vals b { color: var(--ink); font-weight: 600; }
.h-del {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
}

.banner {
  background: #fff3cd;
  color: #5c4400;
  padding: 10px 16px;
  font-size: 14px;
  text-align: center;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--accent);
  color: var(--on-accent);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* account / sync */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; }
#sync-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sync-status.warn { color: var(--lvl3); font-weight: 600; }
.link { border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 4px; }
.pending-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--lvl3);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 6px;
  vertical-align: 1px;
}

/* notes */
.notes-label { display: block; margin: 14px 0 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
#notes {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zooming on focus */
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}
.h-notes { font-size: 14px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; font-style: italic; }
