:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d1b19;
  --muted: #7a746c;
  --line: #e4dfd7;
  --accent: #e8590c;
  --gold: #f5b301;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
h1 { font-size: 1.8rem; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { background: #fde8e8; color: #9b1c1c; padding: 10px 14px; border-radius: 10px; }
.notice { background: #e6f4ea; color: #1e6b34; padding: 10px 14px; border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
.spacer { flex: 1; }

/* Forms */
label { display: block; font-weight: 600; font-size: 0.95rem; margin: 14px 0; }
input:not([type=checkbox]), select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-weight: 400; color: inherit;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
select { width: auto; margin: 0; padding: 8px 12px; }
textarea { resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--ink); color: #fff; border: 0; border-radius: 999px;
  padding: 14px 24px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.small { padding: 8px 14px; font-size: 0.9rem; }
.btn.light { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .grow { flex: 1; margin-bottom: 0; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }

/* Join / login card */
body.center { min-height: 100svh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border-radius: 22px; padding: 32px 24px; width: 100%; max-width: 420px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.card form { text-align: left; }
.card .btn { width: 100%; margin-top: 8px; }
.lens { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #6b6b6b, #111 55%); border: 6px solid var(--ink); box-shadow: 0 0 0 4px var(--accent); }

/* Camera */
body.camera { background: #000; color: #fff; overflow: hidden; }
.viewfinder { position: fixed; inset: 0; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.viewfinder video.mirror { transform: scaleX(-1); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 24px;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
  font-size: 0.95rem;
}
.topbar .event { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .shots { background: rgba(0,0,0,.5); padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.topbar .shots b { color: var(--gold); }
.controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around; align-items: center;
  padding: 24px 16px calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.shutter { width: 80px; height: 80px; border-radius: 50%; border: 5px solid #fff; background: transparent; padding: 5px; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .3; }
.round { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); color: #fff; border: 0; cursor: pointer; margin: 0; }
.round:disabled { opacity: .3; }
.toast { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 130px); transform: translateX(-50%); background: rgba(0,0,0,.75); padding: 8px 16px; border-radius: 999px; font-size: 0.9rem; white-space: nowrap; }
.nocam { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 32px; background: #000; gap: 8px; }
.nocam[hidden] { display: none; }
.nocam .btn { background: #fff; color: #000; margin: 8px auto 0; }

/* Admin */
.nav { display: flex; align-items: center; gap: 4px 18px; flex-wrap: wrap; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.nav a { text-decoration: none; color: var(--muted); padding: 4px 0; }
.nav a.on { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px var(--accent); }
.nav .right { margin-left: auto; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }
.wrap.narrow { max-width: 760px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tabs a { text-decoration: none; padding: 6px 14px; border-radius: 999px; color: var(--muted); }
.tabs a.on { background: var(--ink); color: #fff; }
.tabs span { opacity: .7; margin-left: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.tile { position: relative; margin: 0; background: var(--card); border-radius: 12px; overflow: hidden; border: 3px solid transparent; display: block; }
.tile img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; cursor: zoom-in; background: var(--line); }
.tile.sel { border-color: var(--gold); }
.tile figcaption { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); padding: 6px 8px; }
.tile .star { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border-radius: 50%; border: 0; font-size: 20px; cursor: pointer; background: rgba(0,0,0,.45); color: #fff; }
.tile.sel .star { background: var(--gold); color: #000; }
.tile .del { border: 0; background: none; color: var(--muted); font-size: 0.75rem; cursor: pointer; padding: 0; text-decoration: underline; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 10; display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lightbox img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.lbbar { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); color: #fff; }
.lbbar button { font: inherit; background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; cursor: pointer; }
.lbbar .star.on { background: var(--gold); color: #000; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
td { word-break: break-word; }

/* Album */
.albumhead { text-align: center; padding: 24px 0 8px; }
.albumhead .btn { margin-top: 8px; }
.grid.album .tile img { cursor: pointer; }
.tile .by { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.5); color: #fff; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; }

/* QR */
.qrcard { text-align: center; max-width: 520px; }
.qrcard .big { font-size: 1.4rem; font-weight: 600; margin: 4px 0 12px; }
.qr { width: min(80vw, 380px); margin: 0 auto; }
.qr svg { width: 100%; height: auto; display: block; }
@media print { .noprint { display: none; } body.print { background: #fff; } }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .toolbar .btn { flex: 1; }
}

[hidden] { display: none !important; }
body.nocamera .controls { display: none; }

/* Parties */
.nav .sep { color: var(--muted); }
.parties { display: grid; gap: 10px; margin-bottom: 16px; }
.party { display: grid; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; text-decoration: none; }
.party:hover { border-color: var(--ink); }
.party strong { font-size: 1.1rem; }
.prefix { display: flex; align-items: stretch; margin-top: 6px; }
.prefix > span { display: block; line-height: 44px; flex: 0 1 auto; max-width: 55%; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px; font-weight: 400; color: var(--muted); white-space: nowrap; font-size: 0.9rem; }
.prefix input { flex: 1 1 120px; margin-top: 0 !important; border-radius: 0 10px 10px 0 !important; min-width: 0; }
.btn.danger { background: #b42318; }

/* Party look: own background color and round photo */
body[data-party] { background: var(--party-bg); }
body[data-party] .albumhead, body[data-party] .qrcard { background: var(--card); border-radius: 22px; padding: 24px; margin: 16px auto; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.12); }
.lens.photo { display: block; width: 140px; height: 140px; object-fit: cover; background: var(--line); border: 5px solid #fff; box-shadow: 0 0 0 4px var(--accent), 0 8px 24px rgba(0,0,0,.15); }
.albumhead .lens, .qrcard .lens { margin-bottom: 12px; }
.colorpick { display: flex; align-items: center; gap: 12px; margin-top: 6px; font-weight: 400; }
.colorpick input[type=color] { width: 56px; height: 44px; padding: 4px; margin: 0; cursor: pointer; }
.bgpreview { display: flex; gap: 12px; align-items: center; margin: -4px 0 14px; }
.bgpreview img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.bgpreview .check { margin: 0; }
.codeinput { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; }
