@font-face {
  font-family: 'Lilita One';
  src: url('fonts/LilitaOne-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --ink: #1a0e2e;
  --paper: #fff7ea;
  --red: #e8392f;
  --gold: #ffcf3f;
  --panel: rgba(26, 14, 46, 0.82);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --st: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120c33;
  color: var(--paper);
  font-family: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

.hidden {
  display: none !important;
}

/* ---------------- Menüs ---------------- */
#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2vmin;
  padding: calc(12px + var(--st)) calc(16px + var(--sr)) calc(12px + var(--sb)) calc(16px + var(--sl));
  pointer-events: auto;
  background: radial-gradient(ellipse at 50% 40%, rgba(26, 14, 46, 0.35), rgba(26, 14, 46, 0.78));
  overflow-y: auto;
  touch-action: pan-y;
}

.screen.active {
  display: flex;
  animation: fadein 0.25s ease-out;
}

.screen.dim {
  background: rgba(18, 8, 36, 0.72);
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.85;
  margin-bottom: 1vmin;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
}

.logo-top,
.logo-bottom {
  font-size: clamp(44px, 13vmin, 120px);
  letter-spacing: 0.04em;
  -webkit-text-stroke: 0.06em var(--ink);
  paint-order: stroke fill;
}

.logo-top {
  color: var(--red);
  transform: rotate(-3deg);
}

.logo-bottom {
  color: var(--gold);
  transform: rotate(2deg);
}

h2 {
  margin: 0;
  font-size: clamp(26px, 6.5vmin, 54px);
  font-weight: normal;
  color: var(--gold);
  -webkit-text-stroke: 0.08em var(--ink);
  paint-order: stroke fill;
  text-align: center;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 1.6vmin;
  width: min(420px, 86vw);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  color: var(--ink);
  touch-action: manipulation;
}

button.big {
  font-size: clamp(20px, 4.6vmin, 32px);
  padding: 0.55em 1.1em;
  border-radius: 18px;
  background: linear-gradient(#fff9ec, #ffe2b0);
  box-shadow: 0 6px 0 #a7652f, 0 10px 18px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 56px;
  transition: transform 0.08s;
}

button.big.go {
  background: linear-gradient(#ff7a5c, #e8392f);
  color: #fff;
  box-shadow: 0 6px 0 #8c1612, 0 10px 18px rgba(0, 0, 0, 0.35);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

button.big:active,
button.chip:active,
button.back:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a7652f;
}

button:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
}

.ico {
  font-size: 1.15em;
}

button.chip {
  font-size: clamp(16px, 3.4vmin, 22px);
  padding: 0.45em 0.9em;
  border-radius: 999px;
  background: rgba(255, 247, 234, 0.92);
  box-shadow: 0 4px 0 #a7652f;
  min-height: 44px;
}

button.chip.sel {
  background: var(--gold);
  box-shadow: 0 4px 0 #9b700c, 0 0 0 3px #fff inset;
}

button.back {
  font-size: clamp(16px, 3.4vmin, 22px);
  padding: 0.5em 1em;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  color: var(--paper);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  min-height: 44px;
}

.small-row {
  margin-top: 1vmin;
}

.hint {
  font-family: system-ui, sans-serif;
  font-size: 14px;
  opacity: 0.8;
  margin: 0;
  text-align: center;
  max-width: 520px;
}

.lead {
  font-size: clamp(17px, 3.8vmin, 26px);
  text-align: center;
  margin: 0;
  line-height: 1.3;
}

.err {
  color: #ff9a9a;
  min-height: 1.2em;
  margin: 0;
  font-size: clamp(16px, 3.4vmin, 22px);
  text-align: center;
}

.opts {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.opt-label {
  font-size: clamp(16px, 3.4vmin, 22px);
  opacity: 0.9;
}

/* Spieler mit Name und Ninja-Wahl */
.players {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.player {
  background: var(--panel);
  border-radius: 20px;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  border: 2px solid rgba(255, 255, 255, 0.12);
  max-width: 96vw;
}

.player-title {
  font-size: clamp(15px, 3vmin, 20px);
  opacity: 0.8;
}

.names {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.names input {
  font-family: inherit;
  font-size: clamp(16px, 3.4vmin, 22px);
  width: 8.5em;
  padding: 0.35em 0.6em;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}

.ninja-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 470px;
}

.ninja-card {
  width: clamp(54px, 11vmin, 76px);
  height: clamp(62px, 13vmin, 88px);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  padding: 0;
  box-shadow: none;
  border: 3px solid transparent;
  position: relative;
}

.ninja-card canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.ninja-card.sel {
  border-color: var(--gold);
  background: rgba(255, 207, 63, 0.22);
}

.ninja-name {
  font-size: clamp(15px, 3vmin, 20px);
  color: var(--gold);
}

/* Code-Anzeige und Ziffernblock */
.code {
  font-size: clamp(56px, 16vmin, 120px);
  letter-spacing: 0.12em;
  color: #fff;
  -webkit-text-stroke: 0.06em var(--ink);
  paint-order: stroke fill;
  display: flex;
  gap: 0.15em;
}

#joinCode span {
  display: inline-block;
  width: 0.8em;
  height: 1.05em;
  border-bottom: 6px solid var(--gold);
  text-align: center;
  line-height: 1.05em;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(330px, 80vw);
}

.pad button {
  font-size: clamp(26px, 6vmin, 40px);
  padding: 0.3em 0;
  border-radius: 16px;
  background: linear-gradient(#fff9ec, #ffe2b0);
  box-shadow: 0 5px 0 #a7652f;
  min-height: 52px;
}

.pad button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #a7652f;
}

.pad .pad-ok {
  background: linear-gradient(#ff7a5c, #e8392f);
  color: #fff;
  box-shadow: 0 5px 0 #8c1612;
}

/* Querformat mit wenig Höhe: Ziffernblock neben den Code */
@media (orientation: landscape) and (max-height: 520px) {
  #scr-join {
    flex-direction: row;
    flex-wrap: wrap;
    align-content: center;
    gap: 10px 28px;
  }
  #scr-join h2 {
    width: 100%;
  }
  .pad {
    width: min(300px, 40vw);
    gap: 8px;
  }
  .pad button {
    min-height: 44px;
    font-size: 26px;
    padding: 0.15em 0;
  }
  .code {
    font-size: 64px;
  }
  .screen {
    gap: 8px;
    justify-content: flex-start;
    padding-top: calc(10px + var(--st));
  }
  #scr-start,
  #scr-wait,
  #scr-over,
  #scr-pause,
  #scr-msg {
    justify-content: center;
  }
  .logo-top,
  .logo-bottom {
    font-size: 15vh;
  }
  #scr-start .menu {
    flex-direction: row;
    width: auto;
  }
  #scr-start button.big {
    font-size: 20px;
  }
  .players {
    gap: 10px;
  }
  #scr-setup h2 {
    font-size: 26px;
  }
  #scr-setup .player {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 98vw;
  }
  #scr-setup .player-title {
    display: none;
  }
  #scr-setup .ninja-card {
    width: 50px;
    height: 58px;
  }
  #scr-setup .names input {
    width: 6.5em;
  }
  #scr-setup .chip {
    min-height: 40px;
    font-size: 17px;
    padding: 0.3em 0.75em;
  }
  #scr-setup .ninja-name {
    display: none;
  }
  #scr-setup .opts {
    gap: 6px;
  }
  #scr-setup button.big {
    min-height: 48px;
    font-size: 20px;
    padding: 0.35em 1em;
  }
  #scr-setup .optrow {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .player {
    padding: 6px 10px 8px;
    gap: 5px;
  }
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.trophy {
  font-size: clamp(56px, 14vmin, 110px);
  animation: schweben 1s ease-in-out infinite alternate;
}

@keyframes schweben {
  to {
    transform: translateY(-10px) rotate(4deg);
  }
}

.help {
  max-width: 640px;
  background: var(--panel);
  border-radius: 18px;
  padding: 6px 20px;
  font-family: system-ui, sans-serif;
  font-size: clamp(15px, 3.2vmin, 19px);
  line-height: 1.4;
}

/* ---------------- Im Spiel ---------------- */
.hud-btn {
  position: fixed;
  top: calc(8px + var(--st));
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(26, 14, 46, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.35);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-btn svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}

#count {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(90px, 30vmin, 260px);
  color: var(--gold);
  -webkit-text-stroke: 0.05em var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
}

#count.pop {
  animation: pop 0.9s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  20% {
    transform: scale(1.15);
    opacity: 1;
  }
  35% {
    transform: scale(1);
  }
  100% {
    transform: scale(1);
    opacity: 0.2;
  }
}

#netStatus {
  position: fixed;
  top: calc(64px + var(--st));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(200, 40, 40, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 18px;
  z-index: 6;
  pointer-events: none;
}

/* Touch-Steuerung */
#touch {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  touch-action: none;
}

#touch.live {
  display: block;
}

.tbtn {
  position: absolute;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid rgba(255, 255, 255, 0.45);
  pointer-events: none;
  transition: transform 0.05s, background 0.05s;
}

.tbtn svg {
  width: 52%;
  height: 52%;
  fill: none;
  stroke: #fff;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tbtn.on {
  background: rgba(255, 207, 63, 0.55);
  transform: scale(0.92);
}

#touch.touch-on[data-mode='solo'] .tbtn-p1l,
#touch.touch-on[data-mode='solo'] .tbtn-p1r,
#touch.touch-on[data-mode='solo'] .tbtn-p1u,
#touch.touch-on[data-mode='duo'] .tbtn {
  display: flex;
}

/* Lage der Knöpfe setzt main.js passend zum Spielfeld */

.help .lizenz {
  font-size: 0.8em;
  opacity: 0.8;
}

.help a {
  color: var(--gold);
}

/* Joystick (ein Spieler) */
.stick-base {
  --d: 120px;
  position: absolute;
  width: var(--d);
  height: var(--d);
  margin: calc(var(--d) / -2) 0 0 calc(var(--d) / -2);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
  display: none;
  opacity: 0.6;
  transition: opacity 0.1s;
}

.stick-base.aktiv {
  opacity: 1;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid rgba(255, 255, 255, 0.85);
  transform: translate(-50%, -50%);
}

.stick-base.links .stick-knob,
.stick-base.rechts .stick-knob {
  background: rgba(255, 207, 63, 0.85);
}

.stick-pfeil {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: calc(var(--d) * 0.16);
  color: rgba(255, 255, 255, 0.7);
  font-family: system-ui, sans-serif;
}

.stick-pfeil.l {
  left: 8%;
}

.stick-pfeil.r {
  right: 8%;
}

.stick-base.links .stick-pfeil.l,
.stick-base.rechts .stick-pfeil.r {
  color: var(--gold);
}

#touch.touch-on[data-mode='solo'][data-scheme='joystick'] .stick-base {
  display: block;
}

#touch.touch-on[data-mode='solo'][data-scheme='joystick'] .tbtn-p1l,
#touch.touch-on[data-mode='solo'][data-scheme='joystick'] .tbtn-p1r {
  display: none;
}
