/* ==========================================================================
   Matteverkstaden – Interaktivt Matematiklaboratorium (CSS)
   ========================================================================== */

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #f59e0b;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --dark-bg: #0f172a;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --pan-left-color: #dc2626;
  --pan-right-color: #2563eb;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 28px rgba(0,0,0,0.12);
  --radius-lg: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

body.matteverkstad-page {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f6 100%);
  color: var(--text-main);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

/* ─────────────────────────── HEADER ─────────────────────────── */
.spel-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
  color: #ffffff;
  padding: 12px 24px;
  box-shadow: 0 4px 15px rgba(15, 23, 42, 0.3);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-innehall {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.tillbaka-lank {
  color: #94a3b8;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}

.tillbaka-lank:hover {
  color: #fef08a;
  text-decoration: none;
}

.header-titel {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-ikon {
  font-size: 2.2rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.spel-titel {
  font-size: 1.45rem;
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.5px;
  color: #ffffff;
}

.spel-undertitel {
  font-size: 0.78rem;
  color: #cbd5e1;
  margin: 0;
  font-weight: 600;
}

.header-kontroller {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge-pill-stat {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-icon-toggle {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon-toggle:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* ─────────────────────────── NIVÅ-NAV ─────────────────────────── */
.niva-nav {
  background: #ffffff;
  border-bottom: 2px solid var(--border-color);
  padding: 8px 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}

.niva-nav-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.niva-etikett {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-right: 6px;
}

.niva-knapp {
  border: 2px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  border-radius: 24px;
  padding: 6px 16px;
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.niva-knapp:hover {
  border-color: #3b82f6;
  color: #1d4ed8;
  transform: translateY(-1px);
}

.niva-knapp.aktiv {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #1e40af;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.niva-nr-badge {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.niva-knapp.aktiv .niva-nr-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* ─────────────────────────── LAYOUT GRID ─────────────────────────── */
.spel-main {
  padding: 20px 16px 40px;
}

.matte-layout {
  display: grid;
  grid-template-columns: 310px 1fr 290px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1200px) {
  .matte-layout {
    grid-template-columns: 290px 1fr;
  }
  .palett-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .matte-layout {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────── KORT / PANELER ─────────────────────────── */
.matte-kort {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 20px;
  position: relative;
}

/* ── Vänster panel (Uppgift) ── */
.uppgift-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.uppgift-niva-titel {
  font-size: 1.15rem;
  font-weight: 900;
  margin: 0;
  color: #0f172a;
}

.pussel-rakning {
  background: #f1f5f9;
  color: #475569;
  font-weight: 800;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 12px;
}

.uppgift-instruktion {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 16px;
}

/* Ekvationsruta */
.mal-ekvation-kort {
  background: linear-gradient(135deg, #fefce8 0%, #fef08a 100%);
  border: 2px solid #fde047;
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.ekvation-etikett {
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #854d0e;
  margin-bottom: 4px;
}

.ekvation-stor-text {
  font-size: 1.9rem;
  font-weight: 900;
  color: #713f12;
  letter-spacing: 1px;
}

.ekvation-stor-text .lucka {
  display: inline-block;
  background: #ffffff;
  border: 2px dashed #ca8a04;
  color: #ca8a04;
  padding: 0 10px;
  border-radius: 8px;
  min-width: 36px;
}

/* X-justerare för ekvationer */
.x-justerare-box {
  background: #f5f3ff;
  border: 2px solid #ddd6fe;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  text-align: center;
}

.x-justerare-rubrik {
  font-size: 0.8rem;
  font-weight: 800;
  color: #6b21a8;
  margin-bottom: 8px;
}

.x-kontroll-rad {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.btn-x-steg {
  background: #7c3aed;
  color: #ffffff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-x-steg:hover {
  background: #6d28d9;
  transform: scale(1.08);
}

.x-varde-display {
  font-size: 1.5rem;
  font-weight: 900;
  color: #581c87;
  min-width: 70px;
  background: #ffffff;
  padding: 4px 12px;
  border-radius: 8px;
  border: 2px solid #c4b5fd;
}

/* Ekvationsdisplay i realtid (LCD) */
.realtime-lcd-display {
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-bottom: 14px;
  font-family: 'Courier New', Courier, monospace;
}

.lcd-sida {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lcd-etikett {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 700;
  text-transform: uppercase;
}

.lcd-vikt {
  font-size: 1.6rem;
  font-weight: 900;
}

.lcd-vikt.vanster { color: #f87171; }
.lcd-vikt.hoger { color: #60a5fa; }

.lcd-operator {
  font-size: 2rem;
  font-weight: 900;
  color: #94a3b8;
  transition: all 0.3s;
}

.lcd-operator.balans {
  color: #34d399 !important;
  transform: scale(1.25);
  filter: drop-shadow(0 0 6px rgba(52, 211, 153, 0.6));
}

/* Statusindikator */
.balans-status-rad {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 14px;
  transition: all 0.25s;
}

.balans-status-rad.neutral {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.balans-status-rad.vanster-tung {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.balans-status-rad.hoger-tung {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.balans-status-rad.balanserad {
  background: #d1fae5;
  color: #065f46;
  border: 2px solid #34d399;
  animation: pulse-balans 1.5s infinite;
}

@keyframes pulse-balans {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* Feedback-banner */
.feedback-banner {
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 14px;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.feedback-banner.dold {
  display: none;
}

.feedback-banner.ratt {
  background: #ecfdf5;
  color: #065f46;
  border: 2px solid #10b981;
}

.feedback-banner.fel {
  background: #fef2f2;
  color: #991b1b;
  border: 2px solid #ef4444;
}

.feedback-banner.info {
  background: #fffbeb;
  color: #92400e;
  border: 2px solid #f59e0b;
}

/* Ledtrådskort */
.ledtrad-kort {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.84rem;
  color: #92400e;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}

.ledtrad-kort.dold {
  display: none;
}

/* Knappar i uppgiftspanelen */
.uppgift-knapp-rad {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-aktion {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  text-align: center;
}

.btn-nasta {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.btn-nasta:hover:not(:disabled) {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.4);
}

.btn-nasta:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-aterstall {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
}

.btn-aterstall:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.btn-ledtrad {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #b45309;
}

.btn-ledtrad:hover {
  background: #fef3c7;
}

/* ─────────────────────────── BALANSVÅG (MITTEN) ─────────────────────────── */
.vag-kort {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.vag-kort-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.vag-titel {
  font-size: 1.05rem;
  font-weight: 800;
  color: #1e293b;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.vag-vagledare {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.svg-scen-container {
  width: 100%;
  max-width: 960px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-radius: 16px;
  border: 3px solid #334155;
  box-shadow: inset 0 3px 12px rgba(0,0,0,0.5), var(--shadow-sm);
  position: relative;
  overflow: hidden;
  touch-action: none; /* Pointer Events drag */
}

.balans-svg {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

/* Interaktiva zoner i SVG */
.dropzon-hover {
  filter: drop-shadow(0 0 12px #38bdf8);
}

.fat-skal-vanster.dragover,
.fat-skal-hoger.dragover {
  stroke: #fef08a !important;
  stroke-width: 3.5 !important;
}

/* Rörliga och klickbara vikter */
.svg-vikt-klickbar {
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s;
}

.svg-vikt-klickbar:hover {
  opacity: 0.85;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.6));
}

/* ─────────────────────────── HÖGER PANEL (VIKTER) ─────────────────────────── */
.palett-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.palett-kort {
  padding: 18px;
}

.palett-rubrik {
  font-size: 1.05rem;
  font-weight: 900;
  color: #0f172a;
  margin: 0 0 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.palett-hjalptext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* Vikterna i paletten */
.vikt-rack {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 10px 0 16px;
  border-bottom: 2px solid #f1f5f9;
}

.vikt-knapp-dra {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #ffffff;
  border: 2px solid #92400e;
  border-radius: 12px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15), inset 0 2px 2px rgba(255, 255, 255, 0.4);
  font-weight: 900;
  cursor: grab;
  touch-action: none;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
}

.vikt-knapp-dra:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 8px 16px rgba(180, 83, 9, 0.35);
}

.vikt-knapp-dra:active {
  cursor: grabbing;
}

.vikt-knapp-dra[data-vikt="1"] { width: 50px; height: 50px; font-size: 0.9rem; }
.vikt-knapp-dra[data-vikt="2"] { width: 58px; height: 58px; font-size: 1rem; }
.vikt-knapp-dra[data-vikt="3"] { width: 64px; height: 64px; font-size: 1.05rem; }
.vikt-knapp-dra[data-vikt="5"] { width: 72px; height: 72px; font-size: 1.15rem; }
.vikt-knapp-dra[data-vikt="10"] { width: 80px; height: 80px; font-size: 1.25rem; }

.vikt-knapp-dra.vikt-x-typ {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  border-color: #5b21b6;
  width: 68px;
  height: 68px;
  font-size: 1.15rem;
}

.vikt-enhet {
  font-size: 0.65rem;
  font-weight: 700;
  opacity: 0.85;
}

/* Tangentbords- och klick-alternativ (utan drag) */
.snabbkontroll-sektion {
  margin-top: 10px;
}

.snabb-rubrik {
  font-size: 0.82rem;
  font-weight: 800;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.fat-snabb-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
}

.fat-snabb-box.vanster { border-left: 4px solid var(--pan-left-color); }
.fat-snabb-box.hoger { border-left: 4px solid var(--pan-right-color); }

.fat-snabb-etikett {
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.fat-snabb-etikett.vanster { color: #b91c1c; }
.fat-snabb-etikett.hoger { color: #1d4ed8; }

.snabb-knapp-rad {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.btn-snabb-vikt {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.12s;
  flex: 1;
  min-width: 36px;
  text-align: center;
}

.btn-snabb-vikt:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #1d4ed8;
}

.btn-snabb-angra {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.12s;
}

.btn-snabb-angra:hover {
  background: #ef4444;
  color: #ffffff;
}

/* Tangentbordsguide */
.tangentbord-guide {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.76rem;
  color: #475569;
  margin-top: 10px;
}

.tangentbord-guide kbd {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: monospace;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  color: #0f172a;
}

/* ─────────────────────────── DRAG GHOST ─────────────────────────── */
.drag-svavare {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #ffffff;
  font-weight: 900;
  font-size: 1.1rem;
  padding: 10px 16px;
  border-radius: 12px;
  border: 2px solid #78350f;
  box-shadow: 0 10px 25px rgba(0,0,0,0.35);
  transform: translate(-50%, -50%) rotate(-6deg) scale(1.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* ─────────────────────────── MODAL KANVAS ─────────────────────────── */
.modal-matte {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-matte.oppen {
  display: flex;
}

.modal-innehall {
  background: #ffffff;
  border-radius: 20px;
  border: 3px solid #f59e0b;
  max-width: 480px;
  width: 100%;
  padding: 30px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-ikon {
  font-size: 4rem;
  margin-bottom: 12px;
}

.modal-titel {
  font-size: 1.6rem;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 8px;
}

.modal-text {
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ─────────────────────────── FOOTER ─────────────────────────── */
.spel-footer {
  background: #0f172a;
  color: #94a3b8;
  padding: 16px 24px;
  font-size: 0.85rem;
  border-top: 1px solid #1e293b;
  margin-top: 40px;
}

.footer-innehall {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.footer-lank {
  color: #38bdf8;
  text-decoration: none;
  font-weight: 700;
}

.footer-lank:hover {
  text-decoration: underline;
}
