:root {
  --navy: #0a2a7a;
  --navy-2: #0e3596;
  --navy-deep: #061c55;
  --yellow: #ffc20e;
  --yellow-2: #ffd24d;
  --ice: #eaf2ff;
  --ink: #0d1530;
  --muted: #5b6688;
  --line: #d9e1f2;
  --card: #ffffff;
  --ok: #138a4b;
  --err: #c62828;
  --radius: 14px;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(180deg, #f3f7ff 0%, #e5edfb 100%);
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--display); letter-spacing: .01em; margin: 0 0 .4em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px clamp(12px, 3vw, 40px);
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  box-shadow: 0 2px 14px rgb(0 0 0 / .25);
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.brand-logo { height: 54px; width: auto; border-radius: 6px; }
.brand-text {
  font-family: var(--display); font-style: italic; font-weight: 800;
  color: #fff; font-size: clamp(20px, 2.6vw, 36px); text-transform: uppercase;
  background: linear-gradient(transparent 82%, var(--yellow) 82%, var(--yellow) 92%, transparent 92%);
  padding-bottom: 2px;
}
.top-actions { display: flex; gap: 10px; align-items: center; }
.top-actions svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

.btn-outline, .btn-yellow, .btn-ghost, .btn-navy {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; padding: 10px 20px; font-weight: 700; font-size: 16px;
  border: 2px solid transparent; transition: transform .12s, background .15s, box-shadow .15s;
  text-decoration: none; white-space: nowrap;
}
.btn-outline { background: transparent; color: #fff; border-color: #fff; }
.btn-outline:hover { background: rgb(255 255 255 / .12); }
.btn-yellow { background: var(--yellow); color: var(--navy-deep); }
.btn-yellow:hover { background: var(--yellow-2); transform: translateY(-1px); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { background: var(--ice); }
.btn-block { width: 100%; }
button:disabled { opacity: .6; cursor: wait; transform: none; }

#btn-leaderboard { border-color: var(--yellow); color: var(--yellow); text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 760px) {
  .brand-logo { height: 40px; }
  .brand-text { display: none; }
  .btn-outline, .btn-yellow { padding: 9px 14px; font-size: 15px; }
}
@media (max-width: 520px) {
  .topbar { gap: 8px; padding-inline: 8px; }
  .top-actions { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .top-actions .btn-outline, .top-actions .btn-yellow { padding: 8px 7px; font-size: 12px; gap: 5px; }
  .top-actions svg { display: none; }
}

/* ---------- Home ---------- */
.hero { background: var(--navy-deep); }
.hero-img { display: block; width: 100%; height: auto; max-height: calc(100vh - 74px); object-fit: contain; object-position: center; margin: 0 auto; }
/* Prizes: one wide image on desktop, two stacked crops on mobile */
.prizes-stack { display: none; }
@media (max-width: 760px) {
  .prizes-wide { display: none; }
  .prizes-stack { display: flex; flex-direction: column; gap: 6px; background: var(--navy-deep); }
  .prize-crop { width: 100%; background-image: url("/img/prix.jpg"); background-repeat: no-repeat; background-size: auto 100%; }
  .prize-crop--tech { aspect-ratio: 910 / 941; background-position: left; clip-path: polygon(0 0, 100% 0, 77.58% 100%, 0 100%); }
  .prize-crop--shop { aspect-ratio: 966 / 941; background-position: right; clip-path: polygon(21.12% 0, 100% 0, 100% 100%, 0 100%); }
}
.how {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px;
  padding: 32px clamp(12px, 3vw, 40px); max-width: 1200px; margin: 0 auto;
}
.how-card { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: 0 4px 18px rgb(10 42 122 / .08); border-top: 5px solid var(--yellow); }
.how-card h3 { font-size: 24px; color: var(--navy); text-transform: uppercase; }
.how-card p { margin: 0; color: var(--muted); }
.how-num { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: var(--yellow); font-weight: 800; font-family: var(--display); font-size: 20px; margin-bottom: 8px; }

/* ---------- Portal ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 24px clamp(12px, 3vw, 32px) 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: clamp(30px, 4vw, 44px); color: var(--navy); text-transform: uppercase; line-height: 1; }
.eyebrow { font-weight: 700; color: var(--muted); font-size: 14px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--navy); font-weight: 700; text-decoration: none; margin-bottom: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  position: relative; overflow: hidden;
  background: linear-gradient(140deg, var(--navy-2), var(--navy-deep));
  color: #fff; border-radius: var(--radius); padding: 22px 24px;
  box-shadow: 0 10px 24px rgb(6 28 85 / .25);
}
.stat::after { content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px; border-radius: 50%; background: rgb(255 194 14 / .14); }
.stat-label { font-size: 15px; font-weight: 600; opacity: .85; }
.stat-value { font-family: var(--display); font-weight: 800; font-size: clamp(44px, 6vw, 64px); line-height: 1.05; color: var(--yellow); font-variant-numeric: tabular-nums; }
.stat-note { font-size: 13px; opacity: .75; }
.stat.light { background: var(--card); color: var(--ink); box-shadow: 0 4px 18px rgb(10 42 122 / .08); border: 1px solid var(--line); }
.stat.light .stat-value { color: var(--navy); }
.stat.light::after { background: rgb(10 42 122 / .06); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: 0 4px 18px rgb(10 42 122 / .08); border: 1px solid var(--line); }
.panel h2 { font-size: 26px; color: var(--navy); text-transform: uppercase; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel h2 .count { font-size: 16px; background: var(--ice); color: var(--navy); padding: 3px 10px; border-radius: 999px; font-family: var(--body); }

.inline-form { display: flex; gap: 8px; margin: 10px 0 16px; }
.inline-form input { flex: 1; min-width: 0; }
input {
  width: 100%; font: inherit; padding: 12px 14px; border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 3px rgb(14 53 150 / .15); }
label { display: grid; gap: 6px; font-weight: 600; margin-bottom: 14px; }

.tech-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.tech-item { display: flex; align-items: center; gap: 8px; }
.tech-link {
  flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-radius: 12px; background: var(--ice); color: var(--navy); font-weight: 700; font-size: 18px;
  text-decoration: none; border: 2px solid transparent; transition: border-color .15s, transform .12s;
}
.tech-link:hover { border-color: var(--navy-2); transform: translateX(2px); }
.tech-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--navy); color: var(--yellow); display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 18px; flex: none; }
.tech-name { flex: 1; display: flex; align-items: center; gap: 12px; }
.tech-tests { font-size: 14px; background: var(--yellow); color: var(--navy-deep); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.icon-btn { border: none; background: transparent; color: var(--muted); width: 38px; height: 38px; border-radius: 50%; font-size: 20px; }
.icon-btn:hover { background: #fdeaea; color: var(--err); }

.empty { color: var(--muted); padding: 14px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; }

.dropzone {
  display: grid; place-items: center; gap: 6px; text-align: center;
  padding: 26px 16px; border: 2px dashed #9fb3df; border-radius: 14px; background: #f6f9ff; color: var(--navy);
  cursor: pointer; transition: background .15s, border-color .15s; margin-bottom: 14px;
}
.dropzone:hover, .dropzone.drag { background: var(--ice); border-color: var(--navy-2); }
.dropzone strong { font-size: 18px; }
.dropzone svg { width: 40px; height: 40px; fill: var(--navy); }
.upload-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (max-width: 460px) { .upload-actions { grid-template-columns: 1fr; } }

.test-fields { border: 0; margin: 0; padding: 0; min-width: 0; }
.test-fields legend { color: var(--navy); font-weight: 700; margin-bottom: 10px; padding: 0; }
.vehicle-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(115px, 1fr)); gap: 0 10px; }
.test-selection { overflow-wrap: anywhere; }

.file-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 360px; overflow: auto; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #f6f9ff; border-radius: 10px; font-size: 15px; }
.file-list a { color: var(--navy); font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.file-list a:hover { text-decoration: underline; }
.file-list time { color: var(--muted); font-size: 13px; white-space: nowrap; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo-grid a { position: relative; display: block; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--ice); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; }
.photo-grid span { position: absolute; left: 6px; bottom: 6px; background: rgb(6 28 85 / .8); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.test-card strong { display: block; padding: 6px 2px; color: var(--navy); overflow-wrap: anywhere; }
.test-delete { width: 100%; margin-top: 6px; color: var(--err); }
.test-delete:hover { background: #fdeaea; }

.big-counter { text-align: center; padding: 16px; margin-bottom: 16px; border-radius: 14px; background: linear-gradient(140deg, var(--navy-2), var(--navy-deep)); color: #fff; }
.big-counter .stat-value { font-size: 72px; }

/* ---------- Leaderboard ---------- */
.lb-tabs { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 4px; margin-bottom: 18px; }
.lb-tabs button { border: none; background: transparent; padding: 10px 20px; border-radius: 999px; font-weight: 700; color: var(--navy); }
.lb-tabs button[aria-selected="true"] { background: var(--navy); color: var(--yellow); }

.podium { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 12px; align-items: end; margin-bottom: 18px; }
.podium-spot { background: var(--card); border-radius: var(--radius); padding: 16px 12px; text-align: center; border: 1px solid var(--line); box-shadow: 0 4px 18px rgb(10 42 122 / .08); min-width: 0; }
.podium-spot.first { background: linear-gradient(160deg, var(--navy-2), var(--navy-deep)); color: #fff; padding-top: 26px; }
.podium-spot .medal { font-size: 30px; }
.podium-spot .p-name { font-family: var(--display); font-weight: 800; font-size: 22px; text-transform: uppercase; overflow-wrap: anywhere; }
.podium-spot .p-shop { font-size: 13px; opacity: .8; overflow-wrap: anywhere; }
.podium-spot .p-score { font-family: var(--display); font-weight: 800; font-size: 40px; color: var(--navy); line-height: 1.1; }
.podium-spot.first .p-score { color: var(--yellow); font-size: 52px; }
@media (max-width: 560px) { .podium { grid-template-columns: 1fr; } }

.lb-table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.lb-table th { text-align: left; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 14px; }
.lb-table td { background: #fff; padding: 12px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.lb-table td:first-child { border-left: 1px solid var(--line); border-radius: 10px 0 0 10px; width: 56px; font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--navy); }
.lb-table td:last-child { border-right: 1px solid var(--line); border-radius: 0 10px 10px 0; text-align: right; font-family: var(--display); font-weight: 800; font-size: 24px; color: var(--navy); font-variant-numeric: tabular-nums; }
.lb-table th:last-child { text-align: right; }
.lb-table .sub { display: block; font-size: 13px; color: var(--muted); }
.lb-table tr.mine td { background: #fff8de; border-color: var(--yellow); }

/* ---------- Dialogs & toast ---------- */
.dialog { border: none; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: 0 24px 60px rgb(0 0 0 / .35); }
.dialog::backdrop { background: rgb(6 28 85 / .6); backdrop-filter: blur(3px); }
#dlg-rules { width: min(620px, calc(100vw - 24px)); }
.dialog-body { position: relative; padding: 28px; border-top: 6px solid var(--yellow); }
.dialog-body h2 { font-size: 30px; color: var(--navy); text-transform: uppercase; }
.dialog-close { position: absolute; right: 12px; top: 10px; border: none; background: transparent; font-size: 30px; color: var(--muted); line-height: 1; }
.rules { padding-left: 20px; line-height: 1.55; }
.rules li { margin-bottom: 10px; }
.form-error { color: var(--err); font-weight: 600; margin: 0 0 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--navy-deep); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600; z-index: 50;
  box-shadow: 0 10px 30px rgb(0 0 0 / .3); transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 24px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--err); }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.progress { height: 6px; background: var(--ice); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; background: var(--yellow); width: 0; transition: width .2s; }

/* ---------- Admin ---------- */
.admin-banner { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; background: var(--yellow, #ffc72c); color: var(--navy); padding: 10px 14px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; }
.admin-search { width: 100%; padding: 12px 14px; font: inherit; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.table-scroll { overflow-x: auto; }
.admin-table td:nth-child(n+3), .admin-table th:nth-child(n+3) { text-align: right; white-space: nowrap; }
.admin-table tr.clickable { cursor: pointer; }
.admin-table tr.clickable:hover td, .admin-table tr.clickable:focus td { background: #eef3ff; }
.admin-table tr.clickable:focus { outline: none; }
.admin-table td.empty { font: inherit; color: var(--muted); text-align: center; border: 1px solid var(--line); border-radius: 10px; }
.tech-total { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; padding: 14px 16px; border-radius: 12px; background: var(--navy, #0b2a7a); color: #fff; font-weight: 700; }
.tech-total strong { font-size: 1.6rem; color: var(--yellow, #f6c343); line-height: 1; }
