/* === Schnucki — Villa Kunterbunt === */
:root {
  --paper:        #f7eed8;
  --paper-dark:   #ecdcb6;
  --ink:          #3a2a1f;
  --ink-soft:     #6b4f3b;
  --rot:          #d94e4e;   /* Pippi watermelon */
  --rot-deep:     #b53a3a;
  --senf:         #e2a92e;   /* mustard */
  --senf-dark:    #b9842a;
  --teal:         #2b8a8a;
  --teal-dark:    #1f6868;
  --rose:         #f2c5c0;
  --gold:         #c69a3a;
  --shadow:       0 6px 24px rgba(58,42,31,.18), 0 2px 6px rgba(58,42,31,.12);
  --shadow-soft:  0 2px 10px rgba(58,42,31,.10);
  --radius:       16px;
  --radius-lg:    22px;
  --maxw:         640px;
  --serif:        "Fraunces", Georgia, "Times New Roman", serif;
  --sans:         "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #fce0c5 0, transparent 38%),
    radial-gradient(circle at 90% 92%, #d6e9e3 0, transparent 40%),
    var(--paper);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
}

/* subtle paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  background-image:
    radial-gradient(rgba(58,42,31,.05) 1px, transparent 1px),
    radial-gradient(rgba(58,42,31,.04) 1px, transparent 1px);
  background-size: 3px 3px, 7px 7px;
  background-position: 0 0, 1px 2px;
  mix-blend-mode: multiply;
}

.noscript {
  margin: 2rem;
  padding: 1rem 1.2rem;
  background: var(--rot);
  color: #fff;
  border-radius: var(--radius);
  text-align: center;
}

.app {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.screen { animation: fade-in .5s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* === Title screen === */
.title-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 8px 48px;
  gap: 18px;
}
.title-art { width: min(62vw, 220px); aspect-ratio: 1; }
.pippi-svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 8px 16px rgba(217,78,78,.18));
  animation: bob 5s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-4px) rotate(-1.5deg); } }
.title {
  margin: 0;
  display: grid;
  gap: 6px;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: .01em;
  line-height: 1.05;
}
.title-pre {
  font-size: .8rem;
  font-family: var(--sans);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .22em;
  color: var(--teal);
}
.title-main {
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  font-weight: 900;
  color: var(--rot);
  text-shadow: 2px 2px 0 var(--paper-dark);
}
.title-main em {
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
  font-size: .55em;
  display: inline-block;
  margin: .1em 0;
}
.title-sub {
  font-size: .95rem;
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink-soft);
}
.title-actions { display: flex; flex-direction: column; gap: 10px; width: min(100%, 320px); margin-top: 6px; }
.dedication {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  margin-top: 14px;
  font-size: .95rem;
}

/* === Buttons === */
.btn {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  text-align: center;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, color .2s ease;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: .01em;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  background: var(--rot);
  color: #fff;
  box-shadow: 0 4px 0 var(--rot-deep), var(--shadow-soft);
}
.btn-primary:hover { background: var(--rot-deep); }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 2px dashed var(--ink-soft);
}
.btn-ghost:hover { background: rgba(58,42,31,.06); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* === Game === */
.game-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 0 18px;
  gap: 12px;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}
.iconbtn {
  background: var(--paper-dark);
  border: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}
.chapter-pill {
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  font-size: .85rem;
  padding: 6px 12px;
  border-radius: 999px;
  flex: 1;
  text-align: center;
  letter-spacing: .04em;
}
.stats { display: flex; gap: 6px; }
.stat {
  background: var(--paper-dark);
  border-radius: 12px;
  padding: 6px 8px;
  font-size: .8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  transition: transform .35s ease, background .35s;
}
.stat b { font-weight: 800; }
.stat.bump { animation: bump .55s ease; background: var(--senf); }
@keyframes bump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.25) rotate(-6deg); }
  70%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* === Scene card === */
.scene {
  background: #fffaf0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  position: relative;
  overflow: hidden;
  flex: 1;
  border: 1px solid rgba(58,42,31,.08);
}
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 100% 0%, rgba(226,169,46,.08), transparent 50%);
}
.scene h2 {
  font-family: var(--serif);
  font-weight: 900;
  color: var(--rot);
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 5vw, 1.9rem);
  line-height: 1.15;
}
.scene .subtitle {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--teal);
  font-size: .75rem;
  font-weight: 800;
  margin: 0 0 14px;
}
.scene p {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ink);
}
.scene p.italic { font-style: italic; color: var(--ink-soft); }
.scene .speak {
  background: linear-gradient(180deg, #fff5e0, #fdedc7);
  border-left: 4px solid var(--senf);
  padding: 10px 14px;
  border-radius: 12px;
  margin: 8px 0 14px;
}
.scene .speak.pippi { border-left-color: var(--rot); background: linear-gradient(180deg, #ffe8e6, #ffd5d1); }
.scene .speak.opa   { border-left-color: var(--teal); background: linear-gradient(180deg, #e2efed, #cee4e0); }
.scene .speak strong { font-weight: 800; color: var(--rot); }
.scene .speak.opa strong { color: var(--teal-dark); }

/* === Choices === */
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.choice {
  background: #fffaf0;
  color: var(--ink);
  border: 2px solid var(--paper-dark);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all .18s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-soft);
}
.choice::before {
  content: "›";
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--rot);
  flex: 0 0 auto;
}
.choice:hover { background: var(--paper-dark); transform: translateX(2px); border-color: var(--senf); }
.choice:active { transform: translateX(2px) scale(.99); }
.choice.continue {
  background: var(--rot);
  color: #fff;
  border-color: var(--rot-deep);
  box-shadow: 0 4px 0 var(--rot-deep), var(--shadow-soft);
  justify-content: center;
}
.choice.continue::before { color: #fff; content: "→"; }
.choice.locked { opacity: .55; cursor: not-allowed; pointer-events: none; }
.choice .meta {
  margin-left: auto;
  font-size: .75rem;
  font-weight: 800;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: .1em;
}

/* === Puzzle frames === */
.puzzle {
  background: var(--paper);
  border: 2px dashed var(--senf);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.puzzle h3 {
  font-family: var(--serif);
  margin: 0 0 6px;
  color: var(--rot);
  font-size: 1.1rem;
}
.puzzle .hint {
  font-size: .85rem;
  color: var(--ink-soft);
  font-style: italic;
  margin-bottom: 10px;
}

/* Cipher puzzle */
.cipher {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.35rem;
  letter-spacing: .15em;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  border: 1px solid var(--paper-dark);
  margin-bottom: 10px;
  word-break: break-word;
}
.cipher .ch {
  display: inline-block;
  min-width: 1.2em;
}
.cipher .key { color: var(--rot); font-weight: 700; }
.cipher-form { display: flex; gap: 8px; flex-wrap: wrap; }
.cipher-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: var(--sans);
  font-weight: 700;
  border: 2px solid var(--paper-dark);
  background: #fff;
  border-radius: 12px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .12em;
}
.cipher-input:focus { outline: none; border-color: var(--rot); }

/* Coin puzzle */
.coins {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px 0;
}
.coin {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 3px solid var(--senf-dark);
  background: radial-gradient(circle at 35% 30%, #f6d27a, var(--senf) 60%, var(--senf-dark));
  font-family: var(--serif);
  font-weight: 900;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  line-height: 1;
  box-shadow: 0 3px 0 rgba(58,42,31,.18), inset 0 -3px 4px rgba(58,42,31,.15);
  transition: transform .12s ease;
  user-select: none;
}
.coin small { font-size: .55rem; font-weight: 700; opacity: .7; }
.coin:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(58,42,31,.2), inset 0 -2px 4px rgba(58,42,31,.15); }
.coin.silver {
  background: radial-gradient(circle at 35% 30%, #f4f4f4, #c8c8c8 60%, #898989);
  border-color: #777;
}
.coin.copper {
  background: radial-gradient(circle at 35% 30%, #f3c89a, #c97e3a 60%, #9a5b22);
  border-color: #7c451a;
  color: #2c1a0c;
}
.purse {
  background: var(--ink);
  color: var(--paper);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  font-family: var(--serif);
  margin-top: 10px;
}
.purse .total { font-size: 1.6rem; font-weight: 900; display: block; }
.purse .target { font-size: .85rem; opacity: .8; }
.purse .total.ok { color: #9bdca4; }
.purse .total.over { color: #ffb0a8; }
.purse-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: center; }
.minibtn {
  background: var(--paper-dark);
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: .85rem;
  color: var(--ink);
  cursor: pointer;
}

/* Memory match */
.match-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.match-card {
  aspect-ratio: 3/4;
  border-radius: 12px;
  background: var(--teal);
  cursor: pointer;
  position: relative;
  perspective: 600px;
  transition: transform .25s ease;
}
.match-card .face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  backface-visibility: hidden;
  transition: transform .55s cubic-bezier(.4,.1,.3,1.3);
  text-align: center;
  padding: 4px;
  font-weight: 800;
  font-family: var(--sans);
}
.match-card .back {
  background: var(--teal);
  color: #fff;
  font-family: var(--serif);
  font-weight: 900;
  font-size: 1.4rem;
}
.match-card .back::after { content: "★"; }
.match-card .front {
  background: #fff;
  color: var(--ink);
  transform: rotateY(180deg);
  font-size: clamp(.7rem, 2.4vw, .95rem);
  flex-direction: column;
  gap: 4px;
}
.match-card .front .emoji { font-size: 1.7rem; }
.match-card.flipped .back  { transform: rotateY(180deg); }
.match-card.flipped .front { transform: rotateY(360deg); }
.match-card.matched { animation: matched .5s ease; }
.match-card.matched .front { background: #d8efe6; border: 2px solid var(--teal); }
@keyframes matched { 30% { transform: scale(1.06); } }

/* Music pattern */
.notes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.note {
  aspect-ratio: 1.4/1;
  border: none;
  border-radius: 14px;
  font-size: 1.6rem;
  cursor: pointer;
  font-weight: 900;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0,0,0,.18);
  box-shadow: 0 4px 0 rgba(58,42,31,.25);
  transition: transform .08s ease, filter .12s ease;
}
.note[data-color="rot"]  { background: var(--rot);  }
.note[data-color="senf"] { background: var(--senf); }
.note[data-color="teal"] { background: var(--teal); }
.note[data-color="rose"] { background: var(--rose); color: var(--ink); text-shadow: none; }
.note.playing { transform: translateY(2px) scale(1.05); filter: brightness(1.25); }
.pattern-status {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  margin: 8px 0 0;
  color: var(--ink-soft);
}

/* Word puzzle */
.word-anagram {
  font-family: var(--serif);
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: .15em;
  text-align: center;
  margin-bottom: 8px;
  color: var(--rot);
}
.word-input {
  width: 100%;
  padding: 14px;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--paper-dark);
  background: #fff;
  border-radius: 12px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .15em;
}
.word-input:focus { outline: none; border-color: var(--rot); }

/* Decorative scene art */
.scene-art {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 14px;
  height: auto;
}

/* Inline feedback */
.feedback {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: .92rem;
}
.feedback.ok    { background: #d8efe6; color: var(--teal-dark); }
.feedback.nope  { background: #ffe2dc; color: var(--rot-deep); }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(58,42,31,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fade-in .25s ease;
}
.overlay-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  max-width: 420px;
  width: 100%;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
.overlay-card h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  color: var(--rot);
}
.overlay-card p { margin: 0; font-family: var(--serif); }
.credit-quote {
  font-style: italic;
  color: var(--teal-dark);
  border-left: 3px solid var(--senf);
  padding-left: 10px;
}

/* Ending screen */
.ending {
  text-align: center;
}
.ending h2 {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
}
.ending .heart {
  font-size: 3rem;
  display: block;
  margin: 16px 0;
  animation: bob 4s ease-in-out infinite;
}
.ending .signoff {
  font-family: var(--serif);
  font-style: italic;
  color: var(--teal-dark);
  margin-top: 14px;
}

/* Responsive niceties */
@media (min-width: 720px) {
  .app { padding: 0 24px; }
  body { font-size: 18px; }
  .scene { padding: 28px 28px; }
}
@media (max-width: 360px) {
  .stats .stat b { display: none; }
  .stat { padding: 6px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
