/* =====================================================================
   O-koll – stilmall
   Vit bakgrund och svart text syns bäst utomhus i solljus.
   Lila = orienteringens banfärg. Eleverna ritas som kontrollringar.
   ===================================================================== */

:root {
  --ink: #111111;
  --muted: #5c5c5c;
  --line: #e2e2e2;
  --paper: #ffffff;
  --wash: #f5f5f3;

  --course: #a8129b;
  --course-wash: #f7e6f5;
  --live: #2f8f2f;
  --stale: #b0601a;
  --lost: #8a8a8a;
  --help: #d71f1a;
  --help-wash: #fdeceb;
  --me: #1f8fd6;

  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;

  --radius: 12px;
  --tap: 48px;
  --panel-w: 380px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.16);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--course);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Knappar och formulär
   --------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.btn:hover { background: var(--wash); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--course); border-color: var(--course); color: #fff; }
.btn--primary:hover { background: #8e0f83; border-color: #8e0f83; }

.btn--danger { border-color: var(--help); color: var(--help); }
.btn--danger:hover { background: var(--help-wash); }

.btn--help { background: var(--help); border-color: var(--help); color: #fff; }
.btn--help:hover { background: #b91a16; border-color: #b91a16; }
.btn--help.is-on { background: var(--paper); color: var(--help); }

.btn--on-alarm { background: #fff; border-color: #fff; color: var(--help); }
.btn--on-alarm:hover { background: #fff3f2; }

.btn--small { min-height: 44px; padding: 0 14px; font-size: 0.95rem; }
.btn--wide { width: 100%; }

.link {
  justify-self: start;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--course);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link--danger { color: var(--help); }

.round-btn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.round-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--me); stroke-width: 2.4; stroke-linecap: round; }

.stack { display: grid; gap: 14px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.button-row--fill > * { flex: 1 1 0; }

.field { display: grid; gap: 6px; }
.field label { font-weight: 600; }
.field-hint { display: block; font-weight: 400; font-size: 0.9rem; color: var(--muted); }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 1.0625rem; /* minst 16 px – annars zoomar iPhone in */
}
.input::placeholder { color: #8d8d8d; }
.input--small { min-height: 44px; }
.input--code {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  padding-left: calc(14px + 0.3em); /* väg upp mellanrummet efter sista tecknet */
}
select.input {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23111' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}

input[type='range'] { width: 100%; accent-color: var(--course); min-height: 32px; }

.form-msg { min-height: 1.45em; font-weight: 600; color: var(--muted); }
.form-msg:empty { min-height: 0; }
.form-msg.is-error { color: var(--help); }

.notice {
  padding: 12px 14px;
  border-left: 5px solid var(--help);
  border-radius: 8px;
  background: var(--help-wash);
  font-weight: 600;
}

.hint { color: var(--stale); font-weight: 600; }
.empty { color: var(--muted); }

/* Brytare (checkbox som ser ut som en omkopplare) */
.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  cursor: pointer;
}
.switch input {
  appearance: none;
  flex: none;
  position: relative;
  width: 46px;
  height: 28px;
  margin: 0;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  cursor: pointer;
  transition: background 0.15s;
}
.switch input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.15s;
}
.switch input:checked { background: var(--course); border-color: var(--course); }
.switch input:checked::after { background: #fff; transform: translateX(18px); }

/* Segmenterad knappgrupp (används av kartvy-växlaren och kalibreringen) */
.seg, .view-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
}
.seg button, .view-switch button {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.seg button[aria-checked='true'], .view-switch button[aria-checked='true'] {
  background: var(--ink);
  color: #fff;
}
.view-switch button:disabled { opacity: 0.35; cursor: not-allowed; }

/* ---------------------------------------------------------------------
   Kartan
   --------------------------------------------------------------------- */
.map { background: #eeeeea; }
.leaflet-container { font-family: var(--font); }

/* Baskartan tonas ned när orienteringskartan visas ovanpå */
.map.is-dimmed .leaflet-tile-pane { filter: grayscale(1); opacity: 0.45; }

.o-map-img {
  transform-origin: 0 0;
  max-width: none !important;
  user-select: none;
}

.leaflet-top { top: var(--safe-t); }
.leaflet-right { right: var(--safe-r); }
.leaflet-touch .leaflet-bar a {
  width: 44px;
  height: 44px;
  line-height: 44px;
  font-size: 24px;
}
.leaflet-touch .leaflet-bar { border: 2px solid var(--ink); }

.view-switch {
  position: absolute;
  z-index: 1100;
  top: calc(10px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  box-shadow: var(--shadow);
}

/* Elever som kontrollringar */
.pin-icon { background: none; border: 0; }
.pin { position: relative; width: 30px; height: 30px; }
.pin-ring {
  position: absolute;
  inset: 0;
  border: 4px solid var(--pin, var(--course));
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff, inset 0 0 0 2px #fff;
}
.pin-name {
  position: absolute;
  top: 50%;
  left: 34px;
  transform: translateY(-50%);
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--pin, var(--course));
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.pin--stale .pin-ring { border-color: var(--stale); border-style: dashed; }
.pin--stale .pin-name { color: var(--stale); }
.pin--lost { opacity: 0.7; }
.pin--lost .pin-ring { border-color: var(--lost); border-style: dashed; }
.pin--lost .pin-name { color: #555; }
.pin--help .pin-ring {
  border-color: var(--help);
  background: rgba(215, 31, 26, 0.25);
  animation: pulse 1.2s ease-out infinite;
}
.pin--help .pin-name { background: var(--help); color: #fff; }
.pin--replay-idle { opacity: 0.8; }
.pin--replay-idle .pin-ring { border-style: dashed; }
.hide-pin-names .pin-name { display: none; }
.pin-icon.is-selected .pin-ring { border-width: 6px; transform: scale(1.2); }
.pin-icon.is-selected .pin-name { outline: 2px solid currentColor; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 2px #fff, 0 0 0 2px rgba(215, 31, 26, 0.6); }
  100% { box-shadow: 0 0 0 2px #fff, 0 0 0 22px rgba(215, 31, 26, 0); }
}

/* Registrerade kontroller */
.punch-icon { background: none; border: 0; }
.punch-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 3px solid var(--pin, var(--course));
  border-radius: 50%;
  background: #fff;
  color: var(--pin, var(--course));
  font-family: var(--font-head);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.punch-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 6px;
  padding: 0 5px;
  border: 2px solid var(--course);
  border-radius: 999px;
  color: var(--course);
  font-family: var(--font-head);
  font-size: 0.8rem;
  font-weight: 700;
  vertical-align: 1px;
}

/* Handtag för att placera kartan */
.handle-icon { background: none; border: 0; }
.handle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid var(--course);
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: grab;
}
.handle:active { cursor: grabbing; }
.handle svg { width: 26px; height: 26px; stroke: var(--course); }

/* ---------------------------------------------------------------------
   Startsidan
   --------------------------------------------------------------------- */
.start {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(32px + var(--safe-t)) 24px calc(32px + var(--safe-b));
}
.start-inner { width: 100%; max-width: 400px; }
.start-title {
  font-family: var(--font-head);
  font-size: clamp(3.25rem, 14vw, 4.75rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
}
.start-lead { margin-top: 10px; font-size: 1.2rem; color: var(--muted); }
.start-foot { margin-top: 8px; color: var(--muted); font-size: 0.95rem; }

.course { display: block; width: 100%; max-width: 340px; margin: 12px auto 0; overflow: visible; }
.course-start, .course-leg, .course-control circle {
  fill: none;
  stroke: var(--course);
  stroke-width: 4;
  stroke-linejoin: round;
}
.course-control circle { fill: #fff; transition: fill 0.15s; }
.course-control text {
  fill: var(--course);
  font-family: var(--font-head);
  font-size: 27px;
  font-weight: 700;
  text-anchor: middle;
}
.course-control .course-no { font-size: 30px; }
.course-control:hover circle { fill: var(--course-wash); }
.course-control:focus { outline: none; }
.course-control:focus-visible circle { stroke-width: 7; }

/* ---------------------------------------------------------------------
   Kort (elevens skärmar)
   --------------------------------------------------------------------- */
.screen--center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
}
.card { width: 100%; max-width: 420px; display: grid; gap: 18px; }
.card-title { font-family: var(--font-head); font-size: 2rem; line-height: 1.05; }
.card-mark { width: 64px; height: 64px; fill: none; stroke: var(--course); stroke-width: 3.5; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
}
.brand svg { width: 24px; height: 22px; fill: none; stroke: var(--course); stroke-width: 4; stroke-linejoin: round; }

.privacy {
  padding-left: 12px;
  border-left: 4px solid var(--course);
  color: var(--muted);
  font-size: 0.95rem;
}

.geo-hint { color: var(--muted); font-size: 0.95rem; text-align: center; }
.geo-blocked {
  padding: 10px 12px;
  border-left: 5px solid var(--stale);
  border-radius: 8px;
  background: #fbf1e7;
  font-weight: 600;
}
.help-steps { display: grid; gap: 10px; }
.help-steps ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.help-steps p { margin: 0; }
.help-steps a.btn { color: var(--ink); text-decoration: none; }
.tech { color: #8d8d8d; font-size: 0.8rem; }
.howto { border: 2px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.howto summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.howto ol { margin: 0 0 14px; padding-left: 20px; display: grid; gap: 8px; }

/* ---------------------------------------------------------------------
   Elevens live-vy
   --------------------------------------------------------------------- */
.screen--live {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.page--elev .map { position: relative; flex: 1; min-height: 0; }

#locate-btn {
  position: absolute;
  z-index: 1100;
  top: calc(118px + var(--safe-t));
  right: calc(10px + var(--safe-r));
}

.status-card {
  position: relative;
  z-index: 1100;
  flex: none;
  display: grid;
  gap: 12px;
  padding: 16px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  border-top: 2px solid var(--ink);
  background: var(--paper);
}

.status { display: flex; align-items: center; gap: 12px; }
.status-dot {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--lost);
}
.status[data-tone='ok'] .status-dot { background: var(--live); animation: beacon 2s ease-out infinite; }
.status[data-tone='warn'] .status-dot { background: var(--stale); }
.status[data-tone='wait'] .status-dot { background: none; border: 3px solid var(--lost); }
.status-title { font-weight: 700; font-size: 1.125rem; line-height: 1.2; }
.status[data-tone='warn'] .status-title { color: var(--stale); }
.status-sub { color: var(--muted); font-size: 0.95rem; }
.status-code {
  margin-left: auto;
  padding: 2px 8px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-family: var(--font-head);
  font-weight: 700;
  letter-spacing: 0.12em;
}

@keyframes beacon {
  0% { box-shadow: 0 0 0 0 rgba(47, 143, 47, 0.55); }
  100% { box-shadow: 0 0 0 12px rgba(47, 143, 47, 0); }
}

.help-on {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-left: 6px solid var(--help);
  border-radius: 8px;
  background: var(--help-wash);
}
.help-on-title { color: var(--help); font-weight: 700; font-size: 1.125rem; }
.help-on-fallback { font-weight: 700; }

.notes { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; color: var(--muted); font-size: 0.9rem; }
.notes li::before { content: '–'; margin-right: 6px; }

.punch { display: grid; gap: 6px; }
.btn--punch {
  min-height: 64px;
  background: var(--course);
  border-color: var(--course);
  color: #fff;
  font-size: 1.15rem;
}
.btn--punch:hover { background: #8e0f83; border-color: #8e0f83; }
.btn--punch svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 3; }
.punch-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-weight: 600; }
.punch-info.is-fresh { color: var(--course); }
.punch-info.is-error { color: var(--help); }
.punch-info .link { padding: 0; }
.live-actions { display: grid; grid-template-columns: 3fr 2fr; gap: 8px; }
.live-actions .btn { min-height: 56px; }

@media (min-width: 600px) {
  .status-card {
    width: min(560px, calc(100% - 24px));
    margin: 0 auto 12px;
    border: 2px solid var(--ink);
    border-radius: 16px;
    padding-bottom: 16px;
  }
  .screen--live { background: #eeeeea; }
}

/* ---------------------------------------------------------------------
   Lärarvyn
   --------------------------------------------------------------------- */
.page--larare .map { position: fixed; inset: 0; }

.panel {
  position: fixed;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 20px;
  border: 0;
  background: var(--paper);
  text-align: left;
  cursor: pointer;
}
.panel-brand {
  flex: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 700;
}
.panel-brand::before {
  content: '';
  width: 22px;
  height: 20px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 36'%3E%3Cpath d='M20 3 37 33H3Z' fill='none' stroke='%23a8129b' stroke-width='4' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
}
.panel-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-left: auto; font-size: 0.95rem; color: var(--muted); }
.panel-summary b { color: var(--ink); font-family: var(--font-head); letter-spacing: 0.1em; font-size: 1.05rem; }
.summary-alarm { padding: 1px 8px; border-radius: 999px; background: var(--help); color: #fff; font-weight: 700; }
.chevron { flex: none; width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s; transform: rotate(180deg); }
.panel.is-collapsed .chevron { transform: none; }

.panel-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel-body > .notice { margin: 0 20px 12px; }

.block { display: grid; gap: 14px; padding: 18px 20px; border-top: 1px solid var(--line); }
.block-title { font-family: var(--font-head); font-size: 1.35rem; line-height: 1.1; }
.block-row { display: flex; align-items: center; gap: 10px; }
.block--footer { padding-bottom: calc(18px + var(--safe-b)); }
.count { color: var(--muted); font-size: 0.95rem; }
.conn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.conn::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--lost); }
.conn[data-state='ok'] { color: var(--live); }
.conn[data-state='ok']::before { background: var(--live); }
.signed-in { color: var(--muted); font-size: 0.9rem; }

/* Koden eleverna skriver in */
.join-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: zoom-in;
}
.join-code {
  font-family: var(--font-head);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12em;
}
.join-qr { flex: none; width: 84px; }
.join-qr svg, .code-dialog-qr svg { display: block; width: 100%; height: auto; }
.join-url { color: var(--muted); font-size: 0.95rem; }
.join-url strong { color: var(--ink); word-break: break-all; }

/* Elevlistan */
.students { margin: 0 -8px; padding: 0; list-style: none; }
.student-btn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.student-btn:hover:not(:disabled) { background: var(--wash); }
.student-btn:disabled { cursor: default; }
.student.is-selected .student-btn { background: var(--course-wash); }
.student-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-meta { color: var(--muted); font-size: 0.9rem; text-align: right; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--lost); }
.student--live .dot { border-color: var(--live); background: var(--live); }
.student--stale .dot { border-color: var(--stale); border-style: dashed; }
.student--stale .student-meta { color: var(--stale); font-weight: 600; }
.student--lost .dot { border-style: dashed; }
.student--lost .student-meta { color: var(--ink); font-weight: 600; }
.student--waiting .dot { border-style: dotted; }
.student--stopped .student-name { color: var(--muted); }
.student.student--help .student-btn { background: var(--help-wash); }
.student--help .dot { border-color: var(--help); background: var(--help); }
.student--help .student-meta { color: var(--help); }

/* Tidigare lektioner */
.history { margin: 0 -8px; padding: 0; list-style: none; }
.history-btn {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 56px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.history-btn:hover { background: var(--wash); }
.history-when { font-weight: 700; }
.history-when::first-letter { text-transform: uppercase; }
.history-what { color: var(--muted); font-size: 0.9rem; }

/* Vägval i efterhand */
.review-meta { margin-top: 4px; color: var(--muted); }
.review-meta::first-letter { text-transform: uppercase; }
.hint-muted { color: var(--muted); font-size: 0.95rem; }
.route { display: flex; align-items: center; gap: 2px; }
.route-check {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
}
.route-check input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.swatch {
  width: 22px;
  height: 22px;
  border: 3px solid var(--c);
  border-radius: 6px;
  background: var(--paper);
}
.route-check input:checked + .swatch { background: var(--c); }
.route-check input:focus-visible + .swatch { outline: 3px solid var(--course); outline-offset: 2px; }
.route-btn { flex: 1; grid-template-columns: 1fr auto; }
.route-dl {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.route-dl:hover { background: var(--wash); }
.route-dl svg, .btn-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.stack--tight { gap: 6px; }
.route.is-off .student-name, .route.is-off .student-meta { color: #9a9a9a; }
.route.is-focus .route-btn { background: var(--course-wash); }

.punch-badge { border-color: var(--pin, var(--course)); color: var(--pin, var(--course)); }
.splits { display: grid; gap: 8px; }
.splits-title { margin: 0; font-family: var(--font-head); font-size: 1.1rem; }
.splits-scroll { overflow-x: auto; }
.splits-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.splits-table th, .splits-table td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.splits-table th:first-child, .splits-table td:first-child { text-align: left; }
.splits-table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.splits-table tbody tr { cursor: pointer; }
.splits-table tbody tr:hover, .splits-table tbody tr:focus-visible { background: var(--course-wash); outline: none; }

.replay {
  position: fixed;
  z-index: 1150;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.replay.is-empty { display: none; }
.replay-play {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--course);
  cursor: pointer;
}
.replay-play:hover { background: #8e0f83; }
.replay-play svg { width: 26px; height: 26px; fill: #fff; }
.replay-play .icon-pause, .replay-play.is-playing .icon-play { display: none; }
.replay-play.is-playing .icon-pause { display: block; }
.replay-track { flex: 1; min-width: 0; }
.replay-labels { display: flex; justify-content: space-between; gap: 8px; font-size: 0.9rem; color: var(--muted); }
#replay-clock { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.replay-speed {
  flex: none;
  min-height: 44px;
  padding: 0 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  font-weight: 700;
}

/* Ladda upp karta */
.upload summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; color: var(--course); }
.upload > .stack { padding-top: 8px; }
.file-btn { position: relative; overflow: hidden; justify-self: start; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--course); outline-offset: 2px; }

/* Larm när en elev behöver hjälp */
.help-alert {
  position: fixed;
  z-index: 1300;
  left: 50%;
  top: calc(10px + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 18px;
  border-radius: var(--radius);
  background: var(--help);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: var(--shadow);
  animation: alarm 1s ease-in-out infinite alternate;
}
@keyframes alarm { to { box-shadow: 0 0 0 6px rgba(215, 31, 26, 0.3), var(--shadow); } }

/* Placera kartan */
.calib {
  position: fixed;
  z-index: 1200;
  display: grid;
  gap: 14px;
  padding: 18px 20px calc(18px + var(--safe-b));
  background: var(--paper);
  overflow-y: auto;
}
.calib-help { font-size: 0.95rem; }
.calib-search { display: flex; gap: 8px; }
.calib-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.calib-opacity { display: grid; gap: 2px; flex: 1 1 140px; font-weight: 600; font-size: 0.9rem; }
.nudge { display: flex; gap: 6px; }
.nudge .btn { min-width: 44px; padding: 0; font-size: 1.25rem; }
.calib-actions { display: flex; gap: 10px; }
.calib-actions .btn { flex: 1; }
body.is-calibrating .panel,
body.is-calibrating .view-switch,
body.is-calibrating .help-alert { display: none !important; }

/* Koden i helskärm */
.code-dialog {
  width: min(92vw, 640px);
  max-height: 92dvh;
  padding: 28px 24px 24px;
  border: 0;
  border-radius: 20px;
  text-align: center;
}
.code-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
.code-dialog-url { font-size: clamp(1.1rem, 3.5vw, 1.6rem); color: var(--muted); word-break: break-all; }
.code-dialog-code {
  margin: 8px 0 18px;
  font-family: var(--font-head);
  font-size: clamp(4rem, 17vw, 8.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.1em;
  padding-left: 0.1em;
}
.code-dialog-qr { width: min(56vw, 42dvh, 300px); margin: 0 auto 22px; }

/* Mobil: panelen blir ett ark längst ned */
@media (max-width: 899px) {
  .panel, .calib {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 72dvh;
    border-top: 2px solid var(--ink);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.14);
  }
  .panel { overflow: hidden; }
  .panel-head { padding-left: calc(20px + var(--safe-l)); padding-right: calc(20px + var(--safe-r)); }
  .panel.is-collapsed .panel-body { display: none; }
  .panel.is-collapsed .panel-head { padding-bottom: calc(10px + var(--safe-b)); }
  .calib { max-height: 55dvh; }
  .page--larare .leaflet-bottom { bottom: 92px; }
  body[data-state='review'] .leaflet-bottom { bottom: 176px; }
  .replay {
    left: calc(10px + var(--safe-l));
    right: calc(10px + var(--safe-r));
    bottom: calc(100px + var(--safe-b));
  }
  .help-alert {
    top: calc(66px + var(--safe-t));
    left: calc(10px + var(--safe-l));
    right: calc(66px + var(--safe-r)); /* lämna plats för zoomknapparna */
    max-width: none;
    transform: none;
    justify-content: space-between;
  }
  .page--larare .view-switch { right: auto; }
}

/* Dator/surfplatta på bredden: panelen till vänster, kartan bredvid */
@media (min-width: 900px) {
  .panel, .calib {
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--panel-w);
    border-right: 2px solid var(--ink);
  }
  .calib { align-content: start; }
  .panel-head { pointer-events: none; cursor: default; }
  .chevron { display: none; }
  .page--larare .map { left: var(--panel-w); }
  .page--larare .view-switch { position: fixed; left: calc(var(--panel-w) + 12px); top: 12px; }
  .help-alert { top: 72px; left: calc(50% + var(--panel-w) / 2); }
  .replay {
    left: calc(var(--panel-w) + 16px);
    right: 16px;
    bottom: 24px;
    max-width: 760px;
    margin: 0 auto;
  }
  body[data-state='review'] .leaflet-bottom { bottom: 104px; }
}

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

/* =====================================================================
   Banor, meddelanden, lektionstid och resultat
   ===================================================================== */

/* Kontroller i en bana – som på en orienteringskarta */
.control-icon { background: none; border: 0; }
.control-ring {
  position: absolute;
  inset: 3px;
  border: 4px solid var(--course);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
}
.control-no {
  position: absolute;
  left: 34px;
  top: -6px;
  color: var(--course);
  font-family: var(--font-head);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
}
/* Pulserar en stund när kontrollen dyker upp – inte hela tiden (sparar batteri) */
.control-icon--next .control-ring { border-width: 5px; animation: pulse-course 1.6s ease-out 8; }
.control-icon--done .control-ring { border-color: #8d8d8d; opacity: 0.7; }
.control-icon--done .control-no { color: #8d8d8d; }
.control-icon--done .control-no::after { content: ' ✓'; }
.control-icon--edit { cursor: grab; }
.control-icon--edit .control-ring { background: rgba(168, 18, 155, 0.12); }
@keyframes pulse-course {
  0% { box-shadow: 0 0 0 2px #fff, 0 0 0 2px rgba(168, 18, 155, 0.6); }
  100% { box-shadow: 0 0 0 2px #fff, 0 0 0 18px rgba(168, 18, 155, 0); }
}
.is-editing-course { cursor: crosshair; }
body.is-editing-course .panel,
body.is-editing-course .help-alert { display: none !important; }
.course-stats { font-weight: 700; color: var(--course); }

.field--inline { display: flex; align-items: center; gap: 10px; }
.field--inline .input { width: auto; }

/* Lektionstid hos läraren */
.lesson-timer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.lesson-timer label { font-weight: 600; }
.lesson-timer .input { width: auto; }
.timer-left {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer-left.is-over { color: var(--help); }
.summary-timer { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* Meddelanden hos läraren */
.btn--gather { background: #d97706; border-color: #d97706; color: #fff; }
.btn--gather:hover { background: #b45309; border-color: #b45309; }
.msg-form { display: flex; gap: 8px; }
.msg-form .input { flex: 1; min-width: 0; }
.msg-form .member-role { flex: 0 0 auto; width: auto; }

/* Lärarna på skolan (syns för skolans admin) */
.members { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.member { display: flex; align-items: center; gap: 10px; min-height: 44px; border-bottom: 1px solid var(--line); }
.member-email { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member-role-label { color: var(--muted); font-size: 0.9rem; }

/* Resultat */
.results-scroll { overflow-x: auto; }
.results-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.results-table th, .results-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.results-table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.results-table td:first-child { width: 2ch; color: var(--muted); }
.results-table td:nth-child(2) { white-space: normal; font-weight: 600; }
.results-table tr.is-finished td:nth-child(3) { color: var(--live); font-weight: 700; }
.results-table tr.is-me td { background: var(--course-wash); }

/* Elevens bana */
.status-side { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.status-side .status-code { margin-left: 0; }
.timer-chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.timer-chip.is-soon { background: #d97706; }
.timer-chip.is-over { background: var(--help); }
.course-box { display: grid; gap: 6px; }
.course-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.course-next { font-family: var(--font-head); font-size: 1.35rem; font-weight: 700; color: var(--course); }
.course-sub { color: var(--muted); font-size: 0.95rem; }

/* ”Rätt!” när eleven stämplar */
.toast {
  position: fixed;
  z-index: 1400;
  left: 50%;
  top: calc(80px + var(--safe-t));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(92vw, 420px);
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--live);
  color: #fff;
  box-shadow: var(--shadow);
}
.toast svg { flex: none; width: 40px; height: 40px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.toast p { display: grid; gap: 2px; margin: 0; }
.toast strong { font-family: var(--font-head); font-size: 1.4rem; line-height: 1.1; }
.toast span { font-size: 0.95rem; }
.toast.is-shown { animation: toast-in 0.25s ease-out; }
@keyframes toast-in { from { transform: translate(-50%, -12px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* Meddelande och resultat ovanpå kartan */
.overlay {
  position: fixed;
  z-index: 1500;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: rgba(0, 0, 0, 0.55);
}
.overlay-card {
  width: min(100%, 440px);
  max-height: 100%;
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 22px 20px 18px;
  border-radius: 20px;
  background: var(--paper);
  border-top: 10px solid var(--course);
  box-shadow: var(--shadow);
  animation: pop-in 0.2s ease-out;
}
@keyframes pop-in { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.overlay-card[data-kind='samla'] { border-top-color: #d97706; }
.overlay-card[data-kind='tid'] { border-top-color: var(--ink); }
.overlay-kicker { font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.85rem; color: var(--muted); }
.overlay-card[data-kind='samla'] .overlay-kicker { color: #b45309; }
.overlay-title { margin: 0; font-family: var(--font-head); font-size: 1.8rem; line-height: 1.15; }
.overlay-time { color: var(--muted); font-size: 0.9rem; }
.overlay-card--list { border-top-color: var(--ink); }
.gather-icon { background: none; border: 0; }
.gather-icon span {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  background: #d97706;
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  box-shadow: var(--shadow);
}

/* =====================================================================
   Frågor vid kontrollerna
   ===================================================================== */

/* Baneditorn: kontroller med fråga och vald kontroll */
.control-icon.has-question .control-no::after {
  content: '?';
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--course);
  color: #fff;
  font-size: 0.85rem;
  text-shadow: none;
  vertical-align: 2px;
}
.control-icon.is-selected .control-ring { border-width: 6px; background: rgba(168, 18, 155, 0.25); }

.q-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 2px solid var(--course);
  border-radius: var(--radius);
  background: var(--course-wash);
}
.q-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.q-title { margin: 0; font-family: var(--font-head); font-size: 1.25rem; color: var(--course); }
.q-textarea { min-height: 0; padding: 10px 14px; resize: vertical; line-height: 1.4; }
.q-options { display: grid; gap: 8px; }
.q-options-label { font-weight: 600; }
.q-option-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.q-option-list li { display: flex; align-items: center; gap: 8px; }
.q-option-list input[type='radio'] { flex: none; width: 22px; height: 22px; accent-color: var(--live); }
.q-option-list .input { flex: 1; min-width: 0; }
.q-remove-option {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
}
.q-remove-option:hover { background: var(--paper); color: var(--help); }

/* Lärarens svarsvy */
.answers { display: grid; gap: 16px; }
.answer-group { display: grid; gap: 4px; }
.answer-q { font-weight: 700; display: flex; gap: 8px; align-items: baseline; }
.answer-no {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 3px solid var(--course);
  border-radius: 50%;
  color: var(--course);
  font-family: var(--font-head);
  font-size: 0.85rem;
}
.answer-sum { color: var(--muted); font-size: 0.85rem; padding-left: 34px; }
.answer-rows { margin: 4px 0 0; padding: 0; list-style: none; }
.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'name mark' 'text text';
  align-items: center;
  gap: 2px 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
}
.answer-row .answer-name { grid-area: name; }
.answer-row .answer-text { grid-area: text; }
.answer-row .answer-mark, .answer-row .answer-status { grid-area: mark; }
.answer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answer-text { overflow-wrap: anywhere; }
.answer-status { font-weight: 700; }
.answer-row.is-right .answer-status { color: var(--live); }
.answer-row.is-wrong .answer-status { color: var(--help); }
.answer-mark { display: flex; gap: 4px; }
.mark-btn {
  min-height: 36px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-weight: 700;
  cursor: pointer;
}
.mark-btn--ok[aria-pressed='true'] { border-color: var(--live); background: var(--live); color: #fff; }
.mark-btn--bad[aria-pressed='true'] { border-color: var(--help); background: var(--help); color: #fff; }

/* Elevens fråga */
.pending-btn {
  justify-self: start;
  padding: 6px 12px;
  border: 2px solid var(--course);
  border-radius: 999px;
  background: var(--course-wash);
  color: var(--course);
  font-weight: 700;
  cursor: pointer;
}
.overlay-card[data-kind='fraga'] { border-top-color: var(--course); }
.q-choices { display: grid; gap: 8px; }
.q-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.q-choice[aria-checked='true'] { border-color: var(--course); background: var(--course-wash); }
.q-choice:disabled { cursor: default; }
.q-letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-head);
}
.q-choice[aria-checked='true'] .q-letter { background: var(--course); }
.q-feedback { padding: 10px 14px; border-radius: 10px; font-weight: 700; font-size: 1.1rem; }
.q-feedback--right { background: #e3f3e3; color: var(--live); }
.q-feedback--wrong { background: var(--help-wash); color: var(--help); }
.q-feedback--info { background: var(--wash); color: var(--ink); }
.q-feedback--error { background: var(--help-wash); color: var(--help); font-size: 1rem; }

/* =====================================================================
   Elevens helskärm och lärarens inställningar för mobilerna
   ===================================================================== */
#fullscreen-btn {
  position: absolute;
  z-index: 1100;
  top: calc(118px + var(--safe-t));
  right: calc(10px + var(--safe-r));
}
#fullscreen-btn svg { stroke: var(--ink); }
#fullscreen-btn .icon-shrink, #fullscreen-btn.is-active .icon-expand { display: none; }
#fullscreen-btn.is-active .icon-shrink { display: block; }
#fullscreen-btn:not([hidden]) ~ #locate-btn { top: calc(176px + var(--safe-t)); }
.live-actions.is-single { grid-template-columns: 1fr; }

.view-choices { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; }
.view-choices legend { margin-bottom: 6px; font-weight: 600; }
.check-chip { position: relative; }
.check-chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.check-chip span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-head);
  font-weight: 700;
  cursor: pointer;
}
.check-chip input:checked + span { background: var(--ink); color: #fff; }
.check-chip input:checked + span::before { content: '✓'; margin-right: 6px; }
.check-chip input:focus-visible + span { outline: 3px solid var(--course); outline-offset: 2px; }
.timer-clock { width: auto; }

/* Elevens helskärm: bara kartan, och tiden som är kvar */
body.is-fullscreen .status-card,
body.is-fullscreen .view-switch,
body.is-fullscreen .leaflet-control-zoom,
body.is-fullscreen #locate-btn,
body.is-fullscreen .photo-control { display: none !important; }
body.is-fullscreen .screen--live { background: #000; }
body.is-fullscreen #fullscreen-btn {
  top: calc(10px + var(--safe-t));
  right: calc(10px + var(--safe-r));
  width: 44px;
  height: 44px;
  opacity: 0.85;
}
.fs-timer {
  position: absolute;
  z-index: 1100;
  top: calc(10px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(17, 17, 17, 0.85);
  color: #fff;
  font-family: var(--font-head);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.fs-timer.is-soon { background: rgba(217, 119, 6, 0.92); }
.fs-timer.is-over { background: rgba(215, 31, 26, 0.92); }

/* Foton */
.photo-control button {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 6px;
  border: 0;
  border-radius: 50%;
  background: var(--course);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.photo-control svg, #question-photo svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linejoin: round; }
.overlay-card--photo { border-top-color: var(--course); }
.photo-preview { display: block; width: 100%; max-height: 50dvh; object-fit: contain; border-radius: 10px; background: var(--wash); }
.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.photo-tile { display: grid; gap: 4px; color: var(--ink); text-decoration: none; font-size: 0.8rem; }
.photo-tile img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--wash); }
.photo-tile span { color: var(--muted); }
.photo-tile strong { color: var(--ink); }
.answer-photo img { display: block; width: 120px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; }
.answer-row .answer-photo { grid-area: text; }

/* En elevs egna inställningar */
.ov-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: 2px;
}
.student-detail { background: var(--course-wash); }
.detail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.student-detail .input { background: var(--paper); }

.tip-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
/* Öppnad från hemskärmen på iPhone: kartan går ända upp under statusfältet i helskärm */
@media (display-mode: standalone), (display-mode: fullscreen) {
  body.is-fullscreen .screen--live { height: 100dvh; }
}

/* Meddelanden till och från en enskild elev */
.reply-alert {
  top: calc(70px + var(--safe-t));
  background: var(--course);
  animation: none;
}
.reply-alert span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.reply-alert .btn { background: #fff; color: var(--course); border-color: #fff; }
.dm-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--course);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: 2px;
}
.chat-box { display: grid; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chat-heading { margin: 4px 0 0; font-family: var(--font-head); font-size: 1.05rem; }
.chat-thread { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.bubble {
  display: grid;
  gap: 2px;
  max-width: 85%;
  margin: 0;
  padding: 8px 12px;
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.bubble small { font-size: 0.72rem; opacity: 0.75; }
.bubble--me { justify-self: end; background: var(--course); color: #fff; border-bottom-right-radius: 4px; }
.bubble--them { justify-self: start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.overlay-card--chat .bubble--them { background: var(--wash); }
.overlay-card--chat .chat-thread { max-height: 38dvh; }
.chat-btn { justify-self: stretch; text-align: left; }
.chat-btn.is-unread { background: var(--course); color: #fff; animation: pulse-chat 1.4s ease-in-out infinite alternate; }
@keyframes pulse-chat { to { box-shadow: 0 0 0 5px rgba(168, 18, 155, 0.25); } }

/* =====================================================================
   Lärarens helskärm, mobil, färger och elevens bana
   ===================================================================== */
#map-full-btn {
  position: absolute;
  z-index: 1100;
  top: calc(118px + var(--safe-t));
  right: calc(10px + var(--safe-r));
}
#map-full-btn svg { stroke: var(--ink); }
#map-full-btn .icon-shrink, #map-full-btn.is-active .icon-expand { display: none; }
#map-full-btn.is-active .icon-shrink { display: block; }
body.is-map-only .panel, body.is-map-only .calib { display: none !important; }
body.is-map-only .page--larare .leaflet-bottom, body.is-map-only .leaflet-bottom { bottom: 0; }
.map-only-bar {
  position: absolute;
  z-index: 1100;
  top: calc(64px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  max-width: calc(100% - 90px);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.summary-selected { font-weight: 700; color: var(--course); }

/* Smal skärm: zoomknappar och kartknappar under kartväxlaren */
@media (max-width: 560px) {
  .leaflet-top.leaflet-right { margin-top: 56px; }
  #map-full-btn, #fullscreen-btn { top: calc(174px + var(--safe-t)); }
  #locate-btn { top: calc(174px + var(--safe-t)); }
  #fullscreen-btn:not([hidden]) ~ #locate-btn { top: calc(232px + var(--safe-t)); }
  .map-only-bar { top: calc(64px + var(--safe-t)); max-width: calc(100% - 80px); }
  body.is-fullscreen .leaflet-top.leaflet-right { margin-top: 0; }
}

/* Färger */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 30px;
  height: 30px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--line);
  cursor: pointer;
}
.swatch[aria-checked='true'] { box-shadow: 0 0 0 3px var(--ink); }
.swatch--none { background: repeating-linear-gradient(45deg, var(--course), var(--course) 4px, #fff 4px, #fff 7px); }

/* Elevens bana i elevrutan */
.course-status { display: grid; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.course-status p { margin: 0; }
.ctl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ctl-chip {
  min-width: 38px;
  height: 38px;
  padding: 0 6px;
  border: 3px solid var(--course);
  border-radius: 50%;
  background: var(--paper);
  color: var(--course);
  font-family: var(--font-head);
  font-weight: 700;
  cursor: pointer;
}
.ctl-chip.is-next { background: var(--course); color: #fff; }
.ctl-chip.is-taken { border-color: var(--live); color: var(--live); }
.ctl-chip.is-taken::after { content: '✓'; font-size: 0.7rem; margin-left: 1px; }
.ctl-chip.is-skipped { border-style: dashed; border-color: var(--muted); color: var(--muted); text-decoration: line-through; }
.ctl-chip:disabled { cursor: default; }
.next-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border: 2px solid var(--course);
  border-radius: 999px;
  color: var(--course);
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: 1px;
}
.next-chip.is-done { border-color: var(--live); color: var(--live); }
.chat-system { margin: 0; font-size: 0.8rem; font-style: italic; color: var(--muted); text-align: center; }

/* Elevens iPhone-hjälp, fickläge och besked om ändrad bana */
.ios-hint {
  padding: 10px 12px;
  border-left: 5px solid var(--ink);
  border-radius: 8px;
  background: var(--wash);
  font-size: 0.92rem;
  line-height: 1.45;
}
.pocket-btn { justify-self: start; display: inline-flex; align-items: center; gap: 8px; }
.pocket-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.pocket {
  position: fixed;
  z-index: 1350;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  background: #000;
  color: #8a8a8a;
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.pocket-title { font-family: var(--font-head); font-size: 1.4rem; font-weight: 700; color: #bbb; }
.pocket-time { font-family: var(--font-head); font-size: 2.6rem; font-weight: 700; color: #ddd; font-variant-numeric: tabular-nums; min-height: 1em; }
.pocket-hint { font-size: 0.9rem; }
.pocket-progress { width: 200px; height: 6px; margin: 0 auto; border-radius: 3px; background: #222; overflow: hidden; }
.pocket-progress span { display: block; width: 0; height: 100%; background: #777; }
.overlay-card[data-kind='bana'] { border-top-color: var(--course); }

/* Testa platsen innan lektionen */
.test-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.test-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.test-result {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-left: 6px solid var(--muted);
  border-radius: 10px;
  background: var(--wash);
}
.test-result[data-kind='ok'] { border-left-color: var(--live); background: #e7f4e7; }
.test-result[data-kind='warn'] { border-left-color: #d97706; background: #fdf1e2; }
.test-result[data-kind='error'] { border-left-color: var(--help); background: var(--help-wash); }
.test-title { margin: 0; font-family: var(--font-head); font-size: 1.2rem; font-weight: 700; }
.test-result[data-kind='ok'] .test-title { color: var(--live); }
.test-result[data-kind='error'] .test-title { color: var(--help); }
.test-text { margin: 0; }
.test-map { height: 180px; border-radius: 8px; overflow: hidden; }

/* Uppspelning: tillbaka till alla elever */
.route-back { display: grid; gap: 4px; padding: 0 0 8px; list-style: none; }
.route-back .hint-muted { margin: 0; font-size: 0.85rem; }
.ios-steps { margin: 6px 0; padding-left: 20px; display: grid; gap: 3px; }
/* Fickläge: kartan ritas inte och inga animationer körs (sparar batteri) */
body.is-pocket .map, body.is-pocket .view-switch, body.is-pocket .status-card { visibility: hidden; }

/* Batteritips och påminnelse */
.tips { border: 2px solid var(--line); border-radius: 10px; background: var(--paper); }
.tips summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.tips summary::-webkit-details-marker { display: none; }
.tips summary::after { content: '+'; margin-left: auto; font-size: 1.2rem; color: var(--muted); }
.tips[open] summary::after { content: '–'; }
.tips summary svg { width: 22px; height: 22px; fill: none; stroke: var(--live); stroke-width: 2; }
.tips ul { margin: 0; padding: 0 14px 12px 34px; display: grid; gap: 6px; font-size: 0.95rem; }
.battery-low {
  margin: 0;
  padding: 8px 12px;
  border-left: 5px solid #d97706;
  border-radius: 8px;
  background: #fdf1e2;
  font-weight: 700;
}
.overlay-card[data-kind='batteri'] { border-top-color: #d97706; }

/* Uppspelning: färg för vald elev */
.route-colors { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: 0.85rem; }
.route-colors span { margin-right: 4px; color: var(--muted); }
.swatch-btn {
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}
.swatch-btn[aria-pressed='true'] { box-shadow: 0 0 0 3px var(--ink); }

/* =====================================================================
   Adminsidan: skolor och licenser
   ===================================================================== */
.admin-page { background: var(--wash); }
.admin { display: grid; gap: 16px; max-width: 720px; margin: 0 auto; padding: 24px 16px 48px; }
.admin-new, .school details { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.admin-new summary, .school summary { cursor: pointer; font-weight: 700; }
.admin-new[open] summary, .school details[open] summary { margin-bottom: 14px; }
.school-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.school summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.school-name { font-size: 1.1rem; }
.license { font-size: 0.9rem; font-weight: 600; }
.license--ok { color: var(--live); }
.license--off { color: var(--help); }
.school .members { margin-bottom: 10px; }
.school .member { flex-wrap: wrap; }
