:root {
  --bg: #070b12;
  --bg-2: #0d1420;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.075);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eaf0f7;
  --muted: #8b9ab0;
  --accent: #a3ff4f;
  --accent-ink: #0a1405;
  --red: #ff5f66;
  --blue: #59a7ff;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(89, 167, 255, 0.14), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(255, 95, 102, 0.12), transparent 55%),
    radial-gradient(900px 700px at 50% 120%, rgba(163, 255, 79, 0.08), transparent 60%),
    var(--bg);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
}
h1 {
  font-size: clamp(2rem, 5vw, 2.8rem);
}
h2 {
  font-size: 1.08rem;
}
h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
p {
  margin: 0;
}

.muted {
  color: var(--muted);
  font-weight: 600;
}
.red-text {
  color: var(--red);
}
.blue-text {
  color: var(--blue);
}
.hidden {
  display: none !important;
}

.screen {
  display: none;
  min-height: 100dvh;
}
.screen.active {
  display: block;
}

/* ---------------- LOBI ---------------- */
.lobby-wrap {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: calc(28px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.brand-mark .dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: block;
}
.brand-mark .dot.red {
  background: var(--red);
  box-shadow: 0 0 14px rgba(255, 95, 102, 0.55);
}
.brand-mark .dot.blue {
  background: var(--blue);
  box-shadow: 0 0 14px rgba(89, 167, 255, 0.55);
}
.brand-mark .dot.ball {
  background: #fff;
  width: 11px;
  height: 11px;
  margin: 0 3px;
}
.tagline {
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(320px, 1.15fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.028));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.row.gap {
  gap: 8px;
}
.row.end {
  justify-content: flex-end;
}
.row.center {
  justify-content: center;
}

.input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(163, 255, 79, 0.16);
}
.input::placeholder {
  color: #6c7b90;
}
select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px) scale(0.99);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 26px rgba(163, 255, 79, 0.25);
}
.btn.primary:hover {
  filter: brightness(1.06);
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-color: var(--line-strong);
}
.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}
.btn.small {
  padding: 9px 13px;
  font-size: 0.85rem;
  border-radius: 10px;
}
.btn.big {
  padding: 15px 26px;
  font-size: 1.02rem;
  width: 100%;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn:focus-visible,
.icon-btn:focus-visible,
.kick-btn:focus-visible,
.link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.link {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 8px;
}
.prefs-btn {
  margin-top: 10px;
}
.speed-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
input.range {
  width: 100%;
  margin-top: 10px;
  accent-color: var(--accent);
}
.empty {
  color: var(--muted);
  font-size: 0.92rem;
  padding: 22px 6px;
  text-align: center;
}

.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}
.dot-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f0b429;
  box-shadow: 0 0 10px rgba(240, 180, 41, 0.6);
}
.dot-indicator.online {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(163, 255, 79, 0.7);
}
.dot-indicator.offline {
  background: #ff5f66;
  box-shadow: 0 0 10px rgba(255, 95, 102, 0.6);
}

.mini-rules {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.mini-rules ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.88rem;
  display: grid;
  gap: 6px;
}
.mini-rules b {
  color: var(--text);
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: min(52vh, 430px);
  overflow-y: auto;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
}
.room-item:hover {
  border-color: var(--line-strong);
}
.room-item .room-info {
  min-width: 0;
  flex: 1;
}
.room-item .room-name {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-item .room-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  gap: 8px;
  align-items: center;
}
.badge {
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(163, 255, 79, 0.14);
  color: var(--accent);
  border: 1px solid rgba(163, 255, 79, 0.25);
}
.badge.live {
  background: rgba(255, 95, 102, 0.15);
  color: var(--red);
  border-color: rgba(255, 95, 102, 0.3);
}
.badge.full {
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  border-color: var(--line-strong);
}

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  flex-wrap: wrap;
}

/* ---------------- SOBA ---------------- */
.room-wrap {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
}
.room-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}
.room-title h2 {
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-title .muted {
  font-size: 0.8rem;
}

.room-grid {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 0.85fr) 1fr;
  gap: 12px;
  align-items: stretch;
}

.team-panel {
  min-height: 220px;
}
.team-panel h3 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.team-red h3 {
  color: var(--red);
}
.team-blue h3 {
  color: var(--blue);
}
.team-red {
  border-color: rgba(255, 95, 102, 0.22);
  background: linear-gradient(180deg, rgba(255, 95, 102, 0.09), rgba(255, 255, 255, 0.025));
}
.team-blue {
  border-color: rgba(89, 167, 255, 0.22);
  background: linear-gradient(180deg, rgba(89, 167, 255, 0.09), rgba(255, 255, 255, 0.025));
}
.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.24);
  font-weight: 700;
  font-size: 0.9rem;
}
.player-list li.empty-slot {
  background: transparent;
  border: 1px dashed var(--line);
  color: #5b6a7e;
  font-weight: 600;
  justify-content: center;
}
.player-list .crown {
  color: #ffd85e;
  font-size: 0.85rem;
}
.player-list .you {
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-left: auto;
}

.center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.big-score {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.big-score .dash {
  color: var(--muted);
  font-size: 1.6rem;
}
#room-state {
  font-size: 0.85rem;
  min-height: 1.3em;
}
#start-hint {
  min-height: 1.2em;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  flex: 1;
  min-height: 170px;
}
.chat-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
  min-height: 90px;
  max-height: 24vh;
  font-size: 0.9rem;
}
.chat-log li {
  color: var(--muted);
  word-break: break-word;
}
.chat-log li b {
  color: var(--text);
}
.chat-log li.system {
  color: #6d7c91;
  font-style: italic;
  font-size: 0.82rem;
}
.chat-form {
  display: flex;
  gap: 8px;
}

/* ---------------- IGRA ---------------- */
.screen.game {
  position: fixed;
  inset: 0;
  min-height: 0;
  background: #05080d;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  pointer-events: none;
  z-index: 4;
}
.hud-top {
  top: 0;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(5, 9, 16, 0.72);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.sb-red {
  color: var(--red);
  font-size: 1.2rem;
  min-width: 1.1em;
  text-align: center;
}
.sb-blue {
  color: var(--blue);
  font-size: 1.2rem;
  min-width: 1.1em;
  text-align: center;
}
.sb-clock {
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: 0.04em;
  padding: 0 4px;
  border-left: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
}
.sb-clock.low {
  color: #ffd85e;
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(5, 9, 16, 0.72);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.icon-btn.danger {
  color: var(--red);
}

.goal-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) scale(1);
  z-index: 6;
  font-size: clamp(2.4rem, 9vw, 5rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 0 34px currentColor, 0 8px 30px rgba(0, 0, 0, 0.6);
  animation: goalPop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  pointer-events: none;
  white-space: nowrap;
}
.goal-banner.red {
  color: var(--red);
}
.goal-banner.blue {
  color: var(--blue);
}
@keyframes goalPop {
  0% {
    transform: translateX(-50%) scale(0.5);
    opacity: 0;
  }
  60% {
    transform: translateX(-50%) scale(1.08);
    opacity: 1;
  }
  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

.kickoff-banner {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-weight: 900;
  font-size: clamp(1rem, 3vw, 1.4rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(5, 9, 16, 0.6);
  border: 1px solid var(--line);
  padding: 8px 18px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.joystick {
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
}
.joystick .base {
  position: absolute;
  width: 132px;
  height: 132px;
  left: -66px;
  top: -66px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02) 70%);
  backdrop-filter: blur(2px);
}
.joystick .knob {
  position: absolute;
  width: 58px;
  height: 58px;
  left: -29px;
  top: -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45), inset 0 -3px 6px rgba(0, 0, 0, 0.18);
  will-change: transform;
}

.kick-btn {
  position: absolute;
  right: calc(26px + var(--safe-right));
  bottom: calc(26px + var(--safe-bottom));
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 2px solid rgba(163, 255, 79, 0.55);
  background: radial-gradient(circle at 32% 28%, rgba(163, 255, 79, 0.28), rgba(20, 34, 12, 0.85) 65%);
  color: var(--accent);
  font-family: inherit;
  font-weight: 900;
  font-size: 1.02rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  z-index: 5;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  touch-action: none;
  transition: transform 0.08s ease;
}
.kick-btn:active {
  transform: scale(0.94);
}
.kick-btn .kick-label {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.game-over {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(4, 7, 12, 0.78);
  backdrop-filter: blur(6px);
  padding: 20px;
  text-align: center;
}
.game-over h2 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}
.game-over-score {
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.rotate-hint {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: #05080d;
  color: var(--muted);
  font-weight: 800;
  font-size: 1.05rem;
}
@media (max-width: 960px) and (orientation: portrait) {
  .rotate-hint {
    display: grid;
  }
}

/* ---------------- MODAL / TOAST ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 11, 0.72);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.16s ease both;
}
.modal-card {
  width: min(430px, 100%);
  background: linear-gradient(180deg, #101a27, #0b1219);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-card h2 {
  margin-bottom: 16px;
  font-size: 1.25rem;
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  z-index: 40;
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(16, 24, 34, 0.96);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: min(92vw, 420px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.error {
  border-color: rgba(255, 95, 102, 0.4);
  color: #ffd7d9;
}

/* ---------------- RESPONZIVNO ---------------- */
@media (max-width: 860px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
  .room-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      'red blue'
      'center center';
  }
  .team-red {
    grid-area: red;
  }
  .team-blue {
    grid-area: blue;
  }
  .center-panel {
    grid-area: center;
  }
  .team-panel {
    min-height: 150px;
    padding: 14px;
  }
}

@media (max-width: 560px) {
  .lobby-wrap {
    padding-left: 14px;
    padding-right: 14px;
    gap: 16px;
  }
  .panel {
    padding: 16px;
  }
  .brand {
    gap: 12px;
  }
  .brand-mark {
    padding: 12px 13px;
    border-radius: 16px;
  }
  .room-wrap {
    padding-left: 12px;
    padding-right: 12px;
  }
  .room-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      'center'
      'red'
      'blue';
  }
  .center-panel {
    padding: 16px 12px;
  }
  .big-score {
    font-size: 2rem;
  }
  .kick-btn {
    width: 92px;
    height: 92px;
    right: calc(18px + var(--safe-right));
    bottom: calc(18px + var(--safe-bottom));
  }
  .scoreboard {
    padding: 6px 12px;
    gap: 8px;
  }
}

/* ---------------- TELEFON: KONTROLE VAN TERENA ---------------- */
body.touch-ui .screen.game .joystick {
  width: 124px;
  height: 124px;
  left: calc(18px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  top: auto;
}
body.touch-ui .screen.game .joystick .base {
  left: 0;
  top: 0;
  width: 124px;
  height: 124px;
}
body.touch-ui .screen.game .joystick .knob {
  left: 33px;
  top: 33px;
}
body.touch-ui .screen.game .kick-btn {
  width: 88px;
  height: 88px;
  right: calc(12px + var(--safe-right));
  bottom: calc(18px + var(--safe-bottom));
  font-size: 0.86rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
