/* Giao diện lái xe: nền tối, chữ lớn, màu biển báo (đỏ, vàng, xanh) */
:root {
  --bg: #0b0d10; --panel: #15191e; --line: #262c33; --ink: #f3f5f7; --mute: #9aa4ae;
  --red: #e8251a; --yellow: #f5b800; --blue: #1f6fe5; --green: #18a957;
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  --sl: env(safe-area-inset-left); --sr: env(safe-area-inset-right);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Trang chủ ---------- */
#home { height: 100%; overflow-y: auto; padding: calc(var(--st) + 28px) max(22px, var(--sr)) calc(var(--sb) + 28px) max(22px, var(--sl));
  display: flex; flex-direction: column; gap: 22px; max-width: 640px; margin: 0 auto; }
.brand { display: flex; gap: 16px; align-items: flex-start; }
.logo { width: 64px; height: 64px; flex: none; }
h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.1; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--mute); }
.load { display: grid; gap: 8px; }
.meter { height: 8px; background: var(--panel); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--yellow); transition: width .2s; }
#loadText { color: var(--mute); font-size: 14px; }
.load.ok .meter i { background: var(--green); }
.actions { display: grid; gap: 12px; }
.primary, .secondary { min-height: 58px; border-radius: 14px; border: 0; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center; padding: 0 18px; }
.primary { background: var(--red); color: #fff; }
.primary:disabled { opacity: .45; }
.secondary { background: var(--panel); border: 1px solid var(--line); }
.file { cursor: pointer; }
.links { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.link { background: none; border: 0; color: #7fb0ff; padding: 10px 0; min-height: 44px; }
.link.danger { color: #ff7a70; }
.install { background: var(--panel); border: 1px solid var(--line); padding: 14px 16px; border-radius: 12px; color: var(--mute); }
.install b { color: var(--ink); }
.fine { color: #5d6670; font-size: 13px; margin: auto 0 0; }

/* ---------- Màn hình lái ---------- */
#drive { position: fixed; inset: 0; background: #000; }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: cover; }
#overlay { pointer-events: none; }

.hud-top { position: absolute; top: calc(var(--st) + 10px); left: max(12px, var(--sl)); right: max(12px, var(--sr));
  display: flex; gap: 12px; align-items: flex-start; pointer-events: none; }
.speedo { background: rgba(8,10,12,.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 16px; padding: 8px 16px 8px; min-width: 128px; display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 6px; }
.speedo b { font-size: 52px; line-height: 1; font-variant-numeric: tabular-nums; font-weight: 800; letter-spacing: -0.03em; }
.speedo span { color: var(--mute); font-weight: 600; }
.speedo small { grid-column: 1 / -1; color: var(--mute); font-size: 12px; }
.speedo.over { background: var(--red); animation: pulse .8s infinite alternate; }
.speedo.over span, .speedo.over small { color: #fff; }
@keyframes pulse { to { transform: scale(1.04); } }

.limit { pointer-events: auto; width: 84px; height: 84px; border-radius: 50%; background: #fff; color: #111;
  border: 10px solid var(--red); display: grid; place-content: center; text-align: center; padding: 0; box-shadow: 0 4px 18px rgba(0,0,0,.45); }
.limit b { font-size: 30px; line-height: 1; font-weight: 800; letter-spacing: -0.03em; }
.limit small { font-size: 9px; font-weight: 700; color: #555; }
.lane-pill { margin-left: auto; align-self: center; background: rgba(8,10,12,.72); border-radius: 99px; padding: 8px 14px; font-weight: 700; font-size: 14px; }
.lane-pill.ok { color: #7be3a6; } .lane-pill.dev { color: var(--yellow); } .lane-pill.solid { background: var(--red); color: #fff; }

.alert { position: absolute; left: 50%; top: calc(var(--st) + 108px); transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center; background: rgba(8,10,12,.88); border: 2px solid var(--yellow);
  border-radius: 18px; padding: 10px 18px 10px 10px; max-width: min(92vw, 560px); animation: pop .25s ease-out; }
.alert img { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: #222; flex: none; }
.alert b { display: block; font-size: 24px; line-height: 1.15; }
.alert small { color: var(--mute); font-size: 14px; }
.alert.p3 { border-color: var(--red); }
.alert.danger { background: var(--red); border-color: #fff; }
.alert.danger small { color: #ffe1de; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

.recent { position: absolute; right: max(10px, var(--sr)); bottom: calc(var(--sb) + 70px); display: flex; flex-direction: column; gap: 8px; width: 230px; }
.card { display: flex; gap: 10px; align-items: center; background: rgba(8,10,12,.78); border-radius: 12px; padding: 6px 10px 6px 6px;
  border-left: 4px solid var(--c, var(--yellow)); animation: pop2 .25s ease-out; }
.card img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; flex: none; background: #222; }
.card b { display: block; font-size: 14px; line-height: 1.2; }
.card small { color: var(--mute); font-size: 12px; }
@keyframes pop2 { from { opacity: 0; transform: translateX(20px); } }

.bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px max(12px, var(--sr)) calc(var(--sb) + 8px) max(12px, var(--sl));
  display: flex; gap: 8px; align-items: center; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.stat { flex: 1; font-size: 12px; color: #c6ced6; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic { width: 48px; height: 48px; border-radius: 12px; border: 0; background: rgba(21,25,30,.85); font-size: 20px; display: grid; place-items: center; }
.ic.off { background: var(--red); }
.stop { height: 48px; padding: 0 20px; border-radius: 12px; border: 0; background: #fff; color: #111; font-weight: 800; }

.sim { position: absolute; left: max(12px, var(--sl)); bottom: calc(var(--sb) + 72px); background: rgba(8,10,12,.8); border-radius: 12px; padding: 10px 14px; width: 250px; }
.sim label { display: block; font-size: 13px; margin-bottom: 4px; }

.darkhud { position: absolute; inset: 0; background: #000; display: grid; place-items: center; align-content: center; gap: 18px;
  padding: calc(var(--st) + 20px) 20px calc(var(--sb) + 20px); text-align: center; }
.dk-speed b { font-size: clamp(90px, 26vw, 200px); line-height: .9; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.dk-speed span { display: block; color: var(--mute); font-size: 18px; }
.dk-speed.over b { color: var(--red); }
.dk-limit { width: 110px; height: 110px; border-radius: 50%; background: #fff; color: #111; border: 13px solid var(--red); display: grid; place-content: center; }
.dk-limit b { font-size: 40px; font-weight: 800; }
.dk-last { font-size: 22px; font-weight: 700; color: var(--yellow); min-height: 1.4em; }
.ghost { background: none; border: 1px solid var(--line); color: var(--mute); border-radius: 12px; padding: 12px 18px; }

/* Ngang màn hình: đưa danh sách biển sang phải, cảnh báo cao hơn */
@media (orientation: landscape) and (max-height: 520px) {
  .alert { top: calc(var(--st) + 14px); }
  .recent { bottom: calc(var(--sb) + 66px); width: 210px; }
  .speedo b { font-size: 44px; }
  .limit { width: 74px; height: 74px; border-width: 9px; }
}

/* ---------- Bảng phụ ---------- */
dialog { border: 0; padding: 0; background: var(--panel); color: var(--ink); width: min(100vw, 620px); max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 20px; }
#sheetBody { padding: 8px 18px calc(var(--sb) + 24px); overflow-y: auto; max-height: calc(92vh - 70px); }
.set h3 { margin: 22px 0 8px; font-size: 13px; color: var(--mute); font-weight: 700; }
.set label { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set label.row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.set output { float: right; color: var(--yellow); font-variant-numeric: tabular-nums; }
.set select { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 0 10px; font-size: 16px; }
input[type=range] { width: 100%; accent-color: var(--yellow); min-height: 32px; }
input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--green); }
.set .secondary { margin-top: 10px; min-height: 48px; font-size: 16px; width: 100%; }
.hint { color: var(--mute); font-size: 14px; }
.help ol { padding-left: 22px; } .help li { margin: 10px 0; }

.hist-tools { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.hist-tools .secondary { min-height: 44px; font-size: 15px; flex: 1; }
.trips { display: grid; gap: 8px; margin-bottom: 16px; }
.trip { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--mute); }
.trip b { color: var(--ink); }
.ev { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ev img, .ev .noimg { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; background: #222; display: grid; place-items: center; font-size: 22px; }
.ev b { display: block; font-size: 15px; }
.ev small { color: var(--mute); font-size: 13px; }
.empty { color: var(--mute); padding: 30px 0; text-align: center; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
