:root {
  --bg: #fffdf5;
  --surface: #ffffff;
  --surface-muted: #faf6e8;
  --text: #18181b;
  --text-muted: #52525b;
  --border: #ebe2c5;
  --border-strong: #d8cca6;
  --primary: #ffd100;
  --primary-hover: #ecc100;
  --primary-border: #ca8a04;
  --primary-soft: #fef9c3;
  --primary-text: #854d0e;
  --primary-ink: #18181b;
  --gold: #a16207;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --error: #b91c1c;
  --error-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 10px 30px -12px rgba(24, 24, 27, 0.12), 0 2px 6px rgba(24, 24, 27, 0.04);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  font-family: "IBM Plex Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top right, rgba(255, 209, 0, 0.24), transparent 46%),
    radial-gradient(circle at top left, rgba(255, 209, 0, 0.14), transparent 48%),
    var(--bg);
  padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  line-height: 1.5;
}

.page-shell {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.page-shell-wide {
  max-width: 980px;
}

.page-shell-stage {
  max-width: 1180px;
}

.hidden {
  display: none !important;
}

/* Header */
.hero {
  text-align: center;
  padding: 12px 4px 18px;
}

.hero-accent {
  width: 56px;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #eab308);
  margin: 0 auto 14px;
}

.hero-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.hero-title {
  margin: 0;
  font-size: clamp(23px, 5.8vw, 28px);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

.hero-subtitle {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--text-muted);
}

/* Cards */
.main-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px 18px;
}

.main-card + .main-card {
  margin-top: 16px;
}

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

/* State Panels */
.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 16px 4px;
}

.state-text {
  margin: 14px 0 0;
  font-size: 15px;
  color: var(--text-muted);
}

.state-heading {
  margin: 14px 0 6px;
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
}

.state-description {
  margin: 0;
  font-size: 15px;
  color: var(--text-muted);
  max-width: 36ch;
}

.status-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.status-icon svg {
  width: 28px;
  height: 28px;
}

.status-icon-closed {
  background: var(--error-soft);
  color: var(--error);
}

.status-icon-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-icon-success {
  background: var(--success-soft);
  color: var(--success);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary-border);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* Alerts & Banners */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
  line-height: 1.45;
}

.alert-error {
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid #fecaca;
}

.alert-success {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #bbf7d0;
}

.alert-info {
  background: var(--primary-soft);
  color: var(--primary-text);
  border: 1px solid #fde047;
}

.alert-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #fde68a;
}

/* Form Inputs */
.field-group {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.required {
  color: var(--primary-border);
}

.field-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}

.field-input::placeholder {
  color: #a1a1aa;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary-border);
  box-shadow: 0 0 0 3px rgba(255, 209, 0, 0.35);
}

.field-hint {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Choice Cards */
.field-fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

.choice-grid {
  display: grid;
  gap: 10px;
}

.choice-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choice-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.choice-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.choice-indicator {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.choice-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.choice-card:has(.choice-input:checked) {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(255, 209, 0, 0.3);
}

.choice-card:has(.choice-input:focus-visible) {
  outline: 2px solid var(--primary-border);
  outline-offset: 2px;
}

.choice-input:checked + .choice-indicator {
  border-color: var(--primary-border);
  background: var(--primary);
  box-shadow: inset 0 0 0 3px #ffffff;
}

.choice-input:checked ~ .choice-text {
  color: var(--primary-text);
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.99);
}

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

.btn-sm {
  width: auto;
  min-height: 38px;
  padding: 7px 14px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 2px 8px rgba(202, 138, 4, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: #f3ecda;
}

.btn-voted {
  background: var(--success-soft);
  color: var(--success);
  border: 1.5px solid #86efac;
}

.btn-link {
  background: none;
  border: none;
  padding: 4px 2px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-text);
  cursor: pointer;
  text-decoration: underline;
}

/* Attendee Header Banner */
.attendee-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.attendee-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.attendee-meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.attendee-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Filter Controls */
.filter-bar {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
}

.pill-btn.active {
  background: var(--primary);
  border-color: var(--primary-border);
  color: var(--primary-ink);
  font-weight: 700;
}

/* Contestant Voting Cards */
.contestant-list {
  display: grid;
  gap: 12px;
}

.contestant-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.contestant-card.is-voted {
  border-color: #22c55e;
  background: #f7fef9;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15);
}

.contestant-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.contestant-name {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.contestant-meta {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-yellow {
  background: var(--primary-soft);
  color: var(--primary-text);
  border: 1px solid #fde047;
}

.badge-green {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #86efac;
}

.badge-muted {
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

/* Admin Layout */
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.admin-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.kpi-label {
  font-size: 13px;
  color: var(--text-muted);
}

.kpi-value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.admin-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (min-width: 760px) {
  .admin-grid-2 {
    grid-template-columns: 1.2fr 1fr;
  }
}

.section-title {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

/* Toggle Switch Rows */
.switch-list {
  display: grid;
  gap: 10px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.switch-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.switch-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.switch-toggle {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d4d4d8;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch-toggle input:checked + .switch-slider {
  background: #16a34a;
}

.switch-toggle input:checked + .switch-slider::before {
  transform: translateX(22px);
}

.switch-toggle input:disabled + .switch-slider {
  opacity: 0.6;
  cursor: wait;
}

/* QR Poster Box */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.qr-frame {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 2px solid var(--primary-border);
  background: #ffffff;
}

.qr-url {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.qr-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Tabs & Tables */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary-border);
  color: var(--primary-ink);
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--surface-muted);
  font-weight: 600;
  color: var(--text-muted);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.vote-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

.vote-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.vote-bar-fill {
  height: 100%;
  background: var(--primary-border);
  border-radius: 999px;
}

/* Footer */
.page-footer {
  text-align: center;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Stage Real-Time Results (/results) */
.stage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 20px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.stage-title {
  margin: 0;
  font-size: clamp(22px, 3.2vw, 32px);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.stage-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.stage-pill-open {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #86efac;
}

.stage-pill-closed {
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}

.stage-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.stage-pill-open .stage-dot {
  animation: stagePulse 1.4s ease-in-out infinite;
}

@keyframes stagePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(1.25);
  }
}

.stage-stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.stage-stat-chip strong {
  font-size: 18px;
  color: var(--text);
}

.stage-stat-chip-highlight {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary-text);
}

.podium-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 780px) {
  .podium-grid {
    grid-template-columns: 1fr;
  }
}

.podium-card {
  display: flex;
  flex-direction: column;
  padding: 22px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-card);
}

.podium-rank-1 {
  border-color: var(--primary-border);
  background: linear-gradient(180deg, #fefce8 0%, #ffffff 65%);
}

.podium-rank-2 {
  border-color: #cbd5e1;
}

.podium-rank-3 {
  border-color: #fdba74;
}

.podium-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.podium-rank-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--surface-muted);
  color: var(--text);
}

.podium-rank-1 .podium-rank-badge {
  background: var(--primary);
  color: var(--primary-ink);
}

.podium-pct {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}

.podium-name {
  margin: 0;
  font-size: clamp(20px, 2.2vw, 25px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.podium-meta {
  margin: 4px 0 14px;
  font-size: 14px;
  color: var(--text-muted);
}

.podium-score-row {
  margin-top: auto;
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 10px;
}

.podium-score {
  font-size: clamp(34px, 4vw, 44px);
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.podium-rank-1 .podium-score {
  color: var(--primary-text);
}

.podium-score-unit {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}

.stage-bar-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.stage-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-border));
  transition: width 0.4s ease;
}

.stage-list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.stage-updated {
  font-size: 13px;
  color: var(--text-muted);
}

.stage-rank-list {
  display: grid;
  gap: 10px;
}

.stage-rank-row {
  display: grid;
  grid-template-columns: 52px minmax(160px, 1.3fr) minmax(100px, 1.4fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

@media (max-width: 640px) {
  .stage-rank-row {
    grid-template-columns: 44px 1fr auto;
  }
  .stage-rank-bar {
    grid-column: 1 / -1;
  }
}

.stage-rank-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-text);
}

.stage-rank-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.stage-rank-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.stage-rank-score {
  text-align: right;
  white-space: nowrap;
}

.stage-rank-score strong {
  font-size: 20px;
  color: var(--text);
}

.stage-rank-score span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

/* Print Poster Mode */
@media print {
  body {
    background: #ffffff;
    padding: 0;
  }
  .no-print {
    display: none !important;
  }
  .print-only-card {
    border: none !important;
    box-shadow: none !important;
    padding: 24px !important;
  }
}
