:root {
  --navy-950: #060f1d;
  --navy-900: #091526;
  --navy-800: #0f213b;
  --navy-700: #162e52;
  --navy-600: #1f3f6e;
  --gold-300: #f7e4a3;
  --gold-400: #f0cf72;
  --gold-500: #d4af37;
  --gold-600: #a8821d;
  --text-main: #f4f6fa;
  --text-muted: #9eb0c9;
  --border-gold: rgba(212, 175, 55, 0.28);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --success: #2dd4bf;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.42);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Pyidaungsu", "Myanmar MN", "Noto Sans Myanmar", "Segoe UI", Roboto, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top right, #142a4a 0%, var(--navy-900) 48%, var(--navy-950) 100%);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(9, 21, 38, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-gold);
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--navy-700), var(--navy-950));
  border: 1.5px solid var(--gold-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 17px;
  color: var(--gold-400);
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(212, 175, 55, 0.2);
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--gold-300);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Navigation */
.desktop-nav {
  display: none;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.nav-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
}

.nav-btn.active {
  background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
  color: var(--navy-950);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(9, 21, 38, 0.96);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-gold);
  padding: 6px 6px max(8px, env(safe-area-inset-bottom));
}

.mobile-nav .nav-btn {
  flex-direction: column;
  gap: 3px;
  padding: 7px 4px;
  font-size: 11px;
  border-radius: 10px;
}

.mobile-nav .nav-icon {
  font-size: 18px;
  line-height: 1;
}

/* Main container */
.app-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 104px;
}

.tab-view {
  display: none;
  animation: fadeIn 0.22s ease;
}

.tab-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.card {
  background: linear-gradient(160deg, rgba(22, 46, 82, 0.72), rgba(9, 21, 38, 0.92));
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.card-subtle {
  background: rgba(15, 33, 59, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}

.card-title {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 700;
  color: var(--gold-300);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stat-card {
  background: rgba(15, 33, 59, 0.75);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--gold-400);
}

/* Form controls */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-300);
  margin-bottom: 6px;
}

.input, .select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(212, 175, 55, 0.32);
  background: rgba(6, 15, 29, 0.78);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus, .select:focus {
  border-color: var(--gold-400);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.16);
}

.input::placeholder {
  color: #6b809e;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s, background 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold-300), var(--gold-500) 55%, var(--gold-600));
  color: var(--navy-950);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.28);
}

.btn-gold:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-outline {
  background: rgba(212, 175, 55, 0.08);
  border-color: var(--border-gold);
  color: var(--gold-300);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.16);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
}

/* Segmented Mode Switch */
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(6, 15, 29, 0.72);
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.mode-btn {
  padding: 10px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.25), rgba(212, 175, 55, 0.1));
  color: var(--gold-300);
  border: 1px solid var(--border-gold);
}

/* Play Stage */
.stage-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 430px;
  position: relative;
  overflow: hidden;
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.14);
  border: 1px solid var(--border-gold);
  color: var(--gold-300);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* Scratch Card */
.scratch-wrapper {
  position: relative;
  width: min(330px, 100%);
  height: 210px;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid var(--gold-500);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 24px rgba(212, 175, 55, 0.18);
  margin: 10px auto 14px;
  user-select: none;
  touch-action: none;
}

.scratch-underlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, #1b3863 0%, #0b192c 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.scratch-prize-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gold-400);
  margin-bottom: 6px;
}

.scratch-prize-title {
  font-size: 21px;
  font-weight: 800;
  color: #ffffff;
  margin: 0 0 6px;
  line-height: 1.3;
}

.scratch-prize-desc {
  font-size: 13px;
  color: var(--gold-300);
  margin: 0;
}

#scratchCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* Lucky Spin Wheel */
.wheel-wrapper {
  position: relative;
  width: min(320px, 84vw);
  height: min(320px, 84vw);
  margin: 8px auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-pointer {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid var(--gold-400);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
  z-index: 5;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.55), 0 0 0 5px var(--gold-500);
}

/* Reward Result & Coupon Preview */
.result-box {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

.coupon-preview-img {
  width: 100%;
  max-width: 340px;
  border-radius: 16px;
  border: 1.5px solid var(--gold-500);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55);
  display: block;
  margin: 0 auto 14px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* Badges & Tags */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-active {
  background: rgba(45, 212, 191, 0.16);
  color: #5eead4;
  border: 1px solid rgba(45, 212, 191, 0.35);
}

.badge-redeemed {
  background: rgba(158, 176, 201, 0.14);
  color: var(--text-muted);
  border: 1px solid rgba(158, 176, 201, 0.28);
}

.badge-gold {
  background: rgba(212, 175, 55, 0.18);
  color: var(--gold-300);
  border: 1px solid var(--border-gold);
}

.tier-member { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
.tier-silver { background: rgba(226, 232, 240, 0.22); color: #f1f5f9; }
.tier-gold { background: rgba(212, 175, 55, 0.22); color: var(--gold-300); }
.tier-platinum { background: linear-gradient(135deg, rgba(247,228,163,0.32), rgba(168,130,29,0.32)); color: #fff6d1; border: 1px solid var(--gold-400); }

/* Lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voucher-item, .client-item {
  background: rgba(6, 15, 29, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.voucher-item:hover, .client-item:hover {
  border-color: var(--border-gold);
}

.item-meta {
  min-width: 210px;
  flex: 1;
}

.item-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.code-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--gold-400);
  background: rgba(212, 175, 55, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.6px;
}

/* Reward Pool Editor */
.reward-row {
  display: grid;
  grid-template-columns: 1fr 1fr 78px 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.pool-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pool-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

/* Search bar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar .input {
  flex: 1;
  min-width: 200px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(3, 9, 18, 0.78);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--navy-800);
  border: 1px solid var(--gold-500);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, var(--gold-400), var(--gold-600));
  color: var(--navy-950);
  font-weight: 700;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Kiosk / Client Mode */
body.kiosk-mode .desktop-nav,
body.kiosk-mode .mobile-nav {
  display: none !important;
}

body.kiosk-mode .app-main {
  padding-bottom: 32px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.helper-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Responsive Breakpoints */
@media (min-width: 768px) {
  .desktop-nav {
    display: flex;
  }
  .mobile-nav {
    display: none;
  }
  .app-main {
    padding: 26px 24px 48px;
  }
  .grid-2 {
    grid-template-columns: 1fr 1.15fr;
    align-items: start;
  }
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .toast {
    bottom: 28px;
  }
}

@media (max-width: 520px) {
  .reward-row {
    grid-template-columns: 1fr 72px 36px;
  }
  .reward-row .reward-desc-input {
    grid-column: 1 / -1;
  }
}

[hidden] { display: none !important; }
.owner-login { max-width: 460px; margin: min(10vh, 72px) auto 0; }
.owner-login [role="status"]:empty { display: none; }
body.kiosk-mode :is(#playSetup, #ownerSignOut, #playAgainBtn) { display: none; }
body.kiosk-mode #tab-play > .grid-2 { grid-template-columns: 1fr; }
