:root {
  --papper: #FBF7EF;
  --kant: #E6DCC8;
  --accent: #14535F;   /* petrolblå – en accent */
  --accent-ljus: #DDEDEF;
  --guld: #E9B23C;
  --gron: #3C7A4F;
  --rod: #C1553F;      /* innehållsfärger (formernas egna) */
  --gul: #E9B23C;
  --bla: #2E6FB7;
  --text: #2A2118;
  --dampad: #6B6153;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--papper); color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; overscroll-behavior: none;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; }

/* ---------- HUD ---------- */
#hud {
  flex: 0 0 auto; height: 54px; display: flex; align-items: center;
  gap: 10px; padding: 0 14px; padding-top: env(safe-area-inset-top);
  background: var(--papper); border-bottom: 2px solid var(--kant);
  font-size: 19px; font-weight: 700; color: var(--accent);
}
#hudVanster { display: flex; align-items: center; gap: 8px; }
#nivaKnapp {
  font: inherit; font-size: 18px; font-weight: 700; color: var(--accent);
  background: var(--accent-ljus); border: 2px solid var(--accent);
  border-radius: 12px; padding: 6px 12px; min-height: 44px; cursor: pointer;
}
.stjarna { font-size: 20px; }
#prickar { flex: 1; display: flex; gap: 7px; justify-content: center; }
#prickar i {
  width: 12px; height: 12px; border-radius: 50%;
  background: #EDE5D4; border: 2px solid #D9CDB6;
}
#prickar i.gjord { background: var(--guld); border-color: #C99325; }
#prickar i.nu { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }
#ljud {
  width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--kant);
  background: #fff; font-size: 21px; cursor: pointer; line-height: 1;
}
#framsteg { flex: 0 0 auto; height: 5px; background: #EFE6D4; }
#framsteg i { display: block; height: 100%; width: 0; background: var(--guld); transition: width .25s; }

/* ---------- spel ---------- */
#spel {
  flex: 1 1 auto; min-height: 0; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px; padding: 8px 14px 10px;
}
#topp { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
#fragText { margin: 0; font-size: 21px; font-weight: 700; color: var(--text); }
#krav {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
#krav li {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 2px solid var(--kant); border-radius: 999px;
  padding: 6px 14px; font-size: 17px; color: var(--dampad); min-height: 40px;
}
#krav li .bock {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid #CFD8DC; background: #F3EFE6; position: relative;
}
#krav li.ok { border-color: var(--gron); color: var(--gron); background: #EAF4EC; }
#krav li.ok .bock { background: var(--gron); border-color: var(--gron); }
#krav li.ok .bock::after {
  content: ""; position: absolute; left: 5px; top: 4px; width: 7px; height: 11px;
  border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg);
}

/* ---------- mitt: brett + låda ---------- */
#mitt {
  min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(180px, 24vw, 260px);
  gap: 12px; align-items: stretch;
}
#brett {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(4px, 1vmin, 8px);
  background: #fff; border: 3px solid var(--accent); border-radius: 16px;
  padding: clamp(6px, 1.2vmin, 12px); min-height: 0; position: relative;
}
/* stödlinjer per nivå: nivå 1 = mittenlinjen (spegelaxel),
   nivå 2 = tredjedelslinjer (mittfältet), nivå 3 = inga */
#brett::before, #brett::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 0;
  border-left: 2px dashed #CBD7E8; pointer-events: none;
}
#brett::before { left: 50%; display: none; }
#brett::after { display: none; }
#brett[data-niva="1"]::before { display: block; border-color: #E4C9A8; }
#brett[data-niva="2"]::before { display: block; left: 33.333%; }
#brett[data-niva="2"]::after { display: block; left: 66.666%; }
.cell {
  border: 2px solid #E8E0CE; border-radius: 10px; background: #FDFAF3;
  min-width: 44px; min-height: 44px; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.cell svg { width: 78%; height: 78%; display: block; }
.cell.guptips::after, .cell.tips::after {
  content: ""; position: absolute; inset: -6px; border-radius: 14px;
  border: 4px solid var(--guld); animation: pulsa 1.1s ease-in-out infinite;
}
@keyframes pulsa {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.07); opacity: .55; }
}

#lada {
  display: flex; flex-direction: column; gap: 6px; justify-content: center;
  background: #fff; border: 2px solid var(--kant); border-radius: 16px;
  padding: 10px 12px; min-width: 0; overflow: hidden;
}
.ladaRubrik { margin: 0; font-size: 15px; font-weight: 700; color: var(--dampad); text-transform: uppercase; letter-spacing: .04em; }
#formVal, #fargVal { display: flex; gap: 8px; }
.squeeze { flex: 1 1 0; min-width: 54px; min-height: 54px; border-radius: 12px;
  border: 3px solid var(--kant); background: #FDFAF3; cursor: pointer; padding: 6px;
  display: flex; align-items: center; justify-content: center;
}
.squeeze svg { width: 74%; height: 74%; display: block; }
.squeeze.aktiv { border-color: var(--accent); background: var(--accent-ljus); box-shadow: 0 0 0 2px var(--accent) inset; }
.squeeze:focus-visible { outline: 3px solid var(--accent); }

#botten { min-height: 46px; display: flex; align-items: center; }
#regelRad {
  font-size: 18px; color: var(--gron); font-weight: 700;
  background: #EAF4EC; border: 2px solid #BFDDC8; border-radius: 12px;
  padding: 8px 14px; min-height: 44px; display: flex; align-items: center;
}
#regelRad:empty { display: none; }

/* ---------- startskärm ---------- */
#startskarm {
  position: fixed; inset: 0; background: var(--papper); z-index: 20;
  overflow-y: auto; display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(16px, 4vh, 48px) 20px calc(24px + env(safe-area-inset-bottom));
}
.start-inner { max-width: 680px; width: 100%; }
h1 { margin: 6px 0 4px; font-size: clamp(30px, 5vw, 44px); color: var(--accent); }
.ingress { margin: 0 0 14px; font-size: clamp(17px, 2.2vw, 20px); color: var(--dampad); }
.sa-funkar { margin: 0 0 18px; padding-left: 22px; display: grid; gap: 8px; font-size: 17px; }
#play {
  font: inherit; font-size: 22px; font-weight: 800; color: #fff;
  background: var(--accent); border: none; border-radius: 16px;
  padding: 14px 46px; min-height: 64px; cursor: pointer;
}
#play:active { transform: translateY(1px); }
.larare { margin-top: 22px; font-size: 15px; color: var(--dampad); }
.larare summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 700; }
.larare p { margin: 8px 0; line-height: 1.45; }

/* ---------- betydelsefråga före slutskärmen ---------- */
#fordom {
  position: fixed; inset: 0; z-index: 28; background: var(--papper);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.fordom-inner { max-width: 620px; width: 100%; text-align: center; }
#fordomFraga { font-size: clamp(19px, 3.4vw, 26px); font-weight: 800; color: var(--accent); margin: 0 0 16px; }
.fordomPar { display: flex; gap: 14px; justify-content: center; }
.fordomVal {
  font: inherit; cursor: pointer; background: #fff; border: 3px solid var(--kant);
  border-radius: 16px; padding: 10px; min-width: 132px; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.fordomVal.aktiv { border-color: var(--accent); background: var(--accent-ljus); }
.fordomVal:focus-visible { outline: 3px solid var(--accent); }
.mini {
  display: grid; grid-template-columns: repeat(6, 10px); grid-template-rows: repeat(4, 10px);
  gap: 2px; background: var(--papper); border: 2px solid var(--accent); border-radius: 6px; padding: 3px;
}
.mini i { width: 10px; height: 10px; border-radius: 2px; background: #FDFAF3; border: 1px solid #EDE4D2; position: relative; }
.mini i.c { border-radius: 50%; }
.mini i.t { border-radius: 2px; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.mini i.f { border-width: 0; }
.mini i.rod { background: var(--rod); } .mini i.gul { background: var(--gul); } .mini i.bla { background: var(--bla); }
.fordomPil { font-size: 22px; color: var(--accent); line-height: 1; }
.fordomOrd { font-weight: 800; color: var(--text); }
#fordomSvar {
  min-height: 52px; margin: 16px 0 0; font-size: 18px; color: var(--gron); font-weight: 700;
}

/* ---------- overlay: klart / nivåval ---------- */
#klart, #nivaValj {
  position: fixed; inset: 0; z-index: 30; background: var(--papper);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.klart-inner { max-width: 560px; width: 100%; text-align: center; }
.klart-stjarnor { font-size: clamp(44px, 9vw, 76px); margin: 0; color: var(--guld); }
#klart h2, #nivaValj h2 { margin: 6px 0 8px; color: var(--accent); font-size: clamp(26px, 5vw, 38px); }
#klartText { font-size: 19px; color: var(--dampad); margin: 0 0 20px; }
#klartKnapp, .nivaKnappar button, #stangNiva {
  font: inherit; font-size: 20px; font-weight: 800; color: #fff;
  background: var(--accent); border: none; border-radius: 14px;
  padding: 12px 30px; min-height: 56px; min-width: 150px; cursor: pointer; display: block;
}
.nivaKnappar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
#klartIgen, #stangNiva {
  margin-top: 12px; background: #fff; color: var(--accent);
  border: 2px solid var(--accent); font-weight: 700;
}

/* ---------- stående läge ---------- */
@media (orientation: portrait) {
  #mitt { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  #lada { min-width: 0; flex-direction: row; align-items: center; gap: 10px;
    justify-content: space-between; padding: 8px 10px; }
  .ladaRubrik { margin: 0; }
  #lada > div { display: flex; gap: 8px; }
  .squeeze { min-width: 56px; min-height: 48px; }
  #fragText { font-size: 19px; }
}
@media (max-width: 420px) {
  #krav li { font-size: 15px; padding: 5px 10px; }
  #fragText { font-size: 18px; }
  #ljud { width: 44px; height: 44px; }
  #nivaKnapp { min-height: 44px; font-size: 16px; padding: 5px 10px; }
}

/* ---------- rörelse ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .cell.tips::after, .cell.guptips::after { animation: none !important; opacity: 1; }
}