/* Rate my Glögg
   Layout: one phone-first column (max 640px); wine-red accent on warm paper,
   dark mode is the cellar. Single-series charts use the accent as their one hue. */
:root {
  --bg: #f5efe8;
  --surface: #fffcf8;
  --surface-2: #f0e7df;
  --fg: #2b191d;
  --fg-2: #6a575b;
  --muted: #978689;
  --line: #e3d7cf;
  --accent: #8b1e3f;
  --accent-hover: #731734;
  --accent-fg: #ffffff;
  --accent-soft: #f3dde4;
  --bar: #a3284f;
  --bar-track: #ebe0da;
  --danger: #c23a3a;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1315;
    --surface: #241a1d;
    --surface-2: #2f2326;
    --fg: #f4ebe7;
    --fg-2: #c7b6b9;
    --muted: #8f7e82;
    --line: #3b2d31;
    --accent: #e35a81;
    --accent-hover: #ec6f93;
    --accent-fg: #1a1315;
    --accent-soft: #3d2029;
    --bar: #d94c74;
    --bar-track: #352629;
    --danger: #ef6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

h1, h2 { font-family: var(--font-display); line-height: 1.1; margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.7rem, 6vw, 2.3rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; }
p { margin: 0; }
.eyebrow { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.lede { color: var(--fg-2); max-width: 36ch; }
.hint { color: var(--fg-2); font-size: 0.9rem; }
.muted { color: var(--muted); }
.label { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-2); }
label { font-size: 0.9rem; font-weight: 500; color: var(--fg-2); }

/* --- shell --- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto;
  padding-block: 14px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; color: var(--accent); text-decoration: none; letter-spacing: -0.01em; }
.who {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 0.85rem; font-weight: 500; color: var(--fg-2); max-width: 50%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.who::before { content: "👤 "; }
.app {
  max-width: 640px; margin: 0 auto;
  padding-block: 8px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.screen { display: flex; flex-direction: column; gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row > * { min-width: 0; }

/* --- controls --- */
input[type="text"] {
  width: 100%; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 1.05rem;
}
input[type="text"]:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 18px; font-weight: 600; font-size: 1rem; line-height: 1.2;
  transition: background-color .15s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--fg); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-big { padding: 18px 20px; font-size: 1.15rem; width: 100%; }
.ean-form .row { flex-wrap: nowrap; }
.ean-form input { flex: 1; }
.ean-form label { display: block; margin-bottom: 8px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tabs [role="tab"] {
  flex: 1; border: 0; background: transparent; border-radius: 999px;
  padding: 10px 12px; font-weight: 600; color: var(--fg-2);
}
.tabs [role="tab"][aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.msg { background: var(--accent-soft); color: var(--fg); border-left: 4px solid var(--danger); border-radius: var(--radius-sm); padding: 10px 14px; margin-top: 16px; font-size: 0.95rem; }
.msg.ok { border-left-color: var(--accent); }

/* --- scanner --- */
.viewfinder {
  position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 70vh;
  background: #000; border-radius: var(--radius); overflow: hidden;
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; inset: 35% 10%; border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
  outline: 2px solid rgba(255,255,255,.9);
}
.reticle::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px;
  background: var(--accent); opacity: .9;
}

/* --- product --- */
.product-card {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.product-img { width: 96px; height: 120px; border-radius: var(--radius-sm); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.product-img img { width: 100%; height: 100%; object-fit: contain; }
.noimg { font-size: 2.4rem; }
.product-meta { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.product-meta h2 { overflow-wrap: anywhere; }
.manual { background: var(--surface-2); border-radius: var(--radius); padding: 14px; gap: 8px; }
.manual label { margin-top: 4px; }

.rate-block { display: flex; flex-direction: column; gap: 10px; }
.score-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.score-grid button {
  aspect-ratio: 1.15; min-height: 52px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-display); font-weight: 700; font-size: 1.35rem;
  transition: background-color .12s, border-color .12s;
}
.score-grid button:hover { border-color: var(--accent); }
.score-grid button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.score-word { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; min-height: 1.4em; color: var(--accent); }
.saved h2 { font-size: 1.6rem; }

/* --- results --- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-label { font-size: 0.78rem; color: var(--fg-2); font-weight: 500; }
.kpi-value { font-family: var(--font-display); font-weight: 800; font-size: 1.8rem; line-height: 1.1; }

.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rank { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rank.mine { border-color: var(--accent); }
.rank-head {
  width: 100%; display: grid; grid-template-columns: 28px 52px 1fr auto; gap: 12px; align-items: center;
  background: transparent; border: 0; padding: 12px 14px; text-align: left;
}
.rank-head:hover { background: var(--surface-2); }
.pos { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank:nth-child(1) .pos { color: var(--accent); }
.thumb { width: 52px; height: 64px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb-fallback { font-size: 1.5rem; }
.rank-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.rank-text .name { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.rank-text .rank-brand { font-size: 0.85rem; }
.bar-track { display: block; height: 8px; border-radius: 999px; background: var(--bar-track); margin-top: 4px; overflow: hidden; }
.bar { display: block; height: 100%; width: var(--w, 0%); background: var(--bar); border-radius: 0 999px 999px 0; transition: width .4s ease; }
.rank-num { display: flex; flex-direction: column; align-items: flex-end; gap: 0; }
.avg { font-family: var(--font-display); font-weight: 800; font-size: 1.6rem; line-height: 1; }
.n { font-size: 0.78rem; white-space: nowrap; }

.rank-detail { border-top: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.dist { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; align-items: end; height: 72px; margin-bottom: 18px; position: relative; }
.col { position: relative; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.col-bar { width: 100%; max-width: 24px; margin: 0 auto; background: var(--bar); border-radius: 4px 4px 0 0; height: var(--h, 0%); min-height: 0; }
.col.zero .col-bar { height: 2px; background: var(--bar-track); border-radius: 0; }
.col.mine .col-bar { outline: 2px solid var(--fg); outline-offset: -2px; }
.col-x { position: absolute; top: 100%; left: 0; right: 0; text-align: center; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.col-c { position: absolute; bottom: 100%; left: 0; right: 0; text-align: center; font-size: 0.72rem; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.votes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; }
.votes li { display: flex; justify-content: space-between; gap: 8px; font-size: 0.95rem; border-bottom: 1px solid var(--line); padding: 4px 0; }
.votes li .u { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.votes li.me .u { font-weight: 600; color: var(--accent); }
.votes li b { font-variant-numeric: tabular-nums; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--fg-2); }
.results-title { margin: 28px 0 10px; }
.results-lede { margin: 0 0 20px; }

@media (max-width: 380px) {
  .rank-head { grid-template-columns: 22px 44px 1fr auto; gap: 8px; padding: 10px; }
  .thumb { width: 44px; height: 56px; }
  .avg { font-size: 1.35rem; }
}

