:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #5c606a;
  --line: #dfe1e6;
  --accent: #c4432a;
  --accent-ink: #ffffff;
  --ok: #2f8a57;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; letter-spacing: -0.01em; }
p { margin: 0 0 .8em; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 999px; padding: .65em 1.1em; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  text-decoration: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, background-color .15s ease, border-color .15s ease;
}
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; }
.danger { color: #b3261e; }
.big { width: 100%; padding: 1em; font-size: 1.05rem; }

input[type=text], input[type=password], input[type=number], textarea, select {
  font: inherit; font-size: 16px; width: 100%; padding: .7em .85em; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
label { font-size: .9rem; font-weight: 600; display: block; }
label > input, label > select, label > textarea { margin-top: .35em; font-weight: 400; }
.check { display: flex; align-items: center; gap: .55em; font-weight: 500; }
.check input { width: 1.1em; height: 1.1em; accent-color: var(--accent); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem; }

/* ---------- guest upload ---------- */
.guest { max-width: 460px; margin: 0 auto; padding: max(1rem, env(safe-area-inset-top)) 1rem calc(1.5rem + env(safe-area-inset-bottom)); }
.guest header { text-align: center; padding: 1.2rem 0 1rem; }
.guest header h1 { font-size: 1.6rem; }
.stack { display: grid; gap: .75rem; }
.picker-art { aspect-ratio: 1; width: 60%; margin: .5rem auto 1.2rem; border-radius: 18px;
  background: repeating-linear-gradient(45deg, #eceef1 0 10px, #e3e6ea 10px 20px);
  display: grid; place-items: center; font-size: 3rem; border: 2px dashed #cdd1d8; }
.editor-wrap { position: relative; }
#canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 6px; touch-action: none; background: #ddd; cursor: grab; }
#canvas:active { cursor: grabbing; }
.hint { text-align: center; font-size: .82rem; color: var(--muted); margin: .5rem 0 .2rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #e6e8ec; border-radius: 999px; padding: 4px; }
.seg button { border: 0; background: transparent; padding: .55em; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.tools { display: flex; gap: .5rem; align-items: center; }
.tools input[type=range] { flex: 1; accent-color: var(--accent); }
.swatches { display: flex; gap: .5rem; align-items: center; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.swatch.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.done { text-align: center; }
.error { background: #fdecea; color: #8c1d18; padding: .7em .9em; border-radius: 10px; font-size: .9rem; }

/* ---------- admin ---------- */
.admin { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.brand { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: .5em; text-decoration: none; }
.brand i { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block;
  background-image: linear-gradient(#fff 0 0), linear-gradient(#fff 0 0); background-size: 2px 100%, 100% 2px;
  background-position: 33% 0, 0 33%; background-repeat: no-repeat; }
.grid-events { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.event-card { cursor: pointer; transition: transform .15s ease; }
.event-card:hover { transform: translateY(-2px); }
.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: .2em .6em; border-radius: 999px; background: #e6e8ec; color: var(--muted); }
.pill.live { background: #e3f3e9; color: var(--ok); }
.pill.warn { background: #fdf0dc; color: #8a5a00; }
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }
.qr-box img { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.url { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: #eef0f3; padding: .5em .6em; border-radius: 8px; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0 0 .8rem; }
.progress { height: 10px; background: #e6e8ec; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s ease; }
.sheet-preview { display: grid; gap: 6px; background: #fff; border: 1px solid var(--line); padding: 10px; border-radius: 8px; width: max-content; }
.sheet-preview > div { width: 46px; aspect-ratio: 1; border-radius: 3px; background: #eef0f3 center/cover; border: 1px dashed #cfd3da; }
.sheet-preview > div.filled { border: 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .75rem; }
.photo { position: relative; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.photo img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.photo .meta { padding: .4em .55em; font-size: .78rem; display: flex; justify-content: space-between; gap: .3em; }
.photo .meta span:first-child { font-weight: 700; }
.photo .actions { position: absolute; inset: 0 0 auto auto; display: flex; gap: 4px; padding: 6px; opacity: 0; transition: opacity .15s; }
.photo:hover .actions, .photo:focus-within .actions { opacity: 1; }
.photo .actions button, .photo .actions a { padding: .3em .5em; font-size: .72rem; background: rgba(255,255,255,.95); }
@media (hover: none) { .photo .actions { opacity: 1; } }
.sheets { display: grid; gap: .5rem; }
.sheet-row { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; flex-wrap: wrap; }
.sheet-row.printed { opacity: .6; }
.sheet-row b { min-width: 5.5em; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.settings .full { grid-column: 1 / -1; }
details summary { cursor: pointer; font-weight: 700; list-style: none; }
details summary::after { content: " ▾"; color: var(--muted); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }
.toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .7em 1.1em; border-radius: 999px; font-size: .9rem; box-shadow: var(--shadow); z-index: 10; }
dialog { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* ---------- multi-photo + round ---------- */
#canvas, #decor-canvas, .tile canvas, .lib-tile canvas { --paper: #ffffff; }
.tickets { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin: .8rem 0 1rem; }
.tickets.single { grid-template-columns: 1fr; justify-items: center; }
.tickets.single figure { width: 70%; }
.tickets.single figcaption { font-size: 3rem; }
.tickets figure { margin: 0; }
.tickets img { width: 100%; aspect-ratio: 1; border-radius: 6px; box-shadow: var(--shadow); display: block; }
.tickets img.round { border-radius: 50%; }
.tickets figcaption { font-weight: 800; color: var(--accent); font-size: 1.3rem; margin-top: .3rem; }
.photo img.round, .sheet-preview > div.round { border-radius: 50%; }
.overlay-preview { width: 120px; aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line);
  background: repeating-conic-gradient(#e6e8ec 0 25%, #fff 0 50%) 0 0/16px 16px; }
.overlay-preview img { width: 100%; height: 100%; display: block; }
.settings h3 { margin: .4rem 0 0; font-size: .95rem; }

/* ---------- review grid: all photos at once ---------- */
.review-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
@media (min-width: 420px) { .review-grid { grid-template-columns: repeat(3, 1fr); } }
.tile { position: relative; }
.tile-open { display: block; width: 100%; padding: 0; border: 0; border-radius: 8px; background: #e6e8ec; overflow: hidden; aspect-ratio: 1; }
.tile.round .tile-open { border-radius: 50%; background: #fff; }
.tile-open canvas { width: 100%; aspect-ratio: 1; display: block; }
.tile-loading { position: absolute; inset: 0; display: none; place-items: center; font-size: .8rem; color: var(--muted); }
.tile.loading .tile-loading { display: grid; }
.tile.loading canvas { visibility: hidden; }
.tile-x { position: absolute; top: -6px; right: -6px; width: 28px; height: 28px; padding: 0; font-size: 1.1rem; line-height: 1;
  background: var(--ink); color: #fff; border: 2px solid #fff; }
.bulk { background: #f2f3f5; border-radius: 12px; padding: .8rem; }

/* ---------- frame chips ---------- */
.frames { display: flex; gap: .55rem; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.frame-chip { flex: none; flex-direction: column; gap: .25rem; padding: 0; border: 0; background: none; border-radius: 10px; width: 64px; }
.frame-thumb { width: 64px; height: 64px; border-radius: 8px; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, #8ec5fc, #f6d1a5); outline: 2px solid var(--line); outline-offset: 0; }
.frame-chip.round .frame-thumb { border-radius: 50%; }
.frame-thumb img { width: 100%; height: 100%; display: block; }
.frame-thumb i { font-style: normal; color: #fff; font-size: 1.3rem; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.frame-name { font-size: .72rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64px; }
.frame-chip.on .frame-thumb { outline: 3px solid var(--accent); }
.frame-chip.on .frame-name { color: var(--ink); }

/* ---------- admin: frames list + library ---------- */
.frame-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .6rem; }
.frame-item { display: grid; gap: .25rem; justify-items: center; text-align: center; font-size: .75rem; }
.frame-item .frame-thumb { width: 76px; height: 76px; }
.frame-item .frame-actions { display: flex; gap: 2px; }
.frame-item .frame-actions button { padding: .2em .45em; font-size: .7rem; }
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; max-height: 52vh; overflow: auto; padding: 2px; }
.lib-tile { display: grid; gap: .3rem; justify-items: center; padding: .4rem; border: 2px solid transparent; border-radius: 12px; background: none; font-size: .8rem; }
.lib-tile canvas { width: 100%; aspect-ratio: 1; display: block; }
.lib-tile.on { border-color: var(--accent); }
dialog.wide { width: min(560px, 94vw); }
