/* === Navly — Huvudstylesheet === */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f172a;
  --bg2:      #1e293b;
  --bg3:      #334155;
  --accent:   #3b82f6;
  --accent2:  #2563eb;
  --gron:     #22c55e;
  --rod:      #ef4444;
  --orange:   #f59e0b;
  --text:     #f1f5f9;
  --text2:    #94a3b8;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,0.5);
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  overflow: hidden;
}

/* === Vyer === */
.vy { display: none; position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; }
.vy.aktiv { display: flex; flex-direction: column; }

/* === Topbar === */
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--bg3);
  flex-shrink: 0;
}
.topbar h2 { font-size: 1.1rem; font-weight: 600; }
.btn-back {
  background: none; border: none; color: var(--text);
  font-size: 1.4rem; cursor: pointer; padding: .25rem .5rem;
  line-height: 1;
}

/* === Knappar === */
.btn {
  display: block; width: 100%; padding: .85rem 1.5rem;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; cursor: pointer;
  text-align: center; transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-prim { background: var(--accent); color: #fff; }
.btn-prim:hover { background: var(--accent2); }
.btn-sek { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--rod); color: #fff; }
.btn-prim:disabled { opacity: .4; cursor: not-allowed; }

/* === Startvy === */
#vy-start { justify-content: center; align-items: center; }
.start-inner {
  width: min(420px, 92vw);
  display: flex; flex-direction: column; gap: 1rem;
}
.logo {
  font-size: 3.5rem; font-weight: 800; text-align: center;
  letter-spacing: -.02em; user-select: none;
}
.logo-n { color: var(--accent); }
.logo-liten {
  font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em;
}
.logo-liten::first-letter { color: var(--accent); }
.tagline { text-align: center; color: var(--text2); font-size: .95rem; margin-bottom: .5rem; }
.separator { text-align: center; color: var(--text2); font-size: .85rem; position: relative; }
.separator::before, .separator::after {
  content: ''; position: absolute; top: 50%; width: 40%;
  height: 1px; background: var(--bg3);
}
.separator::before { left: 0; }
.separator::after { right: 0; }
.anslut-form { display: flex; flex-direction: column; gap: .6rem; }

/* === Inputs === */
input[type="text"], input[type="number"], .inp-text {
  width: 100%; padding: .75rem 1rem;
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; outline: none; transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text2); }

/* === Regler & Info-vy === */
.regler-scroll {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
  max-width: 560px; margin: 0 auto; width: 100%;
}
.regler-intro {
  color: var(--text2); font-size: .9rem; line-height: 1.6;
  padding: .75rem 1rem;
  background: rgba(59,130,246,.08); border: 1px solid rgba(59,130,246,.2);
  border-radius: var(--radius);
}
.regler-sektion {
  background: var(--bg2); border-radius: var(--radius);
  padding: 1rem 1rem 1rem 1.25rem;
  border-left: 3px solid var(--sek-farg, var(--accent));
}
.regler-rubrik {
  display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem;
}
.regler-ikon { font-size: 1.2rem; line-height: 1; }
.regler-rubrik > span:last-child {
  font-weight: 700; font-size: .95rem;
  color: var(--sek-farg, var(--accent));
}
.regler-sektion ul { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.regler-sektion li {
  font-size: .875rem; line-height: 1.55; color: var(--text2);
  padding-left: 1rem; position: relative;
}
.regler-sektion li::before {
  content: '–'; position: absolute; left: 0;
  color: var(--sek-farg, var(--accent));
}
.regler-sektion li strong { color: var(--text); }
.regler-footer {
  padding: 1rem 1.25rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--bg3);
  flex-shrink: 0;
}

/* === Setup-vy === */
.setup-content {
  padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;
  max-width: 560px; margin: 0 auto; width: 100%;
}
.setup-label { font-size: .85rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.transport-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
}
.transport-btn {
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
  padding: .75rem .5rem; background: var(--bg2);
  border: 2px solid var(--bg3); border-radius: var(--radius);
  color: var(--text); font-size: .8rem; cursor: pointer; transition: all .15s;
}
.transport-btn span { font-size: .75rem; }
.transport-btn > :first-child { font-size: 1.5rem; }
.transport-btn.aktiv { border-color: var(--accent); background: rgba(59,130,246,.15); }

.slider-row {
  display: flex; align-items: center; gap: 1rem;
}
.slider-row input[type=range] {
  flex: 1; accent-color: var(--accent);
  height: 4px; background: var(--bg3); border: none; padding: 0;
}
.slider-row span { min-width: 4rem; text-align: right; font-weight: 600; color: var(--accent); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-tog {
  position: absolute; inset: 0; background: var(--bg3);
  border-radius: 26px; cursor: pointer; transition: .2s;
}
.slider-tog::before {
  content: ''; position: absolute;
  width: 20px; height: 20px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: .2s;
}
input:checked + .slider-tog { background: var(--accent); }
input:checked + .slider-tog::before { transform: translateX(22px); }

.avancerat-toggle {
  color: var(--text2); font-size: .85rem; cursor: pointer; user-select: none;
}
#avancerat-panel { display: flex; flex-direction: column; gap: .75rem; }

#setup-karta-container {
  position: relative; width: 100%; height: 260px;
  border-radius: var(--radius); overflow: hidden;
  background: var(--bg2);
}
#setup-karta { width: 100%; height: 100%; }
#setup-karta-overlay {
  position: absolute; inset: 0; background: rgba(15,23,42,.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
}

.setup-btns { display: flex; flex-direction: column; gap: .6rem; padding-bottom: 2rem; }
.fairness-info {
  background: rgba(59,130,246,.1); border: 1px solid rgba(59,130,246,.3);
  border-radius: var(--radius); padding: .75rem 1rem;
  font-size: .9rem; color: var(--accent);
}

/* === Lobby-vy === */
.lobby-content {
  padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem;
  max-width: 560px; margin: 0 auto; width: 100%;
}
.spelkod-display {
  display: flex; align-items: center; justify-content: center; gap: .75rem;
  background: var(--bg2); border-radius: var(--radius); padding: 1.25rem;
}
#lobby-spelkod {
  font-size: 2.2rem; font-weight: 800; letter-spacing: .1em; color: var(--accent);
}
.btn-dela {
  background: var(--bg3); border: none; border-radius: 8px;
  padding: .5rem .75rem; color: var(--text); font-size: 1.1rem; cursor: pointer;
}
.lobby-sub { text-align: center; color: var(--text2); font-size: .9rem; }
.spelare-lista-label, .cp-thumbnails-label {
  font-size: .85rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .05em;
}
.spelare-lista { display: flex; flex-direction: column; gap: .5rem; }
.spelare-item {
  display: flex; align-items: center; gap: .75rem;
  background: var(--bg2); border-radius: var(--radius); padding: .75rem 1rem;
}
.spelare-dot {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
}
.spelare-navn { font-weight: 600; }
.spelare-badge {
  margin-left: auto; font-size: .75rem; color: var(--text2);
  background: var(--bg3); padding: .2rem .5rem; border-radius: 6px;
}
.cp-thumbnails {
  display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem;
}
.cp-thumb {
  flex-shrink: 0; width: 80px; height: 60px;
  border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--bg2); border: 2px solid var(--bg3);
  transition: border-color .15s;
}
.cp-thumb:hover { border-color: var(--accent); }
.cp-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cp-thumb-nr {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: var(--text2);
}
.countdown {
  text-align: center; background: var(--bg2); border-radius: var(--radius); padding: 1.5rem;
}
#countdown-siffra {
  font-size: 4rem; font-weight: 800; color: var(--accent); line-height: 1;
}

/* === Spelvy === */
#vy-spel { overflow: hidden; }
#spel-karta { position: absolute; inset: 0; background: #1a2433; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: .75rem 1rem;
  display: flex; align-items: center; gap: .75rem;
  background: linear-gradient(to bottom, rgba(15,23,42,.9) 0%, transparent 100%);
  pointer-events: none;
  z-index: 800;
}
.hud-hastighet {
  display: flex; align-items: baseline; gap: .2rem;
}
#hud-kmh { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.hud-enhet { font-size: .85rem; color: var(--text2); }
.hud-grans { font-size: .85rem; color: var(--text2); }
.hud-grans.over-grans { color: var(--rod); font-weight: 700; }
.hud-cp { margin-left: auto; font-size: .9rem; font-weight: 600; }
.hud-tid { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-cp-btn {
  pointer-events: all; background: rgba(30,41,59,.9); border: none;
  border-radius: 8px; padding: .4rem .6rem; color: var(--text);
  font-size: 1rem; cursor: pointer;
}

.violation-varning {
  position: absolute; bottom: .5rem; left: 50%; transform: translateX(-50%);
  background: rgba(239,68,68,.9); color: white;
  padding: .35rem .85rem; border-radius: 20px; font-size: .85rem; font-weight: 700;
  pointer-events: none;
}

.speed-border {
  position: absolute; inset: 0; z-index: 700; pointer-events: none;
  border: 4px solid var(--rod);
  animation: puls-rod 0.8s ease-in-out infinite;
}
@keyframes puls-rod {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

.cp-notis {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(34,197,94,.95); color: white;
  padding: 1.25rem 2rem; border-radius: var(--radius);
  text-align: center; font-size: 1.1rem; font-weight: 700;
  z-index: 900; max-width: 80vw;
}

.host-toast {
  position: absolute; top: 4.5rem; left: 50%; transform: translateX(-50%);
  background: rgba(30,41,59,.95); border: 1px solid var(--bg3);
  padding: .75rem 1.25rem; border-radius: var(--radius);
  font-size: .9rem; max-width: 80vw; text-align: center;
  z-index: 900;
}

/* === Centrera-knapp (spelvy) === */
.btn-centrera {
  position: absolute; bottom: 3rem; right: 1rem; z-index: 800;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(30,41,59,.92); border: 2px solid var(--bg3);
  color: var(--text); font-size: 1.35rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
  transition: border-color .2s, background .2s, color .2s;
  pointer-events: all;
}
.btn-centrera.aktiv {
  border-color: var(--accent);
  background: rgba(59,130,246,.2);
  color: var(--accent);
}

/* === Checkpoint-lista === */
.cp-bilder-lista {
  padding: 1rem; display: flex; flex-direction: column; gap: 1rem;
}

.cpl-kort {
  background: var(--bg2); border-radius: var(--radius);
  border: 1px solid var(--bg3); overflow: hidden;
}
.cpl-kort.nadd  { border-color: rgba(34,197,94,.5); }
.cpl-kort.nasta { border-color: rgba(245,158,11,.6); }

.cpl-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem;
}
.cpl-titel { font-size: 1rem; font-weight: 700; }
.cpl-badge {
  font-size: .75rem; font-weight: 600;
  padding: .25rem .65rem; border-radius: 20px;
  background: rgba(148,163,184,.15); color: var(--text2);
  flex-shrink: 0;
}
.cpl-badge.nadd  { background: rgba(34,197,94,.2);  color: var(--gron); }
.cpl-badge.nasta { background: rgba(245,158,11,.2); color: var(--orange); }

.cpl-karta { width: 100%; height: 220px; background: #1a2433; display: block; }

.cpl-bild-wrap { position: relative; cursor: pointer; }
.cpl-bild { width: 100%; height: 160px; object-fit: cover; display: block; }
.cpl-bild-fs-btn {
  position: absolute; bottom: .5rem; right: .5rem;
  background: rgba(0,0,0,.7); color: white; border: none;
  border-radius: 6px; padding: .3rem .6rem; font-size: .8rem; cursor: pointer;
}

.cpl-info {
  padding: .75rem 1rem; display: flex; flex-direction: column; gap: .45rem;
  border-top: 1px solid var(--bg3);
}
.cpl-info-rad { display: flex; align-items: baseline; gap: .5rem; font-size: .85rem; }
.cpl-info-ikon { flex-shrink: 0; }
.cpl-info-text { color: var(--text2); }


/* === Checkpoint-detaljvy === */
#vy-cp-detalj { overflow: hidden; }

.cp-detalj-scroll {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
}

.cp-detalj-karta {
  width: 100%; height: 300px; flex-shrink: 0;
  background: var(--bg2);
}
.cp-detalj-karta.stor { height: 400px; }

.cp-detalj-bild-wrap {
  position: relative; flex-shrink: 0;
}
.cp-detalj-bild {
  width: 100%; display: block; max-height: 260px; object-fit: cover;
}
.cp-detalj-bild-fullscreen {
  position: absolute; bottom: .5rem; right: .5rem;
  background: rgba(0,0,0,.7); color: white; border: none;
  border-radius: 6px; padding: .3rem .7rem; font-size: .8rem; cursor: pointer;
}

.cp-detalj-fakta {
  padding: 1rem; display: flex; flex-direction: column; gap: .75rem;
  background: var(--bg2); margin: .75rem; border-radius: var(--radius);
}
.cp-fakta-rad { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.cp-fakta-etikett { font-size: .8rem; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; flex-shrink: 0; }
.cp-fakta-varde { font-size: .9rem; font-weight: 600; text-align: right; }
.cp-fakta-varde.mono { font-family: monospace; font-size: .85rem; }

.cp-detalj-badge {
  margin-left: auto; font-size: .75rem; font-weight: 600;
  padding: .2rem .6rem; border-radius: 20px;
}
.cp-detalj-badge.nadd  { background: rgba(34,197,94,.2);  color: var(--gron); }
.cp-detalj-badge.nasta { background: rgba(245,158,11,.2); color: var(--orange); }
.cp-detalj-badge.kvar  { background: rgba(148,163,184,.15); color: var(--text2); }

.cp-fullscreen {
  position: fixed; inset: 0; background: #000; z-index: 1000;
  display: flex; flex-direction: column;
}
.cp-fs-stang {
  position: absolute; top: 1rem; right: 1rem; z-index: 1001;
  background: rgba(0,0,0,.7); border: none; color: white;
  font-size: 1.5rem; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
}
#cp-fs-innehall { flex: 1; }
#cp-fs-innehall iframe { width: 100%; height: 100%; border: none; }
#cp-fs-innehall img { width: 100%; height: 100%; object-fit: contain; }

/* === Resultatvy === */
.resultat-tabell {
  width: 100%; border-collapse: collapse; margin: 1rem;
  font-size: .85rem;
}
.resultat-tabell th {
  background: var(--bg2); padding: .6rem; text-align: left;
  color: var(--text2); font-size: .75rem; text-transform: uppercase;
}
.resultat-tabell td { padding: .6rem; border-bottom: 1px solid var(--bg2); }
.resultat-tabell tr:nth-child(1) td { font-weight: 700; }

.podium {
  display: flex; align-items: flex-end; justify-content: center; gap: 1rem;
  padding: 1.5rem 1rem 0;
}
.podium-plats {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  flex: 1; max-width: 100px;
}
.podium-ikon { font-size: 1.5rem; }
.podium-namn { font-size: .8rem; font-weight: 600; text-align: center; word-break: break-word; }
.podium-tid { font-size: .75rem; color: var(--text2); }
.podium-steg {
  width: 100%; background: var(--bg2); border-radius: 8px 8px 0 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 800;
}
.podium-plats:nth-child(1) .podium-steg { height: 80px; background: rgba(251,191,36,.3); }
.podium-plats:nth-child(2) .podium-steg { height: 60px; }
.podium-plats:nth-child(3) .podium-steg { height: 45px; }

/* === Violations-vy === */
#violations-karta-container {
  height: 200px; margin: 0;
}
#violations-karta { width: 100%; height: 100%; }
.violations-lista { padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.violation-item {
  background: var(--bg2); border-radius: var(--radius); padding: .75rem 1rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.violation-header { display: flex; justify-content: space-between; align-items: center; }
.violation-kmh { font-weight: 700; color: var(--rod); }
.violation-penalty { font-weight: 700; color: var(--orange); }
.violation-meta { font-size: .8rem; color: var(--text2); }
.violation-status { font-size: .75rem; }
.violation-status.none {}
.violation-status.requested { color: var(--orange); }
.violation-status.approved { color: var(--gron); }
.violation-status.rejected { color: var(--rod); }
.btn-bestrid {
  background: none; border: 1px solid var(--bg3); border-radius: 6px;
  color: var(--text2); padding: .3rem .75rem; font-size: .8rem; cursor: pointer; margin-top: .25rem; align-self: flex-start;
}

/* === Host-panel === */
.host-panel-content { padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.host-section-label { font-size: .85rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.host-msg-row { display: flex; gap: .5rem; }
.host-msg-row .inp-text { flex: 1; }
.host-msg-row .btn { width: auto; padding: .75rem 1.25rem; }
.bestridande-item {
  background: var(--bg2); border-radius: var(--radius); padding: .75rem 1rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.bestridande-btns { display: flex; gap: .5rem; }
.bestridande-btns .btn { width: auto; padding: .5rem 1rem; font-size: .85rem; }

/* === Dialog === */
.dialog-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.dialog {
  background: var(--bg2); border-radius: var(--radius);
  padding: 1.5rem; width: min(360px, 90vw);
  display: flex; flex-direction: column; gap: 1rem;
}
.dialog h3 { font-size: 1.1rem; }
.dialog p { color: var(--text2); font-size: .9rem; }
.dialog-btns { display: flex; gap: .5rem; }
.dialog-btns .btn { flex: 1; }

/* === Leaflet overrides === */
.leaflet-control-attribution { display: none !important; }
.leaflet-control-zoom { display: none; }

/* Spelarmarkör */
.spelare-marker {
  border-radius: 50%; border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.spelare-marker.pulserar {
  animation: pulsera 1.5s ease-out infinite;
}
@keyframes pulsera {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,.5); }
  70% { box-shadow: 0 0 0 12px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* Checkpoint-ikon */
.cp-ikon {
  background: var(--accent); color: white;
  border-radius: 50%; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem;
  border: 3px solid white; box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.cp-ikon.nasta {
  background: var(--orange); width: 44px; height: 44px;
  font-size: 1rem; animation: pulsera 1.5s ease-out infinite;
}

/* === Hjälpklasser === */
.dold { display: none !important; }

/* === Spinner === */
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--bg3); border-top-color: var(--accent);
  animation: snurra .8s linear infinite;
}
@keyframes snurra { to { transform: rotate(360deg); } }

/* === Responsivt === */
@media (min-width: 600px) {
  .setup-content, .lobby-content { padding: 1.5rem 2rem; }
}
