:root {
  --bg: #0e1013;
  --bar: rgba(22, 25, 30, 0.86);
  --panel: #171a1f;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eceef1;
  --muted: #8b929c;
  --field: rgba(255, 255, 255, 0.06);
  --migros: #ff6a00;
  --coop: #e3122a;
  --accent: #ff6a00;
  /* canvas */
  --cell: rgba(255, 255, 255, 0.055);
  --cell-goal: rgba(255, 255, 255, 0.1);
  --pill: rgba(18, 20, 24, 0.9);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* Dark is the default; light is opt-in via the theme button. */
:root[data-theme="light"] {
  --bg: #f3f1ee;
  --bar: rgba(255, 255, 255, 0.86);
  --panel: #ffffff;
  --line: rgba(0, 0, 0, 0.08);
  --text: #1d1f23;
  --muted: #6b7079;
  --field: rgba(0, 0, 0, 0.05);
  --cell: rgba(0, 0, 0, 0.06);
  --cell-goal: rgba(0, 0, 0, 0.1);
  --pill: rgba(255, 255, 255, 0.94);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Cantarell, sans-serif;
  font-variant-numeric: tabular-nums;
}

button, input { font: inherit; color: inherit; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.migros { background: var(--migros); }
.dot.coop { background: var(--coop); }

/* ---- top bar ---------------------------------------------------------- */

.bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 52px;
  padding: 0 12px 0 16px;
  background: var(--bar);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.brand img { border-radius: 5px; }

.stats { display: flex; align-items: center; gap: 16px; min-width: 0; overflow: hidden; }
.stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stat .dot { align-self: center; }
.stat b { font-weight: 600; }
.stat small, .progress small { color: var(--muted); font-size: 12px; }
.stat.total b { font-size: 15px; }

.progress { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.track { display: flex; width: 110px; height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; }
.track span { height: 100%; width: 0; transition: width 0.4s ease; }
#barM { background: var(--migros); }
#barC { background: var(--coop); }

.add { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.seg { display: flex; padding: 2px; border-radius: 8px; background: var(--field); }
.seg button {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--muted);
}
.seg button[aria-checked="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }

.add input {
  height: 32px; width: 110px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 8px; background: var(--field); outline: none;
}
.add input.note { width: 130px; }
.when { display: flex; gap: 4px; }
.when select, .month-edit select {
  height: 32px; padding: 0 6px; border: 1px solid transparent; border-radius: 8px;
  background: var(--field); color: var(--text); font: inherit; outline: none;
}
.when select:focus, .month-edit select:focus { border-color: var(--accent); }
.when option, .month-edit option { background: var(--panel); color: var(--text); }
.add input:focus { border-color: var(--accent); }

button.primary {
  height: 32px; padding: 0 14px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }

button.icon {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted);
}
button.icon:hover { background: var(--field); color: var(--text); }

/* ---- canvas ----------------------------------------------------------- */

#stage { position: fixed; inset: 52px 0 0 0; }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }

#tip {
  position: absolute; z-index: 5; pointer-events: none;
  padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--pill); box-shadow: var(--shadow); font-size: 12px; white-space: nowrap;
}
#tip small { display: block; color: var(--muted); }

.ctl {
  position: absolute; right: 16px; bottom: 16px; z-index: 5;
  display: flex; flex-direction: column; gap: 2px; padding: 4px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bar); backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.ctl button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); }
.ctl button:hover { background: var(--field); color: var(--text); }
.ctl .sep { height: 1px; margin: 3px 6px; background: var(--line); }

.scale, .hint {
  position: absolute; left: 16px; z-index: 5;
  padding: 5px 10px; border-radius: 8px; font-size: 12px; color: var(--muted);
  background: var(--bar); backdrop-filter: blur(14px); border: 1px solid var(--line);
}
.scale { bottom: 16px; }
.hint { bottom: 50px; transition: opacity 0.6s; }
.hint.gone { opacity: 0; pointer-events: none; }

/* ---- drawer ----------------------------------------------------------- */

#drawer {
  position: fixed; top: 52px; right: 0; bottom: 0; z-index: 9;
  display: flex; flex-direction: column;
  width: min(380px, 100vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(100%); visibility: hidden;
  transition: transform 0.25s ease, visibility 0s 0.25s;
}
#drawer.open { transform: none; visibility: visible; transition: transform 0.25s ease; }

/* on desktop the drawer stays docked on the right, next to the map */
@media (min-width: 821px) {
  #drawer { transform: none; visibility: visible; box-shadow: none; }
  #stage { right: 380px; }
  #menuBtn, #closeBtn { display: none; }
}

.tabs { display: flex; align-items: center; gap: 2px; padding: 10px 10px 0 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs [role="tab"] { flex: none; padding: 8px 9px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); cursor: pointer; font-weight: 600; }
.tabs [aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs .close { margin-left: auto; margin-bottom: 4px; position: sticky; right: 0; flex: none; background: var(--panel); }

.pane { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }
.pane h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pane h3:first-child { margin-top: 0; }
.lead { margin: 0 0 4px; color: var(--muted); }
.note-s { margin-top: 18px; font-size: 12px; color: var(--muted); }

.bm { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.bm b { font-size: 16px; }
.bm span { color: var(--muted); }
.bm small { grid-column: 1; color: var(--muted); font-size: 12px; }
.bm .icon { grid-row: 1 / span 2; grid-column: 2; width: 28px; height: 28px; }

.custom-form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.custom-form input { height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px; background: var(--field); outline: none; min-width: 0; }
.custom-form input:focus { border-color: var(--accent); }
.custom-form .wide, .custom-form button { grid-column: 1 / -1; }

.entry { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.entry .main { flex: 1; min-width: 0; }
.entry b { font-weight: 600; }
.entry small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .icon { width: 28px; height: 28px; }
.empty { color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 20;
  padding: 8px 14px; border-radius: 10px; background: var(--text); color: var(--bg);
  transform: translate(-50%, 20px); opacity: 0; transition: all 0.25s ease; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.err { background: var(--coop); color: #fff; }

/* ---- reached comparisons and goal progress --------------------------- */
.badge.done { display: inline-flex; align-items: center; gap: 3px; background: rgba(47, 191, 113, 0.16); color: #2fbf71; }
.badge.done svg { width: 12px; height: 12px; stroke: currentColor; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.goal-progress { padding: 14px; margin-bottom: 4px; border-radius: 10px; background: var(--field); }
.goal-progress .gp-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.goal-progress .gp-head b { font-size: 22px; }
.goal-progress .gp-head span, .goal-progress small { color: var(--muted); }
.goal-progress small { display: block; font-size: 12px; }
.goal-progress p { margin: 10px 0 6px; }
.track.wide { width: 100%; height: 10px; border-radius: 5px; }
.pane h3.month { display: flex; justify-content: space-between; margin-top: 20px; }
.pane h3.month span { text-transform: none; letter-spacing: 0; font-weight: 600; }
.month-edit { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.month-edit .primary, .month-edit .ghost { height: 32px; }

/* ---- shared view ------------------------------------------------------ */
button.share { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; }
button.share svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; }
#sharedBanner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 7;
  display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 14px; max-width: calc(100% - 32px);
  border-radius: 12px; border: 1px solid var(--line); background: var(--bar); backdrop-filter: blur(14px); box-shadow: var(--shadow);
  font-weight: 600; white-space: nowrap;
}
#sharedBanner[hidden] { display: none; }
body.shared .add, body.shared #addOpen, body.shared #bmForm, body.shared .bm .icon { display: none !important; }
body.shared #themeBtn { margin-left: auto; }

/* ---- narrow windows --------------------------------------------------- */

@media (max-width: 1100px) {
  .stat small, .progress small { display: none; }
  .add input.note { display: none; }
}
/* the add form: inline in the bar, a dialog on narrow screens */
#addOpen, #addBackdrop, .add .sheet-head { display: none; }

@media (max-width: 820px) {
  .bar { gap: 10px; padding: 0 8px 0 12px; }
  .brand span, .stat:not(.total), .progress { display: none; }
  #addOpen {
    display: flex; align-items: center; gap: 4px; height: 34px; margin-left: auto; padding: 0 12px 0 8px;
    border: 0; border-radius: 8px;
  }
  #addOpen svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }
  .add { display: none; }
  body.adding #addBackdrop { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, 0.5); }
  body.adding .add {
    display: grid; grid-template-columns: 1fr; gap: 10px;
    position: fixed; top: 12px; left: 12px; right: 12px; z-index: 30; margin: 0;
    max-width: 420px; margin-inline: auto;
    padding: 14px 16px 16px; border: 1px solid var(--line); border-radius: 16px;
    background: var(--panel); box-shadow: var(--shadow);
  }
  body.adding .add .sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; font-weight: 650; }
  body.adding .add .seg button { flex: 1; justify-content: center; padding: 10px 8px; font-size: 15px; }
  body.adding .add input, body.adding .add input.note { display: block; width: 100%; height: 44px; font-size: 16px; }
  body.adding .add button.primary { height: 44px; font-size: 16px; }
  body.adding .add .when select { flex: 1; height: 44px; font-size: 16px; }
}

/* ---- theme button, badges ------------------------------------------- */

#themeBtn .sun { display: none; }
:root[data-theme="light"] #themeBtn .sun { display: block; }
:root[data-theme="light"] #themeBtn .moon { display: none; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--field); color: var(--muted);
}
.badge.global { background: rgba(77, 163, 255, 0.16); color: #4da3ff; }

.bm { cursor: pointer; border-radius: 8px; }
.bm:hover { background: var(--field); }
.bm.custom { cursor: pointer; }

/* ---- benchmark detail card ------------------------------------------- */

#detail {
  position: absolute; left: 16px; top: 16px; z-index: 6;
  width: min(360px, calc(100vw - 32px)); max-height: calc(100% - 110px); overflow-y: auto;
  padding: 16px 18px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow);
}
#detail[hidden] { display: none; }
#detail .head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
#detail .head .icon { margin-left: auto; width: 28px; height: 28px; }
#detail h2 { margin: 0 0 4px; font-size: 18px; line-height: 1.25; letter-spacing: -0.01em; }
#detail .value { font-size: 22px; font-weight: 650; }
#detail .value small { font-size: 13px; font-weight: 500; color: var(--muted); }
#detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0 0; font-size: 13px; }
#detail dt { color: var(--muted); }
#detail dd { margin: 0; }
#detail p.note { margin: 14px 0 0; color: var(--muted); font-size: 13px; }
#detail .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
#detail a { color: var(--accent); }

button.ghost {
  height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: none; cursor: pointer; font-weight: 600;
}
button.ghost:hover { background: var(--field); }

.entry .move { width: auto; padding: 0 8px; gap: 4px; display: flex; font-size: 12px; font-weight: 600; }

/* ---- about ------------------------------------------------------------ */

#tab-about p { margin: 0 0 10px; }
#tab-about .card { padding: 12px 14px; margin: 10px 0; border-radius: 10px; background: var(--field); }
#tab-about .card h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 14px; }
#tab-about .goal { border: 1px solid var(--line); }
#tab-about a { color: var(--accent); }
#tab-about a.guide { display: grid; gap: 2px; color: var(--text); text-decoration: none; border: 1px solid transparent; }
#tab-about a.guide:hover { border-color: var(--line); }
#tab-about a.guide b { color: var(--accent); }
#tab-about a.guide span { font-size: 13px; color: var(--muted); }

/* ---- account ---------------------------------------------------------- */

#tab-account p { margin: 0 0 10px; }
#tab-account > .primary { width: 100%; height: 36px; border: 0; border-radius: 8px; margin-bottom: 6px; }
#tab-account input.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em; text-transform: uppercase; }
.codebox { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--field); }
.codebox code { flex: 1; font: 600 15px/1.3 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em; word-break: break-all; user-select: all; }
#tab-account .card { padding: 12px 14px; margin: 10px 0; border-radius: 10px; border: 1px solid var(--line); font-size: 13px; }
#tab-account .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
button.danger { color: var(--coop); }

/* ---- grouping switch ---------------------------------------------------- */

.seg.grouping { margin: 0 0 12px; }
.seg.grouping button { flex: 1 1 0; justify-content: center; padding: 6px 4px; font-size: 12px; }
.pane h3 .dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; vertical-align: 1px; }

/* ---- leaderboard -------------------------------------------------------- */

.board { list-style: none; margin: 10px 0 0; padding: 0; }
.board li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.board li.me { background: var(--field); border-radius: 8px; box-shadow: inset 3px 0 0 var(--accent); }
.board .rank { font-weight: 700; color: var(--muted); text-align: right; }
.board:not(.self) li:nth-child(-n+3) .rank { color: var(--accent); }
.board .who { display: grid; gap: 2px; min-width: 0; }
.board .who b, .player { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.03em; }
.board .you { color: var(--accent); font-weight: 600; }
.board .who small { font-size: 12px; color: var(--muted); }
.board .split { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.board .split .dot { width: 6px; height: 6px; }
.board .pts { display: grid; justify-items: end; gap: 2px; }
.gap { margin: 4px 0 0; text-align: center; color: var(--muted); }
#tab-board .card { display: grid; gap: 10px; justify-items: start; margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--field); }
