:root {
  --plum: #4b1d6b;
  --plum-2: #2c0f45;
  --pink: #ff3d7f;
  --red: #e8174a;
  --red-dark: #a30d34;
  --cream: #fff7ee;
  --mint: #2fd1ae;
  --mint-dark: #16977c;
  --gold: #ffc93c;
  --ink: #2a1838;
  --muted: #7d6a8a;
  --card: #ffffff;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,61,127,.35), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(47,209,174,.25), transparent 45%),
    linear-gradient(160deg, var(--plum), var(--plum-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
body.plain { padding: 24px 16px; min-height: 100%; }
[hidden] { display: none !important; }
h1, h2, h3, .btn, .fab, .logo { font-family: "Fredoka", "Nunito", sans-serif; }
a { color: var(--red); }

/* --- Logga --- */
.logo { margin: 0 0 4px; font-size: 38px; line-height: 1; color: var(--red); letter-spacing: .5px;
  text-shadow: 0 3px 0 var(--red-dark), 0 6px 14px rgba(163,13,52,.25); }
.logo span { display: block; font-size: 22px; color: var(--plum); text-shadow: none; margin-top: 6px; }
.sub { color: var(--muted); margin: 6px 0 20px; font-weight: 700; }

/* --- Kort & knappar --- */
.card { background: var(--card); border-radius: 28px; padding: 28px 22px; box-shadow: 0 8px 0 rgba(0,0,0,.18), 0 20px 40px rgba(0,0,0,.25); }
.narrow { max-width: 420px; margin: 0 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 12px 20px; font-size: 17px; font-weight: 600;
  color: #fff; background: linear-gradient(180deg, var(--pink), var(--red));
  box-shadow: 0 4px 0 var(--red-dark); cursor: pointer; text-decoration: none;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-dark); }
.btn:disabled { opacity: .55; }
.btn.big { width: 100%; padding: 16px 22px; font-size: 20px; }
.btn.small { padding: 8px 14px; font-size: 15px; box-shadow: 0 3px 0 var(--red-dark); }
.btn.ghost { background: #fff; color: var(--red); box-shadow: 0 3px 0 #f0c9d5, inset 0 0 0 2px #ffd1df; }
.btn.danger.ghost { color: #b3123e; }
.btn.mint { background: linear-gradient(180deg, #4de8c6, var(--mint)); box-shadow: 0 4px 0 var(--mint-dark); }

input, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink);
  border: 2px solid #eadff0; border-radius: 16px; padding: 12px 14px; background: #fff;
  outline: none; transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--pink); }
textarea { resize: vertical; min-height: 64px; }
label { font-weight: 800; }
fieldset { border: 2px dashed #f1dce6; border-radius: 18px; margin: 0 0 16px; padding: 12px 14px; }
fieldset label { display: block; margin: 8px 0; font-size: 14px; }
fieldset input { margin-top: 4px; }
legend { font-weight: 800; color: var(--plum); padding: 0 6px; }

.warn { color: #b3123e; background: #ffe8ef; border-radius: 12px; padding: 8px 12px; font-weight: 700; }
.warn.small { font-size: 13px; padding: 6px 10px; margin: 6px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Login --- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login form { display: grid; gap: 14px; }
.login-candy { width: 72px; height: 72px; display: block; margin: -64px auto 8px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.25)); animation: wiggle 3s ease-in-out infinite; }
.login .card { text-align: center; }
@keyframes wiggle { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.pop { animation: pop .45s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --- Huvudvy --- */
#app { min-height: 100%; padding-bottom: calc(110px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 800; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px; color: #fff;
  background: linear-gradient(180deg, rgba(44,15,69,.95), rgba(44,15,69,.8));
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 34px; height: 34px; }
.brand b { font-family: "Fredoka"; font-size: 20px; display: block; line-height: 1; }
.brand small { opacity: .75; font-weight: 700; }
.gps-badge { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.12); padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; }
.gps-badge i { width: 10px; height: 10px; border-radius: 50%; background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.3); }
.gps-badge.ok i { background: #4de8c6; box-shadow: 0 0 0 3px rgba(77,232,198,.3); animation: pulse 1.6s infinite; }
.gps-badge.meh i { background: var(--gold); box-shadow: 0 0 0 3px rgba(255,201,60,.3); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(77,232,198,0); } }

.map { height: 46vh; min-height: 260px; margin: 0 12px; border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 6px 0 rgba(0,0,0,.25); border: 4px solid #fff; z-index: 1; }
.map-btn { position: relative; float: right; margin: -58px 24px 0 0; z-index: 500; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: #fff; color: var(--plum); font-size: 22px; box-shadow: 0 3px 0 rgba(0,0,0,.2); }

.panel { margin: 18px 12px 0; background: var(--cream); border-radius: var(--radius); padding: 16px; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; }
.panel-head h2 { margin: 0 0 10px; color: var(--plum); }
.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.qitem { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 3px 0 #efdfe8; cursor: pointer; }
.qitem:active { transform: scale(.98); }
.qnum { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-family: "Fredoka"; font-weight: 700;
  background: repeating-linear-gradient(135deg, var(--red) 0 6px, var(--pink) 6px 12px); box-shadow: 0 2px 0 var(--red-dark); }
.qthumb { flex: none; width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: #f4e9f1; }
.qtext { flex: 1; min-width: 0; }
.qtext b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; }
.qtext small { color: var(--muted); font-weight: 700; }
.qflag { font-size: 12px; font-weight: 800; color: #b3123e; }
.empty { color: var(--muted); text-align: center; padding: 12px; }
.footer-links { text-align: center; margin: 16px 0 0; font-weight: 700; }

.fab {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 900;
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 999px; padding: 16px 28px 16px 18px;
  font-size: 21px; font-weight: 700; color: #fff; white-space: nowrap;
  background: linear-gradient(180deg, var(--pink), var(--red)); box-shadow: 0 6px 0 var(--red-dark), 0 14px 30px rgba(0,0,0,.35);
}
.fab:active { transform: translateX(-50%) translateY(4px); box-shadow: 0 2px 0 var(--red-dark); }
.fab-plus { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #fff; color: var(--red); font-size: 26px; line-height: 1; }

/* Kartmarkörer */
.pin { width: 36px; height: 44px; position: relative; }
.pin b { position: absolute; inset: 0 0 8px 0; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); transform-origin: 50% 50%;
  background: repeating-linear-gradient(90deg, var(--red) 0 5px, var(--pink) 5px 10px); border: 3px solid #fff; box-shadow: 0 3px 6px rgba(0,0,0,.35); }
.pin span { position: absolute; top: 5px; left: 0; right: 0; text-align: center; color: #fff; font-family: "Fredoka"; font-weight: 700; font-size: 15px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.me-dot { width: 20px; height: 20px; border-radius: 50%; background: #3a8dff; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(58,141,255,.25); }

/* --- Blad (skapa/redigera) --- */
.sheet { position: fixed; inset: 0; z-index: 1000; background: rgba(20,6,32,.55); display: flex; align-items: flex-end; }
.sheet-inner { width: 100%; max-height: 100%; height: 100%; background: var(--cream); display: flex; flex-direction: column; animation: slideup .28s cubic-bezier(.2,.9,.3,1.1); }
@media (min-width: 640px) { .sheet { align-items: center; justify-content: center; } .sheet-inner { max-width: 560px; height: 92vh; border-radius: 28px; overflow: hidden; } }
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 12px 10px; background: var(--plum); color: #fff; }
.sheet-head h2 { margin: 0; font-size: 21px; flex: 1; text-align: center; }
.spacer { width: 40px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 18px; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px 20px; display: grid; gap: 14px; align-content: start; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 14px calc(12px + var(--safe-b)); background: #fff; box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
.sheet-foot .btn.big { flex: 1; }

.box { background: #fff; border-radius: 18px; padding: 12px 14px; box-shadow: 0 3px 0 #efdfe8; }
.pos-box { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.pos-box .btn { flex: none; }

.photo-tile { position: relative; display: block; border-radius: 22px; overflow: hidden; min-height: 190px; cursor: pointer;
  background: repeating-linear-gradient(135deg, #ffe3ec 0 18px, #fff 18px 36px); border: 3px dashed var(--pink); }
.photo-tile img { display: block; width: 100%; max-height: 52vh; object-fit: cover; }
.photo-empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px; color: var(--red-dark); }
.photo-empty .cam { font-size: 46px; }
.photo-empty b { font-family: "Fredoka"; font-size: 21px; }
.photo-empty small { font-weight: 700; color: var(--muted); }
#photoRetake { justify-self: start; margin-top: -6px; }

.field { display: grid; gap: 6px; }
.field-head { display: flex; align-items: center; justify-content: space-between; }
.mic { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 800;
  background: #fff; color: var(--plum); box-shadow: 0 3px 0 #e2d3ec, inset 0 0 0 2px #eadff0; }
.mic em { font-style: normal; }
.mic.on { background: var(--red); color: #fff; box-shadow: 0 3px 0 var(--red-dark); animation: micpulse 1s infinite; }
@keyframes micpulse { 50% { box-shadow: 0 3px 0 var(--red-dark), 0 0 0 8px rgba(232,23,74,.18); } }

.ai-box { display: grid; gap: 8px; }
.ai-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ai-desc { font-size: 14px; background: #f5eefa; border-radius: 12px; padding: 8px 10px; }
.better { background: #eafbf6; border-radius: 12px; padding: 8px 10px; }
.better small { font-weight: 800; color: var(--mint-dark); }
.better p { margin: 4px 0 8px; font-weight: 700; }
.spinner { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 3px solid #f3c3d3; border-top-color: var(--red); animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); z-index: 2000; background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 999px; font-weight: 800; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: calc(100% - 32px); text-align: center;
  animation: pop .35s cubic-bezier(.2,1.6,.4,1) both; }
.toast.good { background: var(--mint-dark); }
.toast.bad { background: #b3123e; }

/* Konfetti när en fråga sparas */
.confetti { position: fixed; top: -12px; width: 10px; height: 16px; z-index: 3000; pointer-events: none; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

.leaflet-container { font-family: "Nunito", sans-serif; }
.leaflet-popup-content { margin: 10px 12px; font-weight: 700; }
