: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.06rem;
  line-height: 1.35;
  min-height: 2.6em;
}
#scen {
  flex: 1 1 auto;
  min-height: 130px;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--papper2);
}
#duk { 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;
}

#kontroller { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
.rad {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 2px solid #D9CEB8;
  border-radius: 14px;
  padding: 6px 10px;
}
.radnamn { font-size: .95rem; font-weight: 600; opacity: .8; flex: 0 0 auto; width: 5.6em; }
.varde {
  flex: 1 1 auto;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.steg {
  font: inherit;
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  width: 58px; height: 58px;
  border-radius: 12px;
  border: 2px solid #D9CEB8;
  background: var(--papper2);
  color: var(--black);
  cursor: pointer;
}
.steg:active { transform: translateY(1px); }
.steg:disabled { opacity: .3; cursor: default; }
.steg.puls { animation: puls 1.1s ease-in-out infinite; }
@keyframes puls { 0%,100% { box-shadow: 0 0 0 0 rgba(31,111,178,.45); } 50% { box-shadow: 0 0 0 10px rgba(31,111,178,0); } }

#nastarad { flex: 0 0 auto; display: flex; gap: 10px; justify-content: center; }
#kolla, #nasta {
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  padding: 12px 34px;
  min-height: 54px;
  cursor: pointer;
}
#nasta { background: var(--gron); }

/* ---------- 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: .98rem; }
  #hud { gap: 8px; padding: 6px 10px 2px calc(80px + env(safe-area-inset-left)); }
  .radnamn { width: 4.9em; font-size: .9rem; }
  .varde { font-size: 1.2rem; }
  .steg { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .steg.puls { animation: none; box-shadow: 0 0 0 4px rgba(31,111,178,.35); }
  .play:active { transform: none; }
}
