:root {
  --papper: #FBF7EF;
  --papper2: #F2EBDC;
  --black: #2E2A26;
  --accent: #1F6FB2;
  --guld: #F2B01E;
  --gron: #3E8E5A;
  --rod: #C4453C;
  --kotte: #A9693C;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--papper);
  color: var(--black);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- startskärm ---------- */
#startskarm {
  position: fixed;
  inset: 0;
  background: var(--papper);
  overflow: auto;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
}
.startinre { max-width: 680px; width: 100%; margin: auto; text-align: center; }
#startkotte { width: 112px; height: 126px; margin: 0 auto 2px; }
#startkotte svg { width: 100%; height: 100%; }
h1 { font-size: 2rem; margin: 0 0 8px; letter-spacing: .2px; }
.starttext { font-size: 1.06rem; line-height: 1.45; margin: 0 0 12px; }
.starttext.liten { font-size: .9rem; opacity: .75; }
.play {
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 16px;
  padding: 16px 56px;
  min-height: 64px;
  margin: 4px 0 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 #17547f;
}
.play:active { transform: translateY(2px); box-shadow: 0 2px 0 #17547f; }
.larare {
  text-align: left;
  font-size: .82rem;
  line-height: 1.45;
  border-top: 1px solid #E3DAC8;
  margin-top: 8px;
  padding-top: 8px;
  opacity: .85;
}
.larare h2 { font-size: .9rem; margin: 0 0 4px; }
.larare p { margin: 0 0 6px; }

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 84px;
  padding: 8px 12px 4px calc(88px + env(safe-area-inset-left));
  flex: 0 0 auto;
}
#nivaKnapp {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  background: var(--papper2);
  color: var(--black);
  border: 1px solid #E0D6C2;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
.stjarna { color: var(--guld); font-size: 1.3rem; }
#stjarnText { font-weight: 700; font-size: 1.15rem; }
#prickar { display: flex; gap: 5px; margin-left: auto; }
#prickar i { width: 9px; height: 9px; border-radius: 50%; background: #DCD2BF; display: block; }
#prickar i.klar { background: var(--gron); }
#ljud {
  font-size: 1.15rem;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid #E0D6C2;
  background: var(--papper2);
  cursor: pointer;
}

/* ---------- spel ---------- */
#spel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 12px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
}
#fragText {
  flex: 0 0 auto;
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.35;
  min-height: 2.6em;
  font-weight: 600;
}
#scen {
  flex: 1 1 auto;
  min-height: 150px;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--papper2);
}
#scen svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#svarText {
  flex: 0 0 auto;
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
  min-height: 1.3em;
  color: #4A443C;
}
#nastarad { flex: 0 0 auto; display: flex; justify-content: center; }
#nasta {
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: var(--gron);
  border: 0;
  border-radius: 14px;
  padding: 12px 40px;
  min-height: 54px;
  cursor: pointer;
}

/* cellens delar */
.del { cursor: pointer; }
.del.ratt { stroke: var(--gron) !important; filter: drop-shadow(0 0 6px rgba(62,142,90,.6)); }
.del.fel { opacity: .55; }
.del.puls { animation: cellpuls .9s ease-in-out infinite; }
@keyframes cellpuls { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- slutruta ---------- */
#ruta {
  position: fixed;
  inset: 0;
  background: var(--papper);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.ruteinre { text-align: center; max-width: 560px; }
#rutaKotte { width: 120px; height: 134px; margin: 0 auto 6px; }
#rutaKotte svg { width: 100%; height: 100%; }
#rutaText { font-size: 1.2rem; line-height: 1.4; margin: 0 0 10px; }
#rutaSiffra { font-size: 2.2rem; font-weight: 700; color: var(--guld); margin-bottom: 14px; }
#rutaKnapp {
  font-size: 1.5rem;
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

/* ---------- smal skärm ---------- */
@media (max-width: 560px) {
  h1 { font-size: 1.7rem; }
  .starttext { font-size: 1rem; }
  #fragText { font-size: 1.02rem; }
  #hud { gap: 8px; padding: 6px 10px 2px calc(80px + env(safe-area-inset-left)); }
}

@media (prefers-reduced-motion: reduce) {
  .del.puls { animation: none; opacity: .45; }
  .play:active { transform: none; }
}
