:root {
  --ink: #26233a;
  --paper: #fff9ed;
  --coral: #e8505b;
  --coral-dark: #bd3344;
  --yellow: #ffd45c;
  --mint: #62c6a8;
  --blue: #4e78c4;
  --line: #29263b;
  --shadow: 0 8px 0 rgba(38, 35, 58, 0.15);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
  color: var(--ink);
  background: #9fd8d2;
  touch-action: manipulation;
}

* { box-sizing: border-box; }

html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body { min-height: 100dvh; overflow-x: hidden; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  width: 100%;
}

.lobby-screen {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1fr);
  gap: clamp(28px, 6vw, 88px);
  align-items: center;
  padding: clamp(28px, 5vw, 76px);
  background:
    linear-gradient(rgba(255,255,255,.36) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255,255,255,.36) 2px, transparent 2px),
    #9fd8d2;
  background-size: 42px 42px;
}

.brand {
  max-width: 620px;
}

.brand-kicker, .eyebrow {
  display: block;
  color: var(--coral-dark);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.brand h1 {
  margin: 10px 0 18px;
  max-width: 640px;
  color: var(--paper);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(62px, 9vw, 138px);
  font-weight: 900;
  line-height: .82;
  letter-spacing: 0;
  text-shadow: 5px 5px 0 var(--coral), 9px 9px 0 var(--ink);
  transform: rotate(-2deg);
}

.brand p {
  max-width: 560px;
  margin: 32px 0 0;
  font-size: clamp(18px, 2vw, 25px);
  font-weight: 700;
  line-height: 1.45;
}

.setup-panel {
  width: min(100%, 650px);
  justify-self: end;
  padding: clamp(24px, 4vw, 44px);
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: 12px 12px 0 rgba(38,35,58,.2);
}

.field-label, legend {
  display: block;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  color: var(--ink);
  background: white;
  border: 2px solid var(--line);
  border-radius: 5px;
  outline: none;
}

input:focus { box-shadow: 0 0 0 4px rgba(78,120,196,.22); }
fieldset { margin: 26px 0 20px; padding: 0; border: 0; }

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.choice {
  min-height: 42px;
  padding: 8px 10px;
  background: #fff;
  border: 2px solid #bbb5ad;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 800;
}

.choice.active {
  color: white;
  background: var(--blue);
  border-color: var(--line);
  box-shadow: 3px 3px 0 var(--line);
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 7px;
  border: 1px solid var(--line);
  border-radius: 50%;
  vertical-align: -2px;
}
.swatch.light { background: #f2c75c; }
.swatch.dark { background: #47322c; }

.avatar-stage {
  display: grid;
  grid-template-columns: 126px 1fr;
  gap: 15px;
  align-items: center;
  min-height: 122px;
  padding: 8px 16px 8px 4px;
  background: #f3e7d2;
  border: 2px solid var(--line);
  border-radius: 6px;
}

#avatar-preview {
  width: 126px;
  height: 116px;
}

.avatar-stage strong { display: block; margin-bottom: 6px; font-size: 18px; }
.avatar-stage span { color: #686274; font-size: 13px; line-height: 1.35; }
.room-actions { display: grid; gap: 10px; margin-top: 20px; }

.primary-action, .secondary-action {
  min-height: 54px;
  border: 2px solid var(--line);
  border-radius: 5px;
  font-weight: 900;
}

.primary-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  color: white;
  background: var(--coral);
  box-shadow: 5px 5px 0 var(--line);
}
.primary-action:active { transform: translate(3px,3px); box-shadow: 2px 2px 0 var(--line); }
.secondary-action { padding: 0 20px; background: var(--yellow); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#room-code-input { font-size: 22px; font-weight: 900; letter-spacing: 4px; text-transform: uppercase; }
.status-line { min-height: 18px; margin: 16px 0 0; color: var(--coral-dark); font-size: 13px; font-weight: 800; }

.waiting-screen {
  position: relative;
  display: grid;
  place-items: center;
  padding: 30px;
  overflow: hidden;
  text-align: center;
  background: var(--paper);
}

.waiting-screen::before, .waiting-screen::after {
  position: absolute;
  content: "";
  width: 36vw;
  height: 110vh;
  background: var(--coral);
  transform: rotate(18deg);
}
.waiting-screen::before { left: -25vw; }
.waiting-screen::after { right: -25vw; background: var(--blue); }
.waiting-content { position: relative; z-index: 1; width: min(100%, 580px); }
.room-code {
  display: block;
  margin: 14px auto 20px;
  padding: 4px 18px;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(72px, 14vw, 126px);
  letter-spacing: 8px;
}
.waiting-content > p { margin: 0 auto 34px; max-width: 440px; line-height: 1.5; }
.players-waiting { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.player-slot {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: center;
  padding: 16px;
  text-align: left;
  background: white;
  border: 2px solid var(--line);
  border-radius: 6px;
}
.slot-dot { grid-row: 1 / 3; width: 15px; height: 15px; background: #aaa; border: 2px solid var(--line); border-radius: 50%; }
.player-slot.ready .slot-dot { background: var(--mint); }
.player-slot small { color: #77717e; }
.waiting-pulse { display: flex; justify-content: center; gap: 7px; margin: 25px 0 18px; }
.waiting-pulse i { width: 10px; height: 10px; background: var(--coral); border-radius: 50%; animation: pulse 1s infinite alternate; }
.waiting-pulse i:nth-child(2) { animation-delay: .2s; }
.waiting-pulse i:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { to { transform: translateY(-10px); background: var(--blue); } }

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 50%;
  box-shadow: 3px 3px 0 var(--line);
  font-size: 22px;
  font-weight: 900;
}
.back-button { position: absolute; z-index: 3; top: 24px; left: 24px; }
.text-action { padding: 8px; color: var(--blue); background: transparent; border: 0; font-weight: 900; text-decoration: underline; }

.game-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  background: #302b45;
}

.game-header {
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: center;
  min-height: 72px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 3vw, 40px) 10px;
  color: white;
  background: #272338;
  border-bottom: 3px solid #151322;
}
.score-side { min-width: 0; }
.score-side.right { text-align: right; }
.score-side strong { display: block; overflow: hidden; font-size: clamp(15px, 2.4vw, 23px); text-overflow: ellipsis; white-space: nowrap; }
.hearts { display: flex; gap: 5px; margin-top: 5px; }
.right .hearts { justify-content: flex-end; }
.heart {
  width: 18px;
  height: 16px;
  color: var(--coral);
  font-size: 20px;
  line-height: 16px;
  text-shadow: 1px 1px 0 #000;
}
.heart.lost { color: #5c566d; }
.round-info { text-align: center; }
.round-info span { display: block; color: var(--yellow); font-size: 10px; font-weight: 900; }
.round-info strong { font-size: clamp(22px, 4vw, 34px); }

#arena-wrap { position: relative; min-height: 0; overflow: hidden; }
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #78bfd0;
  touch-action: none;
}
.connection-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 5px 8px;
  color: white;
  background: rgba(28,25,42,.74);
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
}
.mute-button { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; font-size: 18px; }
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: min(32vw, 240px);
  text-shadow: 8px 8px 0 var(--coral), 13px 13px 0 var(--ink);
  pointer-events: none;
}

.touch-controls {
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: clamp(12px, 3vw, 28px);
  align-items: center;
  min-height: 126px;
  padding: 12px max(18px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: #272338;
  border-top: 3px solid #151322;
}
.move-controls { display: flex; gap: 12px; }
.control-button {
  width: clamp(68px, 12vw, 92px);
  height: clamp(68px, 12vw, 92px);
  color: white;
  background: #4a4561;
  border: 2px solid #aaa3bf;
  border-radius: 50%;
  box-shadow: 0 6px 0 #151322;
  font-size: 34px;
  font-weight: 900;
  touch-action: none;
  user-select: none;
}
.control-button.pressed, .control-button:active { transform: translateY(5px); box-shadow: 0 1px 0 #151322; background: var(--blue); }
.jump-button { background: var(--mint); border-color: #b9ffe9; }
.throw-button {
  display: grid;
  place-items: center;
  width: clamp(92px, 15vw, 118px);
  height: clamp(92px, 15vw, 118px);
  background: var(--coral);
  border-color: #ffadb3;
}
.throw-button small { margin-top: -11px; font-size: 10px; }
.pillow-icon {
  width: 43px;
  height: 31px;
  background: white;
  border: 3px solid var(--line);
  border-radius: 10px 5px;
  transform: rotate(-9deg);
}

dialog {
  width: min(90vw, 440px);
  padding: 32px;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: 12px 12px 0 rgba(0,0,0,.28);
}
dialog::backdrop { background: rgba(27,24,40,.78); }
.result-art { color: var(--yellow); font-size: 65px; text-shadow: 3px 3px 0 var(--coral); }
dialog h2 { margin: 8px 0; font-family: Impact, "Arial Black", sans-serif; font-size: 48px; letter-spacing: 0; }
dialog p { line-height: 1.45; }
dialog .primary-action { width: 100%; margin: 24px 0 12px; }

@media (max-width: 800px) and (orientation: portrait) {
  .lobby-screen { display: block; padding: 34px 18px; }
  .brand { margin: 0 auto 34px; text-align: center; }
  .brand h1 { font-size: clamp(62px, 22vw, 104px); }
  .brand p { margin-top: 24px; font-size: 17px; }
  .setup-panel { margin: 0 auto; padding: 22px 18px; }
  .players-waiting { grid-template-columns: 1fr; }
}

@media (max-height: 650px) and (orientation: landscape) {
  .game-header { min-height: 55px; padding-top: 6px; padding-bottom: 6px; }
  .touch-controls { min-height: 90px; padding-top: 8px; padding-bottom: 8px; }
  .control-button { width: 62px; height: 62px; font-size: 28px; }
  .throw-button { width: 78px; height: 78px; }
  .pillow-icon { width: 35px; height: 25px; }
}

@media (hover: hover) and (pointer: fine) {
  .choice:hover, .secondary-action:hover { filter: brightness(.96); transform: translateY(-1px); }
  .text-action:hover { color: var(--coral); }
}
