:root {
  --papper: #FBF7EF;
  --papper-mork: #F3ECDE;
  --black: #22302F;
  --petrol: #0F5F6B;
  --petrol-ljus: #DDEDEF;
  --guld: #E9B23C;
  --gron: #2E7D5B;
  --rod: #B4462F;
  --kant: #E2D8C4;
  --radie: 18px;
}

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

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

body {
  display: grid;
  grid-template-rows: auto 4px 1fr;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- HUD ---------- */
#hud { display: flex; align-items: center; gap: 12px; padding: 10px clamp(12px, 3vw, 26px) 6px; }
#hudVanster { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: clamp(17px, 2.4vw, 22px); }
#stjarnText { min-width: 1.4em; }
#prickar { display: flex; gap: 6px; margin: 0 auto; }
.prick { width: 10px; height: 10px; border-radius: 50%; background: var(--kant); }
.prick.klar { background: var(--petrol); }
.prick.nu { box-shadow: 0 0 0 3px var(--petrol-ljus); background: var(--petrol); }
#ljud {
  width: 44px; height: 44px; flex: 0 0 44px;
  border: 2px solid var(--kant); background: #fff; border-radius: 50%;
  font-size: 20px; line-height: 1; cursor: pointer; color: var(--black);
}
#framsteg { background: var(--petrol); width: 0; transition: width .3s ease; }

/* ---------- spel ---------- */
#spel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.6vh, 18px);
  padding: clamp(10px, 2vh, 22px) clamp(12px, 3vw, 40px) clamp(12px, 2.4vh, 26px);
  min-height: 0;
}

#fraga {
  background: #fff;
  border: 2px solid var(--kant);
  border-radius: var(--radie);
  padding: clamp(12px, 2.4vh, 26px) clamp(16px, 3vw, 34px);
  display: flex; align-items: center; justify-content: center; gap: clamp(10px, 2vw, 26px);
  min-height: clamp(74px, 15vh, 130px);
  text-align: center;
}
#fragTexte {
  margin: 0;
  font-size: clamp(21px, 3vw, 34px);
  line-height: 1.3;
  font-weight: 600;
}
#storSym {
  font-size: clamp(40px, 7vw, 76px);
  font-weight: 800;
  color: var(--petrol);
  line-height: 1;
}

#alternativ {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(72px, 168px);
  gap: clamp(10px, 1.8vw, 22px);
  align-content: center;
  min-height: 0;
}
.kort {
  position: relative;
  border: 3px solid var(--kant);
  background: #fff;
  border-radius: var(--radie);
  cursor: pointer;
  color: var(--black);
  font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  min-height: clamp(70px, 13vh, 116px);
  padding: 6px;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.kort:active { transform: scale(.97); }
.kort .sym { font-size: clamp(30px, 4.6vw, 56px); font-weight: 800; line-height: 1.05; }
.kort .namn { font-size: clamp(17px, 2.4vw, 27px); font-weight: 600; }
.kort.atom .namn { font-size: clamp(15px, 2vw, 23px); }
.kort.fel { border-color: var(--rod); background: #FBEDE9; }
.kort.ratt { border-color: var(--gron); background: #E9F5EE; box-shadow: 0 0 0 4px #D6EDE0; }
.kort.slocknad { opacity: .42; }
.kort.traad { opacity: 1; border-color: var(--guld); animation: pulsa 1s ease-in-out infinite; }
#fraga.svarad { border-color: var(--gron); }

@keyframes pulsa {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233,178,60,.85); }
  50% { box-shadow: 0 0 0 12px rgba(233,178,60,0); }
}
@media (prefers-reduced-motion: reduce) {
  .kort.traad { animation: none; box-shadow: 0 0 0 6px rgba(233,178,60,.6); }
  .prick, #framsteg { transition: none; }
}

/* ---------- botten: Kotten, feedback, atomen ---------- */
#botten {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  min-height: clamp(96px, 17vh, 150px);
}
#kotten { width: clamp(74px, 11vh, 118px); height: clamp(74px, 11vh, 118px); flex: 0 0 auto; }
#aterkoppling {
  flex: 1 1 auto;
  font-size: clamp(16px, 2.1vw, 23px);
  line-height: 1.35;
  font-weight: 600;
  color: var(--black);
  opacity: 0;
  transition: opacity .2s ease;
}
#aterkoppling.visa { opacity: 1; }
#visning { flex: 0 0 auto; width: clamp(78px, 12vh, 130px); opacity: 0; transition: opacity .25s ease; }
#visning.visa { opacity: 1; }
#visning .atom { width: 100%; height: auto; display: block; }
#visning .chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-align: center;
  background: var(--petrol-ljus);
  border: 2px solid var(--kant);
  border-radius: 14px;
  padding: 8px 6px;
  min-height: 78px;
}
#visning .chip strong { font-size: clamp(24px, 3vw, 34px); color: var(--petrol); }
#visning .chip span { font-size: clamp(11px, 1.3vw, 14px); font-weight: 600; }

/* ---------- start ---------- */
#startskarm {
  position: fixed; inset: 0;
  background: var(--papper);
  display: flex; align-items: center; justify-content: center;
  padding: clamp(16px, 3vh, 40px);
  overflow: auto;
}
.start-inner { max-width: 640px; width: 100%; text-align: center; }
#kottenStart { width: clamp(88px, 16vh, 130px); height: clamp(88px, 16vh, 130px); }
h1 { font-size: clamp(30px, 5vw, 46px); margin: 6px 0 10px; }
.ingress { font-size: clamp(17px, 2.3vw, 21px); line-height: 1.45; margin: 0 0 14px; }
.sa-funkar {
  list-style: none; padding: 0; margin: 0 0 20px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: clamp(15px, 2vw, 18px);
}
.sa-funkar li {
  background: #fff; border: 2px solid var(--kant); border-radius: 12px;
  padding: 9px 14px;
}
#play {
  min-width: 220px; min-height: 64px;
  font-size: clamp(21px, 3vw, 27px); font-weight: 800;
  color: #fff; background: var(--petrol);
  border: 0; border-radius: 16px; cursor: pointer;
}
#play:active { transform: scale(.98); }
.larare {
  margin-top: 22px; text-align: left;
  font-size: 14px; line-height: 1.5; color: #45585A;
}
.larare summary { cursor: pointer; font-weight: 700; font-size: 15px; min-height: 44px; display: flex; align-items: center; }
.larare p { margin: 10px 0; }

/* ---------- nivå klar ---------- */
#klart {
  position: fixed; inset: 0;
  background: var(--papper);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.klart-inner { text-align: center; max-width: 560px; }
.klart-stjarnor { font-size: clamp(26px, 5vw, 44px); margin: 0 0 6px; line-height: 1.2; word-break: break-all; }
#klart h2 { font-size: clamp(26px, 4.4vw, 40px); margin: 0 0 10px; }
#klartText { font-size: clamp(16px, 2.3vw, 21px); margin: 0 0 22px; }
#klartKnapp {
  display: block; width: 100%; min-height: 62px; margin: 0 0 12px;
  font-size: clamp(19px, 2.7vw, 25px); font-weight: 800;
  color: #fff; background: var(--petrol); border: 0; border-radius: 16px; cursor: pointer;
}
.svag {
  min-height: 52px; padding: 0 22px;
  font-size: clamp(15px, 2vw, 18px); font-weight: 600;
  color: var(--petrol); background: transparent;
  border: 2px solid var(--kant); border-radius: 14px; cursor: pointer;
}

/* ---------- stående / telefon ---------- */
@media (orientation: portrait), (max-width: 640px) {
  #alternativ { grid-template-columns: repeat(2, 1fr); grid-auto-rows: minmax(64px, 1fr); }
  #botten { flex-wrap: wrap; justify-content: center; text-align: center; }
  #aterkoppling { flex: 1 1 100%; order: 3; text-align: center; }
  #visning { order: 2; }
}
@media (max-width: 420px) {
  .kort { min-height: 66px; }
  .sa-funkar li { padding: 7px 12px; }
}