:root {
  --papper: #f7f3e8;
  --papper-mork: #efe8d6;
  --ink: #363125;
  --mjuk: #7d7361;
  --linje: #cfc6b2;
  --accent: #2a6f5f;
  --accent-ljus: #d7e7df;
  --guld: #d8a62c;
  --radie: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--papper);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

/* ---------- startskärm ---------- */
#startskarm {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, 3vh) 20px;
  background: var(--papper);
  z-index: 30;
  overflow: auto;
}
.start-inner { width: min(620px, 100%); text-align: center; }
h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 5.4vw, 44px);
  margin: 0 0 10px;
  letter-spacing: .5px;
}
.ingress { font-size: clamp(15px, 2vw, 18px); line-height: 1.45; color: var(--mjuk); margin: 0 auto 14px; max-width: 34em; }
.start-bild svg { width: min(420px, 86%); height: auto; display: block; margin: 0 auto 10px; }
.spela {
  font: inherit;
  font-size: 22px;
  font-weight: 600;
  color: #fdfbf4;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  padding: 16px 54px;
  min-height: 60px;
  cursor: pointer;
}
.spela:active { transform: translateY(1px); }
.vuxen { font-size: 14px; line-height: 1.5; color: var(--mjuk); margin: 14px auto 6px; max-width: 36em; }
.laroplan { text-align: left; font-size: 13.5px; color: var(--mjuk); margin-top: 6px; }
.laroplan summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; }
.laroplan p { margin: 6px 0; line-height: 1.5; }

/* ---------- spel ---------- */
#spelet {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: max(8px, 1.6vh) max(10px, 2vw);
  gap: max(6px, 1.2vh);
}
.hud { display: flex; align-items: center; gap: 12px; }
.niva {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-ljus);
  border-radius: 999px;
  padding: 6px 14px;
}
.stjarnor { display: flex; align-items: center; gap: 6px; font-size: 19px; color: var(--guld); }
.stjarnor b { font-size: 19px; color: var(--ink); }
.hud-knappar { margin-left: auto; display: flex; gap: 8px; }
.hud-knapp {
  font: inherit;
  font-size: 19px;
  width: 48px; height: 48px;
  border-radius: 12px;
  border: 1.5px solid var(--linje);
  background: #fffdf6;
  color: var(--ink);
  cursor: Pointer;
}
.hud-knapp:active { background: var(--papper-mork); }

.scen {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(96px, 150px) minmax(0, 1fr);
  gap: max(8px, 1.6vw);
  align-items: stretch;
}
.foraldrar { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.foralder {
  background: #fffdf6;
  border: 1.5px solid var(--linje);
  border-radius: var(--radie);
  padding: 8px 6px;
  text-align: center;
}
.f-huvud { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--mjuk); }
.f-kropp { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 3px 0 1px; }
.f-prick { width: 22px; height: 22px; border-radius: 50%; background: #ddd; box-shadow: inset 0 0 0 2px rgba(0,0,0,.12); }
.f-typ { font-family: Georgia, serif; font-size: clamp(19px, 2.4vw, 26px); }
.f-farg { font-size: 13px; color: var(--mjuk); }

.brada { min-height: 0; display: grid; place-items: center; }
.rutnat {
  width: min(100%, 58vh, 560px);
  height: auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 0.72fr 1fr 1fr;
  grid-template-rows: 0.72fr 1fr 1fr;
  gap: max(4px, .8vh);
}

.slot, .cell {
  font: inherit;
  border-radius: var(--radie);
  border: 2px dashed var(--linje);
  background: #fffdf6;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  min-height: 0;
  position: relative;
}
.slot { font-family: Georgia, serif; font-size: clamp(22px, 3.4vw, 34px); color: var(--accent); }
.slot.fylld { border-style: solid; border-color: var(--accent); background: var(--accent-ljus); }
.slot.vald { border-color: var(--guld); box-shadow: 0 0 0 4px rgba(216,166,44,.28); }
.slot.fel { animation: skaka .34s ease; border-color: #c9463d; }

.cell { border-style: solid; border-color: var(--linje); background: #fffdf6; gap: 2px; }
.cell.klar { border-color: var(--accent); }
.cell.vald { box-shadow: 0 0 0 4px rgba(42,111,95,.22); border-color: var(--accent); }
.cell.vant { border-style: dashed; color: var(--mjuk); }
.cell .cell-par { font-family: Georgia, serif; font-size: clamp(19px, 3vw, 30px); line-height: 1; }
.cell .cell-farg { display: flex; align-items: center; gap: 6px; font-size: clamp(12px, 1.5vw, 15px); color: var(--mjuk); }
.cell .cell-farg i { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.15); }
.cell.fel { animation: skaka .34s ease; }
.cell.puls { animation: puls 1.1s ease-in-out infinite; }

.fraga-cell { display: grid; place-items: center; font-size: clamp(13px, 1.6vw, 16px); color: var(--mjuk); }

.bricka { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 62px; align-items: center; }
.val {
  font: inherit;
  font-size: clamp(17px, 2.2vw, 21px);
  min-width: 84px;
  min-height: 56px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2px solid var(--linje);
  background: #fffdf6;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.val i { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.16); }
.val:disabled { opacity: .45; }
.val:active:not(:disabled) { transform: translateY(1px); }
.val.nasta { background: var(--accent); color: #fdfbf4; border-color: var(--accent); }

.svar {
  margin: 0;
  min-height: 2.6em;
  font-size: clamp(14px, 1.9vw, 17px);
  line-height: 1.35;
  text-align: center;
  color: var(--mjuk);
}

#slut {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--papper);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}
.slut-stjarna { font-size: 72px; color: var(--guld); line-height: 1; }
.slut-antal { font-family: Georgia, serif; font-size: 40px; margin: 6px 0 2px; }
.slut-text { color: var(--mjuk); font-size: 20px; margin: 0 0 22px; }

@keyframes skaka {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
@keyframes puls {
  0%, 100% { box-shadow: 0 0 0 0 rgba(216,166,44,0); }
  50% { box-shadow: 0 0 0 7px rgba(216,166,44,.42); }
}

@media (prefers-reduced-motion: reduce) {
  .slot.fel, .cell.fel { animation: none; }
  .cell.puls { animation: none; box-shadow: 0 0 0 4px rgba(216,166,44,.5); }
}

/* stående / smal skärm: föräldrarna som en rad ovanför rutnätet */
@media (max-aspect-ratio: 1/1), (max-width: 620px) {
  .scen { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .foraldrar { flex-direction: row; justify-content: center; }
  .foralder { flex: 1; max-width: 190px; padding: 5px 6px; }
  .f-huvud { font-size: 11px; }
  .f-prick { width: 16px; height: 16px; }
  .rutnat { max-width: min(100%, 430px); }
  .svar { min-height: 3.2em; }
  .bricka { min-height: 58px; }
  .val { min-height: 52px; padding: 6px 14px; }
}