:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d1b19;
  --muted: #6f6a64;
  --line: #e4ded5;
  --accent: #22324a;
  --accent-ink: #ffffff;
  --danger: #b4232a;
  --radius: 14px;
  --tabs: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --ink: #f1eee9;
    --muted: #a49e96;
    --line: #2f3338;
    --accent: #c9d6ea;
    --accent-ink: #15171a;
    --danger: #ff7a7f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabs) + 32px + env(safe-area-inset-bottom));
}

h1 { font-size: 28px; margin: 4px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); margin: 0 0 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0; }
.empty { color: var(--muted); text-align: center; margin: 32px 0; }
.label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 20px 0 8px; }
.grow { flex: 1; min-width: 0; }
.grow small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

header.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }

.primary, .secondary, .danger {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  min-height: 48px;
  font-weight: 600;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary.big { display: block; width: 100%; margin: 16px 0; font-size: 17px; min-height: 54px; }
.secondary { background: var(--card); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.back { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 10px 4px; min-height: 44px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px 4px; text-decoration: underline; text-underline-offset: 3px; }

.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
}
.note .link { padding: 0; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  position: relative;
}
.pill.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.pills.sizes { margin: 12px 0; }
.pill .best {
  position: absolute;
  top: -9px;
  right: -4px;
  background: #30a46c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 6px;
}

.unit { display: flex; gap: 6px; }
.row-gap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.row-gap .label { margin: 0; }
.row-gap.end { margin-top: 24px; }

.text, .paste {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px stops iPhones zooming into the field */
}
.paste { min-height: 120px; resize: vertical; }
.paste.short { min-height: 80px; margin-top: 16px; }

.list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 10px; }
.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
}
.card.row { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.card input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.card.vote { display: grid; gap: 6px; }
.card.vote small { color: var(--muted); }
.size { font-weight: 700; font-size: 18px; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }

.verdict {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 18px;
  font-weight: 600;
}

.viewer {
  height: 52vh;
  min-height: 320px;
  max-height: 560px;
  margin: 12px 0 6px;
  border-radius: var(--radius);
  background: radial-gradient(ellipse at 50% 35%, var(--card), var(--bg));
  overflow: hidden;
  touch-action: pan-y;
}
.viewer.short { height: 40vh; min-height: 260px; }
.viewer canvas { display: block; width: 100%; height: 100%; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

.zones { list-style: none; padding: 0; margin: 16px 0 0; }
.zone { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.zone .word { font-weight: 700; white-space: nowrap; }

.fields { display: grid; gap: 2px; }
.field { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field input {
  width: 84px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  text-align: right;
}
.field .u { color: var(--muted); font-size: 14px; width: 22px; }

.table-wrap { overflow-x: auto; margin: 16px 0 4px; -webkit-overflow-scrolling: touch; }
table.chart { border-collapse: collapse; font-size: 15px; }
table.chart th { text-align: left; font-weight: 600; padding: 4px 8px 4px 0; white-space: nowrap; color: var(--muted); }
.cell {
  width: 76px;
  padding: 9px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  text-align: center;
}
.cell.head { font-weight: 700; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
.tab {
  flex: 1;
  max-width: 130px;
  height: var(--tabs);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
.tab.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

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