
:root {
  --bg: #f5f0eb;
  --paper: #faf7f3;
  --ink: #1a1510;
  --ink-light: #6b5f52;
  --accent: #8b3a2a;
  --border: #d4c9bc;
  --shadow: rgba(26,21,16,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── SCREENS ── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── WELCOME ── */
#screen-welcome {
  background: var(--paper);
  align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
}
.welcome-inner { max-width: 620px; }
.study-label {
  font-size: .72rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-light); margin-bottom: 2rem;
}
h1 {
  font-family: 'Cormorant Garamond', serif; font-weight: 300;
  font-size: clamp(2.4rem, 6vw, 3.8rem); line-height: 1.1; margin-bottom: 1.2rem;
}
.welcome-desc {
  font-size: .95rem; line-height: 1.7; color: var(--ink-light);
  margin-bottom: 2.5rem; max-width: 480px; margin-left: auto; margin-right: auto;
}
.divider { width: 48px; height: 1px; background: var(--border); margin: 2rem auto; }

/* ── BUTTONS ── */
.btn-primary {
  background: var(--ink); color: var(--bg); border: none;
  padding: .85rem 2.2rem; font-family: 'DM Sans', sans-serif;
  font-size: .88rem; letter-spacing: .08em; cursor: pointer;
  transition: background .2s, transform .1s; border-radius: 2px;
}
.btn-primary:hover { background: var(--accent); transform: translateY(-1px); }
.btn-secondary {
  background: transparent; color: var(--ink); border: 1px solid var(--border);
  padding: .75rem 1.8rem; font-family: 'DM Sans', sans-serif;
  font-size: .88rem; letter-spacing: .06em; cursor: pointer;
  transition: border-color .2s, background .2s; border-radius: 2px;
}
.btn-secondary:hover { border-color: var(--ink); background: rgba(26,21,16,.04); }
.btn-group { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; }


/* ── TUTORIAL ── */
#screen-tutorial { align-items: center; justify-content: flex-start; padding: 2rem; background: var(--bg); overflow-y: auto; }
.tutorial-card {
  background: var(--paper); border: 1px solid var(--border); border-radius: 4px;
  padding: 2.5rem; max-width: 700px; width: 100%; box-shadow: 0 4px 24px var(--shadow); margin: auto;
}
.tutorial-card h2 { font-family: 'Cormorant Garamond', serif; font-weight: 400; font-size: 1.8rem; margin-bottom: .4rem; }
.tut-steps { margin: 1.8rem 0; display: flex; flex-direction: column; gap: 1rem; }
.tut-step {
  display: flex; gap: 1rem; align-items: flex-start;
  padding: 1rem 1.2rem; background: var(--bg);
  border-left: 3px solid var(--border); border-radius: 0 2px 2px 0;
}
.tut-step .step-num {
  font-family: 'Cormorant Garamond', serif; font-size: 1.6rem; font-weight: 300;
  color: var(--ink-light); line-height: 1; min-width: 24px;
}
.tut-step .step-text { font-size: .88rem; line-height: 1.6; }
.tut-step .step-text strong { font-weight: 500; }

/* ── SURVEY ── */
#screen-survey { background: var(--bg); padding: 0; }
.survey-header {
  background: var(--paper); border-bottom: 1px solid var(--border);
  padding: .9rem 1.5rem; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem; flex-wrap: wrap; flex-shrink: 0;
}
.survey-header .s-title { font-family: 'Cormorant Garamond', serif; font-size: 1.1rem; font-weight: 400; }
.progress-bar {
  flex: 1; min-width: 120px; max-width: 260px; height: 4px;
  background: var(--border); border-radius: 2px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--ink); transition: width .4s ease; border-radius: 2px; }
.progress-label { font-size: .78rem; color: var(--ink-light); white-space: nowrap; }

.survey-body { display: flex; flex: 1; overflow: hidden; }

/* Image panel */
.img-panel {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 2rem; background: var(--paper);
  border-right: 1px solid var(--border); min-width: 0; overflow-y: auto;
}
.stim-label {
  font-size: .72rem; letter-spacing: .15em; text-transform: uppercase;
  color: var(--ink-light); margin-bottom: .8rem;
}
#stimulus-img {
  max-width: 100%; max-height: 340px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 4px;
  box-shadow: 0 4px 20px var(--shadow); display: none;
}
.img-placeholder {
  width: 240px; height: 240px;
  background: linear-gradient(135deg, #ede5dc, #d4c9bc);
  border: 2px dashed var(--border); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--ink-light); font-size: .82rem; padding: 1.5rem;
}
.intensity-row {
  margin-top: 1.2rem; width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: .4rem;
}
.intensity-row label {
  font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-light);
}
.intensity-row .scale-wrap {
  display: flex; align-items: center; gap: .6rem;
}
.intensity-row .scale-val {
  font-family: 'Cormorant Garamond', serif; font-size: 1.2rem; min-width: 20px; text-align: center;
}
.intensity-row .scale-ends {
  display: flex; justify-content: space-between; font-size: .7rem; color: var(--ink-light);
}
.valence-row {
  margin-top: .8rem; width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: .4rem;
}
.valence-row label {
  font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-light);
}
.valence-btns { display: flex; gap: .5rem; }
.valence-btn {
  flex: 1; padding: .4rem; border: 1.5px solid var(--border); border-radius: 2px;
  background: var(--bg); font-size: .82rem; cursor: pointer; font-family: 'DM Sans', sans-serif;
  color: var(--ink-light); transition: all .15s; text-align: center;
}
.valence-btn.selected { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* Drawing panel */
.draw-panel {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 1.2rem; gap: .7rem; min-width: 0; overflow-y: auto;
}

/* Emotion picker – single row of chips, no layer concept visible */
.emotion-pick-bar {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: .5rem;
}
.emotion-pick-bar .bar-label {
  font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-light);
}
.emotion-chips-row {
  display: flex; flex-wrap: wrap; gap: .35rem;
}
.emo-chip {
  padding: .3rem .8rem; border-radius: 20px;
  border: 1.5px solid var(--border); font-size: .82rem; cursor: pointer;
  background: var(--paper); transition: all .15s; color: var(--ink);
  font-family: 'DM Sans', sans-serif;
}
.emo-chip:hover { border-color: var(--ink-light); }
.emo-chip.active {
  background: var(--chip-color, #888);
  border-color: var(--chip-color, #888);
  color: white; font-weight: 500;
}

/* Active emotion indicator */
.active-emotion-info {
  width: 100%; max-width: 380px;
  display: flex; align-items: center; gap: .6rem;
  font-size: .82rem; min-height: 28px;
}
.aei-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.aei-text { color: var(--ink-light); }
.aei-text strong { color: var(--ink); font-weight: 500; }

/* Layer chips below canvas */
.layer-legend {
  width: 100%; max-width: 380px;
  display: flex; flex-wrap: wrap; gap: .35rem; align-items: center;
}
.ll-label { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-light); width: 100%; }
.ll-chip {
  display: flex; align-items: center; gap: .3rem;
  padding: .22rem .6rem; border-radius: 20px;
  border: 1.5px solid; font-size: .78rem;
  font-family: 'DM Sans', sans-serif; cursor: pointer;
  transition: opacity .15s;
}
.ll-chip .lc-dot { width: 7px; height: 7px; border-radius: 50%; }
.ll-chip .lc-rm { opacity: .5; margin-left: .15rem; font-size: .8rem; }
.ll-chip .lc-rm:hover { opacity: 1; }
.ll-chip.active-ll { opacity: 1; }
.ll-chip:not(.active-ll) { opacity: .5; }

/* Body canvas container – the key: SVG outline sits on TOP via z-index */
.body-canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 320px;
  flex-shrink: 0;
  /* outline canvas rendered underneath; SVG on top */
}
/* All drawing canvases stacked absolutely */
.drawing-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: crosshair;
  /* z-index set by JS: layers 10+, mask canvas 5 */
}
.drawing-layer.inactive { pointer-events: none; }
/* SVG outline on top of everything */

/* Tools */
.draw-tools {
  display: flex; gap: .4rem; align-items: center; flex-wrap: wrap;
  width: 100%; max-width: 380px;
}
.tool-btn {
  padding: .28rem .7rem; border: 1px solid var(--border); border-radius: 2px;
  background: var(--paper); font-size: .78rem; cursor: pointer;
  font-family: 'DM Sans', sans-serif; color: var(--ink-light); transition: all .15s;
}
.tool-btn:hover, .tool-btn.active { border-color: var(--ink); color: var(--ink); background: var(--bg); }
.brush-size-wrap { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--ink-light); }

.survey-footer {
  display: flex; justify-content: flex-end; gap: .8rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  background: var(--paper); flex-wrap: wrap; flex-shrink: 0;
}


/* ── DEMOGRAPHICS ── */
#screen-demo { align-items: center; justify-content: flex-start; padding: 2rem; background: var(--bg); overflow-y: auto; }
.form-card {
  background: var(--paper); border: 1px solid var(--border); border-radius: 4px;
  padding: 2.5rem; max-width: 540px; width: 100%; box-shadow: 0 4px 24px var(--shadow);
  margin: auto;
}
.form-card h2 { font-family: 'Cormorant Garamond', serif; font-weight: 400; font-size: 1.8rem; margin-bottom: .4rem; }
.form-card .subtitle { font-size: .83rem; color: var(--ink-light); margin-bottom: 2rem; }
.field { margin-bottom: 1.4rem; }
.field label {
  display: block; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-light); margin-bottom: .45rem;
}
.field input, .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  padding: .65rem .9rem; font-family: 'DM Sans', sans-serif; font-size: .9rem;
  color: var(--ink); border-radius: 2px; transition: border-color .2s; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--ink); }
.field select { cursor: pointer; }
.radio-group { display: flex; gap: 1rem; flex-wrap: wrap; }
.radio-opt { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .9rem; }
.radio-opt input[type=radio] { accent-color: var(--ink); width: 14px; height: 14px; }
.field-note { font-size: .78rem; color: var(--ink-light); margin-top: .35rem; }

/* ── FOLLOW-UP BLOCK (hauptwohnort) ── */
.followup-block {
  display: none;
  margin-top: .2rem;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  padding: 1.2rem 1.2rem 0.8rem;
  background: #fdf7f5;
  animation: slideDown .25s ease;
}
.followup-block.visible { display: block; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.followup-block .followup-title {
  font-size: .78rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 1rem; font-weight: 500;
  display: flex; align-items: center; gap: .4rem;
}
.followup-block .followup-title::before {
  content: '↳'; font-size: 1rem;
}

.consent-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 2px;
  padding: 1rem; font-size: .82rem; line-height: 1.6; color: var(--ink-light);
  margin-bottom: 1.4rem; max-height: 130px; overflow-y: auto;
}
.consent-check { display: flex; align-items: flex-start; gap: .5rem; font-size: .85rem; cursor: pointer; margin-bottom: 1rem; }
.consent-check input { margin-top: .15rem; accent-color: var(--ink); }

/* ── DANKE ── */
.thank-you { text-align: center; padding: 3rem 2rem; margin: auto; }
.thank-you h2 { font-family: 'Cormorant Garamond', serif; font-weight: 300; font-size: 2.5rem; margin-bottom: .8rem; }
.thank-you p { color: var(--ink-light); font-size: .95rem; line-height: 1.7; }


/* ═══════════════════════════════════════════════════════
   ERGÄNZUNGEN — Server-Version
   ═══════════════════════════════════════════════════════ */

/* ── Einwilligung auf der Startseite ── */
#screen-welcome .consent-box { text-align: left; max-height: none; margin: 0 auto 1rem; max-width: 520px; }
#screen-welcome .consent-check { max-width: 520px; margin: 0 auto 1.2rem; text-align: left; }
.consent-box.consent-missing { border-color: #c0392b; background: #fdf0ee; }

/* Honeypot: unsichtbar für Menschen, Bots füllen es aus */
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.pending-banner {
  margin-top: 1.6rem; padding: .9rem 1.1rem;
  border: 1.5px solid var(--accent); border-radius: 4px; background: #fdf7f5;
  font-size: .82rem; color: var(--ink-light);
  display: flex; align-items: center; justify-content: center; gap: .8rem; flex-wrap: wrap;
}

.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary:disabled:hover { background: var(--ink); }

/* ── Aufmerksamkeitsfrage ── */
.att-opt {
  display: flex; align-items: center; gap: .5rem; cursor: pointer;
  padding: .7rem .8rem; border: 1.5px solid var(--border); border-radius: 4px;
  font-size: .95rem; transition: border-color .15s;
  /* .field label setzt Großbuchstaben – für Antwortoptionen unpassend */
  text-transform: none; letter-spacing: normal; color: var(--ink); margin-bottom: 0;
}
.att-opt input { accent-color: var(--ink); width: 18px; height: 18px; }
.att-opt.selected { border-color: var(--ink); background: rgba(26,21,16,.04); }

/* ═══ REGLER — handytauglich ═══
   Große Trefferfläche, Tippen auf die Skala setzt den Wert,
   die Zahlen darunter sind ebenfalls antippbar. */
.uscale { width: 100%; }
.us-hit {
  position: relative; height: 44px; display: flex; align-items: center;
  cursor: pointer; touch-action: none; padding: 0 14px; margin: 0 -14px;
}
.us-track {
  position: relative; flex: 1; height: 8px;
  background: var(--border); border-radius: 4px;
}
.us-fill { position: absolute; left: 0; top: 0; height: 100%; background: var(--ink); border-radius: 4px; }
.us-thumb {
  position: absolute; top: 50%; width: 28px; height: 28px; margin-left: -14px;
  transform: translateY(-50%); border-radius: 50%;
  background: var(--paper); border: 2.5px solid var(--ink);
  box-shadow: 0 2px 6px var(--shadow); transition: transform .1s;
}
.us-thumb.grabbing, .us-thumb:focus-visible { transform: translateY(-50%) scale(1.15); outline: none; }
.us-numbers { display: flex; justify-content: space-between; gap: .2rem; margin-top: .2rem; }
.us-num {
  flex: 1; min-width: 30px; min-height: 34px;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
  font-family: 'DM Sans', sans-serif; font-size: .82rem; color: var(--ink-light); cursor: pointer;
}
.us-num.active { border-color: var(--ink); color: var(--ink); font-weight: 500; background: var(--paper); }
.scale-ends { display: flex; justify-content: space-between; font-size: .74rem; color: var(--ink-light); }

/* ── Bild: groß, antippbar zum Vergrößern ── */
#stimulus-img { cursor: zoom-in; width: 100%; max-width: 620px; max-height: none; }
.zoom-hint { font-size: .74rem; color: var(--ink-light); margin-top: .4rem; }

#lightbox {
  display: none; position: fixed; inset: 0; z-index: 900;
  background: rgba(26,21,16,.94); align-items: center; justify-content: center;
  overflow: hidden; touch-action: none;
}
#lightbox-img {
  max-width: 96vw; max-height: 92vh; object-fit: contain;
  transform-origin: center center; will-change: transform; cursor: grab; touch-action: none;
}
#lightbox-close {
  position: absolute; top: env(safe-area-inset-top, 12px); right: 12px;
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: rgba(250,247,243,.9); color: var(--ink);
  font-size: 1.5rem; line-height: 1; cursor: pointer; z-index: 2;
}
#lightbox-hint {
  position: absolute; bottom: 16px; left: 0; right: 0; text-align: center;
  color: rgba(250,247,243,.75); font-size: .78rem; pointer-events: none;
}

/* ── Körperfigur: so groß wie der Platz es hergibt ──
   Die Breite wird doppelt gedeckelt: durch --fig-max-w und durch die
   verfügbare Höhe (--fig-max-h × Seitenverhältnis). Ohne die zweite Grenze
   ragt die Figur auf flachen Bildschirmen unten heraus.
   --fig-ar setzt survey.js aus der viewBox der Figur → beim Austausch der
   SVG passt sich alles von selbst an. */
.body-canvas-wrap {
  position: relative; width: 100%; margin: 0 auto; flex-shrink: 0;
  aspect-ratio: var(--fig-ar, 0.57);
  max-width: min(var(--fig-max-w, 360px), calc(var(--fig-ar, 0.57) * var(--fig-max-h, 70vh)));
}
.body-outline-img {
  position: relative; z-index: 100; display: block;
  width: 100%; height: auto;
  pointer-events: none; user-select: none;
}
.drawing-layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  cursor: crosshair; touch-action: none;   /* kein Scrollen/Zoomen beim Malen */
}
.drawing-layer.inactive { pointer-events: none; }

/* ── Fußzeile: Hinweis, wann "Weiter" möglich ist ── */
.survey-footer { align-items: center; }
.next-hint { flex: 1; min-width: 180px; font-size: .78rem; color: var(--accent); margin: 0; }
.brush-size-wrap { flex-direction: column; align-items: stretch; gap: .1rem; min-width: 140px; flex: 1; }

/* ═══ LAYOUT — Handy zuerst ═══ */
.survey-body { display: flex; flex: 1; min-height: 0; }
.img-panel, .draw-panel, .rating-panel, .left-col { min-width: 0; }
.left-col {
  flex: 1; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow-y: auto; min-width: 0;
}
.img-panel { border-right: none; }
.rating-panel {
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
  padding: 0 1.5rem 1.5rem;
}
.rating-panel .intensity-row, .rating-panel .valence-row { margin-top: 0; }

@media (max-width: 900px) {
  .survey-body { flex-direction: column; overflow: visible; }
  #screen-survey { overflow-y: auto; }
  /* Reihenfolge auf dem Handy: Bild → einzeichnen → bewerten.
     display:contents löst die Desktop-Spalte auf, damit die Bewertung
     unter die Figur rutscht und diese direkt nach dem Bild sichtbar wird. */
  .left-col { display: contents; }
  .img-panel { order: 1; }
  .draw-panel { order: 2; }
  .rating-panel { order: 3; padding: 0 .8rem 1rem; }
  .img-panel {
    border-right: none; border-bottom: 1px solid var(--border);
    padding: .6rem .8rem .8rem;
  }
  .draw-panel { border-bottom: 1px solid var(--border); }
  #stimulus-img { max-height: 32vh; }
  .stim-label { margin-bottom: .5rem; }
  .draw-panel { padding: .8rem; gap: .6rem; }
  .body-canvas-wrap { --fig-max-w: min(380px, 90vw); --fig-max-h: 78vh; }
  .survey-header { padding: .7rem .9rem; }
  .survey-footer { padding: .8rem .9rem; gap: .5rem; }
  .survey-footer .btn-primary, .survey-footer .btn-secondary { padding: .8rem 1.3rem; }
  .emo-chip { padding: .45rem .9rem; font-size: .88rem; }   /* größere Tippziele */
  .tool-btn { padding: .45rem .8rem; font-size: .82rem; }
  .valence-btn { padding: .6rem .3rem; }
  .form-card, .tutorial-card { padding: 1.4rem 1.1rem; }
  .field input, .field select { padding: .8rem .9rem; font-size: 1rem; }
  .radio-opt { padding: .3rem 0; font-size: .95rem; }
}

/* Ab Tablet: zwei Spalten, beide Seiten nutzen die volle Höhe */
@media (min-width: 901px) {
  #screen-survey { height: 100vh; overflow: hidden; }
  .img-panel { padding: 1.5rem; flex: 1; }
  .draw-panel { overflow-y: auto; }
  #stimulus-img { max-height: 52vh; }
  /* Abzug für Kopf-/Fußzeile, Emotions-Chips, Werkzeuge und Legende */
  .body-canvas-wrap { --fig-max-w: 420px; --fig-max-h: calc(100vh - 452px); }
}
@media (min-width: 1400px) {
  .body-canvas-wrap { --fig-max-w: 480px; --fig-max-h: calc(100vh - 452px); }
  #stimulus-img { max-height: 58vh; }
}

/* Flache Bildschirme (z. B. 1280×720): Bedienelemente zusammenrücken,
   damit für die Figur mehr Höhe übrig bleibt */
@media (min-width: 901px) and (max-height: 860px) {
  .draw-panel { gap: .45rem; padding: .8rem 1rem; }
  .emotion-pick-bar { gap: .3rem; }
  .emotion-pick-bar .bar-label { font-size: .68rem; line-height: 1.3; }
  .active-emotion-info { min-height: 20px; font-size: .78rem; }
  .brush-size-wrap { flex-direction: row; align-items: center; gap: .5rem; }
  .brush-size-wrap #scale-brush { flex: 1; min-width: 90px; }
  .brush-size-wrap .us-hit { height: 32px; }
  .body-canvas-wrap { --fig-max-h: calc(100vh - 385px); }
}

/* Dezente Versionsanzeige — hilft beim Testen zu erkennen,
   ob der Browser noch eine alte Fassung aus dem Cache zeigt */
.app-version { margin-top: 2rem; font-size: .68rem; color: var(--border); letter-spacing: .05em; }
