/* ==============================================================================================
   Knuddels Beach — stylesheet
   ----------------------------------------------------------------------------------------------
   Layout model: #app is a 4:3 box (800 × 600 world units) that fills as much of the viewport as
   possible and is letterboxed on a dark page. One world unit is exposed as the custom property
   --u (a CSS length). CSS computes it from the viewport as a fallback; ui.js overwrites it with
   the measured clientWidth / 800 on every resize. Everything inside the box is positioned in
   percentages and sized in multiples of --u so the DOM scales exactly like the canvas.

   Look: the classic Java-Swing / Windows-classic beige of the original Knuddels applet — beige
   boxes, thin olive borders, 1px inset highlights, Arial 13px, chunky scrollbars.
   ============================================================================================== */

:root {
  color-scheme: light;

  /* Palette */
  --beige: rgba(246, 240, 214, 0.92);
  --beige-solid: #f6f0d6;
  --beige-dark: #e6e0c6;
  --olive: #8f8a70;
  --olive-light: #d9d3b8;
  --ink: #1d1a0f;
  --ink-soft: #6b6857;
  --red: #e2321f;
  --red-dark: #b3261e;
  --blue: #2f5fd6;
  --blue-dark: #1f4bb8;
  --sand: #f2d64b;
  --sun: #ffd94a;
  --page: #0c0e1a;
  --focus: #3b7ddd;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", Helvetica, "Liberation Sans", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

button {
  font-family: inherit;
}

/* ----------------------------------------------------------------------------------------------
   The 4:3 box
   ---------------------------------------------------------------------------------------------- */

#app {
  --u: calc(min(100vw, 133.333vh) / 800);
  --u: calc(min(100vw, 133.333dvh) / 800);
  position: relative;
  width: min(100vw, 133.333vh);
  width: min(100vw, 133.333dvh);
  height: auto;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  font-size: max(9px, 13 * var(--u));
  line-height: 1.25;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  background: transparent;
}

/* ----------------------------------------------------------------------------------------------
   Bottom panel (SPEC §8, world coords → percentages of the 800 × 600 box)
   chat log      x 7–587  y 505–561      player list  x 591–793  y 505–561
   input row     x 7–593  y 570–586      ignore       x 600–767  y 570–586      leave  x 771–793
   ---------------------------------------------------------------------------------------------- */

#panel {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

#panel > * {
  position: absolute;
  pointer-events: auto;
}

.box {
  position: absolute;
  background: var(--beige);
  border: 1px solid var(--olive);
  border-radius: calc(4 * var(--u));
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.8),
    inset -1px -1px 0 rgba(143, 138, 112, 0.28);
}

#chat-log {
  left: 0.875%;
  top: 84.1667%;
  width: 72.5%;
  height: 9.3333%;
  padding: calc(2 * var(--u)) calc(5 * var(--u));
  overflow-y: scroll;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  scroll-behavior: auto;
}

.chat-line {
  display: block;
  white-space: pre-wrap;
}

.chat-line.self {
  background: rgba(255, 255, 255, 0.28);
}

.chat-name {
  font-weight: bold;
  color: #3b382b;
}

.chat-line.side-0 .chat-name {
  color: var(--red-dark);
}

.chat-line.side-1 .chat-name {
  color: var(--blue-dark);
}

.chat-system {
  display: block;
  font-style: italic;
  color: var(--ink-soft);
}

#player-list {
  left: 73.875%;
  top: 84.1667%;
  width: 25.25%;
  height: 9.3333%;
  padding: calc(2 * var(--u)) calc(5 * var(--u));
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pl-rows {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}

.pl-row {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}

.pl-row.empty {
  opacity: 0.4;
  font-style: italic;
}

.pl-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-row.you .pl-name {
  font-weight: bold;
}

.pl-you {
  margin-left: 0.4em;
  font-size: 0.78em;
  color: var(--ink-soft);
  border: 1px solid var(--olive-light);
  border-radius: 2px;
  padding: 0 0.3em;
  background: rgba(255, 255, 255, 0.45);
}

.pl-code {
  align-self: flex-end;
  flex: none;
  line-height: 1.2;
  font-size: 0.72em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--olive-light);
  border-radius: 2px;
  padding: 0 0.35em;
  letter-spacing: 0.06em;
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
}

/* --- Swing style buttons and inputs --- */

.btn {
  font: inherit;
  font-size: max(9px, 11 * var(--u));
  line-height: 1;
  color: var(--ink);
  background: linear-gradient(#fbf8ec, var(--beige-dark));
  border: 1px solid var(--olive);
  border-radius: calc(3 * var(--u));
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #b9b39a;
  padding: 0 calc(6 * var(--u));
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:hover {
  background: linear-gradient(#fffdf4, #eee8cf);
}

.btn:active,
.btn.active {
  background: #d8d2b6;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.28);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-big {
  font-size: 1em;
  padding: 0.55em 0.9em;
  border-radius: 4px;
}

.btn-primary {
  background: linear-gradient(#ffe777, #f4c93a);
  border-color: #9a8324;
  color: #3a2b00;
  font-weight: bold;
  box-shadow:
    inset 1px 1px 0 #fff6bf,
    inset -1px -1px 0 #c9a52e;
}

.btn-primary:hover {
  background: linear-gradient(#fff0a0, #f7d24a);
}

.btn-primary:active {
  background: #e8bd2c;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.text {
  font: inherit;
  color: #111;
  background: #fff;
  border: 1px solid var(--olive);
  border-radius: 3px;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.14);
  padding: 0.35em 0.5em;
  min-width: 0;
}

.text:focus {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
}

.text::placeholder {
  color: #9a978a;
}

/* --- chat input row --- */

#chat-form {
  left: 0.875%;
  top: 95%;
  width: 73.25%;
  height: max(14px, 2.6667%);
  display: flex;
  gap: calc(3 * var(--u));
  margin: 0;
}

#chat-input {
  flex: 1;
  height: 100%;
  font-size: max(9px, 11 * var(--u));
  padding: 0 calc(4 * var(--u));
  border-radius: calc(3 * var(--u));
  user-select: text;
  -webkit-user-select: text;
}

#chat-send {
  height: 100%;
}

#btn-ignore {
  left: 75%;
  top: 95%;
  width: 20.875%;
  height: max(14px, 2.6667%);
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 calc(3 * var(--u));
}

#btn-ignore.active {
  font-size: max(8px, 9.4 * var(--u));
  letter-spacing: -0.01em;
}

#btn-leave {
  left: 96.375%;
  top: 95%;
  width: 2.75%;
  height: max(14px, 2.6667%);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-leave svg {
  width: 82%;
  height: 82%;
  display: block;
}

/* leave confirmation popover, anchored above the leave button */
#leave-confirm {
  right: 0.875%;
  bottom: 6%;
  padding: calc(4 * var(--u)) calc(6 * var(--u));
  display: flex;
  align-items: center;
  gap: calc(5 * var(--u));
  white-space: nowrap;
  box-shadow:
    0 calc(3 * var(--u)) calc(12 * var(--u)) rgba(0, 0, 0, 0.3),
    inset 1px 1px 0 rgba(255, 255, 255, 0.8);
  background: rgba(246, 240, 214, 0.98);
}

#leave-confirm .btn {
  height: max(14px, 16 * var(--u));
  min-width: calc(30 * var(--u));
}

#leave-confirm::after {
  content: "";
  position: absolute;
  right: calc(8 * var(--u));
  bottom: calc(-5 * var(--u));
  width: calc(8 * var(--u));
  height: calc(8 * var(--u));
  background: inherit;
  border-right: 1px solid var(--olive);
  border-bottom: 1px solid var(--olive);
  transform: rotate(45deg);
}

/* --- local-mode adjustments (the leave button and its confirmation stay available) --- */

#app.local #chat-form,
#app.local #btn-ignore {
  display: none;
}

/* ----------------------------------------------------------------------------------------------
   Blob icons (data-URI SVG so a chat line costs a single <span>)
   ---------------------------------------------------------------------------------------------- */

.blob-icon {
  display: inline-block;
  width: calc(11 * var(--u));
  height: calc(13 * var(--u));
  min-width: 9px;
  min-height: 11px;
  margin-right: 0.3em;
  vertical-align: -0.15em;
  background: no-repeat center / contain;
  flex: none;
}

.blob-icon.big {
  width: 2.3em;
  height: 2.7em;
  margin: 0;
}

.blob-icon.side-0 {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 24'><circle cx='10' cy='15.5' r='8' fill='%23e2321f' stroke='%236d140b' stroke-width='1'/><circle cx='10' cy='7.5' r='6.2' fill='%23e2321f' stroke='%236d140b' stroke-width='1'/><circle cx='10' cy='15.5' r='7.5' fill='%23e2321f'/><circle cx='10' cy='7.5' r='5.7' fill='%23e2321f'/><ellipse cx='7.4' cy='4.4' rx='1.9' ry='1.1' fill='%23ff9a8a' opacity='.7'/><rect x='6.3' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='11' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='7.3' y='6.3' width='.7' height='2.4' fill='%23000'/><rect x='12' y='6.3' width='.7' height='2.4' fill='%23000'/><path d='M7.3 11.4Q10 13.6 12.7 11.4' stroke='%236d140b' stroke-width='.8' fill='none' stroke-linecap='round'/></svg>");
}

.blob-icon.side-1 {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 24'><circle cx='10' cy='15.5' r='8' fill='%232f5fd6' stroke='%2312275e' stroke-width='1'/><circle cx='10' cy='7.5' r='6.2' fill='%232f5fd6' stroke='%2312275e' stroke-width='1'/><circle cx='10' cy='15.5' r='7.5' fill='%232f5fd6'/><circle cx='10' cy='7.5' r='5.7' fill='%232f5fd6'/><ellipse cx='7.4' cy='4.4' rx='1.9' ry='1.1' fill='%23a9c0ff' opacity='.7'/><rect x='6.3' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='11' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='7.3' y='6.3' width='.7' height='2.4' fill='%23000'/><rect x='12' y='6.3' width='.7' height='2.4' fill='%23000'/><path d='M7.3 11.4Q10 13.6 12.7 11.4' stroke='%2312275e' stroke-width='.8' fill='none' stroke-linecap='round'/></svg>");
}

.blob-icon.side-x {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 24'><circle cx='10' cy='15.5' r='8' fill='%23a8a394' stroke='%23555' stroke-width='1'/><circle cx='10' cy='7.5' r='6.2' fill='%23a8a394' stroke='%23555' stroke-width='1'/><circle cx='10' cy='15.5' r='7.5' fill='%23a8a394'/><circle cx='10' cy='7.5' r='5.7' fill='%23a8a394'/><rect x='6.3' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='11' y='5.2' width='2.7' height='4.5' rx='1.1' fill='%23fff'/><rect x='7.3' y='6.3' width='.7' height='2.4' fill='%23000'/><rect x='12' y='6.3' width='.7' height='2.4' fill='%23000'/></svg>");
}

/* ----------------------------------------------------------------------------------------------
   Classic scrollbar for the chat log
   ---------------------------------------------------------------------------------------------- */

#chat-log::-webkit-scrollbar {
  width: max(10px, 13 * var(--u));
}

#chat-log::-webkit-scrollbar-track {
  background: repeating-conic-gradient(#e6e0c6 0 25%, #f6f0d6 0 50%) 0 0 / 2px 2px;
  border-left: 1px solid var(--olive-light);
}

#chat-log::-webkit-scrollbar-thumb {
  background: #e2dcc2;
  border: 1px solid var(--olive);
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #aaa48a;
}

#chat-log::-webkit-scrollbar-button:single-button {
  height: max(10px, 13 * var(--u));
  background: #e2dcc2 no-repeat center / 55%;
  border: 1px solid var(--olive);
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #aaa48a;
}

#chat-log::-webkit-scrollbar-button:single-button:vertical:decrement {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path d='M1 6l3-4 3 4z' fill='%23333'/></svg>");
}

#chat-log::-webkit-scrollbar-button:single-button:vertical:increment {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'><path d='M1 2l3 4 3-4z' fill='%23333'/></svg>");
}

/* Firefox has no ::-webkit-scrollbar; give it a matching thin beige scrollbar. Chrome would let
   scrollbar-color override the styles above, so scope this to Gecko. */
@supports (-moz-appearance: none) {
  #chat-log {
    scrollbar-width: thin;
    scrollbar-color: #d6d0b3 #efe9d0;
  }
}

/* ----------------------------------------------------------------------------------------------
   Mute toggle (top-right corner, above the cloud band; the HUD score ends at y ≈ 19)
   ---------------------------------------------------------------------------------------------- */

#btn-mute {
  position: absolute;
  top: 0.4%;
  right: 0.5%;
  width: max(18px, 17 * var(--u));
  height: max(18px, 17 * var(--u));
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0.45;
  z-index: 7;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#btn-mute:hover,
#btn-mute:focus-visible {
  opacity: 1;
  outline: none;
}

#btn-mute svg {
  width: 100%;
  height: 100%;
  display: block;
}

#btn-mute .mute-cross {
  display: none;
}

#btn-mute.muted .mute-waves {
  display: none;
}

#btn-mute.muted .mute-cross {
  display: block;
}

#btn-mute.muted {
  opacity: 0.85;
}

/* The lobby is modal (and, on phones, larger than the game box): keep the toggle out of it. */
#app.in-lobby #btn-mute {
  display: none;
}

/* ----------------------------------------------------------------------------------------------
   Touch controls — only on coarse pointers
   ---------------------------------------------------------------------------------------------- */

#touch {
  --touch-size: clamp(48px, 78 * var(--u), 112px);
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

@media (pointer: coarse) {
  #touch {
    display: block;
  }
}

.touch-btn {
  position: absolute;
  bottom: 18.5%;
  width: var(--touch-size);
  height: var(--touch-size);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.26);
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  color: rgba(16, 20, 44, 0.72);
  font-size: calc(var(--touch-size) * 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.touch-btn:active,
.touch-btn.pressed {
  background: rgba(255, 255, 255, 0.55);
}

.touch-left {
  left: 2.5%;
}

.touch-right {
  left: calc(2.5% + var(--touch-size) + 2%);
}

.touch-up {
  right: 2.5%;
}

/* ----------------------------------------------------------------------------------------------
   Status pill (top centre) and error toast (bottom centre, above the panel)
   ---------------------------------------------------------------------------------------------- */

#status {
  position: absolute;
  top: 1.2%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  max-width: 60%;
  padding: 0.3em 0.9em 0.3em 0.75em;
  font-size: clamp(11px, 12 * var(--u), 16px);
  color: #fff;
  background: rgba(12, 14, 26, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 2em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

#status::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: var(--sun);
  vertical-align: 0.05em;
  animation: status-pulse 1.4s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 17.5%;
  transform: translateX(-50%);
  z-index: 9;
  max-width: 80%;
  padding: 0.55em 1.1em;
  font-size: clamp(12px, 13 * var(--u), 17px);
  font-weight: bold;
  color: #fff;
  background: #c0281c;
  border: 1px solid #7a1108;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-align: center;
  pointer-events: none;
}

#toast.show {
  animation: toast-in 0.22s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 0.6em); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ----------------------------------------------------------------------------------------------
   Cards (waiting / opponent left / game over)
   ---------------------------------------------------------------------------------------------- */

.card {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 5;
  width: max-content;
  max-width: 88%;
  padding: 1em 1.5em 1.1em;
  font-size: clamp(12px, 13 * var(--u), 18px);
  line-height: 1.3;
  text-align: center;
  color: var(--ink);
  background: rgba(246, 240, 214, 0.97);
  border: 1px solid var(--olive);
  border-radius: 0.5em;
  box-shadow:
    0 0.6em 2em rgba(0, 0, 0, 0.35),
    inset 0 1px 0 #fff;
  animation: card-in 0.25s ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.card h2 {
  margin: 0 0 0.35em;
  font-size: 1.45em;
  line-height: 1.2;
  color: #2a2718;
}

.card-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6em;
  margin-top: 0.9em;
}

/* --- waiting card --- */

.waiting-left {
  margin: 0 0 0.6em;
  padding: 0.35em 0.7em;
  font-weight: bold;
  color: #7a1108;
  background: rgba(226, 50, 31, 0.1);
  border: 1px solid rgba(226, 50, 31, 0.35);
  border-radius: 4px;
}

.bounce-ball {
  position: relative;
  width: 1.6em;
  height: 2.6em;
  margin: 0.2em auto 0.5em;
}

.bounce-ball::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1.4em;
  height: 0.35em;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  animation: ball-shadow 0.8s ease-in-out infinite;
}

.bounce-ball::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0.3em;
  width: 1.3em;
  height: 1.3em;
  margin-left: -0.65em;
  border-radius: 50%;
  border: 2px solid #111;
  background:
    radial-gradient(circle at 35% 30%, #fff 0, #fff 45%, #cfcfcf 100%);
  box-shadow: inset -0.15em -0.15em 0.2em rgba(0, 0, 0, 0.08);
  animation: ball-bounce 0.8s ease-in-out infinite;
}

@keyframes ball-bounce {
  0%, 100% { transform: translateY(0) scale(1.08, 0.92); }
  50% { transform: translateY(-1.1em) scale(0.96, 1.04); }
}

@keyframes ball-shadow {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: 0.22; }
  50% { transform: translateX(-50%) scale(0.6); opacity: 0.1; }
}

.waiting-room {
  margin: 0.2em 0 0.9em;
  padding: 0.6em 0.8em 0.7em;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--olive-light);
  border-radius: 5px;
}

.room-label {
  font-size: 0.8em;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.room-code {
  margin: 0.1em 0 0.45em;
  font-family: "Courier New", Courier, monospace;
  font-size: 1.9em;
  font-weight: bold;
  letter-spacing: 0.25em;
  color: #2a2718;
  user-select: text;
  -webkit-user-select: text;
}

.room-link-row {
  display: flex;
  gap: 0.4em;
  align-items: stretch;
}

.room-link {
  flex: 1;
  width: 18em;
  font-size: 0.85em;
  padding: 0.3em 0.5em;
  color: #333;
  user-select: text;
  -webkit-user-select: text;
}

.room-link-row .btn {
  padding: 0.35em 0.7em;
  font-size: 0.9em;
}

.room-hint {
  margin-top: 0.45em;
  font-size: 0.8em;
  color: var(--ink-soft);
}

/* --- game over card --- */

#gameover {
  min-width: 15em;
}

#gameover.won h2 {
  color: #1f7a2e;
}

#gameover.lost h2 {
  color: #9a1d12;
}

.go-winner {
  color: var(--ink-soft);
}

.go-score {
  margin: 0.4em 0 0.2em;
  font-size: 2.4em;
  font-weight: bold;
  line-height: 1.1;
  font-family: "Arial Narrow", Arial, sans-serif;
  letter-spacing: 0.02em;
}

.go-score .score-l {
  color: var(--red);
}

.go-score .score-r {
  color: var(--blue);
}

.go-score .score-sep {
  margin: 0 0.25em;
  color: #6b6857;
}

.go-elo {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.2em;
  padding: 0.25em 0.7em;
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--olive-light);
  border-radius: 4px;
}

.elo-delta {
  font-weight: bold;
  padding: 0 0.4em;
  border-radius: 3px;
  color: #fff;
  background: #8b8875;
}

.elo-delta.up {
  background: #2f9a43;
}

.elo-delta.down {
  background: #c8352a;
}

/* ----------------------------------------------------------------------------------------------
   Lobby overlay — fixed to the viewport so it stays usable on small phones
   ---------------------------------------------------------------------------------------------- */

#lobby {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: auto;
  background: rgba(12, 14, 26, 0.62);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  font-size: clamp(14px, 12 * var(--u), 17px);
  line-height: 1.3;
}

.lobby-card {
  width: min(100%, 30em);
  margin: auto;
  background: var(--beige-solid);
  border: 1px solid var(--olive);
  border-radius: 0.6em;
  box-shadow:
    0 1em 3em rgba(0, 0, 0, 0.5),
    inset 0 1px 0 #fff;
  overflow: hidden;
  animation: card-in-plain 0.3s ease-out;
}

@keyframes card-in-plain {
  from { opacity: 0; transform: translateY(0.6em); }
  to { opacity: 1; transform: none; }
}

.lobby-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  padding: 1.1em 1em 1.15em;
  background: linear-gradient(
    #1f2d7e 0%,
    #3a3f9c 22%,
    #6f4d9f 44%,
    #b95a8f 60%,
    #dd6f78 72%,
    #f08b58 86%,
    #f7cf62 100%
  );
  border-bottom: 1px solid #a08a2a;
}

.lobby-head::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.45em;
  background: var(--sand);
  border-top: 2px solid #fff6c8;
}

.lobby-head::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 0.8em;
  background: #141833;
  border-radius: 0 0 40% 60% / 0 0 100% 100%;
  opacity: 0.85;
}

.lobby-title {
  position: relative;
  margin: 0;
  font-family: "Arial Rounded MT Bold", "Helvetica Rounded", ui-rounded, "Hiragino Maru Gothic ProN", "Varela Round", "Nunito", Arial, sans-serif;
  font-weight: bold;
  font-size: 2.15em;
  white-space: nowrap;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.45),
    0 0 14px rgba(0, 0, 0, 0.35);
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .lobby-title {
    background: linear-gradient(#ffffff 35%, #ffe27a);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 8px rgba(0, 0, 0, 0.3));
  }
}

.lobby-head .blob-icon {
  position: relative;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}

.lobby-body {
  padding: 1.1em 1.3em 1.2em;
  display: grid;
  gap: 0.75em;
}

.field {
  display: grid;
  grid-template-columns: 6em 1fr;
  align-items: start;
  gap: 0.5em;
}

.field > label,
.field-label {
  padding-top: 0.42em;
  font-weight: bold;
  color: #3b382b;
}

.field-input {
  display: grid;
  gap: 0.3em;
}

.field-input.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3em 0.7em;
}

.field-input.inline .field-error {
  flex-basis: 100%;
}

.field-input.inline .field-label {
  padding-top: 0;
}

.text.short {
  width: 4.2em;
  text-align: center;
}

.field-error {
  font-size: 0.85em;
  color: #b3261e;
  font-weight: bold;
}

.text.invalid {
  border-color: #c0281c;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.14), 0 0 0 2px rgba(192, 40, 28, 0.25);
}

/* Segmented gender control */
.seg {
  display: inline-flex;
  border: 1px solid var(--olive);
  border-radius: 4px;
  overflow: hidden;
  background: var(--beige-dark);
}

.seg label {
  position: relative;
  display: block;
}

.seg input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.seg span {
  display: block;
  min-width: 2.2em;
  padding: 0.32em 0.5em;
  text-align: center;
  font-size: 1.05em;
  line-height: 1.15;
  cursor: pointer;
  color: #4a4636;
  background: linear-gradient(#fbf8ec, var(--beige-dark));
  border-right: 1px solid var(--olive-light);
  box-shadow: inset 1px 1px 0 #fff;
  user-select: none;
  -webkit-user-select: none;
}

.seg label:last-child span {
  border-right: 0;
}

.seg input:checked + span {
  background: #d8d2b6;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font-weight: bold;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.seg input[value="m"]:checked + span {
  color: var(--blue-dark);
}

.seg input[value="w"]:checked + span {
  color: var(--red-dark);
}

.lobby-actions {
  display: grid;
  gap: 0.55em;
  margin-top: 0.2em;
}

.lobby-actions .btn-primary {
  font-size: 1.12em;
  padding: 0.6em 1em;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5em;
}

.text.code {
  width: 6.2em;
  text-align: center;
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
  font-size: 1.05em;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding-left: 0.6em;
  padding-right: 0.4em;
}

.text.code::placeholder {
  letter-spacing: 0.12em;
  font-weight: normal;
}

.text.code.highlight {
  animation: code-glow 1.2s ease-in-out 3;
  border-color: #b8961c;
}

@keyframes code-glow {
  0%, 100% { box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.14), 0 0 0 0 rgba(255, 217, 74, 0); }
  50% { box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.14), 0 0 0 4px rgba(255, 217, 74, 0.85); }
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.7em;
  margin: 0.25em 0;
  font-size: 0.82em;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid #cdc7aa;
}

.lobby-foot {
  padding: 0.65em 1em 0.8em;
  font-size: 0.8em;
  color: var(--ink-soft);
  text-align: center;
  border-top: 1px solid var(--olive-light);
  background: rgba(0, 0, 0, 0.035);
}

.lobby-foot kbd {
  font-family: inherit;
  padding: 0 0.3em;
  border: 1px solid #c9c3a5;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #fff;
  color: #3b382b;
}

/* Narrow phones: smaller title, labels above their fields. */
@media (max-width: 440px) {
  .lobby-head {
    gap: 0.55em;
  }

  .lobby-title {
    font-size: 1.8em;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 0.25em;
  }

  .field > label {
    padding-top: 0;
  }
}

@media (max-width: 340px) {
  .lobby-title {
    font-size: 1.5em;
  }
}

/* ----------------------------------------------------------------------------------------------
   Reduced motion
   ---------------------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .card,
  .lobby-card,
  #toast.show,
  .text.code.highlight,
  #status::before,
  .bounce-ball::before,
  .bounce-ball::after {
    animation: none;
  }
}
