:root {
  --bg: #101a24;
  --panel: #1a2836;
  --panel2: #223548;
  --text: #eef3f8;
  --muted: #9fb1c3;
  --gold: #ffd54a;
  --accent: #ffb300;
  --danger: #ff6b6b;
  --ok: #4cd97b;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { min-height: 100dvh; }
button, input { font: inherit; color: inherit; }
h1, h2 { margin: 0; }

/* Startscherm */
.screen { min-height: 100dvh; display: flex; align-items: flex-start; justify-content: center; padding: 20px 16px; background: radial-gradient(circle at 50% 0%, #25465f, var(--bg) 60%); }
.start-card { margin: auto; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.logo { align-self: center; border-radius: 20px; }
.start-card h1 { font-size: 2rem; letter-spacing: .5px; color: var(--gold); }
.lead { margin: 0; color: var(--text); line-height: 1.45; }
.consent { background: var(--panel); border-radius: 12px; padding: 12px 14px; text-align: left; font-size: .9rem; color: var(--muted); line-height: 1.4; }
.consent p { margin: 0 0 8px; }
.consent p:last-child { margin: 0; }
.consent strong { color: var(--text); }
.safety { background: #3a2a10; border: 1px solid var(--accent); color: #ffe3a3; border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .95rem; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: .85rem; color: var(--muted); }
.field input { background: var(--panel); border: 1px solid #35506a; border-radius: 10px; padding: 12px; font-size: 1.05rem; color: var(--text); }
.field input:focus { outline: 2px solid var(--gold); }
.error { margin: 0; color: var(--danger); font-size: .92rem; line-height: 1.4; }
.link { background: none; border: 0; color: #8cc4ff; text-decoration: underline; padding: 10px; cursor: pointer; }

.btn { background: var(--panel2); border: 1px solid #3d5a76; border-radius: 12px; padding: 12px 18px; cursor: pointer; font-weight: 600; min-height: 44px; }
.btn.primary { background: linear-gradient(#ffd54a, #f0a800); color: #3a2600; border-color: #b87f00; }
.btn.big { font-size: 1.15rem; padding: 14px; }
.btn.small { padding: 8px 12px; min-height: 40px; font-size: .9rem; }
.btn.danger { background: #4a2020; border-color: #8c3b3b; color: #ffbcbc; }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }

/* Hoofdlayout */
#app { position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: var(--app-h, 100dvh); display: flex; flex-direction: column; overflow: hidden; }
#topbar { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l)); flex: 0 0 auto; background: var(--panel); z-index: 20; }
.status { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.status.online .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.badge { background: #3b2e63; color: #d6c7ff; border-radius: 999px; padding: 2px 10px; font-size: .75rem; }
.icon-btn { background: none; border: 0; font-size: 1.5rem; padding: 4px 8px; cursor: pointer; min-width: 44px; min-height: 40px; }
#banners { z-index: 19; }
.banner { background: #5a3a00; color: #ffe3a3; padding: 8px 14px; font-size: .88rem; line-height: 1.35; }

#views { position: relative; flex: 1; min-height: 0; }
.view { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #cfe3d1; }
#arWrap { position: absolute; inset: 0; background: #000; overflow: hidden; touch-action: none; }
.cam-msg { position: absolute; left: 16px; right: 16px; top: 40%; background: rgba(16, 26, 36, .92); padding: 16px; border-radius: 12px; text-align: center; }

#tabbar { flex: 0 0 auto; padding-left: var(--safe-l); padding-right: var(--safe-r); display: flex; background: var(--panel); border-top: 1px solid #2c4258; padding-bottom: var(--safe-b); z-index: 20; }
.tab { flex: 1; background: none; border: 0; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .8rem; cursor: pointer; min-height: 56px; }
.tab .ti { font-size: 1.4rem; line-height: 1; }
.tab.active { color: var(--gold); }

/* Doelkaart op de kaart */
.goal-card { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 500; background: rgba(16, 26, 36, .93); border: 1px solid #35506a; border-radius: 14px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); }
.goal-arrow { font-size: 1.7rem; color: var(--gold); width: 36px; text-align: center; transition: transform .3s linear; }
.goal-text { flex: 1; min-width: 0; }
.goal-dist { font-weight: 700; }
.goal-hint { font-size: .8rem; color: var(--muted); }
.fab { position: absolute; right: 10px; bottom: 28px; z-index: 500; background: rgba(16, 26, 36, .93); border: 1px solid #35506a; border-radius: 999px; padding: 10px 16px; cursor: pointer; min-height: 44px; }
.fab.attn { border-color: var(--gold); color: var(--gold); }

/* Kaart-iconen */
.leaflet-container { font-family: inherit; }
.chest-icon, .me-icon, .player-icon { background: none; border: 0; }
.chest-wrap { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45)); }
.chest-wrap.mine { filter: drop-shadow(0 0 6px #ffd54a) drop-shadow(0 2px 2px rgba(0, 0, 0, .45)); }
.chest-wrap.in-range svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.25); } }
.me-wrap { position: relative; width: 44px; height: 44px; }
.me-dot { position: absolute; left: 14px; top: 14px; width: 16px; height: 16px; background: #3b82f6; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 4px rgba(0, 0, 0, .5); }
.me-cone { position: absolute; inset: 0; display: none; transform-origin: 50% 50%; }
.me-cone::before { content: ""; position: absolute; left: 12px; top: -6px; width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 22px solid rgba(59, 130, 246, .55); }
.player-icon { transition: transform 1s linear; }
.player-wrap { width: 60px; display: flex; flex-direction: column; align-items: center; }
.player-name { background: rgba(16, 26, 36, .85); color: #fff; font-size: 11px; line-height: 1.2; padding: 1px 6px; border-radius: 8px; max-width: 76px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-top: 2px; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }

/* Rugzak */
#view-bag { overflow-y: auto; padding: 14px 14px 20px; background: var(--bg); }
.bag-head { margin-bottom: 12px; }
.bag-summary { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.bag-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.bag-card { position: relative; background: var(--panel); border: 2px solid var(--rar, #888); border-radius: 14px; padding: 12px 8px; text-align: center; }
.bag-emoji { font-size: 2.4rem; line-height: 1.2; }
.bag-name { font-weight: 700; margin-top: 4px; }
.bag-rarity { font-size: .78rem; color: var(--rar, #aaa); margin-top: 2px; }
.bag-count { position: absolute; top: 6px; right: 8px; background: var(--rar, #888); color: #10161c; font-weight: 800; border-radius: 999px; padding: 0 8px; font-size: .85rem; }
.bag-card.unknown { border-style: dashed; border-color: #3b4f63; opacity: .8; }
.bag-card.unknown .bag-emoji { filter: brightness(0); opacity: .35; }
.bag-card.unknown .bag-name, .bag-card.unknown .bag-rarity { color: var(--muted); }

/* Simulatie-bediening */
#simControls { position: absolute; left: 0; right: 0; bottom: 0; height: 0; z-index: 600; pointer-events: none; }
.joy { position: absolute; left: 18px; bottom: 28px; width: 110px; height: 110px; border-radius: 50%; background: rgba(16, 26, 36, .55); border: 2px solid rgba(255, 255, 255, .5); touch-action: none; pointer-events: auto; display: flex; align-items: center; justify-content: center; }
.joy-knob { width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 213, 74, .9); border: 2px solid #7a5200; }
.turn { position: absolute; left: 140px; bottom: 28px; display: flex; gap: 8px; pointer-events: auto; }
.turn button { width: 46px; height: 46px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: rgba(16, 26, 36, .65); font-size: 1.4rem; cursor: pointer; touch-action: none; }
.sim-help { position: absolute; left: 18px; bottom: 6px; font-size: .7rem; color: #fff; background: rgba(0, 0, 0, .45); border-radius: 6px; padding: 1px 6px; }

/* Overlays */
#toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); max-width: 90vw; background: rgba(16, 26, 36, .96); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 16px; z-index: 2000; text-align: center; font-weight: 600; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); }
.overlay { position: fixed; inset: 0; z-index: 1500; background: rgba(5, 10, 16, .78); display: flex; align-items: center; justify-content: center; padding: 16px; }
.panel { background: var(--panel); border: 1px solid #35506a; border-radius: 16px; padding: 18px; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px; }
.panel p { margin: 0; line-height: 1.4; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.check { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.check input { width: 22px; height: 22px; }
.fine { font-size: .8rem; color: var(--muted); }
hr { border: 0; border-top: 1px solid #2c4258; width: 100%; }
.spinner { width: 40px; height: 40px; border: 4px solid #35506a; border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; align-self: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.reward-panel { text-align: center; align-items: center; }
.reward-emoji { font-size: 5rem; animation: pop .5s ease-out; }
.reward-name { font-size: 1.4rem; font-weight: 800; color: var(--gold); }
.reward-rarity { font-weight: 700; letter-spacing: 1px; text-transform: uppercase; font-size: .85rem; }
.reward-text { color: var(--muted); }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.2); } 100% { transform: scale(1); opacity: 1; } }

@media (min-width: 700px) {
  #app { max-width: 560px; margin: 0 auto; border-left: 1px solid #2c4258; border-right: 1px solid #2c4258; }
  .bag-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Mobiel: weergave-wissel, radar, zwevende wisselknop */
body { touch-action: manipulation; }
.status { min-width: 0; }
#statusText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: flex; background: #0e1721; border: 1px solid #35506a; border-radius: 999px; padding: 3px; flex: 0 0 auto; }
.seg-btn { background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 999px; font-weight: 700; font-size: .9rem; cursor: pointer; min-height: 40px; white-space: nowrap; }
.seg-btn.active { background: linear-gradient(#ffd54a, #f0a800); color: #3a2600; }
.flip { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(18px + var(--safe-b) * 0); z-index: 700; background: linear-gradient(#ffd54a, #f0a800); color: #3a2600; border: 2px solid #b87f00; border-radius: 999px; padding: 12px 22px; font-weight: 800; font-size: 1.05rem; min-height: 52px; box-shadow: 0 4px 14px rgba(0,0,0,.5); cursor: pointer; white-space: nowrap; }
.flip:active { transform: translateX(-50%) translateY(1px); }
.radar { position: absolute; left: 10px; top: 10px; width: 112px; height: 112px; border-radius: 50%; z-index: 40; box-shadow: 0 2px 10px rgba(0,0,0,.5); touch-action: manipulation; }
.cam-goal { position: absolute; top: 10px; left: 132px; right: 10px; z-index: 40; background: rgba(16,26,36,.85); border: 1px solid #35506a; border-radius: 14px; padding: 8px 12px; font-weight: 700; text-align: left; line-height: 1.3; }
.cam-goal small { display: block; font-weight: 500; color: var(--muted); }
.goal-card { flex-wrap: wrap; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); }
.goal-card .btn { flex: 1 1 auto; }
.fab { right: calc(10px + var(--safe-r)); bottom: 84px; }
.joy { left: calc(18px + var(--safe-l)); }
@media (max-width: 400px) {
  #statusText { display: none; }
  .seg-btn { padding: 8px 9px; font-size: .85rem; }
  .goal-hint { display: none; }
  .tab { min-height: 52px; }
  .cam-goal { left: 126px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .tab { min-height: 44px; flex-direction: row; justify-content: center; gap: 8px; }
  #topbar { padding-top: calc(3px + var(--safe-t)); padding-bottom: 3px; }
  .flip { bottom: 10px; padding: 8px 16px; min-height: 44px; }
  .fab { bottom: 64px; }
  .radar { width: 88px; height: 88px; }
  .cam-goal { left: 108px; }
}

/* simulatie: draaiknoppen rechtsonder, zodat de wisselknop vrij blijft */
.turn { left: auto; right: calc(18px + var(--safe-r)); bottom: 28px; }

#view-cam.playing .radar, #view-cam.playing .cam-goal { display: none; }
