.lobby-screen, .waiting-screen {
  background: #ffffff;
  padding: 1.25rem;
  color: #1a1a1a;
}

.screen-header { text-align: center; margin-bottom: 1.25rem; position: relative; }
.screen-back {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid #ddd;
  background: #f5f5f5;
  color: #444;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}
.screen-back:hover { background: #eee; }
.screen-header--game .screen-back {
  top: 0.35rem;
  transform: none;
}
.screen-header h2 {
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  color: var(--warm-amber);
  margin-top: 0.5rem;
}

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.7rem;
  color: #888;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid #ddd;
  background: #f5f5f5;
  color: #111;
  font-size: 1rem;
}

#room-code-input {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-weight: 700;
  text-align: center;
}

.role-toggle { display: flex; gap: 0.5rem; }
.role-btn {
  flex: 1;
  padding: 0.75rem;
  border-radius: 10px;
  border: 2px solid #ddd;
  background: #f5f5f5;
  color: #666;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.role-btn.selected {
  border-color: var(--cool-blue);
  color: #111;
  background: rgba(169,201,226,0.15);
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.char-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #f0f0f0;
  cursor: pointer;
  font-size: 0.65rem;
  color: #555;
}
.char-pick svg { width: 48px; height: 58px; }
.char-pick.selected { border-color: var(--warm-amber); background: rgba(212,167,106,0.12); }

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  margin-top: 0.5rem;
}
.btn-primary {
  background: linear-gradient(135deg, var(--cool-blue), var(--warm-amber));
  color: #111;
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  border: 1px solid #ccc;
  color: #444;
}

.lobby-error { color: var(--danger); font-size: 0.8rem; min-height: 1.2rem; margin-bottom: 0.5rem; }
.room-hint { font-size: 0.75rem; color: #888; text-align: center; margin-bottom: 0.75rem; }

.waiting-screen .room-code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-align: center;
  color: #111;
  margin: 0.5rem 0 1rem;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f5f5f5;
  border-radius: 12px;
  margin-bottom: 0.5rem;
  color: #1a1a1a;
}
.player-slot.ready { border: 1px solid var(--success); }
.player-slot.empty { opacity: 0.5; }
.player-slot.spectator {
  border: 1px dashed var(--cool-blue);
  background: rgba(169, 201, 226, 0.12);
}
.player-slot .char-thumb {
  flex-shrink: 0;
  width: 40px;
  height: 48px;
}
.player-slot .char-thumb svg { width: 40px; height: 48px; display: block; }
.player-slot .info { min-width: 0; flex: 1; }
.player-slot .info strong { display: block; font-size: 0.85rem; color: #1a1a1a; }
.player-slot .info span { font-size: 0.7rem; color: #666; }

.share-link {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.7rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin: 0.75rem 0;
  color: #666;
}

/* ===== GAME ===== */
.game-screen, .spectator-screen, .win-screen { background: #ffffff; }

.screen-header--game {
  padding: 0.5rem;
  background: #ffffff;
}

.cliff-arena {
  height: 250px;
  position: relative;
  overflow: hidden;
  background: #56BCEB;
}

.cliff-scene-mount {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.cliff-scene-mount svg { width: 100%; height: 100%; display: block; }

.battle-stage {
  position: absolute;
  bottom: 102px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 0;
  z-index: 10;
  transition: transform 0.7s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.fighter { display: flex; flex-direction: column; align-items: center; position: relative; }
.fighter-left { margin-right: -4px; }
.fighter-right { margin-left: -4px; }
.char-anim { transform-origin: bottom center; }
.char-anim svg,
.fighter svg {
  width: 72px;
  height: 88px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.45));
  display: block;
}

.fighter.pushing .char-anim { animation: char-push 0.28s ease-in-out infinite alternate; }
.fighter-left.pushing .char-anim { animation-name: char-push-left; }
.fighter-right.pushing .char-anim { animation-name: char-push-right; }
.fighter.losing .char-anim { animation: char-fall-left 0.55s ease-in-out infinite alternate; }
.fighter-right.losing .char-anim { animation-name: char-fall-right; }

.fighter.losing .fall-arm-left { animation: arm-wave-left 0.32s ease-in-out infinite alternate; transform-origin: 14px 8px; }
.fighter.losing .fall-arm-right { animation: arm-wave-right 0.32s ease-in-out infinite alternate; transform-origin: 50px 8px; }
.fighter-right.losing .fall-arm-left { animation-name: arm-wave-right; transform-origin: 50px 8px; }
.fighter-right.losing .fall-arm-right { animation-name: arm-wave-left; transform-origin: 14px 8px; }

@keyframes char-push-left {
  0% { transform: translateX(0) scaleX(1); }
  100% { transform: translateX(3px) scaleX(1.01); }
}
@keyframes char-push-right {
  0% { transform: translateX(0); }
  100% { transform: translateX(-3px); }
}
@keyframes char-fall-left {
  0% { transform: translate(0, 0) rotate(-6deg); }
  100% { transform: translate(10px, 14px) rotate(18deg); }
}
@keyframes char-fall-right {
  0% { transform: translate(0, 0) rotate(6deg); }
  100% { transform: translate(-10px, 14px) rotate(-18deg); }
}
@keyframes arm-wave-left {
  0% { transform: rotate(-8deg); }
  100% { transform: rotate(18deg); }
}
@keyframes arm-wave-right {
  0% { transform: rotate(8deg); }
  100% { transform: rotate(-18deg); }
}

.fighter.edge-fall { z-index: 25; pointer-events: none; }
.fighter.edge-fall .char-anim { animation: none !important; }
.fighter-left.edge-fall { animation: fighter-edge-fall-left 0.55s ease-out forwards; }
.fighter-right.edge-fall { animation: fighter-edge-fall-right 0.55s ease-out forwards; }
@keyframes fighter-edge-fall-left {
  0% { transform: translate(0, 0) rotate(-6deg); }
  100% { transform: translate(-22px, 36px) rotate(-32deg); }
}
@keyframes fighter-edge-fall-right {
  0% { transform: translate(0, 0) rotate(6deg); }
  100% { transform: translate(22px, 36px) rotate(32deg); }
}

.fighter-right .char-anim svg { transform: scaleX(-1); }

.strain-line {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 800;
  color: #ffcc66;
  opacity: 0;
  pointer-events: none;
  animation: strain-pop 0.4s ease-in-out infinite;
}
.fighter.pushing .strain-line { opacity: 1; }
.fighter-left .strain-line { top: -8px; right: -4px; }
.fighter-right .strain-line { top: -8px; left: -4px; }

@keyframes strain-pop {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

.fighter-name {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--chrome);
  margin-top: 2px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}

.fighter.word-win-callout {
  animation: word-win-glow 1.3s ease-out;
}
.fighter.word-win-callout .fighter-name {
  color: var(--warm-amber);
  text-shadow: 0 0 8px rgba(212, 167, 106, 0.85), 0 1px 4px rgba(0, 0, 0, 0.9);
}
@keyframes word-win-glow {
  0%, 100% { filter: none; }
  12%, 50% { filter: drop-shadow(0 0 10px rgba(212, 167, 106, 0.95)); }
}
.word-win-label {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--warm-amber);
  white-space: nowrap;
  pointer-events: none;
  z-index: 42;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
  animation: word-win-label 1.3s ease-out forwards;
}
@keyframes word-win-label {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.85); }
  18%, 55% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.95); }
}
.thumbs-fly-up {
  position: absolute;
  left: 50%;
  bottom: 58%;
  transform: translateX(-50%);
  font-size: 1.45rem;
  line-height: 1;
  pointer-events: none;
  z-index: 41;
  animation: thumbs-fly-up 1.3s ease-out forwards;
}
@keyframes thumbs-fly-up {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.5); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0) scale(0.95); }
  70% { opacity: 1; transform: translateX(-50%) translateY(-42px) scale(1.15); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-68px) scale(1); }
}

.wall-block {
  width: 38px;
  height: 82px;
  padding: 3px;
  background: #8a8078;
  border-radius: 2px;
  margin: 0 -8px;
  position: relative;
  z-index: 8;
  border: 2px solid #5a4030;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.25), 2px 0 6px rgba(0,0,0,0.2);
  overflow: hidden;
}

.brick-wall { display: flex; flex-direction: column; gap: 2px; height: 100%; width: 100%; }
.brick-row { display: flex; gap: 2px; flex: 1; min-height: 0; }
.brick-row.offset { margin-left: -8px; padding-left: 6px; }
.brick-row span {
  flex: 1;
  min-width: 0;
  border-radius: 1px;
  background: linear-gradient(180deg, #d47858 0%, #b85a42 45%, #903828 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.28), inset 0 -1px 0 rgba(0,0,0,0.2);
}
.brick-row:nth-child(even) span { background: linear-gradient(180deg, #c86848 0%, #a04832 45%, #802818 100%); }

.wall-block.shove-left { animation: wall-shove-left 0.28s ease-in-out infinite alternate; }
.wall-block.shove-right { animation: wall-shove-right 0.28s ease-in-out infinite alternate; }
@keyframes wall-shove-left { 0% { transform: translateX(0); } 100% { transform: translateX(3px); } }
@keyframes wall-shove-right { 0% { transform: translateX(0); } 100% { transform: translateX(-3px); } }

.wall-crack {
  position: absolute;
  width: 2px;
  height: 24px;
  background: #3a2010;
  top: 28px;
  left: 50%;
  transform: translateX(-50%) rotate(12deg);
  opacity: 0.7;
  z-index: 2;
}

.spec-cliff { height: 210px; }
.spec-cliff .battle-stage { bottom: 86px; }

.game-hud {
  padding: 1rem 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.round-badge {
  text-align: center;
  font-size: 0.65rem;
  color: var(--warm-amber);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.word-display {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin: 0.5rem 0 1rem;
  line-height: 1.4;
  word-break: break-word;
}
.word-display .done { color: var(--cool-blue); }
.word-display .current { color: var(--warm-amber); text-decoration: underline; text-underline-offset: 4px; }
.word-display .todo { color: #444; }
.word-display .error { color: var(--danger); }

.type-input {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  text-align: center;
  border-radius: 12px;
  border: 2px solid var(--cool-blue);
  background: #f5f5f5;
  color: #111;
  margin-bottom: 1rem;
}
.type-input.flash-error { border-color: var(--danger); animation: flash 0.2s; }
@keyframes flash { 50% { background: rgba(232,93,93,0.15); } }

.vs-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.stat-card { background: #f5f5f5; border-radius: 10px; padding: 0.65rem 0.75rem; border: 1px solid #eee; }
.stat-card.you { border: 1px solid rgba(169,201,226,0.5); }
.stat-card .label { font-size: 0.65rem; color: #888; }
.stat-card .wpm { font-size: 1.1rem; font-weight: 700; color: #5a8ab0; }
.stat-bar { height: 5px; background: #ddd; border-radius: 3px; margin-top: 0.35rem; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--cool-blue), var(--warm-amber)); transition: width 0.3s; }

/* Spectator */
.spec-banner {
  background: rgba(212,167,106,0.15);
  border-bottom: 1px solid rgba(212,167,106,0.3);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--warm-amber);
}
.spec-typing { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; flex: 1; background: #ffffff; }
.spec-player { background: #f5f5f5; border-radius: 12px; padding: 0.85rem; border: 1px solid #eee; }
.spec-player-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.spec-player-header svg { width: 32px; height: 38px; }
.spec-player-header .wpm { margin-left: auto; font-size: 0.75rem; color: #5a8ab0; }
.spec-player-header strong { color: #111; }
.spec-typed { font-family: ui-monospace, monospace; font-size: 0.85rem; color: #888; }
.spec-typed .match { color: var(--cool-blue); }

/* Win */
.win-screen {
  background: #ffffff;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  position: relative;
  color: #111;
}
.win-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--warm-amber), #666);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}
#win-subtitle { color: #666; }
.win-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 280px;
  margin-top: 1rem;
}
.win-char svg { width: 120px; height: 140px; animation: bounce 1.5s ease-in-out infinite; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
#fallen-char { display: none; }

.fighter.fall-off-cliff {
  z-index: 30;
  animation: fighter-plunge-off 2.5s ease-in forwards;
  pointer-events: none;
}
.fighter.fall-off-cliff .char-anim {
  animation: none !important;
}
.fighter-left.fall-off-cliff { --fall-x: 36px; }
.fighter-right.fall-off-cliff { --fall-x: -36px; }
.fighter.fall-off-cliff .fall-arm-left {
  animation: arm-wave-left 0.28s ease-in-out infinite alternate;
  transform-origin: 14px 8px;
}
.fighter.fall-off-cliff .fall-arm-right {
  animation: arm-wave-right 0.28s ease-in-out infinite alternate;
  transform-origin: 50px 8px;
}
@keyframes fighter-plunge-off {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  30% { transform: translate(calc(var(--fall-x, 24px) * 0.5), 24px) rotate(-10deg); opacity: 1; }
  65% { transform: translate(var(--fall-x, 24px), 80px) rotate(22deg); opacity: 0.75; }
  100% { transform: translate(calc(var(--fall-x, 24px) * 1.4), 220px) rotate(48deg); opacity: 0; }
}

.fallen-char {
  position: absolute;
  right: 10%;
  bottom: 25%;
  opacity: 1;
  animation: fall-off-plunge 2.4s ease-in forwards;
}
.fallen-char svg { width: 64px; height: 78px; }
.fallen-char .fall-arm-left { animation: arm-wave-left 0.28s ease-in-out infinite alternate; transform-origin: 14px 8px; }
.fallen-char .fall-arm-right { animation: arm-wave-right 0.28s ease-in-out infinite alternate; transform-origin: 50px 8px; }
@keyframes fall-off-plunge {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  35% { transform: translate(24px, 40px) rotate(-12deg); opacity: 0.95; }
  70% { transform: translate(48px, 100px) rotate(28deg); opacity: 0.6; }
  100% { transform: translate(72px, 180px) rotate(52deg); opacity: 0; }
}

.play-again-choice {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(100%, 280px);
  margin-top: 1.5rem;
}
.play-again-prompt {
  color: #666;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

@media (max-width: 380px) {
  .word-display { font-size: 1.1rem; }
  .cliff-arena { height: 220px; }
  .battle-stage { bottom: 88px; }
  .fighter svg { width: 60px; height: 74px; }
}
