/* =========================================
   🌈 MatteMatch v9.0 – Helhetlig og ryddet CSS
   ========================================= */

/* ---------- GRUNNVERDIER ---------- */
:root {
  --cell-size: 6.5vw;
  --gap: 0.25rem;
  --blue1: #1e3a8a;
  --blue2: #3b82f6;
  --accent: #06b6d4;
  --purple: #7c3aed;
  --text: #e0e7ff;
}

/* ---------- GLOBALT ---------- */
body {
  background: linear-gradient(135deg, #0f172a, #312e81);
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  text-align: center;
  margin: 0;
  padding: 2rem;
}

.mattematch-container {
  max-width: 900px;
  margin: 0 auto;
}

/* ---------- TITLER ---------- */
.main-title {
  font-size: 2.4rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}
.subtitle {
  font-size: 1rem;
  opacity: 0.85;
  margin-bottom: 1.5rem;
}
.mode-title {
  font-size: 1.8rem;
  color: #93c5fd;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* ---------- KNAPPER ---------- */
.mm-btn {
  background: linear-gradient(135deg, var(--purple), var(--accent));
  color: #fff;
  border: none;
  padding: 1rem 2rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mm-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 14px rgba(6,182,212,0.7);
}

/* ---------- KNAPPGRUPPER ---------- */
.optionGrid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}
.optionGrid .mm-btn {
  width: 80%;
  max-width: 300px;
}

/* ---------- GRIDMODUS-KNAPPER ---------- */
.grid-mode .optionGrid {
  flex-direction: row;
  justify-content: center;
  gap: 1rem;
}
.grid-mode .mm-btn.active {
  border: 2px solid #fff;
  box-shadow: 0 0 10px rgba(255,255,255,0.6);
  transform: scale(1.05);
}

/* ---------- GANGETABELL-KNAPPER ---------- */
.tableButtons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin: 1.5rem auto;
  max-width: 800px;
}
.tableBtn {
  background: linear-gradient(135deg, var(--accent), var(--blue2));
  color: #fff;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s, box-shadow 0.1s;
}
.tableBtn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 8px rgba(6,182,212,0.6);
}

/* ---------- GRID ---------- */
.grid {
  display: grid;
  justify-content: center;
  align-content: start;
  margin: 1rem auto;
  place-items: center;
}

/* === COMPACT GRID (store knapper) === */
.grid.compact {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 18px;
  max-width: 500px;
  margin: 2rem auto;
}
.grid.compact .cell {
  aspect-ratio: 1/1;
  min-width: 120px;
  background: linear-gradient(145deg, var(--blue1), var(--blue2));
  color: #fff;
  border-radius: 14px;
  font-weight: 700;
  font-size: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  transition: transform 0.15s, background 0.2s;
}
.grid.compact .cell:hover { transform: scale(1.07); }

/* === LARGE GRID (små knapper) === */
.grid.large {
  grid-template-columns: repeat(auto-fit, minmax(var(--cell-size), 1fr));
  justify-content: center;
  align-content: start;
  gap: var(--gap);
  margin: 1rem auto;
  width: 60%;
  max-width: 95vw;
}
.grid.large .cell {
  aspect-ratio: 1/1;
  width: 100%;
  background: linear-gradient(145deg, var(--blue1), var(--blue2));
  color: #fff;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 8px rgba(0,0,0,0.3);
  transition: transform 0.15s, background 0.2s;
}
.grid.large .cell:hover { transform: scale(1.03); }

/* ---------- RIKTIG / FEIL ---------- */
.cell.correct { background: #22c55e !important; }
.cell.wrong   { background: #ef4444 !important; }

/* ---------- TEKST OG STATUS ---------- */
.task, #task {
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 800;
  color: rgba(180,210,255,0.9);
  text-shadow: 0 0 10px rgba(147,197,253,0.8);
  margin: 1rem 0;
}
#progress {
  margin-top: 1rem;
  font-weight: 500;
  opacity: 0.9;
}

/* ---------- TILBAKE-KNAPPER ---------- */
.back-btn, #btnBackOne {
  background: linear-gradient(135deg, var(--purple), var(--accent));
  color: #fff;
  border: none;
  padding: 1rem 2rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.back-btn:hover, #btnBackOne:hover {
  transform: scale(1.05);
  box-shadow: 0 0 14px rgba(6,182,212,0.9);
}

/* ---------- RESULTAT-KNAPPER ---------- */
.result-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  margin-top: 2rem;
}

/* ---------- MINI-SERTIFIKATER ---------- */
.mini-cert-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1rem;
  justify-items: center;
  margin-top: 1.5rem;
}
.mini-cert-box {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 1rem 0.5rem;
  max-width: 120px;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mini-cert-box:hover {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(250,204,21,0.5);
}
.mini-cert-label {
  margin-top: 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

/* ---------- HOVEDSERTIFIKATER ---------- */
.main-cert-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  justify-items: center;
  align-items: start;
  margin: 2rem auto;
  max-width: 650px;
}
.main-cert-box {
  background: linear-gradient(145deg, var(--blue1), var(--blue2));
  border-radius: 12px;
  padding: 1.2rem;
  text-align: center;
  color: #fff;
  font-weight: 600;
  width: 160px;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.main-cert-box:hover {
  transform: scale(1.05);
  box-shadow: 0 0 14px rgba(96,165,250,0.6);
}
.main-cert-icon { font-size: 2rem; margin-bottom: 0.3rem; }
.main-cert-label { font-size: 0.95rem; }

/* ---------- GULL / SØLV GLOWS ---------- */
.main-cert-box[data-status="gold"] .main-cert-icon {
  filter: drop-shadow(0 0 12px gold);
}
.main-cert-box[data-status="silver"] .main-cert-icon {
  filter: drop-shadow(0 0 10px silver);
}

/* ---------- MONSTER-STIL ---------- */
.main-cert-box[data-op="monster"] {
  background: linear-gradient(145deg, #4c1d95, #7e22ce);
  box-shadow: 0 0 20px rgba(168,85,247,0.6);
  color: #fdf4ff;
}

/* Gir luft over tilbakeknappen under sertifikatvalg */
.optionGrid + .back-btn {
  margin-top: 1.8rem;
}

/* ---------------------------------------------------------
   🖱️ Klikkbare elementer – pointer for celler og sertifikatbokser
   --------------------------------------------------------- */
.cell,
.cert-box,
.main-cert-box,
.mini-cert-box,
.tableBtn,
.cert-btn,
.mm-btn {
  cursor: pointer !important;
}

.cell:hover,
.cert-box:hover,
.main-cert-box:hover,
.mini-cert-box:hover,
.tableBtn:hover,
.cert-btn:hover,
.mm-btn:hover {
  transform: scale(1.05);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* =========================================================
   🎮 SPILLSKJERM OG CANVAS – RYDDIG OG BALANSERT
   ========================================================= */

#gameScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 1rem 0 2rem 0;
  position: relative;
}

/* Øverste knapp – Tilbake */
#gameScreen > .back-btn:first-of-type {
  align-self: center;
  margin-bottom: 1rem;
}

/* Canvas – responsiv høyde og balansert proporsjon */
#gameScreen canvas.mm-cert-canvas {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 800px;
  aspect-ratio: 3 / 4;               /* gir et pent portrettforhold */
  height: auto;
  border-radius: 12px;
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.35);
  background: linear-gradient(180deg, #0f172a 0%, #1e1b4b 100%);
}

/* Progress-tekst under spillgriden */
#progress {
  margin-top: 1.2rem;
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.9;
}

/* Nederste knapp – Til forsiden */
#gameScreen > .back-btn:last-of-type {
  margin-top: 2rem;       /* gir luft under canvas */
  align-self: center;
  min-width: 180px;
  order: 99;              /* sikrer at den holder seg nederst */
}

/* Sørg for at knappene ikke overlapper */
#gameScreen .back-btn {
  position: relative;
  z-index: 5;
}

/* =========================================================
   🧠 TRENING – markering av valgte regnearter og nivåer
   ========================================================= */

/* Grunnstil for treningsknapper (om de ikke er definert andre steder) */
.opBtn,
.levelBtn {
  background: linear-gradient(135deg, var(--blue1), var(--blue2));
  color: #fff;
  border: none;
  padding: 0.8rem 1.2rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* 🔹 Når en regneart er valgt */
.opBtn.active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 0 12px rgba(34,197,94,0.7);
  transform: scale(1.05);
}

/* 🔹 Når et vanskelighetsnivå er valgt */
.levelBtn.active {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  box-shadow: 0 0 12px rgba(59,130,246,0.6);
  transform: scale(1.05);
}

/* =========================================================
   🧮 STORE KNAPPER I GANGETABELL-MODUS (3x2-layout)
   ========================================================= */
.tableButtons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem auto 2rem;
  max-width: 500px;
}

/* Gir store, kvadratiske knapper med god avstand */
.tableBtn {
  aspect-ratio: 1 / 1;
  font-size: 1.2rem;
  font-weight: 600;
  padding: 1.2rem;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--blue2));
  color: #fff;
  transition: transform 0.15s, box-shadow 0.15s;
}

.tableBtn:hover {
  transform: scale(1.07);
  box-shadow: 0 0 10px rgba(6,182,212,0.7);
}

/* ---------- RESPONSIVITET ---------- */
@media (max-width: 800px) {
  :root { --cell-size: 7vw; }
  .grid.large { width: 90%; }
  .main-cert-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  :root { --cell-size: 8vw; }
  .grid.large { width: 95%; }
  .main-cert-grid {
    grid-template-columns: repeat(2, 1fr);
    max-width: 360px;
  }
}

/* ---------- SKJERMSTYRING ---------- */
.screen { display: none; opacity: 0; transition: opacity 0.3s ease; }
.screen.active,
.screen:not(.hidden) { display: block; opacity: 1; }
.hidden { display: none !important; opacity: 0 !important; }

/* =========================================================
   📱 MOBILOPTIMALISERING – MatteMatch (kompakt og ryddig)
   ---------------------------------------------------------
   - Hindrer sidescroll og sentrerer alt
   - Store knapper: 3x2 grid
   - Små knapper: kvadratiske og fleksible
   - Justert tekst og luft
   ========================================================= */

@media (max-width: 800px) {

  html, body {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
  }

  .mattematch-container {
    padding: 0 0.5rem;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* --- Canvas (sertifikat) --- */
  #gameScreen canvas.mm-cert-canvas {
    display: block;
    width: 90vw !important;
    height: auto !important;
    aspect-ratio: 3 / 4 !important;
    margin: 0.3rem auto 0.8rem auto !important;
    border-radius: 10px;
  }

  /* --- STORE KNAPPER (3x2 layout) --- */
  .grid.compact,
  #practiceGrid.grid.compact,
  .tableButtons {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.8rem !important;
    justify-content: center !important;
    align-items: center !important;
    width: 92vw !important;
    margin: 0.5rem auto 1rem auto !important;
  }

  .grid.compact .cell,
  #practiceGrid.grid.compact .cell,
  .tableButtons .tableBtn {
    aspect-ratio: 1 / 1 !important;
    width: 100% !important;
    min-width: 90px !important;
    max-width: 150px !important;
    font-size: 1.8rem !important;
    border-radius: 10px !important;
    font-weight: 700 !important;
  }

  /* --- SMÅ KNAPPER (large grid) --- */
  .grid.large {
    grid-template-columns: repeat(auto-fit, minmax(7vw, 1fr)) !important;
    gap: 3px !important;
    justify-content: center !important;
    max-width: 95vw !important;
    margin: 0.5rem auto !important;
  }

  .grid.large .cell {
    aspect-ratio: 1 / 1 !important;
    font-size: 0.9rem !important;
    border-radius: 6px !important;
  }

  /* --- Gangetabell-knapper --- */
  .tableButtons {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.6rem !important;
  }

  .tableBtn {
    width: 100% !important;
    padding: 0.6rem 0.4rem !important;
    font-size: 1rem !important;
  }

  /* --- Sertifikatsider --- */
  .main-cert-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.8rem !important;
    width: 90vw !important;
    margin: 0.5rem auto !important;
  }

  .main-cert-box {
    width: 100% !important;
    padding: 0.8rem 0.4rem !important;
    font-size: 0.85rem !important;
  }

  .mini-cert-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.4rem !important;
    width: 90vw !important;
  }

  /* --- Knapper generelt --- */
  .mm-btn {
    width: 85%;
    max-width: 280px;
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
  }

  #gameScreen .back-btn:first-of-type {
    transform: scale(0.9);
    margin-bottom: 0.6rem;
  }

  #gameScreen .back-btn:last-of-type {
    margin-top: 1rem;
    margin-bottom: 1rem;
    width: 75%;
    max-width: 260px;
    align-self: center;
  }

  /* --- Tekster og luft --- */
  .task, #task {
    font-size: clamp(1.4rem, 5vw, 2.4rem);
    margin-bottom: 0.5rem;
  }

  #progress {
    margin-top: 0.6rem;
    margin-bottom: 1rem;
    font-size: 0.95rem !important;
  }

  /* --- Forside --- */
  #startScreen {
    padding-bottom: 1rem;
  }

  #startScreen img {
    max-width: 130px;
  }

  #startScreen .optionGrid {
    width: 90%;
    max-width: 300px;
    gap: 0.7rem;
    margin: 1rem auto;
  }

  /* --- Ekstra fix for små mobiler (lav høyde) --- */
  @media (max-height: 700px) {
    #gameScreen canvas.mm-cert-canvas {
      max-height: 82vh;
      height: 82vh;
    }
  }
}
