:root {
  color-scheme: dark;
  --bg: #12061a;
  --panel: #241030;
  --panel-2: #33173f;
  --line: #4a2a55;
  --text: #f4ecdf;
  --muted: #bfa9c4;
  --orange: #ff7a1a;
  --gold: #e8a33d;
  --avocado: #8a9a3b;
  --brown: #5a3825;
  --pink: #c33d8f;
  --danger: #ff5a5a;
  --display: "Shrikhand", "Cooper Black", Georgia, serif;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; letter-spacing: 0.01em; }

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  border: 0;
  border-radius: 999px;
  padding: 0.75em 1.2em;
  background: var(--orange);
  color: #1a0a00;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}
.btn:active { transform: translateY(1px); filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-alt { background: var(--gold); }
.btn-ghost { background: transparent; color: var(--text); border: 2px solid var(--line); }
.btn-danger { background: var(--danger); color: #1a0000; }
.btn-big { font-size: 1.25rem; padding: 0.9em 2em; box-shadow: 0 6px 0 #a63f00; }

/* ---------- splash ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(18, 6, 26, 0) 40%, rgba(18, 6, 26, 0.85) 85%),
    url("../images/splash.jpg") center / cover no-repeat,
    url("../images/splash.svg") center / cover no-repeat,
    var(--bg);
  padding: 24px 24px calc(48px + env(safe-area-inset-bottom));
  transition: opacity 0.4s ease;
}
.splash.leaving { opacity: 0; pointer-events: none; }
.splash-inner { max-width: 420px; }
.splash-kicker {
  margin: 0 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold);
}
.splash-title {
  font-size: clamp(3rem, 16vw, 5rem);
  line-height: 0.95;
  color: var(--orange);
  text-shadow: 3px 3px 0 var(--brown), 6px 6px 0 rgba(0, 0, 0, 0.5);
}
.splash-tag { margin: 0.8em 0 1.6em; font-size: 1.05rem; }

/* ---------- main app ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  background: var(--bg);
}
.brand { font-size: 1.5rem; color: var(--orange); }
.progress {
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--panel-2);
  padding: 0.35em 0.8em;
  border-radius: 999px;
  white-space: nowrap;
}

.banner {
  margin: 4px 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border-left: 4px solid var(--gold);
  font-weight: 600;
}

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.actions .btn { flex: 1 1 180px; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 10px 0 18px; }

.section { margin: 0 0 24px; border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.section-art {
  height: 150px;
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  background-size: cover;
  background-position: center;
}
.section-art h2 {
  font-size: 1.7rem;
  color: var(--text);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}
.section-art.costume { background-image: linear-gradient(0deg, rgba(0,0,0,.45), transparent 60%), url("../images/costumes.jpg"), url("../images/costumes.svg"); }
.section-art.food { background-image: linear-gradient(0deg, rgba(0,0,0,.45), transparent 60%), url("../images/food.jpg"), url("../images/food.svg"); }
.section-art.dance { background-image: linear-gradient(0deg, rgba(0,0,0,.45), transparent 60%), url("../images/dancer.jpg"), url("../images/dancer.svg"); }

.cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
  min-height: 60px;
}
.cat-row:active { background: var(--panel-2); }
.cat-name { font-weight: 700; }
.cat-pick { display: block; font-size: 0.9rem; color: var(--muted); margin-top: 2px; }
.cat-pick.voted { color: var(--gold); }
.cat-row .chev { color: var(--muted); font-size: 1.3rem; }
.check {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
}
.check.on { background: var(--avocado); border-color: var(--avocado); color: #10140a; }

.footer { text-align: center; margin-top: 8px; }
.footer a { color: var(--muted); opacity: 0.5; font-size: 0.8rem; text-decoration: none; padding: 8px; }

/* ---------- category view ---------- */
.cat-view {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  background: var(--bg);
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
.cat-view > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.cat-head { display: flex; align-items: center; gap: 12px; padding: 8px 0 12px; }
.cat-head h2 { font-size: 1.5rem; color: var(--orange); }
.cat-hint { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.back {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: none;
  font-size: 1.3rem;
  cursor: pointer;
}
.search {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 12px;
}
.entry-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  background: var(--panel);
  text-align: left;
  cursor: pointer;
  min-height: 56px;
}
.entry.selected { border-color: var(--gold); background: var(--panel-2); }
.entry-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  background: var(--brown);
  color: var(--text);
}
.empty { color: var(--muted); text-align: center; margin: 24px 0; }
#catAddBtn { width: 100%; }

/* ---------- add dialog ---------- */
.sheet {
  width: min(520px, calc(100% - 32px));
  border: 0;
  border-radius: 20px;
  padding: 20px;
  background: var(--panel);
  color: var(--text);
}
.sheet::backdrop { background: rgba(8, 2, 12, 0.7); }
.sheet h2 { font-size: 1.4rem; color: var(--orange); margin-bottom: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; }
.field input, .field select {
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.types { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.types legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.types label { flex: 1 1 90px; }
.types input { position: absolute; opacity: 0; pointer-events: none; }
.types span {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid var(--line);
  cursor: pointer;
  font-weight: 600;
}
.types input:checked + span { border-color: var(--gold); background: var(--panel-2); color: var(--gold); }
.types input:focus-visible + span { outline: 2px solid var(--orange); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.sheet-actions .btn { flex: 1; }
.error { color: var(--danger); font-weight: 600; margin: 0 0 12px; }

/* ---------- results ---------- */
.results-head { text-align: center; margin: 8px 0 18px; }
.results-head h2 { font-size: 2rem; color: var(--gold); }
.result-card { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.result-card h3 { font-size: 1.15rem; color: var(--orange); margin-bottom: 8px; }
.place { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.place .medal { width: 28px; text-align: center; font-size: 1.2rem; }
.place .who { flex: 1; font-weight: 600; }
.place.first .who { font-size: 1.15rem; color: var(--gold); }
.place .count { color: var(--muted); font-size: 0.9rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.bad { background: var(--danger); color: #1a0000; }

/* ---------- host page ---------- */
.host { max-width: 860px; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { font-size: 1.3rem; color: var(--orange); margin-bottom: 12px; }
.toggles { display: grid; gap: 12px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toggle-row strong { display: block; }
.toggle-row small { color: var(--muted); }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 8px 12px; }
.stat b { font-size: 1.2rem; color: var(--gold); margin-right: 4px; }
.host-result { border-top: 1px solid var(--line); padding: 10px 0; }
.host-result:first-of-type { border-top: 0; }
.host-result h3 { font-family: inherit; font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 2.5em; gap: 8px; align-items: center; margin: 4px 0; font-size: 0.92rem; }
.bar { position: relative; padding: 4px 8px; border-radius: 6px; overflow: hidden; background: var(--bg); }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--brown); }
.bar span { position: relative; }
.bar-row b { text-align: right; }
.entry-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.entry-row:first-of-type { border-top: 0; }
.entry-row .entry-name { flex: 1 1 160px; }
.entry-row input, .entry-row select, .add-row input, .add-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.entry-row input { flex: 1 1 160px; }
.small-btn { min-height: 38px; padding: 0.4em 0.9em; font-size: 0.9rem; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.add-row input { flex: 1 1 200px; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 2px solid var(--line); background: none; border-radius: 999px; padding: 0.3em 0.8em; cursor: pointer; font-size: 0.9rem; }
.chip.on { border-color: var(--gold); color: var(--gold); }
.login { max-width: 360px; margin: 18vh auto 0; }
