:root {
  font-family: "Noto Sans Thai", Tahoma, sans-serif;
  color: #321426;
  background: #fff1f6;
  --pink: #e52d78;
  --ink: #321426;
  --muted: #8a7380;
  --line: #f0d4df;
  --card: #fff;
  --shadow: 0 8px 24px rgba(136, 26, 74, .09);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: radial-gradient(circle at 12% 0, #ffe5f0 0, transparent 32%), linear-gradient(180deg, #fff8fb, #fdebf3); }
button, input, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
.vote-shell { width: min(1540px, 100%); margin: auto; padding: 8px clamp(8px, 1.4vw, 20px) 20px; }

.vote-hero { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 14px; border-radius: 17px; color: #fff; background: linear-gradient(105deg, #ee3c86, #c6105d); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { width: 50px; height: 50px; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 3px 7px rgba(72, 0, 31, .2)); }
.brand p, .section-heading p { margin: 0; color: #ff3b86; font-size: 9px; font-weight: 900; letter-spacing: .12em; }
.brand p { color: #fff; opacity: .85; }
.brand h1 { margin: 0; font-size: clamp(20px, 2vw, 30px); line-height: 1.12; }
.brand span { font-size: 12px; opacity: .92; }
.hero-actions { display: flex; align-items: center; gap: 7px; }
.map-link, .admin-button { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 12px; border: 1px solid rgba(255, 255, 255, .45); border-radius: 11px; color: #fff; background: rgba(255, 255, 255, .12); text-decoration: none; font-size: 12px; font-weight: 800; white-space: nowrap; }
.admin-button { cursor: pointer; }
.admin-button.authenticated { border-color: #baf5cc; background: rgba(24, 117, 58, .28); }
.live { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 5px 10px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 11px; background: rgba(97, 0, 40, .18); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .16); animation: pulse 1.8s infinite; }
.live div { display: flex; flex-direction: column; }
.live strong { font-size: 10px; letter-spacing: .1em; }
.live span { font-size: 9px; white-space: nowrap; }

.mode-banner { margin: 7px 0 0; padding: 7px 11px; border: 1px solid #f3bd5d; border-radius: 10px; color: #7a5000; background: #fff7df; font-size: 11px; font-weight: 700; }
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 7px 0; }
.summary article { min-height: 68px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 8px; }
.summary span { font-size: 11px; color: var(--muted); }
.summary strong { justify-self: end; font-size: 27px; line-height: 1; }
.summary small { font-size: 10px; color: var(--muted); }

.candidates-panel { margin-top: 7px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); overflow: hidden; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 1px 0 0; font-size: 17px; }
.section-heading > span { font-size: 10px; color: var(--muted); text-align: right; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; padding: 9px 12px; background: #fffafd; }
.filters label { display: flex; flex-direction: column; gap: 3px; }
.filters label span { font-size: 9px; color: var(--muted); font-weight: 700; }
.filters input, .filters select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid #eacbd8; border-radius: 10px; color: var(--ink); background: #fff; outline: none; }
.filters input:focus, .filters select:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(229, 45, 120, .12); }
.reset-button { align-self: end; min-height: 40px; padding: 0 12px; border: 1px solid #ef9cb9; border-radius: 10px; color: #fff; background: #a5154c; cursor: pointer; font-size: 11px; font-weight: 800; }
.reset-button:disabled { opacity: .55; cursor: wait; }
.admin-score-panel { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid #efc1d3; border-bottom: 1px solid #efc1d3; color: #6f123d; background: #fff0f6; }
.admin-score-panel[hidden] { display: none; }
.admin-score-panel div { display: flex; flex-direction: column; }
.admin-score-panel strong { font-size: 12px; }
.admin-score-panel span { color: var(--muted); font-size: 10px; }
.admin-score-panel button { min-height: 40px; padding: 0 12px; border: 0; border-radius: 10px; color: #fff; background: #9f1247; font-size: 11px; font-weight: 900; cursor: pointer; }
.admin-score-panel button:disabled { opacity: .45; cursor: not-allowed; }

.candidate-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; padding: 9px; }
.candidate-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 90px; padding: 9px; border: 1px solid var(--line); border-radius: 13px; background: #fff; transition: transform .18s, border-color .18s, box-shadow .18s; }
.candidate-card:hover { transform: translateY(-1px); border-color: #efa8c4; box-shadow: 0 7px 18px rgba(146, 25, 75, .10); }
.candidate-info { min-width: 0; }
.candidate-code { display: inline-flex; margin-bottom: 3px; padding: 1px 6px; border-radius: 999px; color: #c02062; background: #fde8f1; font-size: 9px; font-weight: 900; }
.candidate-info h3 { display: -webkit-box; margin: 0; overflow: hidden; font-size: 13px; line-height: 1.3; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.candidate-info p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.candidate-score { margin-top: 4px; color: #c51f65; font-size: 17px; font-weight: 900; }
.admin-score-editor { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.admin-score-editor span { color: #8a4966; font-size: 9px; font-weight: 800; }
.admin-score-editor input { width: 92px; min-height: 38px; padding: 0 8px; border: 1px solid #dc8eae; border-radius: 9px; color: #70113d; background: #fff8fb; font-size: 15px; font-weight: 900; outline: none; }
.admin-score-editor input:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(229, 45, 120, .12); }
.admin-score-editor input.invalid { border-color: #c51f45; background: #fff0f2; }
.vote-button { min-width: 70px; min-height: 48px; padding: 0 10px; border: 0; border-radius: 12px; color: #fff; background: linear-gradient(180deg, #f04489, #d71968); box-shadow: 0 5px 12px rgba(205, 23, 100, .2); font-size: 12px; font-weight: 900; cursor: pointer; touch-action: manipulation; user-select: none; }
.vote-button:hover { filter: brightness(1.05); }
.vote-button:active { transform: scale(.96); }
.vote-button:disabled { opacity: .55; cursor: wait; }
.vote-button.success { animation: votePop .45s; }
.empty-state { text-align: center; padding: 24px; color: var(--muted); }
footer { text-align: center; padding: 10px 8px 0; color: #9a7585; font-size: 10px; }

.toast { position: fixed; z-index: 1000; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 520px); padding: 10px 15px; border-radius: 12px; color: #fff; background: #401427; box-shadow: 0 12px 32px rgba(59, 4, 28, .28); font-size: 12px; font-weight: 800; text-align: center; }
.toast.error { background: #8d183f; }

.admin-dialog { width: min(92vw, 430px); padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: #fff; box-shadow: 0 24px 80px rgba(49, 6, 26, .32); }
.admin-dialog::backdrop { background: rgba(48, 9, 28, .56); backdrop-filter: blur(3px); }
.admin-form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.admin-dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.admin-dialog-heading p { margin: 0; color: var(--pink); font-size: 10px; font-weight: 900; letter-spacing: .14em; }
.admin-dialog-heading h2 { margin: 2px 0 0; font-size: 23px; }
.dialog-close { width: 44px; height: 44px; border: 0; border-radius: 12px; color: #8e5e72; background: #fbe9f1; font-size: 27px; line-height: 1; cursor: pointer; }
.admin-dialog-copy { margin: 0; color: var(--muted); font-size: 12px; }
.admin-form label { display: flex; flex-direction: column; gap: 5px; }
.admin-form label span { font-size: 12px; font-weight: 800; }
.admin-form input { width: 100%; min-height: 48px; padding: 0 13px; border: 1px solid #e4bdcd; border-radius: 12px; color: var(--ink); background: #fff; outline: none; }
.admin-form input:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(229, 45, 120, .12); }
.admin-error { margin: 0; padding: 9px 11px; border-radius: 10px; color: #8d183f; background: #fde8ee; font-size: 12px; font-weight: 800; }
.admin-submit { min-height: 48px; border: 0; border-radius: 13px; color: #fff; background: linear-gradient(180deg, #ed3b82, #c81862); font-weight: 900; cursor: pointer; }
.admin-submit:disabled { opacity: .55; cursor: wait; }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes votePop { 50% { transform: scale(1.08); } }

@media (max-width: 1200px) {
  .candidate-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .candidate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
  .search { grid-column: span 2; }
  .reset-button { width: 100%; }
}

@media (max-width: 680px) {
  .vote-shell { padding: 6px 6px 16px; }
  .vote-hero { display: grid; gap: 8px; padding: 9px; border-radius: 14px; }
  .brand { gap: 8px; }
  .brand img { width: 40px; height: 40px; }
  .brand h1 { font-size: 18px; }
  .brand span { font-size: 10px; }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }
  .map-link, .admin-button { min-height: 44px; padding: 0 8px; white-space: normal; text-align: center; }
  .live { display: none; }
  .mode-banner { font-size: 10px; }
  .summary article { min-height: 58px; padding: 7px 9px; grid-template-columns: 1fr auto; gap: 3px 6px; }
  .summary small { grid-column: 2; }
  .summary strong { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 23px; }
  .section-heading { align-items: flex-start; padding: 8px 10px; }
  .section-heading h2 { font-size: 16px; }
  .section-heading > span { max-width: 48%; font-size: 9px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 7px; padding: 8px; }
  .search { grid-column: span 2; }
  .reset-button { grid-column: span 2; min-height: 44px; }
  .admin-score-panel { align-items: stretch; flex-direction: column; gap: 7px; padding: 8px; }
  .admin-score-panel button { min-height: 46px; }
  .candidate-grid { grid-template-columns: 1fr; gap: 6px; padding: 7px; }
  .candidate-card { min-height: 84px; padding: 8px; }
  .candidate-info h3 { font-size: 12.5px; }
  .candidate-score { font-size: 16px; }
  .admin-score-editor { justify-content: space-between; }
  .admin-score-editor input { width: 104px; min-height: 44px; font-size: 16px; }
  .vote-button { min-width: 76px; min-height: 52px; font-size: 13px; }
}

@media (max-width: 380px) {
  .brand p { font-size: 7px; }
  .brand h1 { font-size: 16px; }
  .summary span { font-size: 9px; }
  .summary strong { font-size: 21px; }
  .filters { grid-template-columns: 1fr; }
  .search, .reset-button { grid-column: auto; }
}

@media (hover: none) {
  .candidate-card:hover { transform: none; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}
