/* Morserunner 2 – Sepia wie ein altes Telegrafenblatt. */
:root {
  --kit-ink: #3a2716;
  --kit-ink-soft: #6e5236;
  --kit-accent: #9e3b26;
  --kit-accent-ink: #fbf3e1;
  --kit-card: #f6ead0;
  --kit-good: #4f6b2a;
  --kit-bad: #9e3b26;
  --kit-font: Georgia, "Times New Roman", serif;
  --paper: #f3e6c8;
  --paper-2: #e6d2a6;
  --ink: #3a2716;
  --brass: #b8862f;
  --red: #9e3b26;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--paper);
  color: var(--ink); font-family: var(--kit-font); font-weight: 700;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#app { position: relative; height: 100%; max-width: 560px; margin: 0 auto; pointer-events: none; }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 4px) calc(var(--safe-l) + 14px);
  opacity: 0; visibility: hidden; transform: translateY(24px) scale(.98);
  transition: opacity .35s ease, transform .5s cubic-bezier(.2, 1.4, .4, 1), visibility 0s .35s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.screen.active > * { pointer-events: auto; }
#screen-game.active > * { pointer-events: none; }
#screen-game .hud, #screen-game .hud *, #screen-game .intro-letter { pointer-events: auto; }

.topbar { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.spacer { flex: 1; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: var(--kit-line); background: var(--kit-card); color: var(--ink);
  font: 700 24px/1 var(--kit-font); cursor: pointer; box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center;
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.screen-title { flex: 1; text-align: center; margin: 0; font-size: 22px; }

/* ---------- Start ---------- */
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 4vh; text-align: center; gap: 6px; }
.kicker { margin: 0; font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--red); font-weight: 700; }
.title {
  margin: 0; font-size: clamp(44px, 13.5vw, 72px); line-height: 1; letter-spacing: -1px; color: var(--ink);
  text-shadow: 3px 3px 0 var(--paper-2), 5px 5px 0 rgba(58, 39, 22, .25); font-style: italic;
}
.title span { display: inline-block; animation: hop 2.8s cubic-bezier(.3, 1.6, .5, 1) infinite; animation-delay: calc(var(--i) * .09s); }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-10px) rotate(-3deg); } }
.title-code { display: flex; gap: 14px; justify-content: center; margin: 6px 0 2px; }
.tc-letter { display: flex; gap: 4px; align-items: center; }
.title-code i { display: block; height: 8px; border-radius: 4px; background: var(--ink); opacity: .25; animation: blink 4.2s steps(1) infinite; animation-delay: calc(var(--i) * .2s); }
.title-code i.dit { width: 8px; }
.title-code i.dah { width: 24px; }
@keyframes blink { 0% { opacity: 1; background: var(--red); } 8% { opacity: .25; background: var(--ink); } }
.subtitle { margin: 4px 0 0; font-size: 17px; max-width: 320px; font-weight: 400; font-style: italic; }

.actions { display: grid; gap: 10px; margin: 0 auto 10px; width: min(100%, 340px); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  font: 700 18px/1.1 var(--kit-font); padding: 14px 10px; border-radius: 16px; border: var(--kit-line); cursor: pointer; min-height: 52px;
  box-shadow: 0 5px 0 var(--ink); color: var(--ink); background: var(--kit-card); transition: transform .1s;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.btn:active { transform: translateY(5px); box-shadow: none; }
.btn small { font-size: 13px; font-weight: 400; opacity: .9; font-style: italic; }
.btn-primary { background: var(--red); color: #fbf3e1; font-size: 25px; padding: 16px; animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.035); } }
.btn-ghost { background: rgba(243, 230, 200, .75); }
.btn.locked { opacity: .6; }
.lock { width: 1em; height: 1em; vertical-align: -0.12em; fill: currentColor; }
.lock path { fill: none; stroke: currentColor; stroke-width: 2.6; }

.kit-footer { color: var(--paper); text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.kit-footer a { color: inherit; }

/* ---------- Strecke ---------- */
.chapter-nav { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.chapter-info {
  flex: 1; min-width: 0; text-align: center; padding: 8px 10px; border-radius: 16px; background: var(--ink); color: var(--paper);
  box-shadow: 0 4px 0 rgba(58, 39, 22, .45);
}
.chapter-info small { display: block; font-size: 11px; letter-spacing: 3px; text-transform: uppercase; font-weight: 400; opacity: .85; }
.chapter-info h3 { margin: 2px 0; font-size: 21px; line-height: 1.15; }
.chapter-info p { margin: 0; font-size: 14px; color: #e9c77a; }
.chapter-info.swap { animation: chIn .4s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes chIn { from { opacity: 0; transform: scale(.9); } }
.icon-btn:disabled { opacity: .35; box-shadow: none; }
.chapter-dots { display: flex; justify-content: center; margin: 6px 0 4px; }
.chapter-dots button { flex: 0 0 33px; width: 33px; height: 36px; border: 0; background: none; padding: 0; cursor: pointer; display: grid; place-items: center; }
.chapter-dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(58, 39, 22, .25); border: 2px solid transparent; transition: transform .25s cubic-bezier(.3, 1.8, .5, 1); }
.chapter-dots .done i { background: var(--brass); }
.chapter-dots .cur i { background: var(--red); transform: scale(1.5); }
.level-grid {
  flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start;
  padding: 4px 2px 16px; touch-action: pan-y;
}
.level-card {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; row-gap: 2px; align-items: center;
  text-align: left; min-height: 62px; padding: 8px 10px; border: var(--kit-line); border-radius: 14px; background: var(--kit-card);
  color: var(--ink); font-family: var(--kit-font); box-shadow: 0 4px 0 var(--ink); cursor: pointer;
  animation: cardIn .45s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: calc(var(--i) * .03s);
}
.level-grid.back .level-card { animation-name: cardInBack; }
@keyframes cardIn { from { opacity: 0; transform: translateX(28px); } }
@keyframes cardInBack { from { opacity: 0; transform: translateX(-28px); } }
.level-card:active { transform: translateY(4px); box-shadow: none; }
.level-card.next { background: #f0d58e; }
.level-card.locked { background: #e2d3b1; color: #6e5236; box-shadow: 0 4px 0 #b39a72; border-color: #b39a72; }
.lv-num { grid-row: 1 / 3; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--paper); font-size: 16px; }
.level-card.locked .lv-num { background: #c9b48e; color: #6e5236; }
.lv-num .lock { width: 16px; height: 16px; }
.theme-night .lv-num { background: #20160d; }
.theme-fog .lv-num { background: #7d715c; }
.theme-capitol .lv-num { background: var(--red); }
.lv-name { font-size: 14px; line-height: 1.15; overflow-wrap: anywhere; }
.lv-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 400; }
.lv-sub b { letter-spacing: 1px; }
.lv-stars { font-size: 13px; letter-spacing: 1px; white-space: nowrap; }
.lv-stars i { font-style: normal; opacity: .25; }
.lv-stars i.on { opacity: 1; color: var(--brass); }

/* ---------- Spiel ---------- */
.hud { gap: 6px; }
.pill {
  display: flex; flex-direction: column; align-items: center; min-width: 56px; padding: 4px 10px; border-radius: 14px;
  background: rgba(246, 234, 208, .9); border: 2px solid var(--ink);
}
.pill small { font-size: 10px; letter-spacing: .5px; text-transform: uppercase; font-weight: 400; }
.pill b { font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pill.bump b, .pill.bump span { animation: bump .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 40% { transform: scale(1.45); } }
.combo-pill.hot { background: var(--brass); }
.lives { flex-direction: row; gap: 2px; font-size: 24px; min-width: 0; color: var(--red); padding: 6px 10px; }
.lives span { display: inline-block; }
.lives .gone { opacity: .4; color: var(--ink); }

.tape-wrap { display: flex; justify-content: center; margin-top: 8px; }
.tape {
  display: flex; gap: 6px; padding: 6px 16px; min-height: 42px; align-items: center; max-width: 100%; overflow: hidden;
  background: repeating-linear-gradient(90deg, #f6ead0 0 18px, #efe0bd 18px 20px); border: 2px solid var(--ink); border-radius: 4px;
  box-shadow: 0 3px 0 rgba(58, 39, 22, .4); font-size: 22px; letter-spacing: 2px;
}
.tape span { opacity: .35; min-width: 14px; text-align: center; }
.tape span.done { opacity: 1; animation: stamp .3s cubic-bezier(.3, 1.8, .5, 1); }
.tape span.cur { opacity: 1; color: var(--red); border-bottom: 3px solid var(--red); }
@keyframes stamp { from { transform: scale(1.8); } }
.stage-label { text-align: center; font-size: 13px; margin-top: 6px; font-style: italic; text-shadow: 0 0 6px var(--paper), 0 0 2px var(--paper); }

.intro {
  margin: 14px auto 0; width: min(100%, 360px); padding: 14px 16px; text-align: center;
  background: var(--kit-card); border: var(--kit-line); border-radius: 18px; box-shadow: 0 6px 0 var(--ink);
  opacity: 0; transform: translateY(-20px) scale(.9); transition: opacity .3s, transform .45s cubic-bezier(.2, 1.6, .4, 1);
}
.intro.show { opacity: 1; transform: none; }
.intro-kicker { margin: 0; font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: var(--red); }
.intro h2 { margin: 2px 0 6px; font-size: 24px; }
.intro-story { margin: 0 0 10px; font-size: 15px; font-weight: 400; font-style: italic; line-height: 1.35; }
.intro-letters { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.intro-letters:empty { display: none; }
.intro-letter, .cb-letter {
  display: grid; justify-items: center; gap: 2px; min-width: 66px; min-height: 66px; padding: 6px 10px; cursor: pointer;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; color: var(--ink); font-family: var(--kit-font);
}
.intro-letter b, .cb-letter b { font-size: 28px; line-height: 1; }
.intro-letter span, .cb-letter span { font-size: 20px; letter-spacing: 2px; color: var(--red); }
.ping { animation: ping .4s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes ping { 40% { transform: scale(1.15) rotate(-3deg); background: #f0d58e; } }
.intro-go { margin: 12px 0 0; font-size: 16px; animation: breathe 1.6s ease-in-out infinite; }

.banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.8); opacity: 0; max-width: calc(100% - 32px);
  padding: 10px 18px; border-radius: 14px; background: var(--ink); color: var(--paper); font-size: 18px; text-align: center;
  transition: opacity .25s, transform .4s cubic-bezier(.2, 1.6, .4, 1);
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.keybox { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 18px); display: grid; justify-items: center; gap: 8px; }
.key {
  position: relative; width: 150px; height: 46px; border-radius: 23px; border: 3px solid var(--paper); overflow: hidden;
  background: rgba(58, 39, 22, .6); box-shadow: 0 6px 0 rgba(0, 0, 0, .45); transition: transform .06s, box-shadow .06s;
}
.key.down { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0, 0, 0, .45); }
.key-fill { position: absolute; inset: 0; background: var(--brass); transform-origin: left; transform: scaleX(0); }
.key-sym { position: absolute; inset: 0; display: grid; place-items: center; color: var(--paper); font-size: 34px; line-height: 1; }
.key-hint { margin: 0; color: var(--paper); font-size: 15px; text-shadow: 0 1px 2px #000; text-align: center; padding: 0 12px; }

/* ---------- Dialoge ---------- */
.kit-dialog .kit-card { background: var(--kit-card); }
.result-card { text-align: center; }
.stars { display: flex; justify-content: center; gap: 6px; font-size: 46px; min-height: 0; }
.stars span { color: rgba(58, 39, 22, .2); }
.stars span.on { color: var(--brass); text-shadow: 0 3px 0 var(--ink); animation: starIn .6s cubic-bezier(.3, 1.9, .5, 1) both; animation-delay: calc(.3s + var(--i) * .25s); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.res-score { margin: 0; }
.res-score b { font-size: 52px; color: var(--red); }
.res-best { margin: 0 0 8px; }
.telegram { margin: 6px 0 10px; padding: 10px 12px; background: #f0dfb8; border: 2px dashed var(--ink); border-radius: 6px; transform: rotate(-1deg); }
.telegram-head { margin: 0 0 4px; font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--red); }
.telegram-text { margin: 0; font-family: "Courier New", Courier, monospace; font-size: 16px; letter-spacing: 1px; overflow-wrap: anywhere; }
.res-fact { margin: 0 0 12px; font-size: 14px; font-weight: 400; font-style: italic; line-height: 1.4; }
.help-list { margin: 0 0 14px; padding-left: 20px; display: grid; gap: 8px; font-weight: 400; line-height: 1.4; }
.help-list b { font-weight: 700; }
.codebook-hint { margin: 0 0 10px; font-weight: 400; font-style: italic; }
.codebook { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 6px; max-height: 52vh; overflow-y: auto; margin-bottom: 12px; padding: 2px; }
.cb-letter { min-width: 0; }
.cb-letter span { font-size: 16px; }
.cb-letter i { font-style: normal; font-size: 10px; letter-spacing: 1px; color: var(--brass); }
.cb-letter.locked { opacity: .4; cursor: default; }

@media (max-height: 640px) {
  .hero { padding-top: 0; }
  .title { font-size: 44px; }
  .subtitle { display: none; }
}
