:root {
  color-scheme: dark;
  --bg: #0b0807;
  --surface: #1a110e;
  --surface-strong: #211510;
  --surface-soft: rgba(255, 255, 255, 0.055);
  --border: rgba(247, 206, 105, 0.2);
  --border-soft: rgba(255, 255, 255, 0.1);
  --gold: #f2c14e;
  --gold-light: #ffe59b;
  --text: #fffaf0;
  --muted: #c5bbb2;
  --danger: #ff9a90;
  --success: #a7ebba;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html {
  min-width: 320px;
  min-height: 100%;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 16%, rgba(171, 33, 23, 0.24), transparent 32rem),
    radial-gradient(circle at 88% 82%, rgba(216, 153, 40, 0.13), transparent 30rem),
    linear-gradient(145deg, #090605 0%, #160d0a 52%, #080605 100%);
  overflow-x: hidden;
  overflow-x: clip;
}
body.modal-open { overscroll-behavior: none; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  left: 16px;
  top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--gold-light);
  color: #1c1104;
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 36px 36px;
  -webkit-mask-image: radial-gradient(circle at center, #000, transparent 78%);
  mask-image: radial-gradient(circle at center, #000, transparent 78%);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 48px));
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  align-items: center;
  gap: clamp(28px, 5vw, 76px);
}

.wheel-panel { min-width: 0; text-align: center; }
.wheel-stage {
  position: relative;
  width: min(100%, 720px);
  aspect-ratio: 1;
  margin: 0 auto;
  isolation: isolate;
  contain: layout paint;
  filter: drop-shadow(0 26px 38px rgba(0, 0, 0, 0.48));
}
.wheel-stage::before {
  content: "";
  position: absolute;
  inset: 18%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 218, 111, 0.19), rgba(124, 25, 15, 0.07) 50%, transparent 72%);
}
.wheel-stage > img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.wheel-image {
  z-index: 1;
  transform: rotate(0deg);
  transform-origin: 50% 50%;
  backface-visibility: hidden;
}
.wheel-image.is-spinning {
  will-change: transform;
  transition-property: transform;
  transition-duration: var(--spin-duration, 6500ms);
  transition-timing-function: cubic-bezier(.12, .58, .1, 1);
}
.wheel-frame { z-index: 2; pointer-events: none; }
.wheel-caption {
  max-width: 560px;
  margin: -18px auto 0;
  padding-inline: 16px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.redeem-panel {
  width: 100%;
  padding: clamp(28px, 4vw, 44px);
  border: 1px solid var(--border);
  border-radius: 28px;
  background: linear-gradient(155deg, rgba(36, 23, 18, 0.98), rgba(15, 10, 8, 0.98));
  box-shadow: var(--shadow);
}
.brand-header { margin-bottom: 28px; }
.brand-line { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brand-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 229, 155, 0.32);
  border-radius: 13px;
  background: linear-gradient(145deg, #f4d77e, #ae741e);
  box-shadow: 0 10px 25px rgba(187, 126, 29, 0.2);
  color: #1b1104;
  font-size: 0.82rem;
  font-weight: 950;
  letter-spacing: -0.04em;
}
.eyebrow {
  display: block;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.brand-header h1 {
  margin: 0;
  font-size: clamp(2.45rem, 5vw, 4.35rem);
  line-height: 0.94;
  letter-spacing: -0.065em;
}
.brand-header p { margin: 17px 0 0; color: var(--muted); line-height: 1.65; }

.redeem-form { display: grid; gap: 11px; }
.redeem-form label {
  margin-top: 5px;
  color: var(--gold-light);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.redeem-form input,
.search-field input {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  outline: none;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.redeem-form input { height: 54px; padding: 0 16px; }
.redeem-form input::placeholder,
.search-field input::placeholder { color: #80766f; }
.redeem-form input:focus,
.search-field input:focus {
  border-color: var(--gold);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 4px rgba(242, 193, 78, 0.12);
}
.redeem-form input[aria-invalid="true"] { border-color: var(--danger); }

.form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.button {
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 850;
  letter-spacing: 0.035em;
  touch-action: manipulation;
  transition: filter 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}
.button:hover:not(:disabled) { filter: brightness(1.08); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:focus-visible,
.icon-button:focus-visible { outline: 3px solid rgba(255, 229, 155, 0.72); outline-offset: 3px; }
.button:disabled { cursor: not-allowed; opacity: 0.5; }
.button-primary {
  color: #1c1104;
  background: linear-gradient(180deg, #ffe999, #d69620);
  box-shadow: 0 10px 30px rgba(214, 150, 32, 0.2);
}
.button-secondary { border: 1px solid rgba(255, 255, 255, 0.14); background: rgba(255, 255, 255, 0.07); }
.button-contact {
  width: 100%;
  margin-top: 1px;
  border: 1px solid rgba(155, 231, 176, 0.22);
  background: rgba(155, 231, 176, 0.07);
  color: #cff7d9;
  text-decoration: none;
}
.button-compact { min-height: 40px; padding: 0 15px; border: 1px solid rgba(255, 255, 255, 0.13); background: rgba(255, 255, 255, 0.06); font-size: 0.78rem; }

.status-notice {
  margin: -8px 0 20px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 154, 144, 0.28);
  border-radius: 12px;
  background: rgba(181, 35, 28, 0.12);
  color: #ffd4cf;
  font-size: 0.84rem;
  line-height: 1.5;
}
.archive-note { margin: 22px 0 0; color: #8d827a; font-size: 0.73rem; line-height: 1.5; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(3, 2, 2, 0.84);
  cursor: default;
}
.modal-dialog {
  position: relative;
  width: min(920px, 100%);
  max-height: min(800px, calc(100dvh - 40px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: #150e0b;
  box-shadow: var(--shadow);
}
.modal:not([hidden]) .modal-backdrop { animation: modal-backdrop-in 180ms ease-out both; }
.modal:not([hidden]) .modal-dialog { animation: modal-dialog-in 220ms cubic-bezier(.2, .8, .2, 1) both; }
@keyframes modal-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.modal-header h2 { margin: 0; font-size: 1.5rem; }
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-size: 1.55rem;
  line-height: 1;
  touch-action: manipulation;
}
.history-meta { padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 0.83rem; }
.search-field { width: min(320px, 55%); }
.search-field input { height: 42px; padding: 0 13px; }
.table-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; border-block: 1px solid rgba(255, 255, 255, 0.07); scrollbar-gutter: stable; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 13px 24px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.055); }
th { position: sticky; top: 0; z-index: 1; background: #201510; color: var(--gold-light); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; }
td:first-child, th:first-child { width: 82px; text-align: center; }
td:last-child { color: #f5d782; font-weight: 700; }
.pagination { padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 0.8rem; }
.empty-state { margin: 0; padding: 50px 20px; text-align: center; color: var(--muted); }

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  padding: 14px 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: #231711;
  box-shadow: var(--shadow);
  color: var(--text);
  text-align: center;
  line-height: 1.45;
}
.toast[data-type="error"] { border-color: rgba(255, 154, 144, 0.36); color: #ffd5d1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
noscript { display: block; padding: 16px; text-align: center; color: var(--danger); }

.error-page { grid-template-columns: 1fr; place-items: center; }
.error-card { max-width: 560px; text-align: center; }
.error-card h1 { margin: 8px 0 12px; font-size: clamp(2rem, 8vw, 3.6rem); letter-spacing: -0.05em; }
.error-card p { color: var(--muted); line-height: 1.7; }
.error-card .button { margin-top: 12px; text-decoration: none; }

@media (max-width: 980px) {
  .app-shell { width: min(760px, calc(100% - 28px)); grid-template-columns: 1fr; gap: 18px; padding-top: 18px; }
  .wheel-stage { width: min(100%, 620px); }
  .wheel-caption { margin-top: -20px; }
  .redeem-panel { width: min(620px, 100%); margin: 0 auto; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 520px); gap: 12px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .wheel-stage { width: 100%; }
  .wheel-caption { margin-top: -12px; padding-inline: 8px; font-size: 0.77rem; }
  .redeem-panel { padding: 24px 18px; border-radius: 22px; }
  .brand-header { margin-bottom: 24px; }
  .brand-header h1 { font-size: clamp(2.4rem, 14vw, 3.55rem); }
  .form-actions { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: end; }
  .modal-dialog { max-height: 92dvh; border-radius: 24px 24px 0 0; border-bottom: 0; }
  .history-meta { align-items: stretch; flex-direction: column; padding-inline: 16px; }
  .modal-header { padding-inline: 16px; }
  .search-field { width: 100%; }
  th, td { padding: 12px 13px; }
  td:first-child, th:first-child { width: 58px; }
  .pagination { padding-inline: 12px; gap: 8px; }
  .pagination > span { font-size: 0.72rem; text-align: center; }
  .button-compact { padding-inline: 11px; font-size: 0.71rem; }
}

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

/* Popup pemenang memakai sistem modal yang sama dengan History */
.winner-dialog {
  width: min(560px, 100%);
  grid-template-rows: auto minmax(0, 1fr);
}
.winner-content {
  min-height: 0;
  padding: clamp(28px, 5vw, 46px);
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
}
.winner-label {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid rgba(247, 206, 105, .22);
  border-radius: 999px;
  background: rgba(242, 193, 78, .07);
  color: var(--gold);
  font-size: .69rem;
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.winner-prize {
  display: block;
  max-width: 470px;
  margin: 20px auto 15px;
  color: var(--gold-light);
  font-size: clamp(1.9rem, 7vw, 3.35rem);
  line-height: 1.04;
  letter-spacing: -.045em;
  overflow-wrap: anywhere;
}
.winner-content p {
  max-width: 410px;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.65;
}
.winner-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 28px;
}
.winner-actions .button { text-decoration: none; }

@media (max-width: 560px) {
  .winner-modal { align-items: center; padding: 16px; }
  .winner-dialog {
    max-height: calc(100dvh - 32px);
    border: 1px solid var(--border);
    border-radius: 24px;
  }
  .winner-content { padding: 28px 18px 22px; }
  .winner-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .modal:not([hidden]) .modal-backdrop,
  .modal:not([hidden]) .modal-dialog { animation: none; }
}
