:root {
  --bg: #fff6ec;
  --card: #ffffff;
  --ink: #3d2220;
  --muted: #7d5f58;
  --line: #f0d9cc;
  --pink: #e8557a;
  --pink-ink: #ffffff;
  --frosting: #ffe0e8;
  --mint: #2f9e86;
  --caramel: #c98b4b;
  --choc: #5a2d26;
  --danger: #b3261e;
  --shadow: 0 2px 0 rgba(90, 45, 38, .08), 0 8px 24px rgba(90, 45, 38, .08);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #24120f;
    --card: #351d18;
    --ink: #fbe9dc;
    --muted: #cba698;
    --line: #5a352c;
    --pink: #ff7a9c;
    --pink-ink: #3a0d1a;
    --frosting: #4b2430;
    --mint: #6fd6bd;
    --caramel: #e0a566;
    --choc: #1c0d0a;
    --danger: #ff8a80;
    --shadow: 0 8px 24px rgba(0, 0, 0, .35);
    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.5 ui-rounded, "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}
h1, h2 { font-family: "Iowan Old Style", Georgia, "Palatino Linotype", serif; line-height: 1.15; margin: 0; }
a { color: var(--pink); }
:focus-visible { outline: 3px solid var(--caramel); outline-offset: 2px; }

/* hero with sprinkles */
.hero {
  background:
    radial-gradient(circle at 12% 30%, #ffd166 0 3px, transparent 4px),
    radial-gradient(circle at 28% 70%, #8fe3cf 0 3px, transparent 4px),
    radial-gradient(circle at 55% 25%, #fff 0 3px, transparent 4px),
    radial-gradient(circle at 72% 65%, #ffd166 0 3px, transparent 4px),
    radial-gradient(circle at 90% 30%, #8fe3cf 0 3px, transparent 4px),
    linear-gradient(135deg, #e8557a, #f08aa3 60%, #f6b3a0);
  background-size: 160px 90px, 200px 110px, 140px 100px, 180px 90px, 220px 120px, auto;
  color: #fff; border-bottom: 6px solid var(--caramel);
  padding: 20px 16px 22px;
}
@media (prefers-color-scheme: dark) { .hero { background-color: var(--choc); filter: saturate(.85) brightness(.85); } }
.hero-inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 12px 24px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hero h1 { font-size: clamp(1.7rem, 6vw, 2.6rem); text-shadow: 0 2px 0 rgba(90, 45, 38, .35); }
.tagline { margin: 4px 0 0; opacity: .95; text-shadow: 0 1px 0 rgba(90, 45, 38, .35); }
.who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who .name { background: rgba(255, 255, 255, .92); color: #3d2220; padding: 6px 12px; border-radius: 999px; font-weight: 700; max-width: 100%; overflow-wrap: anywhere; }

/* layout: one column on phones, side panel + list on wide screens */
.layout { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .layout { grid-template-columns: 340px 1fr; align-items: start; gap: 24px; padding: 24px 16px; }
  .side { position: sticky; top: 16px; }
}
.side { display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 1.3rem; margin-bottom: 10px; }
.rules ul { margin: 0; padding-left: 1.2em; }
.rules li { margin: 4px 0; }

/* forms */
label { display: block; font-weight: 700; margin: 12px 0 4px; font-size: .92rem; }
label small { font-weight: 400; color: var(--muted); }
input {
  width: 100%; font: inherit; color: inherit; background: var(--bg); border: 2px solid var(--line);
  border-radius: 12px; padding: 11px 12px; min-height: 46px;
}
input:disabled { opacity: 1; cursor: not-allowed; background: var(--line); color: var(--muted); border-style: dashed; -webkit-text-fill-color: var(--muted); }
input:focus { border-color: var(--pink); outline: none; box-shadow: 0 0 0 3px var(--frosting); }
.hint { min-height: 1.4em; margin: 6px 0 0; font-size: .88rem; color: var(--muted); }
.hint.warn { color: var(--danger); }
.hint button { font: inherit; }
.error { color: var(--danger); min-height: 1.3em; margin: 8px 0; font-size: .92rem; }
.note { color: var(--muted); font-size: .94rem; margin: 6px 0; }
.note.warn { color: var(--ink); background: var(--frosting); padding: 10px 12px; border-radius: 12px; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 999px; min-height: 46px; padding: 0 20px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink);
}
.btn:hover { border-color: var(--pink); }
.btn.primary { background: var(--pink); border-color: var(--pink); color: var(--pink-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn[disabled] { opacity: .6; cursor: progress; }
#addForm .btn { width: 100%; margin-top: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row .btn { flex: 1 1 auto; }
.link { background: none; border: 0; padding: 0; color: var(--pink); text-decoration: underline; cursor: pointer; }

/* list */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.list-head h2 { font-size: 1.7rem; }
.sub { color: var(--muted); margin: 4px 0 12px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.live i { width: 9px; height: 9px; border-radius: 50%; background: var(--caramel); }
.live.on i { background: var(--mint); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px transparent; } 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--mint) 60%, transparent); } }

.ranked { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.entry {
  display: grid; grid-template-columns: auto auto 1fr; gap: 4px 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
}
.entry.out { opacity: .92; box-shadow: none; }
.rank {
  width: 46px; height: 50px; display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(160deg, var(--pink), var(--caramel));
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
}
.entry.out .rank { background: var(--line); color: var(--muted); }
.entry.nat20 .rank { background: linear-gradient(160deg, #ffcf4d, #e8557a); }
.votes { display: flex; flex-direction: column; align-items: center; }
.votes button {
  width: 44px; height: 36px; border: 0; background: transparent; cursor: pointer; font-size: 1.15rem; color: var(--muted); border-radius: 10px;
}
.votes button:hover { background: var(--frosting); }
.votes button[aria-pressed="true"].up { color: var(--mint); background: color-mix(in srgb, var(--mint) 18%, transparent); }
.votes button[aria-pressed="true"].down { color: var(--danger); background: color-mix(in srgb, var(--danger) 15%, transparent); }
.score { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: center; line-height: 1; }
.info { min-width: 0; }
.info .t { font-weight: 800; font-size: 1.05rem; overflow-wrap: anywhere; }
.info .meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.info .recipe { display: inline-block; margin-top: 2px; font-weight: 700; font-size: .92rem; }
.cutoff {
  list-style: none; text-align: center; color: var(--muted); font-size: .85rem; font-weight: 700;
  display: flex; align-items: center; gap: 10px; margin: 6px 0;
}
.cutoff::before, .cutoff::after { content: ""; flex: 1; border-top: 2px dashed var(--caramel); }
.empty { text-align: center; padding: 28px; color: var(--muted); }
.rolled { margin-top: 24px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.rolled summary { cursor: pointer; font-weight: 800; min-height: 32px; }
.rolled ul { margin: 8px 0 0; padding-left: 1.2em; }
.rolled li { margin: 6px 0; overflow-wrap: anywhere; }

.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; }

/* dialogs */
dialog {
  border: 0; border-radius: 20px; padding: 22px; width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(60, 20, 20, .55); }
dialog h2 { font-size: 1.4rem; margin-bottom: 8px; padding-right: 36px; }
.x { position: absolute; top: 10px; right: 10px; margin: 0; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--bg); color: var(--ink); cursor: pointer; font-size: 1rem; }
.tabs { display: flex; gap: 6px; margin: 10px 0; background: var(--bg); border-radius: 999px; padding: 4px; }
.tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--pink); color: var(--pink-ink); }
.namebox {
  font: 700 1.2rem/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border: 2px dashed var(--caramel); border-radius: 12px; padding: 14px; margin: 8px 0; text-align: center;
}
.dupes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dupes li { background: var(--bg); border-radius: 12px; padding: 10px 12px; overflow-wrap: anywhere; }
.dupes small { color: var(--muted); display: block; }

.toasts { position: fixed; left: 12px; right: 12px; bottom: 12px; display: grid; gap: 8px; justify-items: center; pointer-events: none; z-index: 10; }
.toast { pointer-events: auto; background: var(--choc); color: #fff3e8; border-radius: 14px; padding: 12px 16px; max-width: 520px; box-shadow: var(--shadow); animation: up .2s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* admin */
.admin { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.admin table { width: 100%; border-collapse: collapse; }
.admin th, .admin td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.admin .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.die { font-size: 1.1rem; font-weight: 800; padding: 12px; background: var(--frosting); border-radius: 12px; margin-top: 10px; }
@media (max-width: 640px) {
  .admin table, .admin thead, .admin tbody, .admin tr, .admin td { display: block; }
  .admin thead { display: none; }
  .admin tr { border-bottom: 2px solid var(--line); padding: 8px 0; }
  .admin td { border: 0; padding: 3px 0; }
}
