:root {
  --bg: #fff8ee;
  --surface: #ffffff;
  --ink: #2b1b12;
  --ink-soft: #7a6553;
  --accent: #ff5a36;
  --accent-ink: #fffaf5;
  --gold: #f5a623;
  --line: #f0e4d3;
  --badge-open-ink: #1f7a4d;
  --badge-open-bg: #e2f5ea;
  --badge-closed-ink: #b03a2e;
  --badge-closed-bg: #fbe7e4;
  --badge-recent-ink: #9a6b12;
  --badge-recent-bg: #fdf0d5;
  --shadow: 0 12px 32px -12px rgba(43, 27, 18, 0.25);
  --radius-lg: 28px;
  --radius-md: 16px;
  --font-display: "Baloo 2", system-ui, sans-serif;
  --font-body: "Be Vietnam Pro", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b140f;
    --surface: #251b14;
    --ink: #f5ece0;
    --ink-soft: #c2ab95;
    --accent: #ff7a52;
    --accent-ink: #241209;
    --gold: #ffc24b;
    --line: #3a2c20;
    --badge-open-ink: #7fd6a6;
    --badge-open-bg: #1d3a2b;
    --badge-closed-ink: #ff9b8c;
    --badge-closed-bg: #402320;
    --badge-recent-ink: #ffcf7a;
    --badge-recent-bg: #3b2e15;
    --shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

/* Các rule display:flex bên dưới mạnh hơn UA style của [hidden],
   nên phải khẳng định lại ở đây — nếu không cả 3 card sẽ hiện cùng lúc. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  padding-block: max(24px, env(safe-area-inset-top, 0px)) 40px;
  padding-inline: 16px;
  position: relative;
  overflow-x: hidden;
}

.bg-dots {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--line) 2px, transparent 2px);
  background-size: 28px 28px;
  opacity: 0.6;
}

.page {
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hero {
  text-align: center;
  padding-block: 8px 4px;
}

.hero-die {
  font-size: 2.4rem;
  display: inline-block;
  animation: wobble 3.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .hero-die { animation: none; }
}

@keyframes wobble {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  margin: 6px 0 4px;
  letter-spacing: -0.01em;
}

.tagline {
  color: var(--ink-soft);
  margin: 0;
  font-size: 0.98rem;
  text-wrap: balance;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-weight: 600;
  font-size: 0.92rem;
}

.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

input[type="text"]:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.hint {
  color: var(--ink-soft);
  font-size: 0.86rem;
  margin: 0;
}

.error {
  color: #c0392b;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.02rem;
  padding: 14px 20px;
  border-radius: 999px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

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

.btn-ghost {
  background: var(--bg);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-weight: 600;
}

.btn-link {
  background: none;
  color: var(--ink-soft);
  text-decoration: underline;
  font-size: 0.88rem;
  padding: 4px;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.results-head h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.3rem;
}

.place-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.place-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
}

.place-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.place-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.place-info .name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-info .meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dice-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0;
}

.dice-cube {
  font-size: 3.2rem;
}

.dice-cube.spinning {
  animation: spin 0.55s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.15); }
  to { transform: rotate(360deg) scale(1); }
}

.slot {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink-soft);
  text-align: center;
  min-height: 1.6em;
}

.winner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.winner-photo {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.winner-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.winner-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: var(--gold);
  font-weight: 700;
  margin: 0;
}

#winner-name {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 6vw, 2rem);
  margin: 0;
  text-wrap: balance;
}

.winner-meta {
  color: var(--ink-soft);
  margin: 0;
  font-size: 0.94rem;
}

.winner-address {
  color: var(--ink-soft);
  margin: 0;
  font-size: 0.88rem;
  text-wrap: balance;
}

.winner-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.78rem;
  padding-top: 8px;
  text-wrap: balance;
}

@media (max-width: 420px) {
  .card { padding: 18px; }
  .winner-actions { flex-direction: column; width: 100%; }
  .winner-actions > * { width: 100%; }
}

/* ---------- Bộ lọc: chỉ quán đang mở / né quán vừa ăn ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.toggle:has(input:checked) {
  border-color: var(--accent);
  color: var(--ink);
}

/* ---------- Nhãn trạng thái trên từng quán ---------- */

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-open {
  color: var(--badge-open-ink);
  background: var(--badge-open-bg);
}

.badge-closed {
  color: var(--badge-closed-ink);
  background: var(--badge-closed-bg);
}

.badge-recent {
  color: var(--badge-recent-ink);
  background: var(--badge-recent-bg);
}

.badge-unknown {
  color: var(--ink-soft);
  background: var(--line);
}

.empty-note {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  text-align: center;
}

.pool-count {
  text-align: center;
}

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

/* ---------- Lịch sử quán đã trúng ---------- */

.history-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.history-head h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
}

.history-name {
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-when {
  color: var(--ink-soft);
  font-size: 0.78rem;
  flex-shrink: 0;
}
