/* =============================================================
   Enhanced Stylesheet v12.2 – jsPsych Standard Progressive Matrices
   Palette: Mist Blue (Hue ≈ 210°)
   ============================================================= */

/******************** 1. Root Tokens ********************/
:root {
  /* Mist-Blue palette */
  --clr-accent-h: 210;
  --accent-50: hsl(210 28% 97%);
  --accent-100: hsl(210 24% 92%);
  --accent-200: hsl(210 22% 84%);
  --accent-300: hsl(210 20% 70%);
  --accent-400: hsl(210 22% 60%);
  --accent-500: hsl(210 24% 50%);
  --accent-600: hsl(210 26% 42%);
  --accent-700: hsl(210 28% 36%);

  /* Neutrals */
  --grey-100: #fff;
  --grey-200: #f7f7f7;
  --grey-300: #e6e6e6;
  --grey-400: #d0d0d0;
  --grey-500: #9e9e9e;
  --grey-600: #666;
  --grey-700: #444;
  --grey-800: #222;
  --grey-900: #151515;

  /* Semantic */
  --primary-color: var(--grey-800);
  --secondary-color: var(--grey-600);
  --accent-color: var(--accent-500);
  --box-bg: var(--grey-100);
  --bg-color: var(--grey-200);
  --border-color: var(--grey-300);
  --success-bg: hsla(141, 45%, 55%, 0.23);
  --danger-bg: hsla(4, 70%, 55%, 0.23);

  /* Typography */
  --font-base: clamp(1rem, 0.9rem+0.45vw, 1.2rem);
  --lh-base: 1.45;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: var(--font-base);
  line-height: var(--lh-base);
  color: var(--primary-color);
  background: var(--bg-color);
  scroll-behavior: smooth;
}

/******************** Dark-Mode Override ********************/
body.dark {
  --clr-accent-h: 214;
  --accent-50: hsl(214 30% 95%);
  --accent-100: hsl(214 26% 88%);
  --accent-200: hsl(214 24% 78%);
  --accent-300: hsl(214 22% 64%);
  --accent-400: hsl(214 24% 56%);
  --accent-500: hsl(214 26% 48%);
  --accent-600: hsl(214 28% 42%);
  --accent-700: hsl(214 30% 36%);

  --primary-color: var(--grey-100);
  --secondary-color: var(--grey-400);
  --box-bg: var(--grey-900);
  --bg-color: var(--grey-800);
  --border-color: var(--grey-700);
}

/******************** 2. Reset & Generics ********************/
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
a {
  text-decoration: none;
  color: inherit;
}

/******************** 3. Header ********************/
#jspsych-content {
  max-width: 1800px;
  margin-inline: auto;
  width: 100%;
}
#spm-header {
  position: relative;
  --gap: clamp(0.35rem, 0.8vw, 1rem);
  width: min(70%, 1800px);
  margin: 0rem auto 0.4rem;
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  align-items: center !important;
  min-height: 5.6rem !important; /* Increase and force exact height */
  padding: 0.5rem 0 !important;
}
/* Page Counter */
#spm-page-counter {
  justify-self: start; /* Override to left-align */
  font-size: clamp(2.4rem, 1.3em + 3vw, 3.5rem);
  font-weight: 400;
  color: #000;
  line-height: 1;
  background: var(--accent-50);
  padding: 0.12em 0.6em;
  border-radius: 9px;
  flex: 0 0 auto !important;
}

#spm-timer {
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) !important;
  height: 2.5rem !important;
  width: auto !important;
  min-width: 5rem !important;
  text-align: center;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 600;
  color: var(--secondary-color);
}

/* Special styling for opacity-based hidden timer */
#spm-timer[style*="opacity:0"] {
  visibility: visible !important; /* Force it to take space */
}

/******************** 4. Progress Bar ********************/
#spm-progress {
  width: min(70%, 1800px);
  height: 10px;
  margin: 0 auto 1.4rem;
  background: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.08);
}
#spm-progress::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 12px var(--accent-400);
  pointer-events: none;
  opacity: 0.55;
}
#spm-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-400), var(--accent-600));
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

/******************** 5. Card Container & Dividers ********************/
#spm-container {
  width: min(70%, 1800px);
  margin: 0 auto 2.2rem;
  background: var(--box-bg);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: clamp(1.25rem, 2.6vw, 2.3rem);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 2vw, 1.6rem);
}
#spm-container > * + * {
  border-top: 1px solid var(--border-color);
}

/******************** 6. Prompt & Instructions ********************/
#spm-prompt-box,
#spm-instructions-box {
  background: var(--bg-color);
  padding: 1rem 1.4rem;
  border-radius: 10px;
  color: var(--secondary-color);
  text-align: center;
  line-height: 1.4;
}

/******************** 7. Stimulus Box ********************/
#spm-stimulus-box {
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1/1;
  margin-inline: auto;
  background: var(--grey-100);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.05);
}
body.dark #spm-stimulus-box {
  background: var(--grey-100);
}
.spm-stimulus-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/******************** 8. Answer Grid ********************/
#spm-gray-box {
  --size-min: 7.2rem;
  --size-target: 9rem;
  --size-max: 11rem;
  width: 80%;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  justify-content: center;
  padding: 1.1rem;
  background: var(--bg-color);
  border-radius: 14px;
}

/******************** 9. Answer Items ********************/
.spm-item-container {
  flex: 0 0 clamp(var(--size-min), var(--size-target), var(--size-max));
  aspect-ratio: 1/1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--box-bg);
  border: none;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.spm-item-container:hover {
  transform: translateY(-6px) scale(1.06);
  box-shadow: 0 0 0 2px var(--accent-400), 0 9px 22px rgba(0, 0, 0, 0.13);
}
.spm-item-container:has(input:checked) {
  background: var(--accent-300);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.08);
}
.spm-item-container:has(input:checked) .spm-label {
  background: transparent;
  color: var(--accent-700);
}
.spm-item-container:active {
  animation: hapticFlash 0.15s ease-out;
}
@keyframes hapticFlash {
  0% {
    box-shadow: 0 0 0 0 var(--accent-300) inset;
  }
  50% {
    box-shadow: 0 0 0 6px var(--accent-300) inset;
  }
  100% {
    box-shadow: 0 0 0 0 var(--accent-300) inset;
  }
}

/* Feedback tint */
.feedback .spm-item-container {
  cursor: default;
  transform: none;
  box-shadow: none;
}
.feedback .spm-item-container[data-correct="true"] {
  background: var(--success-bg);
}
.feedback .spm-item-container[data-incorrect="true"] {
  background: var(--danger-bg);
}

.spm-item-container img {
  width: 85%;
  height: 75%;
  object-fit: contain;
  margin: auto;
  background: #fff;
  border: none;
}
.spm-label {
  width: 100%;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.35rem;
  font-size: 0.78em;
  font-weight: 700;
  color: var(--primary-color);
  background: var(--box-bg);
  border-radius: 0 0 12px 12px;
  background: transparent; /* statt var(--box-bg) */
  transition: color 0.25s; /* kein bg-Transition mehr nötig */
}
body.dark .spm-label {
  color: var(--grey-100);
}

/******************** 10. Hidden Checkbox ********************/
.spm-item-container input[type="checkbox"] {
  display: none;
}

/******************** 11. Ripple Fallback ********************/
.spm-item-container:active::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(0, 0, 0, 0.07);
  animation: ripple 0.45s ease-out;
}
@keyframes ripple {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/******************** 12. Footer & Skip Checkbox ********************/
#spm-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}
#spm-skip-container {
  visibility: hidden;
  font-size: 0.9em;
  color: var(--secondary-color);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
#spm-skip-container.visible {
  visibility: visible;
}
#spm-skip-container input {
  appearance: none;
  cursor: pointer;
  width: 1.25em;
  height: 1.25em;
  border: 2px solid var(--accent-500);
  border-radius: 4px;
  display: inline-block;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
#spm-skip-container input:checked {
  background: var(--accent-500);
  border-color: var(--accent-500);
}
#spm-skip-container input:checked::before {
  content: "\2713";
  color: #fff;
  font-size: 0.8em;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/******************** 13. Next Button ********************/
#spm-next {
  padding: 0.9em 2.6em;
  background: linear-gradient(90deg, var(--accent-400), var(--accent-600));
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 1.02em;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
  transition: transform 0.18s, box-shadow 0.25s;
  position: relative;
  overflow: hidden;
}
#spm-next::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.25);
  mix-blend-mode: overlay;
  pointer-events: none;
}
#spm-next:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}
#spm-next:disabled {
  background: var(--border-color);
  color: var(--secondary-color);
  cursor: default;
  box-shadow: none;
}

/******************** 14. Motion Safe ********************/
/******************** 15. Responsive Tweaks – COUNTER ADJUSTED ********************/

/******************** Media – Höhen ************************/
/* Proportionen wie bei max-height:700px, jetzt für Breite ≤ 1200px */
@media (max-width: 1200px) {
  :root {
    --font-base: clamp(0.5rem, 0.4rem + 0.12vw, 0.65rem);
  }

  #spm-header {
    height: 5rem;
  }

  #spm-container {
    gap: 0.3rem;
    padding-top: 0.6rem;
    padding-bottom: 0;
    margin-bottom: -0.2rem;
  }
  #spm-container > * + * {
    padding-top: 0.4rem;
  }

  #spm-timer {
    font-size: 1.5rem;
    padding-top: 1rem;
    gap: 0;
  }

  #spm-progress {
    height: 3px;
    margin: 0 auto 0.4rem;
  }

  #spm-stimulus-box {
    max-width: 190px;
    padding: 0.7rem;
  }

  #spm-gray-box {
    width: 60% !important;
    --size-target: 9.8rem !important;
  }
  #spm-prompt-box {
    min-height: 7.2rem;
  }
  #spm-instructions-box {
    line-height: 1.4;
    padding: 0.3rem;
  }

  #spm-page-counter {
    font-size: clamp(1rem, 1.4rem + 0.7vw, 1.5rem) !important;
  }
  #spm-next {
    font-size: 0.58em;
    padding: 0.5em 1em;
  }
  #spm-prompt-text,
  #spm-instructions-text {
    font-size: 0.5em !important;
    padding: 0;
  }

  .spm-label {
    font-size: 0.5em;
    padding-bottom: 1rem;
  }

  #spm-skip-container {
    font-size: 0.7em;
    padding-bottom: 1rem;
  }
}

/* Proportionen wie bei max-height:700px, jetzt für Breite ≤ 900px */
@media (max-width: 900px) {
  :root {
    --font-base: clamp(0.5rem, 0.4rem + 0.12vw, 0.65rem);
  }

  #spm-header {
    height: 5rem;
  }

  #spm-container {
    gap: 0.3rem;
    padding-top: 0.6rem;
    padding-bottom: 0;
    margin-bottom: -0.2rem;
  }
  #spm-container > * + * {
    padding-top: 0.4rem;
  }

  #spm-timer {
    font-size: 1.5rem;
    padding-top: 1rem;
    gap: 0;
  }

  #spm-progress {
    height: 3px;
    margin: 0 auto 0.4rem;
  }

  #spm-stimulus-box {
    max-width: 190px;
    padding: 0.7rem;
  }

  #spm-gray-box {
    width: 60% !important;
    --size-target: 9.8rem !important;
  }
  #spm-prompt-box {
    min-height: 7.2rem;
  }
  #spm-instructions-box {
    line-height: 1.4;
    padding: 0.3rem;
  }

  #spm-page-counter {
    font-size: clamp(1rem, 1.4rem + 0.7vw, 1.5rem) !important;
  }
  #spm-next {
    font-size: 0.58em;
    padding: 0.5em 1em;
  }
  #spm-prompt-text,
  #spm-instructions-text {
    font-size: 0.5em !important;
    padding: 0;
  }

  .spm-label {
    font-size: 0.5em;
    padding-bottom: 1rem;
  }

  #spm-skip-container {
    font-size: 0.7em;
    padding-bottom: 1rem;
  }
}

@media (max-width: 600px) {
  :root {
    --font-base: clamp(0.46rem, 0.36rem + 0.15vw, 0.6rem);
  } /* Schrift ↓ */
  #spm-stimulus-box {
    max-width: 200px;
  } /* Stimulus ↑ */

  #spm-gray-box {
    width: 90%;
    --size-target: 9.1rem;
    gap: 0.4rem;
  } /* Grid ↑ */
  #spm-page-counter {
    font-size: clamp(0.85rem, 0.55rem + 0.8vw, 1.1rem) !important;
  }
  #spm-timer {
    font-size: 0.64rem;
  }

  #spm-next {
    font-size: 0.7em;
    padding: 0.55em 1.5em;
  }
  #spm-prompt-box {
    min-height: 2rem;
  }
  #spm-prompt-text,
  #spm-instructions-text {
    font-size: 0.5em !important;
  }
}

/******************** Media – Höhen ************************/
@media (max-height: 850px) {
  :root {
    --font-base: clamp(0.5rem, 0.4rem + 0.12vh, 0.65rem);
  }

  #spm-header {
    height: 5rem; /* Allow variable height on smaller screens */
  }

  #spm-container {
    gap: 0.3rem;
    padding-top: 0.6rem;
    padding-bottom: 0rem;
    margin-bottom: -0.2rem;
  }
  #spm-container > * + * {
    padding-top: 0.4rem;
  }

  #spm-timer {
    font-size: 1.5rem;
    padding-top: 1rem;
    gap: 0;
  }

  #spm-progress {
    height: 3px;
    margin: 0 auto 0.4rem;
  }

  #spm-stimulus-box {
    max-width: 190px;
    padding: 0.7rem;
  }

  #spm-gray-box {
    width: 60% !important;
    --size-target: 9.8rem !important;
  }
  #spm-prompt-box {
    min-height: 7.6rem;
  }
  #spm-instructions-box {
    line-height: 1.4;
    padding: 0.3rem;
  }

  #spm-page-counter {
    font-size: clamp(1rem, 1.4rem + 0.7vw, 1.5rem) !important;
  }
  #spm-next {
    font-size: 0.58em;
    padding: 0.5em 1em;
  }
  #spm-prompt-text,
  #spm-instructions-text {
    font-size: 0.5em !important;
    padding: 0rem;
  }

  .spm-label {
    font-size: 0.5em;
    padding-bottom: 1rem;
  }

  #spm-skip-container {
    font-size: 0.7em;
    padding-bottom: 1rem;
  }
}

@media (max-height: 700px) {
  :root {
    --font-base: clamp(0.5rem, 0.4rem + 0.12vh, 0.65rem);
  }

  #spm-header {
    height: 5rem; /* Allow variable height on smaller screens */
  }

  #spm-container {
    gap: 0.3rem;
    padding-top: 0.6rem;
    padding-bottom: 0rem;
    margin-bottom: -0.2rem;
  }
  #spm-container > * + * {
    padding-top: 0.4rem;
  }

  #spm-timer {
    font-size: 1.5rem;
    padding-top: 1rem;
    gap: 0;
  }

  #spm-progress {
    height: 3px;
    margin: 0 auto 0.4rem;
  }

  #spm-stimulus-box {
    max-width: 190px;
    padding: 0.7rem;
  }

  #spm-gray-box {
    width: 60% !important;
    --size-target: 9.8rem !important;
  }
  #spm-prompt-box {
    min-height: 7.2rem;
  }
  #spm-instructions-box {
    line-height: 1.4;
    padding: 0.3rem;
  }

  #spm-page-counter {
    font-size: clamp(1rem, 1.4rem + 0.7vw, 1.5rem) !important;
  }
  #spm-next {
    font-size: 0.58em;
    padding: 0.5em 1em;
  }
  #spm-prompt-text,
  #spm-instructions-text {
    font-size: 0.5em !important;
    padding: 0rem;
  }

  .spm-label {
    font-size: 0.5em;
    padding-bottom: 1rem;
  }

  #spm-skip-container {
    font-size: 0.7em;
    padding-bottom: 1rem;
  }
}

/******************** Mobile Header Fallback ********************/
@media (max-width: 640px) {
  #spm-header {
    grid-template-columns: 1fr;
    text-align: center;
    height: auto; /* Allow variable height on mobile */
    padding-bottom: 0.6rem; /* Ensure consistent spacing */
  }
  #spm-page-counter,
  #spm-timer {
    position: static;
    transform: none;
    justify-self: center;
  }
  #spm-page-counter,
  #spm-timer {
    position: static;
    transform: none;
    justify-self: center;
  }
}
