:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #ffc72c; /* vàng taxi */
  --accent-ink: #1f2937;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2c313b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1rem; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
a { color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 9px 16px;
  background: var(--accent); color: var(--accent-ink);
  font: 600 14px/1 inherit; text-decoration: none; cursor: pointer;
  transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.spin { font-size: 20px; padding: 16px 48px; letter-spacing: .08em; box-shadow: 0 6px 20px rgba(255, 199, 44, .35); }
.btn.google { background: #fff; color: #1f2937; border: 1px solid #d1d5db; padding: 12px 22px; font-size: 15px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; font: inherit; font-size: 13px; padding: 0; }
.icon { background: none; border: 0; cursor: pointer; font-size: 16px; padding: 4px; color: var(--muted); }
.icon.danger:hover { color: var(--danger); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  padding: 12px 16px; background: #1f2937; color: #fff;
}
.topbar h1 { font-size: 1.15rem; overflow-wrap: anywhere; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.3); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #d1d5db; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; }
.conn.ok i { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.conn.bad i { background: #ef4444; }

.banner {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: #fef3c7; color: #78350f; text-align: center;
}

/* ---------- Dashboard ---------- */
.dashboard {
  display: grid; gap: 16px; padding: 16px; max-width: 1100px; margin: 0 auto;
  grid-template-columns: 1fr;
}
@media (min-width: 860px) {
  .dashboard { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
}
.wheel-area { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.wheel-box { width: min(92vw, 560px, 70vh); aspect-ratio: 1; }
.wheel-box.small { width: min(100%, 380px); margin: 0 auto; }
.wheel-box canvas { width: 100%; height: 100%; display: block; }
.spin-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.status { font: 700 12px/1 ui-monospace, monospace; padding: 6px 10px; border-radius: 999px; background: var(--line); }
.status.idle { background: #dcfce7; color: #166534; }
.status.spinning { background: #fef3c7; color: #92400e; }
.status.result { background: #dbeafe; color: #1e40af; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 0; min-height: 1.5em; }

.side { display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.result-box {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px;
  border-left: 6px solid var(--c, var(--line)); background: var(--bg); font-size: 1.1rem;
}
.result-box img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.result-box.empty { color: var(--muted); font-size: .95rem; border-left-color: var(--line); }
.decide-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.history { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; }
.history li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.history li i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.history li img { width: 24px; height: 24px; object-fit: cover; border-radius: 5px; flex: none; }
.history .h-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history li time { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; flex: none; background: var(--line); color: var(--muted); }
.tag.keep { background: #dcfce7; color: #166534; }
.tag.remove { background: #fee2e2; color: #991b1b; }
.tag.pending { background: #fef3c7; color: #92400e; }
.muted { color: var(--muted); }

.center-msg { text-align: center; padding: 15vh 20px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.center-msg p { font-size: 1.15rem; margin: 0; }
.big-emoji { font-size: 64px; }
.error { color: var(--danger); font-size: 14px; }

.footer { text-align: center; padding: 24px 16px; font-size: 13px; color: var(--muted); display: flex; gap: 16px; justify-content: center; }

/* ---------- Result overlay (FR-15) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(circle at center, color-mix(in srgb, var(--c, #333) 55%, #000) 0%, #000 85%);
  display: flex; align-items: center; justify-content: center;
  animation: fadein .25s ease-out;
}
.overlay-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; height: 100%; justify-content: center; padding: 56px 16px 24px; }
.overlay img { max-width: 100%; max-height: calc(100% - 120px); object-fit: contain; image-rendering: auto; border-radius: 6px; }
.overlay.has-image .overlay-text { font-size: clamp(20px, 4vw, 36px); }
.overlay-text { color: #fff; font-weight: 800; font-size: clamp(32px, 9vw, 96px); text-align: center; overflow-wrap: anywhere; text-shadow: 0 4px 24px rgba(0,0,0,.5); }
.overlay-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px;
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px; padding: 10px 18px; font: 600 15px/1 inherit; cursor: pointer;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Editor ---------- */
.editor { display: grid; gap: 16px; padding: 16px; max-width: 1200px; margin: 0 auto; grid-template-columns: 1fr; }
.editor .banner { border-radius: 10px; }
@media (min-width: 960px) {
  .editor { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .editor .banner { grid-column: 1 / -1; }
  .editor-preview { position: sticky; top: 16px; }
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; min-width: 220px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: end; }
.field.toggle { flex-direction: row; align-items: center; gap: 10px; }
.field.toggle input { width: 20px; height: 20px; accent-color: #f59e0b; }
.field.toggle span { color: var(--text); font-weight: 500; font-size: 14px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--text); font: inherit;
}
input.invalid { border-color: var(--danger); }
textarea { margin-top: 10px; resize: vertical; }

.options-head, .options li {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: 40px minmax(0, 1fr) 72px 76px 52px 32px;
}
.options-head { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 0 6px; }
.options { list-style: none; margin: 0; padding: 0; }
.options li { padding: 8px 0; border-top: 1px solid var(--line); }
.options li.zero { opacity: .6; }
.options input[type=color] { width: 36px; height: 36px; border: 0; padding: 0; background: none; cursor: pointer; }
.img-cell { display: flex; align-items: center; gap: 2px; }
.img-cell img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; cursor: pointer; }
.prob { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
@media (max-width: 520px) {
  .options-head { display: none; }
  .options li { grid-template-columns: 40px minmax(0, 1fr) 90px 48px; grid-template-areas: "c n n d" "i i w p"; row-gap: 6px; }
  .options li > :nth-child(1) { grid-area: c; }
  .options li > :nth-child(2) { grid-area: n; }
  .options li > :nth-child(3) { grid-area: i; }
  .options li > :nth-child(4) { grid-area: w; }
  .options li > :nth-child(5) { grid-area: p; }
  .options li > :nth-child(6) { grid-area: d; }
}
.share-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0; font-size: 13px; }
.share-box code { background: var(--bg); padding: 4px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.btn.save { width: 100%; }
.live { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.live .conn { color: var(--muted); font-weight: 400; }
.pending-box { background: #fef3c7; color: #78350f; border-radius: 10px; padding: 12px; margin-bottom: 12px; animation: pulse 1.6s ease-in-out infinite; }
.pending-box p { margin: 0 0 8px; font-weight: 600; }
.pending-box .result-box { background: #fff; color: #111827; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .5); } 50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
