:root {
  --ink: #2b1a0e;
  --parch: #f3e2b3;
  --parch2: #dcc285;
  --wood: #6b4423;
  --wood2: #3d2412;
  --gold: #ffd34d;
  --gold2: #c8872a;
  --red: #d23c3c;
  --red2: #8e1f24;
  --sea: #0b1624;
  --hud: rgba(11, 22, 36, .78);
  --white: #fffaf0;
  --xp: #53c6ff;
  --xp2: #1f6fb0;
  --px: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--sea); color: var(--white);
  font-family: 'Pixelify Sans', monospace; font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
img { image-rendering: pixelated; }

canvas#game {
  position: fixed; inset: 0; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
}

/* Retro-Filter */
#crt {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.45) 100%),
    repeating-linear-gradient(to bottom, rgba(0,0,0,.13) 0 1px, transparent 1px 3px);
}
body.nocrt #crt { background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,.35) 100%); }

#hurt {
  position: fixed; inset: 0; pointer-events: none; z-index: 4;
  box-shadow: inset 0 0 90px 10px rgba(220, 20, 30, .9);
  opacity: 0; transition: opacity .35s;
}
#hurt.on { opacity: .85; transition: none; }

/* Joystick */
#joyBase {
  position: fixed; z-index: 6; width: 104px; height: 104px; margin: -52px 0 0 -52px;
  border-radius: 50%; border: 3px solid rgba(255,250,240,.45); background: rgba(0,0,0,.18);
  pointer-events: none; display: none;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; background: rgba(255,250,240,.75); border: 3px solid var(--wood2);
}

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
.xpbar {
  position: relative; height: 16px; background: #10213a; border: 3px solid var(--wood2);
  box-shadow: 0 0 0 2px var(--parch2);
}
.xpbar .fill { height: 100%; width: 0; background: linear-gradient(var(--xp), var(--xp2)); transition: width .12s; }
#lvText { position: absolute; right: 6px; top: -1px; font-family: var(--px); font-size: 9px; line-height: 12px; text-shadow: 1px 1px 0 #000; }
.hudrow { display: flex; align-items: flex-start; justify-content: space-between; margin-top: 6px; }
.hudstat { font-family: var(--px); font-size: 11px; text-shadow: 2px 2px 0 #000; min-width: 80px; padding-top: 6px; }
.hudstat.right { text-align: right; color: var(--gold); margin-right: 44px; }
.timer { font-family: var(--px); font-size: 20px; text-shadow: 3px 3px 0 #000; }
.slots { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.slots > div { display: flex; gap: 3px; flex-wrap: wrap; max-width: 60vw; }
.slot { position: relative; width: 26px; height: 26px; background: var(--hud); border: 2px solid var(--wood); }
.slot img { width: 100%; height: 100%; }
.slot i { position: absolute; right: -2px; bottom: -3px; font-style: normal; font-family: var(--px); font-size: 7px; color: var(--gold); text-shadow: 1px 1px 0 #000, -1px -1px 0 #000; }
.hudbtn {
  position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 26px); right: max(10px, env(safe-area-inset-right));
  pointer-events: auto; width: 38px; height: 38px; cursor: pointer;
  font-family: var(--px); font-size: 11px; background: var(--hud); border: 3px solid var(--parch2);
}
#bossbar { position: absolute; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(420px, 80vw); text-align: center; }
.bname { font-family: var(--px); font-size: 10px; color: #ffb3a8; text-shadow: 2px 2px 0 #000; margin-bottom: 4px; }
.bbar { height: 12px; background: #2a0d10; border: 3px solid #000; }
.bfill { height: 100%; width: 100%; background: linear-gradient(#ff5a4e, #a3161f); transition: width .15s; }
#banner {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center; padding: 0 16px;
  font-family: var(--px); font-size: clamp(12px, 3.2vw, 22px); color: var(--gold);
  text-shadow: 3px 3px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  opacity: 0; pointer-events: none; line-height: 1.5;
}
#banner.show { animation: banner 2.6s ease-out forwards; }
#banner.boss { color: #ff7a6e; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.6); }
  10% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* Screens */
.screen {
  position: fixed; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto; touch-action: pan-y;
}
.screen.on { display: flex; }
.screen.dim { background: rgba(5, 10, 20, .62); }
#screen-menu { background: radial-gradient(ellipse at 40% 50%, rgba(5,10,20,.1), rgba(5,10,20,.55)); }

.panel {
  background: var(--parch); color: var(--ink);
  border: 4px solid var(--wood2);
  box-shadow: inset 0 0 0 3px var(--parch2), 0 6px 0 rgba(0,0,0,.45);
  padding: 18px 20px; max-width: 100%;
}
.panel h2 { font-family: var(--px); font-size: 16px; color: var(--red2); text-align: center; margin-bottom: 14px; line-height: 1.4; }
.panel.wide { width: min(720px, 100%); }

.menuwrap { display: flex; align-items: center; justify-content: center; gap: clamp(20px, 6vw, 90px); flex-wrap: wrap; width: 100%; margin: auto; }
.logo { text-align: center; }
.logo img { width: 96px; height: auto; display: block; margin: 0 auto 6px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.5)); }
.logo h1 {
  font-family: var(--px); font-weight: 400; line-height: 1.25;
  font-size: clamp(22px, 5.4vw, 46px); color: var(--gold);
  text-shadow: 0 4px 0 var(--gold2), 4px 4px 0 var(--wood2), -3px -3px 0 var(--wood2), 3px -3px 0 var(--wood2), -3px 4px 0 var(--wood2), 0 8px 0 rgba(0,0,0,.4);
}
.logo h1 span { display: block; }
.logo h1 span + span { color: #fff6e0; text-shadow: 0 4px 0 #b9a06a, 4px 4px 0 var(--wood2), -3px -3px 0 var(--wood2), 3px -3px 0 var(--wood2), -3px 4px 0 var(--wood2), 0 8px 0 rgba(0,0,0,.4); }
.logo .sub { margin-top: 16px; font-family: var(--px); font-size: clamp(9px, 1.6vw, 13px); letter-spacing: 4px; text-shadow: 2px 2px 0 #000; }

.side { display: flex; flex-direction: column; gap: 10px; width: min(330px, 100%); }
.panel.menu { padding: 8px; }
.mi {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; padding: 9px 10px; cursor: pointer;
}
.mi img { width: 32px; height: 32px; flex: none; }
.mi .t { font-size: 20px; font-weight: 700; color: var(--wood2); }
.mi .s { font-size: 12px; opacity: .7; }
button.mi:hover, button.mi:focus-visible { background: rgba(107, 68, 35, .14); outline: none; }
button.mi:hover .t { color: var(--red2); }
.mi.off { opacity: .45; cursor: default; }
.panel.stats { font-size: 13px; line-height: 1.5; padding: 10px 14px; }
.panel.stats b { color: var(--red2); }

.btn {
  font-family: var(--px); font-size: 11px; cursor: pointer; padding: 12px 16px;
  background: var(--red); color: #fff; border: 3px solid var(--wood2);
  box-shadow: inset 0 -4px 0 var(--red2), 0 4px 0 rgba(0,0,0,.35);
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--red2); }
.btn.ghost { background: var(--parch2); color: var(--ink); box-shadow: inset 0 -4px 0 #b9a06a, 0 4px 0 rgba(0,0,0,.25); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.col { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* Charakterwahl */
.chars { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.char {
  background: #fff3cf; border: 3px solid var(--wood); padding: 10px 6px; text-align: center; cursor: pointer;
}
.char img { width: 64px; height: 84px; object-fit: contain; display: block; margin: 0 auto 6px; }
.char .n { font-weight: 700; font-size: 15px; }
.char .d { font-size: 11px; opacity: .75; }
.char canvas.portrait { width: auto; height: 84px; max-width: 100%; object-fit: contain; display: block; margin: 0 auto 6px; image-rendering: pixelated; }
.char .perk { margin-top: 4px; color: #1f7a2e; opacity: 1; }
.char.sel { border-color: var(--red); box-shadow: 0 0 0 3px var(--gold); }
.char.locked { filter: grayscale(1); opacity: .5; cursor: default; }
.char.locked img { filter: brightness(0); opacity: .6; }
.charinfo { margin-top: 12px; font-size: 14px; text-align: center; }
.stage { margin-top: 12px; text-align: center; font-size: 15px; }
.stage span { opacity: .65; }

/* Level-Up */
.lvwrap { text-align: center; width: 100%; max-width: 900px; }
.glow { font-family: var(--px); font-size: clamp(20px, 5vw, 34px); color: var(--gold); text-shadow: 3px 3px 0 var(--wood2), -2px -2px 0 var(--wood2), 0 0 20px rgba(255, 211, 77, .6); margin-bottom: 18px; }
.cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.card {
  width: min(250px, 100%); background: var(--parch); color: var(--ink); text-align: left;
  border: 4px solid var(--wood2); box-shadow: inset 0 0 0 3px var(--parch2), 0 6px 0 rgba(0,0,0,.45);
  padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  animation: cardIn .25s backwards;
}
.card:nth-child(2) { animation-delay: .06s; }
.card:nth-child(3) { animation-delay: .12s; }
@keyframes cardIn { from { transform: translateY(30px); opacity: 0; } }
.card:hover, .card.focus { transform: translateY(-4px); box-shadow: inset 0 0 0 3px var(--gold), 0 10px 0 rgba(0,0,0,.45); }
.card .top { display: flex; align-items: center; gap: 10px; }
.card img { width: 40px; height: 40px; flex: none; }
.card .nm { font-weight: 700; font-size: 17px; line-height: 1.1; }
.card .tag { font-family: var(--px); font-size: 8px; color: var(--red2); margin-top: 4px; }
.card .tag.new { color: #1f7a2e; }
.card .ds { font-size: 14px; line-height: 1.35; }
.card .key { font-family: var(--px); font-size: 8px; opacity: .45; align-self: flex-end; }
.hint { margin-top: 14px; font-size: 13px; opacity: .7; }

@media (max-width: 640px), (max-height: 500px) and (orientation: landscape) {
  .card { width: min(330px, 100%); padding: 10px; flex-direction: row; align-items: center; }
  .card .ds { font-size: 13px; }
  .card .key { display: none; }
  .cards { flex-direction: column; align-items: center; gap: 8px; }
  .glow { margin-bottom: 10px; }
}

/* Pause / Ende */
.build { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 320px; }
.build .slot { width: 34px; height: 34px; border-color: var(--wood2); background: #fff3cf; }
.endsub { text-align: center; margin: -6px 0 12px; font-size: 14px; opacity: .8; }
.endstats { display: grid; grid-template-columns: auto auto; gap: 6px 22px; font-size: 16px; }
.endstats div:nth-child(even) { text-align: right; font-weight: 700; }
.endstats .rec { color: #1f7a2e; }
.help { list-style: none; max-width: 440px; display: flex; flex-direction: column; gap: 9px; font-size: 15px; line-height: 1.35; }
.toggles { display: flex; flex-direction: column; gap: 8px; min-width: 260px; }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 20px; background: none; border: 0; cursor: pointer; font-size: 17px; padding: 6px 2px; color: var(--ink); }
.toggle i { font-style: normal; font-family: var(--px); font-size: 9px; padding: 6px 8px; background: var(--wood); color: #fff; min-width: 54px; text-align: center; }
.toggle.on i { background: #2f8a3e; }
.slider { display: flex; align-items: center; gap: 12px; font-size: 17px; padding: 6px 2px; color: var(--ink); }
.slider span { flex: none; }
.slider i { font-style: normal; font-family: var(--px); font-size: 9px; padding: 6px 4px; background: var(--wood); color: #fff; min-width: 54px; text-align: center; }
.slider input {
  flex: 1; min-width: 100px; height: 28px; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.slider input::-webkit-slider-runnable-track { height: 8px; background: var(--parch2); border: 2px solid var(--wood2); }
.slider input::-moz-range-track { height: 8px; background: var(--parch2); border: 2px solid var(--wood2); }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 22px; margin-top: -9px; background: var(--red); border: 3px solid var(--wood2); border-radius: 0; }
.slider input::-moz-range-thumb { width: 14px; height: 18px; background: var(--red); border: 3px solid var(--wood2); border-radius: 0; }

#legal {
  position: fixed; left: 8px; bottom: max(4px, env(safe-area-inset-bottom)); z-index: 21; font-size: 10px; opacity: .55;
  pointer-events: none; text-shadow: 1px 1px 0 #000; max-width: calc(100% - 16px);
}
body.playing #legal { display: none; }
@media (max-width: 640px) {
  .hudstat { font-size: 9px; min-width: 60px; }
  .timer { font-size: 16px; }
  .hudstat.right { margin-right: 44px; }
}
