/* ==========================================================================
   Ultranav — designspråk
   Mörkt skiffer med bärnstensaccent, ljust tema för sol och rött nattema.
   Linjeikoner (js/icons.js), grupperade kontroller, stora tryckytor.
   Optimerat för iPad Pro 10,5" (1112×834 liggande / 834×1112 stående).
   ========================================================================== */

/* ---------- Tokens: Mörkt (standard) ---------- */
:root {
  --bg: #0f1720;
  --panel: #16212d;
  --panel2: #1d2a38;
  --raise: #263648;
  --line: #2c3d50;
  --line-strong: #3a5068;
  --text: #e8eef4;
  --muted: #8ea2b6;
  --accent: #f2b632;
  --accent-strong: #f7c552;
  --accent-text: #1b1300;
  --ok: #3ccf7a;
  --warn: #ffb020;
  --bad: #ff5a52;
  --route: #d63bd6;
  --popup-bg: #ffffff; --popup-text: #13202d; --popup-line: #d5dde5; --popup-muted: #586b7e;
  --popup-primary: #1d6fd6; --popup-primary-text: #ffffff;
  --shadow: 0 6px 22px rgba(0, 0, 0, .42);
  --radius: 14px;
  --touch: 56px;
  --instH: 66px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --serif: var(--display); /* rubriker och namn */
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safeT: env(safe-area-inset-top, 0px); --safeB: env(safe-area-inset-bottom, 0px);
  --safeL: env(safe-area-inset-left, 0px); --safeR: env(safe-area-inset-right, 0px);
}
/* ---------- Ljust (sol i cockpit) ---------- */
body.day {
  --bg: #f4f6f8; --panel: #ffffff; --panel2: #eef2f6; --raise: #e2e8ef; --line: #dbe2ea; --line-strong: #c3cfdb;
  --text: #13202d; --muted: #586b7e; --accent: #d48f00; --accent-strong: #e8a312; --accent-text: #ffffff;
  --shadow: 0 6px 20px rgba(20, 35, 55, .16);
}
/* ---------- Natt (rött, bevarar mörkerseendet) ---------- */
body.night {
  --bg: #050505; --panel: #0d0807; --panel2: #160c0a; --raise: #22100d; --line: #3a1a14; --line-strong: #4a1f19;
  --text: #ff8a70; --muted: #a8523f; --accent: #ff5a3c; --accent-strong: #ff7a5c; --accent-text: #100;
  --ok: #c8603a; --warn: #ff7a3c; --bad: #ff3c3c; --route: #ff3c8a;
  --popup-bg: #160c0a; --popup-text: #ff8a70; --popup-line: #4a1f19; --popup-muted: #a8523f;
  --popup-primary: #ff5a3c; --popup-primary-text: #100;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 16px/1.4 var(--sans); -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
input, select, textarea { -webkit-user-select: text; user-select: text; font-family: var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
a { color: var(--accent); }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.ic { display: inline-block; vertical-align: -0.22em; flex: none; }
.hidden { display: none !important; }

/* Etiketter i kapitäler — återkommande stilgrepp */
.caps, .inst .lbl, .tabbody h3, .popover h3, #fab button small, .tabs button span, #drawBar button small {
  font-family: var(--sans); text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
}

/* ---------- Instrumentlist ---------- */
#instruments { display: flex; align-items: stretch; height: calc(var(--instH) + var(--safeT));
  padding: var(--safeT) calc(6px + var(--safeR)) 0 calc(4px + var(--safeL));
  background: var(--panel);
  border-bottom: 1px solid var(--line-strong); flex: none; z-index: 1000; overflow: hidden; }
.ibtn { width: var(--touch); flex: none; border: 0; background: transparent; color: var(--accent);
  display: flex; align-items: center; justify-content: center; }
.ibtn:active { color: var(--accent-strong); }
.inst { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: center; align-items: center;
  border-left: 1px solid var(--line); padding: 0 2px; }
.inst.wide { flex: 1.8 1 0; }
.inst .lbl { font-size: 11px; color: var(--muted); line-height: 1; margin-bottom: 4px; }
.inst .val { font: 600 24px/1.1 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  font-variant-numeric: tabular-nums; color: var(--text); }
.inst .unit { font-size: 10px; color: var(--muted); line-height: 1.1; }
.inst.wide .val { font: 700 20px/1.1 var(--display); }
.inst.alert .val { color: var(--bad); }
@media (max-width: 900px) {
  .inst .val { font-size: 19px; } .inst.wide .val { font-size: 16px; }
  #instruments .inst:nth-of-type(10) { display: none; }
}

/* ---------- Karta ---------- */
#mapwrap { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; background: #c9d6df; }
body.night #map { background: #111; }
body.night .leaflet-tile-pane { filter: sepia(1) saturate(3) hue-rotate(-40deg) brightness(.55); }
.leaflet-gl-layer { pointer-events: none; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.leaflet-control-scale-line { font: 600 11px var(--sans); }

/* Popuper — pergamentkort */
.leaflet-popup-content-wrapper { background: var(--popup-bg); color: var(--popup-text); border-radius: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--popup-line); }
.leaflet-popup-tip { background: var(--popup-bg); border: 1px solid var(--popup-line); }
.leaflet-container a.leaflet-popup-close-button { color: var(--popup-muted); font-size: 22px; width: 32px; height: 32px; top: 6px; right: 6px; }
.leaflet-popup-content { margin: 14px 16px; font-size: 15px; min-width: 230px; line-height: 1.45; }
.leaflet-popup-content h4 { margin: 0 0 6px; font: 700 18px/1.25 var(--display); color: var(--popup-text); padding-right: 22px; }
.leaflet-popup-content .muted { color: var(--popup-muted); }
.leaflet-popup-content table { border-collapse: collapse; font-size: 14px; }
.leaflet-popup-content td { padding: 2px 8px 2px 0; vertical-align: top; }
.leaflet-popup-content .asp { border-left: 4px solid #888; padding: 5px 9px; margin: 6px 0; background: rgba(0, 0, 0, .04); border-radius: 0 8px 8px 0; }
.leaflet-popup-content .pbtns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.leaflet-popup-content .pbtns button { min-height: 44px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--popup-primary);
  background: var(--popup-primary); color: var(--popup-primary-text); font-weight: 600; display: inline-flex; align-items: center; gap: 7px; }
.leaflet-popup-content .pbtns button.sec { background: #eef2f6; color: #13202d; border-color: #d5dde5; }
body.night .leaflet-popup-content .pbtns button.sec { background: transparent; color: var(--text); border-color: var(--line-strong); }
.leaflet-popup-content .metar { background: rgba(0, 0, 0, .04); color: var(--popup-text); border-color: var(--popup-line); }
.leaflet-popup-content .metar .muted { color: var(--popup-muted); }
.popinfo { display: flex; align-items: center; gap: 6px; }

/* Kartsymboler */
.wp-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--route); border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5); color: #fff; font: 700 13px/25px var(--sans); text-align: center; }
.wp-label { background: rgba(255, 255, 255, .94); color: #111; border: 0; border-radius: 7px;
  font: 700 13px/1.3 var(--sans); padding: 2px 7px; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); white-space: nowrap; }
.draw-label, .draw-seg { background: rgba(15, 23, 32, .88); color: #fff; border: 0; border-radius: 7px; padding: 2px 7px;
  font: 700 12px/1.3 var(--mono); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); white-space: nowrap; }
.leg-label { background: var(--route); color: #fff; border: 0; border-radius: 7px; padding: 2px 7px;
  font: 600 12px/1.3 var(--mono); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); white-space: nowrap; }
.wp-label::before, .leg-label::before, .draw-label::before, .draw-seg::before, .ap-label::before { display: none; }
.ap-label { background: transparent; border: 0; box-shadow: none; color: #0b2a6b; font: 700 11px var(--sans);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff; padding: 0; }
.own-ship { width: 56px; height: 56px; }
.own-ship svg { width: 56px; height: 56px; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .8)); transition: transform .3s linear; }
.wxdot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px #000; }
.dvert { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid #ff375f; color: #111;
  font: 700 10px/16px var(--sans); text-align: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.dpin { width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5); margin: 1px 2px; }

/* ---------- Kontrollräcke (knapparna till höger) ---------- */
#fab { position: absolute; z-index: 900; right: calc(10px + var(--safeR)); top: 10px; bottom: 10px;
  display: flex; flex-direction: column; gap: 8px; overflow-y: auto; scrollbar-width: none; }
#fab::-webkit-scrollbar { display: none; }
#fab .grp { display: flex; flex-direction: column; gap: 3px; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 18px; padding: 4px; box-shadow: var(--shadow); }
#fab button { position: relative; width: 64px; height: 58px; border: 0; border-radius: 13px; background: transparent;
  color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: background-color .15s, color .15s; }
#fab .grp button + button::before { content: ""; position: absolute; top: -2px; left: 14px; right: 14px; height: 1px; background: var(--line); }
#fab button small { font-size: 10px; color: var(--muted); line-height: 1; }
#fab button:active { background: var(--raise); }
#fab button.on { background: linear-gradient(180deg, var(--accent-strong), var(--accent)); color: var(--accent-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25); }
#fab button.on::before, #fab button.on + button::before { opacity: 0; }
#fab button.on small { color: var(--accent-text); }
#fab .grp.zoom button { height: 50px; }
@media (max-height: 720px) { #fab button { height: 50px; } #fab button small { display: none; } }

/* Lägesbanner (ruttläge) */
#editBanner { position: absolute; z-index: 950; left: calc(10px + var(--safeL)); top: 10px; max-width: calc(100% - 110px);
  background: var(--panel); color: var(--text); border: 1px solid var(--route); border-left: 5px solid var(--route);
  padding: 8px 8px 8px 14px; border-radius: var(--radius); display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); }
#editBanner .ic { color: var(--route); }
#toast { position: absolute; z-index: 1200; left: 50%; bottom: 26px; transform: translateX(-50%); max-width: 80%;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-strong); border-left: 4px solid var(--accent);
  padding: 12px 18px; border-radius: 12px; font-size: 15px; pointer-events: none; text-align: center; box-shadow: var(--shadow); }

/* ---------- Knappar ---------- */
.btn { min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--panel2);
  color: var(--text); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { background: var(--raise); }
.btn .ic { color: var(--accent); }
.btn.primary { background: linear-gradient(180deg, var(--accent-strong), var(--accent)); color: var(--accent-text); border-color: var(--accent); }
.btn.primary .ic { color: var(--accent-text); }
.btn.danger { color: var(--bad); } .btn.danger .ic { color: var(--bad); }
.btn.small { min-height: 42px; padding: 0 12px; font-size: 14px; }
.btn.icon { padding: 0; width: 44px; min-height: 44px; }
.btn[disabled] { opacity: .6; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
#editBanner button, .modalbtns button { min-height: 44px; padding: 0 18px; border: 0; border-radius: 11px; font-weight: 700;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent)); color: var(--accent-text); display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Popover (lager) ---------- */
.popover { position: absolute; z-index: 1001; right: calc(88px + var(--safeR)); top: 10px; width: 350px; max-height: calc(100% - 20px);
  overflow-y: auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 18px; padding: 10px 16px 14px;
  box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.popover h3 { margin: 12px 0 4px; font-size: 12px; color: var(--muted); }
.lrow { display: flex; align-items: center; gap: 12px; min-height: 50px; border-bottom: 1px solid var(--line); }
.lrow:last-child { border-bottom: 0; }
.lrow label { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 50px; }
.lrow input[type=radio], .lrow input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.lrow .note { display: block; font-size: 12px; color: var(--muted); }
.lrow input[type=range] { width: 86px; accent-color: var(--accent); }

/* ---------- Terrängprofil ---------- */
#profilePanel { position: absolute; z-index: 890; left: calc(10px + var(--safeL)); right: calc(92px + var(--safeR));
  bottom: calc(10px + var(--safeB)); height: 190px; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
body.side-open #profilePanel { left: calc(min(440px, 92vw) + 10px); }
#profileCanvas { width: 100%; height: 100%; display: block; }
#profileLegend { position: absolute; top: 6px; right: 12px; font: 12px var(--serif); color: var(--muted); }

/* ---------- Sidopanel ---------- */
#side { position: absolute; z-index: 1100; top: calc(var(--instH) + var(--safeT)); bottom: 0; left: 0; width: min(440px, 92vw);
  background: var(--panel); border-right: 1px solid var(--line-strong); display: flex; flex-direction: column;
  box-shadow: 6px 0 28px rgba(0, 0, 0, .4); padding-left: var(--safeL); padding-bottom: var(--safeB); }
.tabs { display: flex; border-bottom: 1px solid var(--line-strong); flex: none; background: var(--bg); }
.tabs button { flex: 1; min-height: 62px; border: 0; background: transparent; color: var(--muted); padding: 6px 2px 4px;
  border-bottom: 2px solid transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.tabs button span { font-size: 10.5px; line-height: 1; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--panel); }
.tabs button.close { flex: 0 0 52px; color: var(--muted); }
.tabbody { flex: 1; overflow-y: auto; padding: 12px 16px 40px; -webkit-overflow-scrolling: touch; }
.tabbody h3 { margin: 20px 0 8px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tabbody h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tabbody h3:first-child { margin-top: 4px; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 54px; border-bottom: 1px solid var(--line); }
.field > span { flex: 1; }
.field small { display: block; color: var(--muted); font-size: 12px; }
.field input, .field select, .search { min-height: 44px; font-size: 17px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); padding: 0 10px; }
.field input:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.field input[type=number] { width: 110px; text-align: right; font-family: var(--mono); }
.field input[type=text], .field input[type=password], .field input[type=url] { width: 210px; }
.field input[type=datetime-local] { width: 230px; }
.field input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }
.search { width: 100%; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.okbox, .warnbox, .badbox { display: flex; gap: 10px; align-items: flex-start; border-radius: 12px; padding: 10px 12px; margin: 8px 0;
  font-size: 14px; border: 1px solid; background: var(--panel2); }
.okbox { border-color: var(--ok); } .okbox > .ic { color: var(--ok); }
.warnbox { border-color: var(--warn); } .warnbox > .ic { color: var(--warn); }
.badbox { border-color: var(--bad); } .badbox > .ic { color: var(--bad); }
.okbox > div, .warnbox > div, .badbox > div { flex: 1; }

/* Navlogg och brytpunkter */
.wplist { list-style: none; margin: 0; padding: 0; }
.wplist li { display: flex; align-items: center; gap: 6px; min-height: 54px; border-bottom: 1px solid var(--line); }
.wplist .num { width: 28px; height: 28px; border-radius: 50%; background: var(--route); color: #fff; font: 700 13px var(--sans);
  display: flex; align-items: center; justify-content: center; flex: none; }
.wplist .nm { flex: 1; min-width: 0; }
.wplist .nm input { width: 100%; min-height: 40px; font: 600 16px var(--serif); border: 1px solid transparent; background: transparent;
  color: var(--text); border-radius: 8px; padding: 0 6px; }
.wplist .nm input:focus { border-color: var(--line-strong); background: var(--bg); }
.wplist .alt { width: 76px; min-height: 40px; font: 15px var(--mono); text-align: right; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); padding: 0 6px; }
.wplist .ib { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center; color: var(--muted); }
.wplist .ib:active { background: var(--raise); }
.wplist li.active { background: rgba(242, 182, 50, .12); }
table.navlog { width: 100%; border-collapse: collapse; font: 13px/1.3 var(--mono); margin-top: 6px; }
table.navlog th { font: 600 11px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: right;
  padding: 4px 3px; border-bottom: 1px solid var(--line-strong); }
table.navlog td { text-align: right; padding: 7px 3px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.navlog td:first-child, table.navlog th:first-child { text-align: left; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
table.navlog td:first-child { font-family: var(--serif); font-weight: 600; }
table.navlog tr.tot td { font-weight: 700; border-top: 2px solid var(--line-strong); }
table.navlog .warnmark { color: var(--warn); vertical-align: -3px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 15px; }
.kv b { font-variant-numeric: tabular-nums; }

/* Fältlista */
.aplist { list-style: none; margin: 0; padding: 0; }
.aplist li { display: flex; align-items: center; gap: 8px; min-height: 62px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.aplist .info { flex: 1; min-width: 0; }
.aplist .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font: 600 16px var(--serif); }
.aplist .info span { font-size: 13px; color: var(--muted); }
.aplist .dist { text-align: right; font: 600 17px/1.2 var(--mono); min-width: 84px; }
.aplist .dist small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.tag { display: inline-block; font: 700 11px var(--sans); padding: 1px 6px; border-radius: 6px; background: var(--panel2);
  border: 1px solid var(--line); margin-right: 5px; vertical-align: 2px; }
.tag.ul, .aplist .info .tag.ul, .aplist .info .tag.ul { background: #2d7d46; color: #fff; border-color: #2d7d46; }

/* Väder */
.metar { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; margin: 6px 0;
  font: 13px/1.45 var(--mono); -webkit-user-select: text; user-select: text; white-space: pre-wrap; }
.metar .st { font: 600 15px var(--serif); display: flex; justify-content: space-between; margin-bottom: 4px; }
.cat { font: 700 12px var(--sans); padding: 1px 8px; border-radius: 8px; color: #fff; }
.cat.VFR { background: #2d9d4f; } .cat.MVFR { background: #1f6fd0; } .cat.IFR { background: #d33; } .cat.LIFR { background: #a020c0; }

/* Modal */
#modal { position: absolute; inset: 0; z-index: 2000; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; }
.modalbox { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 20px; width: min(580px, 92vw); max-height: 86vh;
  overflow-y: auto; padding: 20px 22px; box-shadow: var(--shadow); }
.modalbox h3 { font: 700 21px/1.25 var(--display); margin: 0 0 12px; color: var(--text); }
.modalbtns { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ---------- Ritverktyg ---------- */
#drawBar { position: absolute; z-index: 960; left: calc(10px + var(--safeL)); top: 10px; max-width: calc(100% - 110px);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 18px; padding: 5px; box-shadow: var(--shadow); }
#drawBar .dbtns { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
#drawBar button { min-width: 60px; height: 56px; border-radius: 13px; border: 0; background: transparent; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
#drawBar button small { font-size: 10px; color: var(--muted); line-height: 1; }
#drawBar button:active { background: var(--raise); }
#drawBar button.on, #drawBar button.primary { background: linear-gradient(180deg, var(--accent-strong), var(--accent)); color: var(--accent-text); }
#drawBar button.on small, #drawBar button.primary small { color: var(--accent-text); }
#drawBar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 6px 4px; }
#drawReadout { padding: 8px 8px 3px; font: 16px var(--sans); font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); margin-top: 5px; }
.asp { border-radius: 0 10px 10px 0; background: var(--panel2); }
.asp.asp-bad { background: rgba(255, 90, 82, .14); }
.asp.asp-warn { background: rgba(255, 176, 32, .12); }
.aplist .info b.popinfo { display: flex; align-items: center; gap: 6px; }
.aplist .info b.popinfo .ic { color: var(--accent); }

/* ---------- UX-detaljer ---------- */
.inst.tappable { cursor: pointer; }
.inst.tappable .lbl { display: inline-flex; align-items: center; gap: 3px; }
.inst.tappable:active { background: var(--panel2); }
/* vald baskarta och aktiva lager markeras tydligt */
.lrow { border-radius: 10px; padding: 0 8px; margin: 0 -8px; border-bottom-color: transparent; }
.lrow + .lrow { border-top: 1px solid var(--line); }
.lrow:has(input:checked) { background: var(--panel2); }
/* tomma lägen */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 22px 12px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); margin: 6px 0; }
.empty .ic { color: var(--accent); margin-bottom: 4px; }
.empty b { color: var(--text); font-size: 16px; }
.empty span { font-size: 14px; line-height: 1.45; }
/* tydlig tangentbords-/fokusmarkering */
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Lagerpanel: baskartor som kort, kartlager som reglage */
.basegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 4px; }
.basecard { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--panel2); font-weight: 600; font-size: 15px; cursor: pointer; }
.basecard input { position: absolute; opacity: 0; pointer-events: none; }
.basecard .ic { color: var(--muted); }
.basecard.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.basecard.on .ic { color: var(--accent); }
.lrow label { justify-content: space-between; font-size: 16px; }
.lrow:has(input:checked) { background: transparent; }
.lrow input[type=range] { width: 100%; margin: -6px 0 10px; }
.lrow { flex-wrap: wrap; }
.lrow label { flex: 1 1 100%; }
input.switch { -webkit-appearance: none; appearance: none; width: 50px !important; height: 30px !important; border-radius: 15px;
  background: var(--raise); border: 1px solid var(--line-strong); position: relative; transition: background .15s; flex: none; margin: 0; }
input.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: transform .15s; }
input.switch:checked { background: var(--accent); border-color: var(--accent); }
input.switch:checked::after { transform: translateX(20px); }

/* Sökbart väderfält */
.wxsearch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 52px; padding: 5px 6px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--bg); }
.wxsearch:focus-within { outline: 2px solid var(--accent); }
.wxsearch input { flex: 1; min-width: 140px; min-height: 40px; border: 0; background: transparent; color: var(--text); font-size: 17px; outline: none; padding: 0 6px; }
.chips { display: contents; }
.chip { display: inline-flex; align-items: center; gap: 2px; height: 36px; padding: 0 2px 0 12px; border-radius: 18px; background: var(--panel2);
  border: 1px solid var(--line-strong); font: 700 15px var(--mono); }
.chip button { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; border-radius: 16px; }
.suggest { list-style: none; margin: 6px 0 0; padding: 4px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel);
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; }
.suggest button { width: 100%; min-height: 50px; display: flex; align-items: center; gap: 12px; padding: 0 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); text-align: left; }
.suggest button:active { background: var(--raise); }
.suggest b { font: 700 16px var(--mono); min-width: 52px; }
.suggest span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest small { color: var(--muted); font-size: 12px; white-space: nowrap; }
#editBanner button.sec { background: var(--panel2); color: var(--text); border: 1px solid var(--line-strong); }
#editBanner button.sec .ic { color: var(--accent); }
.lrow:has([data-manage]) label { flex: 1 1 auto; }
.lrow:has([data-manage]) { flex-wrap: nowrap; gap: 8px; }
.modalbox h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 6px; }

/* Konto */
#side { width: min(470px, 94vw); }
body.side-open #profilePanel { left: calc(min(470px, 94vw) + 10px); }
.tabs button { padding: 6px 0 4px; min-width: 0; }
.tabs button span { font-size: 9.5px; letter-spacing: .04em; }
.tabs button.close { flex: 0 0 44px; }
.seg { display: flex; background: var(--panel2); border: 1px solid var(--line-strong); border-radius: 12px; padding: 3px; margin: 4px 0 8px; }
.seg button { flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.field input[type=email] { width: 240px; }
.acct { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.acct .ic { color: var(--accent); }
.acct b { display: block; font-size: 16px; }
.acct span { font-size: 13px; color: var(--muted); }
.benefits { list-style: none; margin: 0; padding: 0; }
.benefits li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; font-size: 15px; }
.benefits .ic { color: var(--accent); margin-top: 1px; }

/* ---------- Inloggningssida ---------- */
#gate { position: fixed; inset: 0; z-index: 5000; background: var(--bg); display: flex; align-items: center; justify-content: center; overflow: hidden; }
#gate .scene { position: absolute; inset: 0; width: 100%; height: 100%; }

.gatecard { position: relative; width: min(420px, calc(100vw - 32px)); background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line-strong); border-radius: 22px; padding: 24px 24px 20px; box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); margin-bottom: 18vh; }
@media (orientation: portrait) { .gatecard { margin-bottom: 30vh; } }
.gatecard .brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.gatecard .brand img { border-radius: 12px; }
.gatecard h1 { margin: 0; font: 700 26px/1.1 var(--display); letter-spacing: -.01em; }
.gatecard p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.authform { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.afield { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.afield input { min-height: 48px; font-size: 17px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); padding: 0 12px; }
.afield input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.btn.wide { width: 100%; min-height: 52px; font-size: 16px; margin-top: 4px; }
.linkbtn { background: none; border: 0; color: var(--accent); font-weight: 600; min-height: 40px; align-self: center; }
.muted.small { font-size: 12px; text-align: center; }
body.gated #fab, body.gated #instruments { visibility: hidden; }

/* ---------- Landskap på inloggningssidan (skymning, stiliserat, med rörelse) ---------- */
#gate { background: #0b121a; }
.scene .sk0 { stop-color: #0a1018; } .scene .sk1 { stop-color: #16273a; } .scene .sk2 { stop-color: #2a4157; }
.scene .gl0 { stop-color: #f2b632; stop-opacity: .22; } .scene .gl1 { stop-color: #f2b632; stop-opacity: 0; }
.scene .moon { fill: #f4d58d; }
.scene .star { fill: #dfe7ef; }
.scene .cl { fill: #2a3f55; opacity: .55; }
.scene .m1 { fill: #31475e; } .scene .snow { fill: none; stroke: #9fb3c6; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.scene .m2 { fill: #263a4f; } .scene .m3 { fill: #1d2e40; }
.scene .tr { fill: #16263a; } .scene .tr.far { fill: #18293b; } .scene .tr.near { fill: #0a121a; }
.scene .vale { fill: #19293a; }
.scene .field.f1 { fill: #22364a; } .scene .field.f2 { fill: #283f53; }
.scene .furrow { fill: none; stroke: #304a62; stroke-width: 1.5; }
.scene .lake { fill: #2b4d68; } .scene .river { fill: none; stroke: #2b4d68; stroke-width: 9; stroke-linecap: round; }
.scene .moonpath { fill: none; stroke: #f4d58d; stroke-width: 2.5; stroke-linecap: round; }
.scene .ripple-static { fill: none; stroke: #6f93b1; stroke-width: 1.5; stroke-linecap: round; opacity: .45; }
.scene .strip { fill: none; stroke: #2f4a3c; stroke-width: 10; stroke-linecap: round; }
.scene .stripmk { fill: none; stroke: #8ea2b6; stroke-width: 1.5; stroke-linecap: round; opacity: .7; }
.scene .hs { fill: #101c27; } .scene .door { fill: none; stroke: #2c3d50; stroke-width: 1.5; }
.scene .win { fill: #f2b632; }
.scene .road { fill: none; stroke: #2c3d50; stroke-width: 2.5; stroke-dasharray: 2 5; stroke-linecap: round; }
.scene .pole { stroke: #8ea2b6; stroke-width: 2; }
.scene .sockp { fill: #f2b632; }
.scene .pad { fill: #22364a; stroke: #8ea2b6; stroke-width: 1.2; } .scene .padh { fill: none; stroke: #f2b632; stroke-width: 1.6; stroke-linecap: round; }
.scene .dock { fill: none; stroke: #6c5a46; stroke-width: 5; stroke-linecap: round; }
.scene .dock.thin { stroke-width: 2.5; }
.scene .cab { fill: #2a2018; } .scene .cab-roof { fill: #14100c; } .scene .cab-chim { fill: #14100c; }
.scene .cab-log { fill: none; stroke: #3d2f22; stroke-width: 1.2; } .scene .cab-door { fill: #14100c; stroke: none; }
.scene .smoke { fill: none; stroke: #8ea2b6; stroke-width: 2; stroke-linecap: round; opacity: .35; }
.scene .logs { fill: none; stroke: #6c5a46; stroke-width: 2.5; stroke-linecap: round; }
.scene .flame.f1 path { fill: #f2b632; } .scene .flame.f2 path { fill: #ff7a2e; }
.scene .spark { fill: #ffcf6b; opacity: 0; }
.scene .fireglow { opacity: .9; }
.scene .pier { fill: #6c5a46; } .scene .pier-post { stroke: #4a3c2e; stroke-width: 2; stroke-linecap: round; }
.scene .fg { fill: #0d161f; }
.scene .ring { fill: none; stroke: #9fc0d8; stroke-width: 1.4; opacity: 0; }
.scene .ac-body, .scene .ac-wheel { fill: #f2b632; }
.scene .ac-line { fill: none; stroke: #6b4a00; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.scene .ac-hub { fill: #6b4a00; }
.scene .ac-rotor { fill: none; stroke: #f2b632; stroke-width: 2.4; stroke-linecap: round; }

/* rörelse */
.scene .fly, .scene .bobsky, .scene .drift, .scene .heli, .scene .bob, .scene .ring, .scene .sock, .scene .ac-rotor, .scene .star, .scene .shimmer {
  transform-box: fill-box; transform-origin: center; }
.scene .fly.near { animation: scFly 42s linear infinite; }
.scene .flame, .scene .spark, .scene .smoke, .scene .fireglow { transform-box: fill-box; }
.scene .flame { transform-origin: 50% 100%; }
.scene .flame.f1 { animation: scFlicker .9s ease-in-out infinite; }
.scene .flame.f2 { animation: scFlicker 1.3s ease-in-out infinite reverse; }
.scene .fireglow { transform-origin: center; animation: scGlowPulse 1.1s ease-in-out infinite alternate; }
.scene .spark.k1 { animation: scSpark 2.2s ease-out infinite; --dx: 4px; }
.scene .spark.k2 { animation: scSpark 2.8s ease-out infinite .9s; --dx: -3px; }
.scene .spark.k3 { animation: scSpark 2.5s ease-out infinite 1.6s; --dx: 2px; }
.scene .smoke { animation: scSmoke 6s ease-out infinite; }
.scene .glow-win { animation: scWin 4s ease-in-out infinite; }
.scene .fly.far { animation: scFly 95s linear infinite; animation-delay: -40s; opacity: .8; }
.scene .bobsky { animation: scBob 5s ease-in-out infinite alternate; }
.scene .drift.d1 { animation: scDrift 80s ease-in-out infinite alternate; }
.scene .drift.d2 { animation: scDrift 110s ease-in-out infinite alternate-reverse; }
.scene .drift.d3 { animation: scDrift 95s ease-in-out infinite alternate; }
.scene .heli { animation: scHeli 16s ease-in-out infinite; }
.scene .ac-rotor { animation: scRotor .22s linear infinite alternate; }
.scene .bob { animation: scBobSmall 3.2s ease-in-out infinite alternate; }
.scene .ring.r1 { animation: scRing 5s ease-out infinite; }
.scene .ring.r2 { animation: scRing 5s ease-out infinite; animation-delay: 2.5s; }
.scene .sock { transform-origin: left center; animation: scSock 2.6s ease-in-out infinite alternate; }
.scene .shimmer { animation: scShimmer 3.5s ease-in-out infinite alternate; }
.scene .star.s0 { animation: scTwinkle 3.1s ease-in-out infinite alternate; }
.scene .star.s1 { animation: scTwinkle 4.3s ease-in-out infinite alternate; animation-delay: -1.5s; }
.scene .star.s2 { animation: scTwinkle 5.7s ease-in-out infinite alternate; animation-delay: -3s; }
@keyframes scFlicker { 0% { transform: scale(1, 1); } 30% { transform: scale(.92, 1.12); } 55% { transform: scale(1.06, .9); } 80% { transform: scale(.96, 1.08); } 100% { transform: scale(1, 1); } }
@keyframes scGlowPulse { from { opacity: .7; } to { opacity: 1; } }
@keyframes scSpark { 0% { transform: translate(0, 0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(var(--dx, 3px), -26px); opacity: 0; } }
@keyframes scSmoke { 0% { transform: translateY(4px); opacity: 0; } 30% { opacity: .38; } 100% { transform: translate(6px, -14px); opacity: 0; } }
@keyframes scWin { 0%, 100% { opacity: 1; } 50% { opacity: .78; } }
@keyframes scFly { from { transform: translateX(-260px); } to { transform: translateX(1900px); } }
@keyframes scBob { from { transform: translateY(-6px); } to { transform: translateY(6px); } }
@keyframes scBobSmall { from { transform: translateY(0); } to { transform: translateY(1.6px); } }
@keyframes scDrift { from { transform: translateX(-90px); } to { transform: translateX(90px); } }
@keyframes scRotor { from { transform: scaleX(.35); } to { transform: scaleX(1); } }
@keyframes scRing { 0% { transform: scale(.5); opacity: .7; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes scSock { from { transform: rotate(-7deg); } to { transform: rotate(5deg); } }
@keyframes scShimmer { from { opacity: .2; } to { opacity: .75; } }
@keyframes scTwinkle { from { opacity: .25; } to { opacity: 1; } }
@keyframes scHeli {
  0%, 12% { transform: translateY(0); }
  40% { transform: translateY(-64px); }
  48% { transform: translateY(-60px); } 56% { transform: translateY(-66px); } 64% { transform: translateY(-60px); } 72% { transform: translateY(-64px); }
  92%, 100% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .scene * { animation: none !important; } .scene .fly.near { transform: translateX(420px); } .scene .fly.far { transform: translateX(1000px); } }
#gateNote:not(:empty) { margin-bottom: 6px; }

/* Påskägg: gryning efter en stund på inloggningssidan */
.scene .dawnsky { opacity: 0; transition: opacity 16s ease-in-out 4s; }
.scene .stars { transition: opacity 8s ease; }
.scene .moonset { transition: transform 14s ease-in; }
.scene .sunrise { transform: translateY(330px); transition: transform 18s ease-out 6s; }
.scene .sun { fill: #ffe39a; }
.scene .birds { opacity: 0; transform: translate(-120px, 230px); }
.scene .bird { fill: none; stroke: #1d2e40; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scene :is(.m1, .m2, .m3, .tr, .vale, .lake, .river, .fg, .cl, .hs, .cab, .cab-roof, .strip, .pad) { transition: fill 16s ease 4s, stroke 16s ease 4s; }
.scene .win, .scene .fireglow { transition: opacity 10s ease 8s; }
.scene.dawn .dawnsky { opacity: 1; }
.scene.dawn .stars { opacity: 0; }
.scene.dawn .moonset { transform: translateY(260px); }
.scene.dawn .sunrise { transform: translateY(0); }
.scene.dawn .m1 { fill: #7d90aa; } .scene.dawn .m2 { fill: #64789a; } .scene.dawn .m3 { fill: #52688a; }
.scene.dawn .tr, .scene.dawn .tr.far { fill: #3a5272; } .scene.dawn .tr.near { fill: #1e2c3d; }
.scene.dawn .vale { fill: #4b6185; } .scene.dawn .fg { fill: #2a3a50; }
.scene.dawn .lake { fill: #79a8cc; } .scene.dawn .river { stroke: #79a8cc; }
.scene.dawn .cl { fill: #f4ddc6; } .scene.dawn .hs { fill: #2c3a4c; }
.scene.dawn .strip { stroke: #4f7a52; } .scene.dawn .pad { fill: #52688a; }
.scene.dawn .win { opacity: 0; animation: none; } .scene.dawn .fireglow { opacity: .35; animation: none; }
.scene.dawn .moonpath { stroke: #fff1c4; }
.scene.dawn .birds { animation: scBirds 30s linear 14s infinite; }
@keyframes scBirds { 0% { transform: translate(-120px, 230px); opacity: 0; } 5% { opacity: 1; } 95% { opacity: 1; } 100% { transform: translate(1800px, 150px); opacity: 0; } }
