:root {
  --bg-1: #03121f;
  --bg-2: #132c48;
  --card: rgba(8, 20, 34, 0.84);
  --line: rgba(148, 195, 255, 0.28);
  --text: #ecf4ff;
  --muted: #97b7d6;
  --accent: #57c5ff;
  --accent-2: #ffd54f;
  --danger: #ff7a7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Outfit', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #1e4e7f 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, #0a5771 0%, transparent 45%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

html.login-screen-active,
body.login-screen-active {
  overflow-y: hidden;
}

.aurora {
  position: fixed;
  inset: -25%;
  background: conic-gradient(from 120deg, rgba(87, 197, 255, 0.22), rgba(255, 213, 79, 0.2), rgba(87, 197, 255, 0.05));
  filter: blur(70px);
  animation: drift 12s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes drift {
  from {
    transform: translate(-5%, -3%) scale(1);
  }
  to {
    transform: translate(4%, 5%) scale(1.1);
  }
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 16px));
  margin: 0 auto;
}

.card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.25);
}

.login-card {
  width: min(720px, 100%);
  margin: clamp(4px, 1vh, 16px) auto;
  padding: 26px 30px 16px;
  text-align: center;
}

.login-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
}

.login-title__line {
  display: block;
}

.login-title__line--meta {
  font-size: 0.5em;
  letter-spacing: 0.14em;
}

.brand-logo {
  display: block;
  height: auto;
  object-fit: contain;
}

.brand-logo--hero {
  width: min(180px, 42vw);
  margin: 0 auto 10px;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.32));
}

.version-note {
  margin: 10px 0 0;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.78;
}

h1,
h2 {
  margin: 0 0 10px;
  font-family: 'Chakra Petch', sans-serif;
  letter-spacing: 0.04em;
}

p {
  color: var(--muted);
}

.login-card > p {
  margin: 0 0 10px;
}

.login-card form {
  margin: 8px auto 0;
  max-width: 560px;
}

.login-status-line {
  min-height: 1.4em;
  margin: 10px auto 0;
  max-width: 560px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

input,
select,
button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
}

input,
select {
  flex: 1;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 11px 12px;
}

select {
  color-scheme: dark;
}

option {
  background: #0b1f34;
  color: var(--text);
}

button {
  background: linear-gradient(140deg, var(--accent), #31a9eb);
  color: #001321;
  border: 0;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.06);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.danger-btn {
  background: linear-gradient(145deg, #ff8484, #ff6464);
  color: #240606;
}

.hidden {
  display: none !important;
}

.lobby-layout {
  display: grid;
  grid-template-columns: 1.15fr 1.65fr 0.9fr;
  gap: 12px;
  min-height: calc(100vh - 24px);
}

.room-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.95fr;
  gap: 12px;
  min-height: calc(100vh - 24px);
}

.lobby-brand {
  grid-column: 1 / -1;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo--lobby {
  width: 72px;
  flex: 0 0 auto;
}

.lobby-brand__copy {
  min-width: 0;
}

.lobby-brand h2 {
  margin-bottom: 4px;
}

.lobby-brand p {
  margin: 0;
  color: var(--muted);
}

.room-brand {
  align-items: center;
}

.room-brand__actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.column {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.chat-log,
.games-list,
.players-list,
.room-players {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.17);
  padding: 10px;
  overflow-y: auto;
}

.chat-log {
  flex: 1;
  min-height: 280px;
  max-height: calc(100vh - 210px);
}

.games-list,
.players-list,
.room-players {
  min-height: 220px;
}

.games-list {
  flex: 1;
  min-height: 420px;
}

.chat-form,
.create-form {
  margin-top: auto;
}

.create-form {
  margin-top: 0;
  flex-wrap: wrap;
}

.create-form__label {
  width: 100%;
  color: var(--muted);
  font-size: 0.92rem;
}

.create-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

.create-actions button {
  flex: 1;
}

.chat-item {
  margin-bottom: 8px;
  line-height: 1.3;
}

.chat-item.player {
  color: var(--accent-2);
}

.chat-player-name {
  font-weight: 700;
}

.chat-item.system {
  color: var(--accent);
}

.game-row,
.player-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.game-row strong {
  margin-right: 8px;
}

.game-badge {
  display: inline-block;
  border: 1px solid rgba(255, 213, 79, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  color: var(--accent-2);
  background: rgba(255, 213, 79, 0.08);
}

.player-row.in-game {
  border-color: rgba(255, 213, 79, 0.45);
}

.game-meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 5px 0 8px;
}

.status-line {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.room-players-card {
  min-height: 0;
}

.room-settings {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.room-settings__label {
  color: var(--muted);
  font-size: 0.92rem;
}

.room-settings__buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.room-settings__buttons button.active {
  border-color: rgba(255, 208, 111, 0.75);
  background: rgba(255, 208, 111, 0.16);
  color: #fff0c9;
}

.room-players {
  flex: 1;
}

.room-player-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) auto auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.room-player-main {
  min-width: 0;
}

.room-player-main strong,
.room-player-main span {
  display: block;
}

.room-player-main span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.92rem;
}

.room-team-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.room-team-actions button {
  padding: 8px 10px;
}

.team-chip {
  min-width: 98px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.team-chip.team-1 {
  color: #ffd1c8;
  border-color: rgba(255, 126, 99, 0.55);
  background: rgba(255, 126, 99, 0.14);
}

.team-chip.team-2 {
  color: #d7e5ff;
  border-color: rgba(87, 197, 255, 0.55);
  background: rgba(87, 197, 255, 0.14);
}

.game-card {
  padding: 14px;
}

.game-card--local-nibbles-touch {
  padding: 10px;
}

.game-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#game-status {
  margin: 0;
  flex: 1;
}

#game-canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  margin-top: 12px;
  margin-left: auto;
  margin-right: auto;
  background: linear-gradient(#80d8ff, #9de4ff 65%, #f7be63 65%, #e89e39);
}

.game-stage {
  position: relative;
  margin-top: 12px;
}

.game-stage #game-canvas {
  margin-top: 0;
}

.controls {
  margin: 8px 0 0;
  font-size: 0.92rem;
}

.znz-panel {
  position: absolute;
  inset: 16px;
  display: grid;
  grid-template-columns: minmax(220px, 290px) 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 10px 12px;
  pointer-events: none;
}

.znz-selection-bar {
  grid-column: 1 / -1;
  justify-self: center;
  max-width: min(100%, 520px);
  padding: 8px 14px;
  border: 1px solid rgba(149, 203, 255, 0.32);
  border-radius: 999px;
  background: rgba(7, 19, 31, 0.78);
  color: #dcecff;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-align: center;
}

.znz-resource-bar {
  align-self: start;
  justify-self: start;
  padding: 10px 14px;
  border: 1px solid rgba(137, 209, 255, 0.34);
  border-radius: 14px;
  background: rgba(6, 19, 31, 0.84);
  color: #f1f8ff;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.84rem;
  letter-spacing: 0.06em;
  pointer-events: auto;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.24);
}

.znz-actions {
  align-self: end;
  justify-self: start;
  width: min(100%, 250px);
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.znz-action-group,
.znz-queue-bar,
.znz-info-bar {
  border: 1px solid rgba(125, 188, 255, 0.24);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(6, 19, 31, 0.9), rgba(7, 13, 24, 0.92));
  box-shadow: 0 20px 34px rgba(0, 0, 0, 0.24);
}

.znz-action-group {
  padding: 8px 8px 10px;
  overflow: visible;
}

.znz-action-group__title {
  margin: 0 0 8px;
  color: #f1f7ff;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.znz-action-group__buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, 42px);
  gap: 6px;
}

.znz-action-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid rgba(155, 209, 255, 0.18);
  background: linear-gradient(140deg, rgba(23, 45, 68, 0.98), rgba(9, 20, 34, 0.98));
  color: #ebf5ff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  text-align: center;
  overflow: visible;
}

.znz-action-btn__icon {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.znz-action-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: 210px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(146, 210, 255, 0.3);
  background: rgba(8, 18, 30, 0.96);
  color: #e8f6ff;
  font-size: 0.74rem;
  line-height: 1.35;
  text-align: left;
  white-space: pre-line;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 16px 24px rgba(0, 0, 0, 0.28);
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 5;
}

.znz-action-btn:hover::after,
.znz-action-btn:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.znz-action-btn--build {
  border-color: rgba(255, 214, 103, 0.22);
}

.znz-action-btn--stop {
  border-color: rgba(127, 197, 255, 0.26);
}

.znz-action-btn.active {
  outline: 2px solid rgba(255, 213, 79, 0.82);
  outline-offset: 1px;
  background: linear-gradient(140deg, rgba(58, 42, 9, 0.98), rgba(22, 16, 6, 0.98));
}

.znz-right-rail {
  grid-column: 2;
  align-self: end;
  justify-self: end;
  width: min(100%, 280px);
  display: grid;
  gap: 10px;
  pointer-events: auto;
}

.znz-queue-bar {
  padding: 12px;
}

.znz-info-bar {
  padding: 12px;
}

.znz-queue-bar__title {
  margin: 0 0 10px;
  color: #f1f7ff;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.znz-queue-list {
  display: grid;
  gap: 8px;
}

.znz-queue-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #d9ecff;
  font-size: 0.84rem;
}

.znz-queue-empty {
  color: #9fc6ea;
  font-size: 0.82rem;
}

.znz-info-bar__title {
  margin: 0 0 8px;
  color: #f1f7ff;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.znz-info-bar__status {
  margin-bottom: 10px;
  color: #9fe6ba;
  font-size: 0.8rem;
}

.znz-info-bar__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: #d9ecff;
  font-size: 0.82rem;
}

.znz-info-bar__row:first-of-type {
  border-top: 0;
}

.touch-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  width: min(100%, 336px);
  gap: 6px;
  margin: 10px auto 0;
  align-items: stretch;
}

.nibbles-touch-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
  margin-top: 10px;
  align-items: stretch;
}

.local-nibbles-touch {
  margin-top: 10px;
}

.local-nibbles-touch__label {
  margin-bottom: 6px;
  color: var(--muted);
  font-family: 'Chakra Petch', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.local-nibbles-touch__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: stretch;
}

.swipe-pad,
.shoot-btn {
  border-radius: 14px;
  border: 1px solid var(--line);
}

.swipe-pad {
  min-height: 120px;
  background:
    radial-gradient(circle at center, rgba(87, 197, 255, 0.22), rgba(87, 197, 255, 0.02) 70%),
    rgba(255, 255, 255, 0.04);
  position: relative;
  touch-action: none;
  user-select: none;
  overflow: hidden;
}

.swipe-pad--blobby {
  background:
    linear-gradient(90deg, rgba(87, 197, 255, 0.18), rgba(255, 255, 255, 0.02) 24%, rgba(255, 255, 255, 0.02) 76%, rgba(87, 197, 255, 0.18)),
    rgba(255, 255, 255, 0.04);
}

.swipe-pad--blobby .swipe-pad__hint--blobby {
  font-size: 0.84rem;
}

.swipe-pad--blobby .swipe-pad__hint--blobby::before,
.swipe-pad--blobby .swipe-pad__hint--blobby::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.48);
  font-size: 1rem;
  line-height: 1;
}

.swipe-pad::before,
.swipe-pad::after {
  content: '';
  position: absolute;
  inset: 50%;
  background: rgba(255, 255, 255, 0.08);
  transform: translate(-50%, -50%);
}

.swipe-pad::before {
  width: 1px;
  height: 78%;
}

.swipe-pad::after {
  width: 78%;
  height: 1px;
}

.swipe-pad.swipe-pad--blobby::before {
  width: 1px;
  height: 74%;
}

.swipe-pad.swipe-pad--blobby::after {
  width: 80%;
  height: 1px;
  opacity: 0.35;
}

.swipe-pad--blobby .swipe-pad__hint--blobby::before {
  content: '<';
  left: 14px;
}

.swipe-pad--blobby .swipe-pad__hint--blobby::after {
  content: '>';
  right: 14px;
}

.swipe-pad__hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text);
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.shoot-btn {
  min-height: 120px;
  background: linear-gradient(145deg, #ffb24f, #ff7d42);
  color: #1f0b03;
}

.jump-btn {
  min-height: 120px;
  border-radius: 18px;
  border: 1px solid rgba(255, 205, 107, 0.36);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.26), transparent 52%),
    linear-gradient(160deg, #ffe07f, #ff9347);
  color: #2a1205;
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.jump-btn:active {
  transform: translateY(1px) scale(0.985);
}

.swipe-pad--compact {
  min-height: 92px;
}

.shoot-btn--compact {
  min-height: 92px;
}

.game-card--local-nibbles-touch .controls {
  margin-top: 6px;
  font-size: 0.82rem;
  text-align: center;
}

.game-card--local-nibbles-touch .local-nibbles-touch {
  margin-top: 8px;
}

.game-card--local-nibbles-touch .local-nibbles-touch__label {
  margin-bottom: 4px;
}

@media (max-width: 1120px) {
  .lobby-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .room-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .chat-log,
  .games-list,
  .players-list {
    min-height: 180px;
  }

  .app-shell {
    width: calc(100% - 8px);
    margin: 0 auto;
  }

  .column {
    padding: 10px;
  }

  .lobby-brand {
    gap: 12px;
  }

  .room-brand__actions {
    margin-left: 0;
    width: 100%;
  }

  .room-brand__actions button {
    flex: 1;
  }

  .brand-logo--lobby {
    width: 60px;
  }

  .game-card {
    padding: 10px;
  }

  #game-canvas {
    border-radius: 10px;
  }

  .controls {
    font-size: 0.86rem;
  }

  .nibbles-touch-controls {
    grid-template-columns: 1fr 92px;
  }

  .touch-controls {
    grid-template-columns: minmax(0, 1fr) 92px;
    width: min(100%, 312px);
  }

  .local-nibbles-touch__grid {
    grid-template-columns: 1fr 84px;
  }

  .room-player-row {
    grid-template-columns: 1fr;
  }

  .room-team-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  .brand-logo--hero {
    width: min(148px, 42vw);
    margin-bottom: 8px;
  }

  .lobby-brand {
    padding: 12px;
    align-items: flex-start;
  }

  .brand-logo--lobby {
    width: 48px;
  }

  .game-card--local-nibbles-touch {
    padding: 8px;
  }

  .game-card--local-nibbles-touch .game-head {
    gap: 8px;
  }

  .game-card--local-nibbles-touch .controls {
    font-size: 0.76rem;
  }

  .game-card--local-nibbles-touch .local-nibbles-touch__grid {
    grid-template-columns: 1fr 76px;
    gap: 8px;
  }

  .game-card--local-nibbles-touch .swipe-pad--compact,
  .game-card--local-nibbles-touch .shoot-btn--compact {
    min-height: 76px;
  }

  .touch-controls {
    gap: 6px;
  }

  .touch-controls .swipe-pad--blobby,
  .touch-controls .jump-btn {
    min-height: 92px;
  }

  .touch-controls .swipe-pad__hint--blobby {
    font-size: 0.78rem;
  }
}
