:root {
  --bg: #F2F8F8;
  --bg-side: #f3f7f8;
  --bg-elev: #ffffff;
  --bg-elev-2: #ffffff;
  --line: #d5e2e6;
  --text: #1c2b33;
  --muted: #5f737c;
  --faint: #7d9199;
  --gold: #edb202;
  --gold-deep: #c89600;
  --teal: #6fb0ab;
  --teal-deep: #4C8D8C;
  --teal-soft: #A4D3CF;
  --ink: #1c2b33;
  --good: #3b6f6e;
  --bad: #d64550;
  --info: #4C8D8C;
  --shadow: 0 16px 40px rgba(76, 141, 140, 0.12);
  --radius: 22px;
  --font: "Outfit", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 280px at 12% -20%, rgba(111, 176, 171, 0.28), transparent 55%),
    linear-gradient(180deg, #F2F8F8 0%, #f8fafc 55%, #ffffff 100%);
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { background: transparent; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar, .main {
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: auto;
}
.sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  padding: calc(22px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.main {
  padding: calc(22px + var(--safe-t)) 22px calc(28px + var(--safe-b));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 8px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 680;
  letter-spacing: -0.03em;
}
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.side-actions, .row-actions, .prize-actions, .adder, .preset-row, .top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.side-actions { padding: 0 4px; }

.raffle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.raffle-card {
  display: flex;
  gap: 6px;
  align-items: stretch;
  border: 1px solid var(--line);
  background: #F2F8F8;
  border-radius: 16px;
  padding: 6px;
}
.raffle-card.active {
  border-color: var(--teal);
  background: rgba(111, 176, 171, 0.14);
}
.card-open {
  flex: 1;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 12px;
  padding: 8px 8px 8px 10px;
  min-width: 0;
}
.card-title {
  display: block;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.badge.ok { background: rgba(61, 220, 151, 0.14); color: var(--good); }
.badge.bad { background: rgba(255, 107, 120, 0.14); color: var(--bad); }
.badge.live { background: rgba(237, 178, 2, 0.16); color: #9a7200; }

.delivery {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(111, 176, 171, 0.12);
  border: 1px solid var(--teal-soft);
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.45;
}
.delivery strong { display: block; margin-bottom: 6px; }
.delivery ol { margin: 0; padding-left: 1.3rem; }
.delivery li { margin: 3px 0; }
.delivery.bad {
  background: rgba(255, 107, 120, 0.1);
  border-color: rgba(255, 107, 120, 0.35);
}
.hover-tip {
  position: fixed;
  z-index: 40;
  max-width: min(280px, calc(100vw - 24px));
  padding: 8px 10px;
  border-radius: 10px;
  background: #f6f3ec;
  color: #1a1408;
  font-size: 0.82rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}
.side-note, .fine {
  color: var(--faint);
  font-size: 0.8rem;
  line-height: 1.45;
  margin: 0;
  padding: 0 6px;
}
.side-foot { margin-top: auto; display: grid; gap: 8px; }

.main-inner { max-width: 760px; margin: 0 auto; }
.kicker {
  margin: 0 0 6px;
  color: var(--teal-deep);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.display {
  margin: 0;
  font-family: var(--display);
  font-weight: 680;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.lede {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
  max-width: 46ch;
}

.hero-steps {
  display: grid;
  gap: 10px;
  margin: 28px 0;
}
.hero-steps article {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.step-n {
  font-family: var(--display);
  color: var(--teal-deep);
  font-size: 1.2rem;
}
.hero-steps h3 { margin: 0 0 4px; font-size: 1rem; }
.hero-steps p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.topbar h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.rules {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(61, 220, 151, 0.08);
  margin-bottom: 18px;
}
.rules strong { font-size: 0.98rem; letter-spacing: -0.02em; }
.rules span { color: var(--muted); font-size: 0.88rem; }
.rules.info { background: rgba(255, 255, 255, 0.03); }
.rules.bad {
  background: rgba(255, 107, 120, 0.1);
  border-color: rgba(255, 107, 120, 0.35);
}
.rules.bad span { color: #9f1239; }

.panel {
  background: #F2F8F8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.panel .hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}
.panel-index {
  color: var(--teal-deep);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 6px;
}

.field { display: grid; gap: 6px; min-width: 0; }
.field span, .inline-label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="text"], input[type="number"], .text-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
}
input::placeholder { color: var(--faint); }
input[type="number"] { appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }

.preset-row { margin: 12px 0 4px; }
.preset, .chip, .btn, .icon-btn {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 14px;
}
.preset.active {
  background: var(--teal);
  color: #ffffff;
  border-color: transparent;
  font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-right: 6px;
  font-variant-numeric: tabular-nums;
}
.chip.outside { border-color: rgba(255, 107, 120, 0.45); color: #9f1239; }
.chip button {
  border: 0;
  background: transparent;
  color: inherit;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
}
.adder input[type="text"] { flex: 1 1 180px; }
.adder input[type="number"] { flex: 0 0 92px; width: 92px; }

.btn {
  border-radius: 14px;
  font-weight: 650;
  min-height: 48px;
  padding: 10px 16px;
}
.btn.primary {
  background: var(--teal);
  color: #ffffff;
  border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn.danger {
  background: rgba(255, 107, 120, 0.12);
  color: #9f1239;
  border-color: rgba(255, 107, 120, 0.3);
}
.btn.small, .icon-btn { min-height: 40px; border-radius: 12px; }
.btn:disabled, .icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn {
  width: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: none;
}
.btn.block { width: 100%; }

.prize-adder {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}
.prize-adder input[type="text"] { flex: 1 1 100%; }
.prize-adder .field { flex: 1 1 140px; min-width: 0; }
.prize-adder .btn { flex: 1 1 160px; }
.panel .split-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 64px 0 16px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.split-label::before,
.split-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
#prize-box { margin-top: 0; }
.subhead.excluded-head { margin-top: 42px; }

.prize-list { display: grid; gap: 12px; }
.prize {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: #F2F8F8;
}
.prize.excluded { opacity: 0.85; }
.prize-top { display: flex; gap: 10px; align-items: center; }
.prize-top input { flex: 1; min-width: 0; }
.prize-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.prize-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.prize-move { display: flex; gap: 8px; flex: none; }
.subhead {
  margin: 18px 0 8px;
  font-size: 0.92rem;
  color: var(--muted);
}
.empty-inline {
  margin: 0;
  color: var(--faint);
  font-size: 0.9rem;
}

.action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0 calc(8px + var(--safe-b));
  background: linear-gradient(180deg, transparent, var(--bg) 28%);
}

.stage { max-width: 680px; margin: 0 auto; }
.ticket {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: 28px 22px 26px;
  background: #ffffff;
  border: 1px solid var(--teal-soft);
  box-shadow: var(--shadow);
  text-align: center;
}
.ticket-name {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  letter-spacing: -0.03em;
}
.ticket-kicker {
  margin: 10px 0 0;
  color: var(--teal-deep);
  font-weight: 650;
  min-height: 1.4em;
}
.tombola {
  position: relative;
  width: min(100%, 340px);
  height: 280px;
  margin: 18px auto 8px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(164, 211, 207, 0.45), transparent 42%),
    radial-gradient(circle at 50% 50%, rgba(180, 210, 210, 0.55) 0 54%, transparent 55%);
  overflow: hidden;
}
.tombola::before {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 2px dashed var(--teal);
  pointer-events: none;
}
.tombola.spinning::before { animation: cage-spin 1.1s linear infinite; }
.tombola-orbit { position: absolute; inset: 0; z-index: 1; }
.pick-spot {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
}
.pick-spot .btn { min-width: 180px; }
.tombola.spinning .pick-spot { visibility: hidden; }
.orbit-ball {
  position: absolute;
  min-width: 40px;
  height: 40px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: radial-gradient(circle at 50% 30%, #fff6d8, #edb202 55%, #c89600);
  color: var(--ink);
  font-family: var(--display);
  font-size: 13px;
  font-weight: 680;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  box-shadow: inset 0 -6px 8px rgba(90, 50, 0, 0.2), 0 8px 12px rgba(0, 0, 0, 0.28);
}
.tombola.spinning .balls { visibility: hidden; }
.tombola .balls {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  align-items: center;
}
.balls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 22px 0 8px;
  min-height: 84px;
}
@keyframes cage-spin { to { transform: rotate(360deg); } }
.balls span {
  width: 64px;
  height: 80px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 28%, #fff6d8, #edb202 46%, #c89600);
  color: var(--ink);
  font-family: var(--display);
  font-size: 42px;
  font-weight: 680;
  box-shadow: inset 0 -10px 14px rgba(90, 50, 0, 0.18), 0 12px 24px rgba(0, 0, 0, 0.28);
}
.balls[data-len="4"] span { width: 56px; font-size: 36px; }
.balls[data-len="5"] span,
.balls[data-len="6"] span { width: 46px; height: 64px; font-size: 28px; border-radius: 14px; }
.balls[data-len="7"] span,
.balls[data-len="8"] span { width: 36px; height: 52px; font-size: 22px; border-radius: 12px; }
.balls.landed span { animation: pop 0.45s ease both; }
.balls.landed span:nth-child(2) { animation-delay: 0.04s; }
.balls.landed span:nth-child(3) { animation-delay: 0.08s; }
.balls.landed span:nth-child(4) { animation-delay: 0.12s; }
.balls.landed span:nth-child(5) { animation-delay: 0.16s; }
.balls.landed span:nth-child(6) { animation-delay: 0.2s; }
@keyframes pop {
  0% { transform: translateY(8px) scale(0.86); }
  100% { transform: none; }
}

.trust {
  margin: 14px 0 0;
  color: var(--faint);
  font-size: 0.8rem;
}
.queue { display: grid; gap: 8px; margin-top: 16px; }
.queue-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 12px 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #F2F8F8;
}
.queue-item.done { border-color: var(--teal-soft); }
.queue-item.current { outline: 1px solid var(--teal); }
.q-title { font-weight: 650; overflow-wrap: anywhere; }
.inline-label { display: flex; align-items: center; gap: 8px; }
.inline-label input { width: 74px; min-height: 40px; padding: 8px 10px; }
.q-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.q-num {
  font-family: var(--display);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}
.history { margin-top: 18px; }
.history details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.history summary { cursor: pointer; color: var(--muted); }
.history-block { padding: 10px 0 4px; }
.history-block h4 { margin: 0 0 6px; font-size: 0.92rem; }
.history-block p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle[aria-pressed="true"] {
  background: rgba(111, 176, 171, 0.18);
  border-color: var(--teal);
  color: var(--teal-deep);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%) translateY(16px);
  background: #f6f3ec;
  color: #1a1408;
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 20;
  max-width: min(92vw, 420px);
  text-align: center;
}

.swal2-popup.bc-swal {
  width: min(92vw, 440px);
  padding: 28px 22px 22px;
  background: #F2F8F8;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 22px;
  font-family: var(--font);
  box-shadow: var(--shadow);
}
.bc-swal-text {
  margin: 0;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.45;
}
.bc-swal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  margin: 22px 0 0;
}
.bc-swal-actions .btn { flex: 1; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.winner-card { text-align: center; }
.winner-kicker {
  margin: 0;
  color: var(--teal-deep);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.winner-number {
  display: inline-block;
  margin: 14px 0 0;
  padding: 8px 22px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 28%, #fff6d8, #edb202 46%, #c89600);
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(3rem, 10vw, 4.4rem);
  font-weight: 680;
  letter-spacing: -0.04em;
  line-height: 1.05;
  box-shadow: inset 0 -10px 14px rgba(90, 50, 0, 0.18);
  animation: pop 0.5s ease both;
}
.winner-prize {
  margin: 16px 0 0;
  font-size: 1.25rem;
  font-weight: 650;
}
.winner-place {
  margin: 6px 0 0;
  color: var(--muted);
}
.fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}
.fx.celebrating { z-index: 2000; }
.noscript {
  padding: 24px;
}

.empty-side {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (hover: hover) {
  .btn.primary:hover { filter: brightness(1.06); }
  .raffle-card:hover { border-color: rgba(255, 243, 220, 0.22); }
  .btn:active, .preset:active, .icon-btn:active { transform: translateY(1px); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar, .main { max-height: none; min-height: 100dvh; }
  .app[data-view="edit"] .sidebar,
  .app[data-view="draw"] .sidebar { display: none; }
  .app[data-view="list"] .main { display: none; }
  .main { padding-inline: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .queue-item { grid-template-columns: 1fr auto; }
  .queue-item .btn { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
  .balls span { width: 48px; height: 64px; font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  body { background: white; color: black; }
  .sidebar, .action-bar, .toggles, .toast, .fx, .top-actions, .btn, .icon-btn, .tombola-orbit { display: none !important; }
  .tombola { height: auto; overflow: visible; background: none; }
  .tombola::before { display: none; }
  .tombola .balls { position: static; visibility: visible; }
  .app { display: block; }
  .main { max-height: none; overflow: visible; }
  .ticket, .queue-item, .panel { box-shadow: none; color: black; background: white; }
}
