:root {
  --brand: #0f2d5c;
  --brand-light: #dbe9ff;
  --grey: #767676;
  --ns-bg: #dbe9ff;
  --ew-bg: #fde0e0;
  --ok: #1e8e3e;
  --fail: #c0201b;
  --selected: #8ec5ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #f4f6fa;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  color: #111;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 980px;
  margin: 0 auto;
}

#app-header {
  background: var(--brand);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
#app-header h1 {
  margin: 0;
  font-size: 1.15em;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.level-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 90px;
}
.level-card {
  width: 48px;
  height: 73px;
  background-size: cover;
  background-position: center;
  background-color: #fff;
  border: 2px solid #fff;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.level-bar {
  width: 90px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.level-bar-fill {
  height: 100%;
  background: #fff;
  border-radius: 999px;
  width: 0%;
  transition: width 0.7s ease-out;
}
.btn-uitleg {
  flex-shrink: 0;
  background: #fff;
  color: var(--brand);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85em;
  padding: 8px 14px;
  border-radius: 6px;
  white-space: nowrap;
}
.btn-uitleg:hover { background: var(--brand-light); }
.btn-uitleg-disabled {
  color: #999;
  cursor: default;
  opacity: 0.7;
}
.btn-uitleg-disabled:hover { background: #fff; }

#oef-content {
  flex: 1;
  padding: 24px;
}

.prompt {
  font-size: 1.15em;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
}

.context-block {
  margin-bottom: 20px;
}

.sub-part {
  border: 1px solid #d5dce8;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
  background: #fff;
}
.sub-part-label {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 0.8em;
  margin-right: 8px;
}
.sub-part-prompt {
  font-weight: 600;
  margin-bottom: 10px;
  margin-right: 10px;
  display: inline;
}

/* ---------- Kaart-widget ---------- */
.playing-card {
  display: inline-block;
  width: 78px;
  height: 118px;
  background-size: cover;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  vertical-align: top;
}
.playing-card:hover { transform: translateY(-4px); }
.playing-card.selected {
  box-shadow: 0 0 0 3px var(--selected);
  background-color: var(--selected);
  transform: translateY(-6px);
}
.playing-card.placed {
  cursor: default;
}
.playing-card.placed:hover { transform: none; }
.playing-card.ghost {
  opacity: 0.25;
  cursor: default;
}
.playing-card.ghost:hover { transform: none; }

/* ---------- Sorteer-rij (drag) ---------- */
.sort-row {
  display: flex;
  align-items: center;
  padding: 20px 10px;
  background: #fff;
  border: 1px solid #d5dce8;
  border-radius: 8px;
  min-height: 150px;
  user-select: none;
}
.sort-gap {
  width: 14px;
  align-self: stretch;
  flex-shrink: 0;
}
.sort-gap.gap-active {
  background: var(--brand-light);
  border-radius: 4px;
}
.playing-card.dragging { opacity: 0.4; }

/* ---------- Kompas ---------- */
.compass {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 8px;
  max-width: 920px;
  margin: 0 auto 20px;
  padding: 14px;
  border: 3px solid var(--brand);
  border-radius: 10px;
  background: #fff;
}
.compass-cell {
  border-radius: 6px;
  padding: 6px;
  min-height: 40px;
  min-width: 0;
}
/* Elke windrichting krijgt altijd hetzelfde vaste "vak", ongeacht of er
   kaarten in staan - net als de vaste windrichting-boxen in de bridge-
   voorbeelden-maker. Is er een hand, dan wordt die er gewoon overheen
   gelegd; is er niks te tonen, dan blijft het lege, egale vak gewoon staan
   in plaats van een los wit blokje. */
.compass-cell:not(.pos-center) {
  position: relative;
  min-width: 140px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: #fff;
  border: 1.5px solid var(--brand);
  border-radius: 0;
}
/* .fan-hand/.dummy-hand hebben elders (buiten het kompas) een asymmetrische
   marge (8px boven, 20px onder) voor ruimte onder het label - binnen een vak
   staat het label al in de normale flow erboven, dus hier op 0 gezet zodat
   de kaarten direct onder het label beginnen zonder extra witruimte. */
.compass-cell:not(.pos-center) .fan-hand,
.compass-cell:not(.pos-center) .dummy-hand {
  margin: 0;
}
.compass-cell.pos-noord { grid-column: 2; grid-row: 1; }
.compass-cell.pos-west  { grid-column: 1; grid-row: 2; }
.compass-cell.pos-center{ grid-column: 2; grid-row: 2; display:flex; align-items:center; justify-content:center; min-width: 190px; min-height: 270px; }
.compass-cell.pos-oost  { grid-column: 3; grid-row: 2; }
.compass-cell.pos-zuid  { grid-column: 2; grid-row: 3; }
.compass-cell.ns { background: var(--ns-bg); }
.compass-cell.ew { background: var(--ew-bg); }

.dir-label {
  font-weight: 700;
  color: var(--brand);
  text-align: center;
  margin-bottom: 4px;
  font-size: 0.9em;
}
.points-value {
  text-align: center;
  font-size: 1.1em;
  font-weight: 600;
}

.suit-symbol.black { color: #111; }
.suit-symbol.red { color: #c0201b; }

/* Nette rij (andere handen dan die van de leerling) */
.hand-row-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hand-suit-row-real {
  display: flex;
  align-items: center;
  gap: 3px;
}
.hand-suit-row-real .suit-symbol {
  width: 16px;
  font-weight: 700;
  font-size: 1em;
  text-align: center;
  flex-shrink: 0;
}
.playing-card.row-card {
  width: 28px;
  height: 42px;
  cursor: default;
}
.playing-card.row-card:hover { transform: none; }

/* Waaier (hand van de leerling) - afmetingen en posities worden per kaart
   in JS berekend (zelfde algoritme als de voorbeeld-handmaker-app) en als
   inline style gezet; hier alleen het draaimechanisme. */
.fan-hand {
  position: relative;
  margin: 8px auto 20px;
  /* Alle kaarten erin staan position:absolute, dus dit vak heeft zelf geen
     eigen inhoud die zijn breedte "verdient" - zonder flex-shrink:0 zou de
     flexbox-vak-centrering het vak (onzichtbaar) laten krimpen naar ~0 en
     dan verkeerd centreren, terwijl de kaarten daarbinnen op hun vaste
     pixel-positie blijven staan en zo uit het midden lijken te schuiven. */
  flex-shrink: 0;
}
.fan-rotator {
  position: absolute;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}
.playing-card.fan-card {
  position: absolute;
  transition: top 0.15s ease, box-shadow 0.12s ease;
}
.playing-card.fan-card:hover { filter: brightness(1.03); }

/* Dummy (andere hand dan die van de leerling, als er wel een hand van de
   leerling in dezelfde context staat): kolom per kleur, kaarten overlappen
   verticaal zodat alleen de index (rang + kleursymbool linksboven) van elke
   kaart zichtbaar blijft - net genoeg om de kaart te herkennen, en veel
   compacter dan een nette rij. Breedte/hoogte per kolom worden per kaart in
   JS berekend en als inline style gezet. */
.dummy-hand {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin: 8px auto 20px;
  flex-shrink: 0;
}
.dummy-col {
  position: relative;
  flex-shrink: 0;
}
.playing-card.dummy-card {
  position: absolute;
  left: 0;
  top: 0;
  cursor: default;
}
.playing-card.dummy-card:hover { transform: none; }

.hands-context {
  display: flex;
  gap: 40px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: flex-start;
}
.hand-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.trick-cross {
  position: relative;
  width: 190px;
  height: 270px;
  margin: 0 auto;
}
.trick-cross .playing-card {
  position: absolute;
  width: 68px;
  height: 102px;
}
.trick-cross .tc-noord { top: 0; left: 61px; }
.trick-cross .tc-zuid  { top: 168px; left: 61px; }
.trick-cross .tc-west  { top: 84px; left: 0; }
.trick-cross .tc-oost  { top: 84px; left: 122px; }
.trick-cross .tc-placeholder {
  border: 2px dashed #aab2c0;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
}

/* Kompasblokje: altijd zichtbaar bij meer dan één hand, slagkaarten (met
   hogere z-index, later in de DOM) mogen het een beetje overlappen. */
.compass-box {
  position: absolute;
  top: 107px;
  left: 67px;
  width: 56px;
  height: 56px;
  background: #fff;
  border: 2px solid var(--brand);
  border-radius: 4px;
  z-index: 0;
}
.compass-box span {
  position: absolute;
  font-weight: 700;
  font-size: 0.8em;
  color: var(--brand);
}
.compass-box .cb-n { top: 2px; left: 50%; transform: translateX(-50%); }
.compass-box .cb-z { bottom: 2px; left: 50%; transform: translateX(-50%); }
.compass-box .cb-w { left: 4px; top: 50%; transform: translateY(-50%); }
.compass-box .cb-o { right: 4px; top: 50%; transform: translateY(-50%); }

/* ---------- EK / TF knoppen ---------- */
.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.ek-btn {
  padding: 10px 18px;
  border: 2px solid var(--brand);
  border-radius: 6px;
  background: #fff;
  color: var(--brand);
  font-weight: 600;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.12s ease;
}
.ek-btn:hover { background: var(--brand-light); }
.ek-btn.selected {
  background: var(--selected);
  border-color: var(--brand);
}
.ek-btn.suit-btn {
  font-size: 1.4em;
  padding: 8px 16px;
  min-width: 50px;
}

/* ---------- AN / TEXT input ---------- */
.an-input, .text-input {
  font-size: 1.1em;
  padding: 8px 12px;
  border: 2px solid var(--brand);
  border-radius: 6px;
  width: 140px;
}
.text-input { width: 260px; }
.input-error {
  color: var(--fail);
  font-size: 0.85em;
  margin-top: 6px;
  display: none;
}

/* ---------- Footer ---------- */
#app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  background: #fff;
  border-top: 1px solid #d5dce8;
}
.nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 126px;
  height: 126px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
#btn-prev { left: 32px; }
#btn-next { right: 32px; }
.nav-arrow:disabled { opacity: 0.3; cursor: default; }
.footer-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.btn-submit {
  padding: 10px 22px;
  font-size: 1em;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.btn-submit.dim { opacity: 0.35; }
.positie-indicator {
  font-size: 0.85em;
  color: var(--grey);
}

/* ---------- Feedback ---------- */
.feedback-panel {
  margin: 0 24px 20px;
  padding: 18px 20px;
  border-radius: 10px;
  border: 2px solid;
}
.feedback-panel.correct {
  background: #eaf7ee;
  border-color: var(--ok);
}
.feedback-panel.incorrect {
  background: #fbeceb;
  border-color: var(--fail);
}
.feedback-titel {
  font-size: 1.2em;
  font-weight: 700;
  margin-bottom: 8px;
}
.feedback-panel.correct .feedback-titel { color: var(--ok); }
.feedback-panel.incorrect .feedback-titel { color: var(--fail); }
.feedback-uitleg { line-height: 1.5; }

.xp-celebration {
  position: relative;
  margin-top: 12px;
  padding: 20px 22px;
  border-radius: 10px;
  background: #fff;
  border: 2px solid #000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  overflow: visible;
  animation: xp-celebration-in 0.4s ease-out;
}
@keyframes xp-celebration-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.xp-message {
  margin: 0 0 14px;
  font-weight: 800;
  font-size: 1.6em;
  color: var(--ok);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  transform-origin: left center;
  animation: xp-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes xp-pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  60% {
    transform: scale(1.18);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.xp-bar {
  width: 260px;
  max-width: 100%;
  height: 16px;
  border-radius: 999px;
  background: #d5ead9;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: var(--ok);
  border-radius: 999px;
  transition: width 0.9s cubic-bezier(0.22, 0.9, 0.3, 1);
}
.xp-flying-bubble {
  position: fixed;
  left: 0;
  top: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, var(--ok));
  box-shadow: 0 0 8px rgba(30, 142, 62, 0.6);
  pointer-events: none;
  z-index: 999;
}
.level-widget-pulse {
  animation: level-widget-pulse 0.65s ease-out;
}
@keyframes level-widget-pulse {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.25);
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.8));
  }
  100% {
    transform: scale(1);
  }
}
.toast-message {
  color: var(--fail);
  font-size: 0.9em;
  margin-top: 8px;
}

/* ---------- Level-up scherm (nieuwe kaart bereikt) ---------- */
.levelup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 45, 92, 0);
  z-index: 1000;
  cursor: pointer;
  transition: background 0.3s ease;
}
.levelup-overlay[hidden] {
  display: none;
}
.levelup-overlay.show {
  background: rgba(15, 45, 92, 0.72);
}
.levelup-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 36px 44px;
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}
.levelup-overlay.show .levelup-box {
  transform: scale(1);
  opacity: 1;
}
.levelup-card {
  width: 140px;
  height: 214px;
  background-size: cover;
  background-color: #fff;
  border: 3px solid #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 8px rgba(255, 255, 255, 0.15);
  animation: levelup-card-float 1.8s ease-in-out infinite;
}
@keyframes levelup-card-float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-10px) rotate(1.5deg); }
}
.levelup-text {
  margin: 0;
  max-width: 340px;
  text-align: center;
  font-size: 1.5em;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* ---------- Level-uitleg scherm (klik op het level-widget) ---------- */
.level-widget { cursor: pointer; }
.level-info-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 45, 92, 0);
  z-index: 1000;
  padding: 20px;
  transition: background 0.3s ease;
}
.level-info-overlay[hidden] {
  display: none;
}
.level-info-overlay.show {
  background: rgba(15, 45, 92, 0.72);
}
.level-info-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  padding: 36px 28px 28px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}
.level-info-overlay.show .level-info-box {
  transform: scale(1);
  opacity: 1;
}
.level-info-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--grey);
  font-size: 1.4em;
  line-height: 1;
  cursor: pointer;
}
.level-info-close:hover { background: #eef1f6; color: #111; }
.level-info-intro {
  margin: 0;
  text-align: center;
  color: #333;
  line-height: 1.4;
}
.level-info-label {
  margin: 0;
  font-weight: 700;
  text-align: center;
}
.level-info-card {
  width: 120px;
  height: 183px;
  background-size: cover;
  background-position: center;
  background-color: #fff;
  border: 3px solid var(--brand);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.level-info-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e4e9f2;
  overflow: hidden;
}
.level-info-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
  width: 0%;
  transition: width 0.7s ease-out;
}
.level-info-progress {
  margin: 0;
  font-size: 0.9em;
  color: var(--grey);
}
