:root {
  /* Dark "cosmic luck" theme, matched against a screenshot of the reference
     site (duduang19.pages.dev): deep navy-purple base, gold as the loud
     accent (headlines, CTA, active states), violet kept subtle/structural. */
  --bg: #0a0820;
  --bg-glow: #241a4d;
  --surface: #171236;
  --surface-2: #1f1a45;
  --ink: #f3f0fc;
  --ink-soft: #ada4d6;
  --primary: #8a63f5;
  --primary-dark: #5a35d6;
  --gold: #f4b942;
  --gold-light: #ffe3a3;
  --gold-dark: #d1791f;
  --gold-ink: #3a2205;
  --danger-bg: rgba(244, 185, 66, 0.12);
  --danger-ink: #f4b942;
  --border: rgba(255, 255, 255, 0.10);
  --radius: 20px;
  --nav-h: 60px;
  --nav-gap: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* The `hidden` HTML attribute must always win over component `display`
   rules (e.g. .modal-overlay / .btn set display:flex, which would
   otherwise override the browser's default `[hidden]{display:none}` and
   leave "hidden" elements visible). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--nav-gap) + var(--safe-bottom) + 14px);
  background:
    radial-gradient(ellipse 600px 320px at 50% 0%, var(--bg-glow) 0%, rgba(10, 8, 32, 0) 70%),
    var(--bg);
  background-attachment: fixed;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: transparent;
  color: var(--ink);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-header__inner {
  max-width: 480px;
  margin: 0 auto;
  padding: 18px 16px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-logo-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  box-shadow: 0 2px 12px rgba(244, 185, 66, 0.35);
  flex-shrink: 0;
}
.app-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--ink);
}

.app-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 14px 4px;
}

.view { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.card-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.card-title-row .card-title { margin: 0; }

.muted { color: var(--ink-soft); font-size: 0.88rem; margin: 4px 0; }
.muted.small { font-size: 0.78rem; }

/* Disclaimer */
.disclaimer-bar {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border: 1px solid rgba(244, 185, 66, 0.35);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
}

/* Digit picker */
.digit-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.digit-btn {
  padding: 12px 6px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.digit-btn.active {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  border-color: var(--gold);
  color: var(--gold-ink);
}
.digit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Result display */
.result-display {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 64px;
  align-items: center;
  padding: 10px 4px;
}
.result-placeholder {
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.digit-box {
  width: 42px;
  height: 56px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1.5px solid rgba(244, 185, 66, 0.5);
  color: var(--gold);
  font-size: 1.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 14px rgba(244, 185, 66, 0.25);
  animation: pop 0.25s ease;
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Slot-machine spin effect while a result is being generated */
.digit-box--spin {
  color: var(--ink-soft);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: none;
  animation: spinPulse 0.35s ease-in-out infinite;
}
@keyframes spinPulse {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50% { transform: translateY(-3px); opacity: 1; }
}
.digit-box--settle {
  animation: settlePop 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes settlePop {
  0% { transform: scale(1.18); }
  55% { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.result-meta {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  min-height: 1.2em;
  margin: 2px 0 12px;
}

/* Share row — appears under the result once a number has been generated */
.share-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
  margin-bottom: 14px;
  animation: pop 0.25s ease;
}
.share-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
}
.share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink-soft);
}
.share-btn__icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, outline-color 0.15s ease;
}
.share-btn__icon svg {
  width: 19px;
  height: 19px;
  fill: #fff;
}
.share-btn:active .share-btn__icon { transform: scale(0.92); }
.share-btn__label {
  font-size: 0.64rem;
  font-weight: 600;
  white-space: nowrap;
}
.share-btn--fb .share-btn__icon { background: #1877f2; }
.share-btn--line .share-btn__icon { background: #06c755; }
.share-btn--x .share-btn__icon { background: #15181c; border: 1.5px solid rgba(255, 255, 255, 0.18); }
.share-btn--copy .share-btn__icon { background: linear-gradient(135deg, var(--gold-light), var(--gold)); }
.share-btn--copy .share-btn__icon svg { fill: var(--gold-ink); }
.share-btn--copied .share-btn__icon {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.share-invite {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  margin: 0;
}

.generate-buttons {
  display: grid;
  gap: 10px;
}
.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}
.btn-title { font-size: 0.98rem; font-weight: 700; }
.btn-sub { font-size: 0.74rem; opacity: 0.85; font-weight: 400; }
.btn-primary { background: linear-gradient(135deg, var(--gold), #d98c1f); color: #2c1900; box-shadow: 0 3px 10px rgba(244, 185, 66, 0.3); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border: 1.5px solid var(--border); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

/* History list (home + profile) */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-empty { color: var(--ink-soft); font-size: 0.85rem; padding: 6px 0; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.history-item__number {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
.history-item__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(244, 185, 66, 0.18);
  color: #f4c76a;
}
.badge.pure { background: rgba(66, 185, 244, 0.18); color: #8fd4ff; }
.history-item__time { font-size: 0.7rem; color: var(--ink-soft); }

/* Stats page */
.period-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}
.select-input {
  width: 100%;
  padding: 10px 30px 10px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background-color: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%23ada4d6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}
.select-input:focus {
  outline: none;
  border-color: var(--gold);
}
#period-draws:not(:empty) { margin-top: 10px; }

.latest-draw .draw-date { font-weight: 700; margin-bottom: 8px; }
.prize-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.86rem;
}
.prize-row:last-child { border-bottom: none; }
.prize-row__name { color: var(--ink-soft); flex-shrink: 0; }
.prize-row__numbers { font-weight: 700; text-align: right; letter-spacing: 1px; }

.draw-list { display: flex; flex-direction: column; gap: 6px; }
.draw-item {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  font-size: 0.88rem;
}
.draw-item__detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.source-note { text-align: center; color: var(--ink-soft); font-size: 0.72rem; margin: 4px 0 8px; }

/* Profile */
.profile-card { text-align: center; }
.avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto;
  box-shadow: 0 2px 14px rgba(244, 185, 66, 0.3);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 2, 12, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  max-width: 420px;
  width: 100%;
  padding-bottom: calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
}
.modal-box h2 { margin-top: 0; font-size: 1.05rem; color: var(--gold); }
.modal-box p { font-size: 0.9rem; line-height: 1.55; color: var(--ink-soft); }

/* Bottom nav — floating, centered pill with a frosted-glass background */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-gap) + var(--safe-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  height: var(--nav-h);
  padding: 6px;
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 999px;
  background: rgba(23, 18, 54, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  z-index: 50;
}
.nav-item {
  flex: 0 0 auto;
  width: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.66rem;
  align-self: stretch;
  border-radius: 999px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-icon { font-size: 1.2rem; line-height: 1; }
.nav-item.active {
  background: rgba(244, 185, 66, 0.16);
  color: var(--gold);
  font-weight: 700;
}

@media (min-width: 480px) {
  .app-main { padding: 18px; }
}
