/* Menus of the Android app. The race view itself is styled by css/touch.css. */

:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --author: #22c55e;
    --gold: #facc15;
    --silver: #cbd5e1;
    --bronze: #d97706;
}

body { font-family: system-ui, 'Inter', sans-serif; }
button { border: 0; font: inherit; cursor: pointer; }
h1, h2, h3, p, ul { margin: 0; }
[hidden] { display: none !important; }

/* Classes the shared game code uses for its finish panel. */
.text-sky-400 { color: var(--accent); }
.text-sm { font-size: 0.875rem; }
.text-slate-300 { color: #cbd5e1; }

/* --- Screens -------------------------------------------------------------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
    box-sizing: border-box;
}
.screen.centered {
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
}
.title {
    font-size: 2.6rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.02em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.error { color: #f87171; min-height: 1.2em; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.85rem; }

.bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
}
.bar h2 { font-size: 1.25rem; font-weight: 700; flex: 1; text-transform: capitalize; }
.bar .back {
    width: 44px;
    height: 40px;
    padding: 0;
    font-size: 1.8rem;
    line-height: 1;
    background: var(--panel);
    color: var(--text);
    box-shadow: none;
    border: 1px solid var(--line);
}
.status-chip {
    font-size: 0.8rem;
    padding: 3px 10px;
    border-radius: 999px;
    background: #7c2d12;
    color: #fed7aa;
}
.status-chip:empty { display: none; }

.content {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 14px 20px;
}
.content.text { max-width: 720px; line-height: 1.5; display: flex; flex-direction: column; gap: 10px; }
.content.text ul { padding-left: 4px; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.content.text li { margin-left: 0; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 8px; vertical-align: -2px; }

/* --- Name ----------------------------------------------------------------- */
.name-form { display: flex; gap: 10px; }
.name-form input { width: 220px; font-size: 1.1rem; }

/* --- Main menu ------------------------------------------------------------ */
.menu-screen {
    background:
        linear-gradient(90deg, rgba(15, 23, 42, 0.92) 0%, rgba(15, 23, 42, 0.55) 45%, rgba(15, 23, 42, 0.1) 100%),
        var(--menu-bg, linear-gradient(180deg, #60b0ff 0%, #60b0ff 45%, #484 45%, #2d5a2d 100%)) center / cover no-repeat;
    justify-content: space-between;
}
.menu-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 260px;
    padding: 14px 0 0 28px;
}
.menu-column .title { margin-bottom: 4px; }
.menu-button {
    padding: 0.55rem 1rem;
    font-size: 1.05rem;
    text-align: left;
    background: rgba(30, 41, 59, 0.88);
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: none;
}
.menu-button:hover { background: rgba(30, 41, 59, 0.88); }
.menu-button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; }
.menu-button.primary:hover { background: var(--accent); }
.menu-button:disabled { opacity: 0.45; color: var(--muted); }
.menu-footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 28px 10px;
    font-size: 0.85rem;
    color: #f1f5f9;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}
#offline-note { color: #fed7aa; text-align: right; max-width: 60%; }

/* --- Groups and maps ------------------------------------------------------ */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    text-align: left;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-weight: 400;
}
.card:hover { background: var(--panel); }
.card:disabled { opacity: 0.45; }
.card .name { font-size: 1.05rem; font-weight: 700; text-transform: capitalize; }
.card .sub { font-size: 0.82rem; color: var(--muted); }
.card .mine { font-size: 0.85rem; color: var(--text); display: flex; align-items: center; gap: 6px; }

.id-form { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.id-form input { width: 150px; }
.id-form button { padding: 0.5rem 1rem; }

table.board { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
/* The header row stays in place; the maps scroll under it. */
table.board th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    padding: 8px 8px 6px;
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg);
    box-shadow: inset 0 -1px 0 var(--line);
}
table.board td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.board td.num, table.board th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.board tr.mine td { color: var(--accent); }
.empty { color: var(--muted); padding: 16px 0; }

/* --- Map ------------------------------------------------------------------ */
.map-detail { display: flex; gap: 14px; height: 100%; overflow: hidden; }
/* Left: name and Play, the preview, then the facts about the map. */
.map-main {
    flex: 0 0 46%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#map-preview, canvas.preview {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    object-fit: contain;      /* the preview stays square in the space left */
}
.map-side {
    flex: 1 1 0;
    min-width: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.map-side h3 { font-size: 0.95rem; color: var(--muted); margin-top: 2px; }
.stats { display: flex; gap: 2px 12px; flex-wrap: wrap; justify-content: center; font-size: 0.82rem; color: var(--muted); flex: 0 0 auto; }
.stats b { color: var(--text); font-weight: 700; }
.medals { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.medal { display: inline-flex; align-items: center; gap: 5px; }
.medal-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.3); }
.medal-dot.author { background: var(--author); }
.medal-dot.gold { background: var(--gold); }
.medal-dot.silver { background: var(--silver); }
.medal-dot.bronze { background: var(--bronze); }
.you { font-size: 0.95rem; display: flex; align-items: center; gap: 6px; }
.leader {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.92rem;
}
.leader .rank { width: 1.4em; color: var(--muted); }
.leader .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader .time { font-variant-numeric: tabular-nums; }
.leader.mine .who { color: var(--accent); font-weight: 700; }
.leader label { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--muted); width: 74px; justify-content: flex-end; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 0.92rem; }
#map-play { text-align: center; padding: 0.4rem 2rem; flex: 0 0 auto; }
.map-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 0 0 auto; }
.map-head h2 { font-size: 1.1rem; font-weight: 700; text-transform: capitalize; min-width: 0; }

/* --- Play browser ---------------------------------------------------------- */
.browse { flex: 1 1 0; min-height: 0; display: flex; }
.browse-col {
    flex: 0 0 auto;
    width: 150px;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    padding: 8px;
    box-sizing: border-box;
}
#browse-groups { display: flex; flex-direction: column; gap: 6px; }
#browse-maps { width: 176px; }
.browse-main { flex: 1 1 0; min-width: 0; overflow-y: auto; padding: 10px 12px; box-sizing: border-box; }
.browse-main.flush-top { padding-top: 0; }
.row-list { display: flex; flex-direction: column; gap: 6px; }
.list-row {
    width: 100%;
    padding: 7px 10px;
    border-radius: 9px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    text-align: left;
    font-weight: 400;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.list-row:hover { background: var(--panel); }
.list-row.selected { background: #0c4a6e; border-color: var(--accent); }
.list-row:disabled { opacity: 0.45; }
.list-row .name { font-size: 0.95rem; font-weight: 700; text-transform: capitalize; }
.list-row .sub { font-size: 0.75rem; color: var(--muted); }
.list-row .mine { font-size: 0.78rem; display: flex; align-items: center; gap: 5px; }
.browse-col .id-form { gap: 6px; margin-bottom: 8px; }
.browse-col .id-form input { width: 100%; box-sizing: border-box; }
.browse-col .id-form button { flex: 1; padding: 0.4rem 0.3rem; font-size: 0.78rem; }

/* --- Settings ------------------------------------------------------------- */
.settings { max-width: 560px; display: flex; flex-direction: column; gap: 8px; }
.settings h3 { font-size: 0.85rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 10px; }
.settings .row { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-height: 2.6rem; box-sizing: border-box; }
.settings input[type="text"] { width: 180px; }
.settings input[type="checkbox"] { width: 1.4rem; height: 1.4rem; accent-color: var(--accent); }

/* --- Race view additions --------------------------------------------------- */
#side-toggle {
    display: none;
    position: fixed;
    top: 8px;
    right: calc(8px + env(safe-area-inset-right));
    z-index: 60;
    width: 40px;
    height: 36px;
    padding: 0;
    font-size: 1.1rem;
    background: rgba(51, 65, 85, 0.85);
    color: var(--text);
    border: 1px solid #475569;
    box-shadow: none;
}
.racing #side-toggle { display: block; }
/* In 3D view with the menu hidden, the minimap is in that corner: the button
   goes under it. In top view the button stays where it is. */
.racing.side-hidden.view-3d #side-toggle { top: var(--toggle-top, 8px); }

/* The race information (left panel) can be hidden too. The view then starts
   at the left edge, with the time, the checkpoints and a see-through
   speedometer drawn over it (#hud). */
#info-toggle {
    display: none;
    position: fixed;
    top: 8px;
    left: calc(8px + env(safe-area-inset-left));
    z-index: 60;
    width: 34px;
    height: 30px;
    padding: 0;
    font-size: 1rem;
    background: rgba(51, 65, 85, 0.85);
    color: var(--text);
    border: 1px solid #475569;
    box-shadow: none;
}
.racing #info-toggle { display: block; }
.racing.info-hidden.finished #info-toggle { display: none; }   /* the end-of-race panel is there */
#hud {
    display: none;
    position: fixed;
    top: 4px;
    left: calc(50px + env(safe-area-inset-left));
    z-index: 55;
    width: 150px;
    height: 150px;
    pointer-events: none;
}
.racing.info-hidden:not(.finished) #hud { display: block; }
.touch.info-hidden #info { display: none !important; }
/* The end-of-race panel (time, replay, restart) still has to be reachable. */
.touch.info-hidden.finished #info {
    display: flex !important;
    position: fixed;
    top: 0;
    bottom: 0;
    left: env(safe-area-inset-left);
    width: var(--side-w, 190px);     /* the free column left of the top view */
    height: auto;
    z-index: 55;
}

/* Race layout: [ info | view ] with the race menu as a panel on the right
   that slides out of the screen; the 3D view then takes its place. */
.touch body { justify-content: flex-start; }
.touch.racing:not(.view-3d) #canvas_div { margin-left: var(--top-view-margin, 0px); }
.touch #info { flex: 0 0 var(--left-w, 190px); }
.touch.racing #touch-side {
    position: fixed;
    top: 0;
    bottom: 0;
    right: env(safe-area-inset-right);
    width: var(--side-w, 190px);
    box-sizing: border-box;
    padding-top: 52px;
    transition: transform 0.2s ease-out;
}
.touch.racing.side-hidden #touch-side { transform: translateX(calc(100% + env(safe-area-inset-right))); }

#error-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 8px;
    z-index: 200;
    padding: 8px 12px;
    border-radius: 8px;
    background: #7f1d1d;
    color: #fee2e2;
    font-size: 0.8rem;
}
.bar .gear {
    width: 44px;
    height: 40px;
    padding: 0;
    font-size: 1.3rem;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: none;
}

/* Control options */
.touch.ctl-swap #touch-steer { left: auto; right: calc(12px + env(safe-area-inset-right)); }
.touch.ctl-swap #touch-drive { right: auto; left: calc(12px + env(safe-area-inset-left)); }
.touch.ctl-stacked #touch-drive { flex-direction: column-reverse; gap: 8px; }
.touch.ctl-stacked #touch-drive .touch-zone { height: 74px; width: 96px; }

.load-more { margin: 12px auto; flex: 0 0 auto; }
#error-banner.notice { background: #14532d; color: #dcfce7; }

/* --- Shared bits ------------------------------------------------------------ */
.button-row { display: flex; gap: 8px; flex: 0 0 auto; }
.button-row .menu-button { flex: 1; text-align: center; padding: 0.45rem 0.5rem; font-size: 0.92rem; }
.menu-button.center { text-align: center; }
.menu-button.danger { color: #fca5a5; }
.menu-button.primary:disabled { color: var(--bg); }
.small-button { padding: 0.25rem 0.6rem; font-size: 0.8rem; background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.description { font-size: 0.88rem; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.description:empty { display: none; }
.map-head .menu-button { text-align: center; padding: 0.4rem 0.8rem; flex: 0 0 auto; }
#map-play { padding: 0.4rem 1.4rem; }
.map-head h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
textarea {
    font: inherit;
    width: 100%;
    box-sizing: border-box;
    resize: none;
    background: #0b1220;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
}
.driver-chip {
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.88);
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: none;
    font-size: 0.85rem;
}

/* --- Questions and forms ---------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(2, 6, 23, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}
.modal-box {
    width: min(460px, 100%);
    max-height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.modal-box h3 { font-size: 1.1rem; color: var(--accent); }
.modal-box p { font-size: 0.95rem; line-height: 1.4; }
.modal-box .field { display: flex; flex-direction: column; gap: 3px; font-size: 0.82rem; color: var(--muted); }
.modal-box .field input, .modal-box .field select { width: 100%; box-sizing: border-box; font-size: 1rem; }
.modal-box input[type="checkbox"] { width: 1.4rem; height: 1.4rem; flex: 0 0 auto; accent-color: var(--accent); }
.modal-box .error:empty { display: none; }

/* --- Map editor: hub -------------------------------------------------------- */
.editor-list { width: 220px; display: flex; flex-direction: column; gap: 6px; }
.editor-list .menu-button { padding: 0.45rem 0.8rem; font-size: 0.95rem; flex: 0 0 auto; }
.editor-list h3 { font-size: 0.78rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 8px; }
.editor-list .list-row { flex: 0 0 auto; }
.medal-edit { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.medal-edit label { display: flex; align-items: center; gap: 5px; }
.medal-edit input { width: 4.6rem; padding: 4px 6px; font-size: 0.9rem; }
.map-side select { max-width: 60%; }
.campaign { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.campaign h2 { font-size: 1.2rem; }
.campaign h3 { font-size: 0.95rem; color: var(--muted); }
.campaign .status-line { color: var(--accent); font-size: 0.9rem; }
.campaign input[type="checkbox"] { width: 1.4rem; height: 1.4rem; flex: 0 0 auto; accent-color: var(--accent); }

/* --- Map editor: grid ------------------------------------------------------- */
.mapedit { flex: 1 1 0; min-height: 0; display: flex; }
.edit-scroll { flex: 1 1 0; min-width: 0; overflow: auto; background: #0f172a; }
#edit-canvas { display: block; touch-action: none; }
.edit-tools {
    flex: 0 0 230px;
    box-sizing: border-box;
    border-left: 1px solid var(--line);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}
.edit-head { display: flex; align-items: center; gap: 10px; }
.edit-head h2 { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-head .back { width: 44px; height: 38px; padding: 0; font-size: 1.8rem; line-height: 1; background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: none; flex: 0 0 auto; }
.edit-brushes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.edit-brushes button {
    padding: 0.45rem 0.4rem;
    font-size: 0.82rem;
    white-space: nowrap;
    text-align: left;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: none;
}
.edit-brushes button.selected { background: #0c4a6e; border-color: var(--accent); }
.edit-brushes .swatch { margin-right: 5px; }
.edit-tools .hint { font-size: 0.78rem; }

/* --- Profile ---------------------------------------------------------------- */
.profile-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.profile-head h2 { font-size: 1.4rem; color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.tile span { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 5px; }
table.board th .medal-dot { vertical-align: -1px; }
.cap { text-transform: capitalize; }
.settings > *, .campaign > *, .editor-list > * { flex-shrink: 0; }
.menu-button.unavailable { opacity: 0.45; }

/* --- Full screen map ---------------------------------------------------------- */
#map-preview, canvas.preview { touch-action: manipulation; }
.viewer { position: fixed; inset: 0; z-index: 120; background: #0b1220; }
.viewer-scroll { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#viewer-canvas { display: block; margin: 0 auto; }
#viewer-close {
    position: absolute;
    top: 8px;
    right: calc(8px + env(safe-area-inset-right));
    width: 44px;
    height: 40px;
    padding: 0;
    font-size: 1.1rem;
    background: rgba(51, 65, 85, 0.85);
    color: var(--text);
    border: 1px solid #475569;
    box-shadow: none;
}

/* Logging in to an existing account */
.text-button { background: none; border: none; box-shadow: none; color: var(--accent); font: inherit; font-size: 0.9rem; text-decoration: underline; padding: 10px; cursor: pointer; }

/* Web version on a computer: keyboard instead of the thumb pads */
.keys-only { display: none; }
.desktop .keys-only { display: block; }
.desktop .pads-only { display: none; }
.desktop #touch-steer, .desktop #touch-drive { display: none !important; }
.pads-group { display: contents; }
.desktop .pads-group { display: none; }
input[type="password"] { background-color: #334155; color: #e2e8f0; padding: 0.5rem; border-radius: 0.5rem; border: 1px solid #475569; min-height: 2.4rem; -webkit-user-select: text; user-select: text; }
.text a { color: var(--accent); word-break: break-all; }
