/* RM Fury Web */
@font-face { font-family: "DS-Digital"; src: url("ds-digi.ttf") format("truetype"); font-display: swap; }

:root {
  --bg: #eef0f3; --panel: #ffffff; --ink: #1d2330; --muted: #6b7280; --line: #d5d9e0; --head: #f6f7f9;
  --blue: #0000ff; --red: #e00000; --orange: #ff8000; --teal: #00a7a7; --green: #009a00;
  --accent: #1f6fd1; --rows: 20;
  /* altura de cada linha da comparação: as N linhas sempre cabem na janela */
  --rh: clamp(22px, calc((100dvh - 178px) / var(--rows)), 46px);
  --cmp-font: calc(var(--rh) * 0.52);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.3 system-ui, "Segoe UI", Roboto, Arial, sans-serif; display: flex; flex-direction: column; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; color: var(--ink); }
button:hover { border-color: #aab; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: #b42318; border-color: #b42318; }
button.link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 6px 8px; }
input { font: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; text-align: center; background: #fff; color: var(--ink); }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---- login ---- */
.login-body { align-items: center; justify-content: center; background: #1d2330; }
.login { background: #fff; padding: 28px 32px; border-radius: 12px; width: min(340px, calc(100vw - 32px)); display: grid; gap: 12px; text-align: center; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login img { justify-self: center; }
.login label { display: grid; gap: 4px; text-align: left; font-weight: 600; font-size: 13px; }
.login input { text-align: left; padding: 8px 10px; font-size: 16px; }
.login button { background: var(--accent); color: #fff; border: 0; padding: 10px; font-weight: 700; font-size: 15px; }
.erro { color: #b42318; margin: 0; }

/* ---- topo ---- */
#top { display: flex; align-items: center; gap: 18px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.field input, .box { font-size: 20px; font-weight: 700; width: 120px; padding: 4px 6px; text-align: center; border: 1px solid #b9bec7; border-radius: 4px; background: #fff; display: inline-block; min-height: 34px; }
.box.gray { background: #e0e0e0; }
.itens { color: #00b4b4; font-weight: 800; font-size: 22px; }
.spacer { flex: 1; }
.user { color: var(--muted); font-size: 13px; }
#btn-connect { font-size: 16px; padding: 8px 16px; }

/* ---- abas ---- */
#tabs { display: flex; gap: 2px; padding: 6px 10px 0; background: var(--bg); align-items: end; flex-wrap: wrap; }
#tabs [data-tab] { border-radius: 6px 6px 0 0; border-bottom: 0; background: #dfe3e8; font-weight: 700; font-size: 13px; padding: 7px 14px; }
#tabs [data-tab].active { background: var(--panel); color: var(--accent); }
#btn-hist { margin-left: auto; font-size: 13px; }
main { flex: 1; min-height: 0; background: var(--panel); margin: 0 10px; border: 1px solid var(--line); border-top: 0; display: flex; }
.tab { display: none; flex: 1; min-width: 0; flex-direction: column; }
.tab.active { display: flex; }
#status { padding: 4px 12px; font-weight: 700; font-size: 13px; background: var(--panel); border-top: 1px solid var(--line); cursor: pointer; margin-top: 6px; }

/* ---- comparação ---- */
.cmp-wrap { overflow: auto; flex: 1; padding: 4px 8px; }
table.cmp { border-collapse: separate; border-spacing: 3px 2px; width: 100%; font-size: var(--cmp-font); }
.cmp th { font-size: max(10px, calc(var(--cmp-font) * 0.62)); color: var(--blue); font-weight: 700; white-space: nowrap; padding: 0 2px; }
.cmp th.red { color: var(--red); }
.cmp tr.grp th { color: var(--ink); text-align: left; border-bottom: 2px solid var(--line); padding-bottom: 1px; }
.cmp td { height: var(--rh); padding: 0; }
.cmp td.c { background: #fff; border: 1px solid #c7ccd4; text-align: center; font-weight: 700; white-space: nowrap; padding: 0 4px; min-width: 2.6em; }
.cmp td.sep, .cmp th.sep { width: 14px; min-width: 14px; background: none; border: 0; }
.cmp input { width: 3.1em; height: var(--rh); font-size: var(--cmp-font); font-weight: 700; padding: 0; }
.cmp td.nome { position: relative; font-weight: 400; width: 30%; min-width: 9em; max-width: 1px; overflow: hidden; text-overflow: ellipsis; }
.cmp td.nome span { display: block; overflow: hidden; text-overflow: ellipsis; }
.cmp .bar { position: absolute; left: 0; right: 0; top: 0; height: 4px; background: #e3e6ea; }
.cmp .bar b { display: block; height: 100%; width: 0; background: var(--accent); transition: width .9s linear; }
.cmp .bar b.late { background: #d11f1f; }
.cmp .click { cursor: pointer; }
.cmp .click:hover { background: #f0f6ff; }
.blue { color: var(--blue); } .red { color: var(--red); } .orange { color: var(--orange); } .teal { color: var(--teal); } .green { color: var(--green); }
.cmp td.atu.over { background: #ff0000; color: #fff; }

/* ---- listas ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 8px 10px; font-weight: 700; border-bottom: 1px solid var(--line); }
.toolbar label { display: flex; gap: 6px; align-items: center; }
.toolbar input { font-size: 16px; font-weight: 700; }
.t2 { width: 3em; } .t3 { width: 4em; } .t8 { width: 6.5em; }
.table-wrap { overflow: auto; flex: 1; min-height: 0; }
.table-wrap.short { max-height: 30vh; flex: none; }
table.list { border-collapse: collapse; width: 100%; font-size: 15px; }
.list th { position: sticky; top: 0; background: var(--head); border-bottom: 1px solid var(--line); padding: 6px 8px; font-size: 12px; white-space: nowrap; z-index: 1; }
.list td { padding: 5px 8px; border-bottom: 1px solid #eceef2; white-space: nowrap; }
.list .c { text-align: center; } .list .l { text-align: left; } .list th.w { width: 30%; }
.list tr.sel td { background: var(--accent); color: #fff; }
.list tr.mark td { color: #8a8f98; }
.list tr.good td { color: #08870a; } .list tr.bad td { color: #c00000; }
.list tr.inbox td { background: #fff3b0; }
.list tr.sel.inbox td { background: var(--accent); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 10px; }

/* ---- modais ---- */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.modal-box { background: #fff; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; max-height: calc(100dvh - 24px); max-width: 100%; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; font-weight: 700; color: #c00000; border-bottom: 1px solid var(--line); }
.modal-head button { border: 0; font-size: 22px; line-height: 1; padding: 0 6px; background: none; }
.modal-head a { font-size: 13px; font-weight: 600; color: var(--accent); }
.modal-box.laps { width: 460px; height: min(760px, calc(100dvh - 24px)); }
.modal-box.hms { width: 640px; }
.modal-box.cel-box { width: min(900px, 100%); background: #2b2b2b; }
.cel-box .modal-head { color: #fff; border-color: #444; }
.cel-box .modal-head button { color: #fff; }

/* tempo de pista */
.hms-grid { display: grid; grid-template-columns: auto 5.2em 1fr 1fr; gap: 6px 8px; padding: 12px 14px 16px; align-items: center; }
.hms-grid label { font-weight: 800; font-size: 22px; grid-column: 1; }
.dig { font-family: "DS-Digital", Consolas, monospace; font-size: 40px; font-weight: 700; text-align: center; border: 2px inset #ccc; padding: 2px 6px; min-height: 1.3em; }
.dig.wide { grid-column: 2 / 5; } .dig.wide2 { grid-column: 3 / 5; } .dig.nr { grid-column: 2; color: var(--blue); }
.dig.pos { grid-column: 3 / 5; grid-row: span 2; line-height: 1.1; }
.dig.gray { background: #e0e0e0; } .dig.green { background: #00ff00; } .dig.yellow { background: #ffff80; }
.dig.red { background: #ff0000; color: #fff; } .dig.blue { background: #0000ff; color: #fff; } .dig.black { background: #000; color: #fff; }
#hms-a { grid-column: 2 / 5; }
#hms-feitas, #hms-falta { grid-column: 2; }

/* emulador celular (posições em % do desenho original 745x385) */
.phone { position: relative; width: min(860px, calc(100vw - 48px), calc((100dvh - 120px) * 1.935)); aspect-ratio: 745 / 420; container-type: inline-size;
  margin: 10px auto 14px; color: #00ff00; font-family: Arial, sans-serif; }
.screen { position: absolute; left: 1%; right: 1%; top: 1%; height: 89%; border-radius: 6cqw; background: #000;
  border: 1.6cqw solid #e9e9e9; box-shadow: inset 0 0 0 1px #111, 0 0 0 1px #bdbdbd; }
.screen > * { position: absolute; }
.p-top, .p-row { left: 4%; right: 4%; display: grid; grid-template-columns: 1fr 1fr 1fr; text-align: center; white-space: nowrap; }
.p-top { top: 6%; font-size: 3.5cqw; }
.p-name { top: 18%; left: 0; right: 0; text-align: center; color: #fff; font-size: 3.4cqw; }
.p-big { top: 25%; left: 0; right: 0; text-align: center; font: 700 12cqw/1 Verdana, sans-serif; }
.p-row.gaps { top: 57%; font-size: 4.4cqw; }
.p-row.laps { top: 71%; font-size: 4.4cqw; }
.p-row.info { top: 86%; font-size: 2.9cqw; }
.p-row .yellow { color: #ffff00; font: 700 4.6cqw Verdana, sans-serif; }
.flag { left: 3%; top: 17%; width: 5.5%; height: 6.5%; border: 1px solid #555; }
.lapbox { top: 45%; left: 18%; width: 5%; aspect-ratio: 1; background: #fff; color: #000; display: grid; place-items: center; font: 700 2.4cqw Arial, sans-serif; font-style: normal; }
.lapbox.r { left: auto; right: 18%; }
.p-foot { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; background: #f0f0f0; color: #000; font: 700 2.1cqw Verdana, sans-serif; padding: .6cqw; border-radius: 4px; }

/* só o celular (?cel=KART) */
body.cel-only > header, body.cel-only > nav, body.cel-only > main, body.cel-only > footer { display: none; }
body.cel-only { background: #000; }
body.cel-only #m-cel { background: #000; padding: 0; }
body.cel-only .cel-box { width: 100%; height: 100%; max-height: none; border-radius: 0; box-shadow: none; background: #000; justify-content: center; }
body.cel-only .cel-box .modal-head { display: none; }
body.cel-only .phone { width: min(100vw - 8px, (100dvh - 8px) * 1.774); }

/* log */
.drawer { position: fixed; right: 12px; bottom: 40px; width: min(620px, calc(100vw - 24px)); height: min(60vh, 560px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 16px 40px rgba(0,0,0,.25); display: flex; flex-direction: column; z-index: 15; }
.drawer-head { background: #ff8000; color: #fff; font-weight: 700; padding: 6px 10px; border-radius: 10px 10px 0 0; display: flex; justify-content: space-between; }
.drawer-head button { background: none; border: 0; color: #fff; font-size: 20px; padding: 0 4px; }
#log-text { flex: 1; margin: 0; overflow: auto; padding: 8px; font: 12px/1.35 Consolas, "Courier New", monospace; white-space: pre; }

@media (max-width: 760px) {
  #top { gap: 8px 12px; }
  .field { font-size: 14px; } .field input, .box { font-size: 16px; width: 96px; min-height: 30px; }
  .itens, .user { display: none; }
  main { margin: 0; }
  :root { --rh: 30px; }
}
