:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #667168;
  --line: #dce4db;
  --surface: #ffffff;
  --soft: #f4f8f1;
  --green: #06c755;
  --green-dark: #049540;
  --red: #e9473f;
  --gold: #f4b942;
  --blue: #2878d7;
  --shadow: 0 22px 60px rgba(28, 57, 38, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(6, 199, 85, 0.16), transparent 28%),
    linear-gradient(145deg, #f7faf5 0%, #eff7f1 42%, #fff8e5 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.user-shell {
  grid-template-columns: minmax(320px, 620px);
  justify-content: center;
}

.admin-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.hidden {
  display: none !important;
}

.draw-panel,
.admin-panel {
  min-width: 0;
  border: 1px solid rgba(220, 228, 219, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.draw-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px;
  overflow: hidden;
}

.admin-panel {
  padding: 24px;
}

.brand-row,
.section-header,
.item-footer,
.draw-actions {
  display: flex;
  align-items: center;
}

.brand-row {
  width: 100%;
  justify-content: space-between;
  gap: 12px;
}

.line-badge,
.odds-note,
.eyebrow,
.coupon-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.line-badge {
  border-radius: 999px;
  padding: 7px 11px;
  color: white;
  background: var(--green);
}

.odds-note {
  color: var(--green-dark);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 20px;
  font-size: clamp(38px, 6vw, 64px);
  line-height: 1;
  letter-spacing: 0;
}

.lead {
  max-width: 420px;
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.8;
  text-align: center;
}

.status-message {
  min-height: 24px;
  margin-top: 10px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-message.is-error {
  color: var(--red);
}

.machine-wrap {
  width: min(100%, 380px);
  height: 330px;
  margin-top: 18px;
  display: grid;
  place-items: center;
}

.machine {
  position: relative;
  width: 280px;
  height: 280px;
  transform: scale(1.12);
  transform-origin: center;
}

.drum {
  position: absolute;
  left: 32px;
  top: 16px;
  width: 210px;
  height: 210px;
  border: 14px solid var(--red);
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: inset 0 0 0 12px #ffd4ca, 0 16px 36px rgba(146, 45, 38, 0.18);
}

.machine.is-spinning .drum {
  animation: spinDrum 0.35s linear infinite;
}

.drum-window {
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle, #ffffff 0%, #f8f4ea 70%);
}

.drum-rim {
  position: absolute;
  inset: 72px;
  border-radius: 50%;
  background: var(--gold);
  border: 9px solid #fff1b9;
}

.ball {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, 0.12);
}

.ball-a { left: 28px; top: 34px; background: var(--green); }
.ball-b { left: 104px; top: 42px; background: var(--blue); }
.ball-c { left: 66px; top: 96px; background: var(--gold); }
.ball-d { left: 122px; top: 112px; background: var(--red); }
.ball-e { left: 30px; top: 126px; background: #ff8a3d; }

.machine.is-spinning .ball {
  animation: tumble 0.5s ease-in-out infinite alternate;
}

.machine.is-spinning .ball-b,
.machine.is-spinning .ball-d {
  animation-direction: alternate-reverse;
}

.handle {
  position: absolute;
  right: 8px;
  top: 88px;
  width: 80px;
  height: 24px;
  border-radius: 999px;
  background: #26352d;
  transform-origin: 16px 50%;
}

.handle span {
  position: absolute;
  right: -18px;
  top: -15px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--green);
  border: 8px solid #effff4;
  box-shadow: 0 8px 16px rgba(4, 149, 64, 0.25);
}

.machine.is-spinning .handle {
  animation: crank 0.42s ease-in-out infinite;
}

.tray {
  position: absolute;
  left: 82px;
  bottom: 14px;
  width: 120px;
  height: 54px;
  border-radius: 8px 8px 28px 28px;
  background: #24372d;
  display: grid;
  place-items: center;
}

.result-ball {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  background: var(--muted);
  transform: translateY(-22px);
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.14);
}

.result-ball.drop {
  animation: dropBall 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.draw-actions {
  width: 100%;
  gap: 10px;
}

.primary-button,
.ghost-button,
.use-button,
.text-button,
.item-action {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  flex: 1;
  color: white;
  background: var(--green);
  box-shadow: 0 12px 24px rgba(6, 199, 85, 0.26);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.ghost-button,
.text-button {
  color: var(--green-dark);
  background: #eaf9ef;
}

.ghost-button {
  padding: 0 14px;
}

.coupon-card {
  width: 100%;
  margin-top: 18px;
  padding: 18px;
  border: 2px dashed var(--green);
  border-radius: 8px;
  background: #fbfff7;
}

.coupon-card strong {
  display: block;
  margin-top: 4px;
  font-size: 44px;
  line-height: 1;
}

.coupon-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.coupon-card dt,
.item-meta,
.stats-grid span {
  color: var(--muted);
  font-size: 12px;
}

.coupon-card dd {
  margin: 4px 0 0;
  font-weight: 800;
}

.coupon-expiry {
  grid-column: 1 / -1;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.coupon-help {
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.coupon-qr {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.coupon-qr img {
  width: min(220px, 72vw);
  height: auto;
  aspect-ratio: 1;
  background: white;
}

.coupon-qr p {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

#couponStatus.used {
  color: #a33128;
}

.stats-grid div {
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
}

.section-header {
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  color: var(--green-dark);
}

h2 {
  margin-top: 4px;
  font-size: 26px;
}

.admin-title {
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.2;
}

.admin-status {
  text-align: left;
}

.text-button {
  padding: 0 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.stats-grid b {
  display: block;
  margin-top: 5px;
  font-size: 24px;
}

.admin-tabs {
  display: flex;
  gap: 2px;
  margin-top: 20px;
  border-bottom: 1px solid var(--line);
}

.admin-tab {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 0 16px;
  color: var(--muted);
  font-weight: 800;
  background: transparent;
}

.admin-tab.is-active {
  border-bottom-color: var(--green);
  color: var(--ink);
}

.admin-view {
  padding-top: 2px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(360px, 1.2fr);
  gap: 28px;
  margin-top: 28px;
}

.analytics-block + .analytics-block {
  border-left: 1px solid var(--line);
  padding-left: 28px;
}

.block-heading,
.bar-meta,
.export-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.block-heading h2 {
  margin: 0;
  font-size: 18px;
}

.block-heading span,
.bar-meta span,
.bar-row small,
.export-item span,
.export-note {
  color: var(--muted);
  font-size: 12px;
}

.bar-list {
  display: grid;
  gap: 18px;
  margin-top: 20px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--soft);
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.monthly-chart {
  height: 220px;
  display: grid;
  grid-template-columns: repeat(12, minmax(22px, 1fr));
  align-items: end;
  gap: 6px;
  margin-top: 18px;
  overflow-x: auto;
}

.month-column {
  min-width: 26px;
  height: 190px;
  display: grid;
  grid-template-rows: 22px 1fr 20px;
  align-items: end;
  gap: 4px;
  text-align: center;
}

.month-value,
.month-column small {
  color: var(--muted);
  font-size: 10px;
}

.month-bar {
  position: relative;
  height: 140px;
  border-bottom: 1px solid var(--line);
}

.month-bar span {
  position: absolute;
  right: 18%;
  bottom: 0;
  left: 18%;
  min-height: 0;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
}

.export-controls {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto auto auto;
  gap: 10px;
  margin-top: 20px;
  align-items: end;
}

.export-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.export-controls input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

.export-save {
  padding: 0 16px;
}

.export-note {
  margin-top: 12px;
}

.export-list {
  display: grid;
  gap: 0;
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.export-item {
  min-height: 68px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.export-item b,
.export-item span {
  display: block;
}

.export-item span {
  margin-top: 4px;
}

.admin-controls {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  margin: 18px 0;
}

.admin-login {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 18px;
  padding: 12px;
  border-radius: 8px;
  background: #fbfdf9;
}

.admin-controls label,
.admin-login label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.admin-controls select,
.admin-controls input,
.admin-login input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

.text-button:disabled,
.item-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.coupon-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.coupon-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: white;
}

.coupon-item > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.item-discount {
  font-size: 24px;
}

.item-code {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.item-meta {
  margin-top: 6px;
}

.item-footer {
  justify-content: space-between;
  margin-top: 12px;
  gap: 12px;
}

.item-status {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
}

.item-status.unused {
  color: var(--green-dark);
  background: #eaf9ef;
}

.item-status.used {
  color: #7c261f;
  background: #ffe9e4;
}

.item-action {
  min-height: 36px;
  padding: 0 12px;
  color: white;
  background: var(--ink);
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfdf9;
}

.staff-page {
  background: #f3f7f2;
}

.staff-shell {
  width: min(520px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0;
}

.staff-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: white;
  box-shadow: 0 16px 44px rgba(28, 57, 38, 0.12);
}

.staff-header,
.staff-confirm-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.staff-title {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.2;
}

.staff-logout {
  border: 0;
  padding: 8px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: transparent;
}

.staff-login {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.staff-login label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.staff-login input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

.staff-message {
  text-align: left;
}

.staff-content {
  margin-top: 24px;
}

.staff-discount {
  padding: 22px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.staff-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 20px;
}

.staff-details > div {
  min-width: 0;
  padding: 18px 12px;
  border-bottom: 1px solid var(--line);
}

.staff-details > div + div {
  border-left: 1px solid var(--line);
}

.staff-details dt {
  color: var(--muted);
  font-size: 12px;
}

.staff-details dd {
  margin: 7px 0 0;
  font-weight: 800;
}

.staff-status {
  display: inline-block;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
}

.staff-status.available {
  color: var(--green-dark);
  background: #eaf9ef;
}

.staff-status.used,
.staff-status.expired {
  color: #7c261f;
  background: #ffe9e4;
}

.staff-use-button {
  width: 100%;
}

.staff-use-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.staff-confirm {
  margin-top: 16px;
  border-top: 2px solid var(--red);
  padding-top: 16px;
}

.staff-confirm p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.staff-confirm-actions {
  margin-top: 14px;
}

.staff-confirm-actions button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 800;
}

.danger-button {
  color: white;
  background: var(--red);
}

@keyframes spinDrum {
  to { transform: rotate(360deg); }
}

@keyframes tumble {
  from { transform: translate(-5px, 8px); }
  to { transform: translate(8px, -7px); }
}

@keyframes crank {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(48deg); }
}

@keyframes dropBall {
  0% { transform: translateY(-110px) scale(0.65); opacity: 0; }
  72% { transform: translateY(-18px) scale(1.08); opacity: 1; }
  100% { transform: translateY(-22px) scale(1); opacity: 1; }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 560px);
    padding: 10px 0 24px;
  }

  .admin-shell {
    width: min(100% - 20px, 620px);
    padding: 10px 0 24px;
  }

  .draw-panel,
  .admin-panel {
    padding: 18px;
  }

  .draw-actions,
  .admin-controls,
  .admin-login,
  .coupon-card dl,
  .analytics-grid,
  .export-controls {
    grid-template-columns: 1fr;
  }

  .analytics-block + .analytics-block {
    border-top: 1px solid var(--line);
    border-left: 0;
    padding-top: 24px;
    padding-left: 0;
  }

  .analytics-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .export-controls .text-button,
  .export-save {
    width: 100%;
  }

  .draw-actions {
    display: grid;
  }

  .ghost-button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-tab {
    flex: 1;
    padding: 0 8px;
    font-size: 13px;
  }

  .staff-shell {
    width: min(100% - 16px, 520px);
    padding: 8px 0 20px;
  }

  .staff-panel {
    padding: 18px;
  }

  .staff-header {
    align-items: flex-start;
  }

  .staff-details {
    grid-template-columns: 1fr;
  }

  .staff-details > div + div {
    border-left: 0;
  }

  .staff-confirm-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .machine {
    transform: scale(1.04);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
