@font-face {
  font-family: "Fredoka";
  src: url("assets/fonts/Fredoka.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b5e20;
}

body {
  /* Everything scales with the window */
  font-size: max(12px, min(2.6vh, 1.5vw));
  font-family: "Fredoka", "Comic Sans MS", "Trebuchet MS", sans-serif;
  color: white;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #1b5e20;
}

/* The canvas fills the window without distortion (letterboxed) */
#field {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
}

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 0.7em;
  padding: 0.4em 1em;
  background: #ffca28;
  color: #263238;
}

button:focus-visible {
  outline: 0.2em solid white;
}

.hud-button {
  position: absolute;
  top: 0.6em;
  right: 0.8em;
  width: 2.6em;
  height: 2.6em;
  padding: 0;
  font-size: 1.2em;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: white;
  border: 0.12em solid rgba(255, 255, 255, 0.6);
}

#fullscreenButton {
  right: 4.2em;
  z-index: 5;
}

#fullscreenButton svg {
  width: 55%;
  height: 55%;
  fill: none;
  stroke: white;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fullscreenButton .icon-exit,
#fullscreenButton.active .icon-enter {
  display: none;
}

#fullscreenButton.active .icon-exit {
  display: inline;
}

/* --- Overlays --- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  background: rgba(10, 25, 20, 0.72);
  overflow: hidden;
}

.panel {
  width: min(44em, 94vw);
  max-height: 96vh;
  overflow-y: auto;
  padding: 0.8em 1.4em 1.2em;
  border-radius: 1.4em;
  background: rgba(38, 50, 56, 0.95);
  box-shadow: 0 0.6em 2em rgba(0, 0, 0, 0.5);
}

.panel h2 {
  margin: 0.2em 0 0.6em;
}

/* --- Logo --- */
.logo {
  height: 5.5em;
  max-width: 100%;
  overflow: visible;
  margin-bottom: 0.4em;
}

.compact .logo {
  display: none;
}

.logo-letters {
  font-family: "Arial Black", Impact, sans-serif;
  font-weight: 900;
  stroke: #1b2a30;
  stroke-width: 10px;
  stroke-linejoin: round;
  paint-order: stroke;
}

.spinning-ball {
  animation: spin 6s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* --- Main menu --- */
.big-button {
  font-size: 1.5em;
  padding: 0.45em 1.6em;
  margin-bottom: 0.5em;
}

.mode-buttons {
  display: flex;
  gap: 0.7em;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0.4em 0 0.8em;
}

.mode-button {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  width: 12.5em;
  padding: 0.7em 0.6em;
  background: #43a047;
  color: white;
  border: 0.15em solid rgba(255, 255, 255, 0.3);
}

.mode-button:hover {
  background: #4caf50;
}

.mode-title {
  font-size: 1.3em;
}

.mode-hint {
  font-size: 0.8em;
  font-weight: 400;
  opacity: 0.9;
}

.menu-row {
  display: flex;
  gap: 0.6em;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0.5em 0;
}

.secondary-button {
  background: #546e7a;
  color: white;
}

.toggle {
  background: #546e7a;
  color: white;
  opacity: 0.6;
}

.toggle.on {
  opacity: 1;
}

.stats {
  margin: 0.6em 0 0;
  opacity: 0.75;
  font-size: 0.9em;
}

/* --- Settings --- */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8em;
  margin-bottom: 0.8em;
  text-align: left;
}

.setting {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0.8em;
  padding: 0.6em;
}

.setting.wide {
  grid-column: 1 / -1;
}

.setting-label {
  font-weight: 600;
  margin: 0.2em 0 0.4em;
}

.option {
  background: #607d8b;
  color: white;
  margin: 0.15em;
  padding: 0.3em 0.7em;
}

.option.chosen {
  background: #ffeb3b;
  color: #263238;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
  margin-bottom: 0.4em;
}

.swatch {
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  border-radius: 50%;
  border: 0.15em solid #263238;
}

.swatch.chosen {
  outline: 0.2em solid #ffeb3b;
  transform: scale(1.15);
}

.team-name {
  width: 100%;
  font: inherit;
  padding: 0.25em 0.5em;
  border-radius: 0.5em;
  border: none;
}

.pads {
  font-size: 0.85em;
  margin-bottom: 0.5em;
  opacity: 0.85;
  overflow-wrap: anywhere;
}

/* --- Locker --- */
.tiles {
  display: flex;
  gap: 0.6em;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.8em;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  width: 7.5em;
  padding: 0.4em;
  background: #455a64;
  color: white;
  font-size: 0.85em;
  border: 0.15em solid transparent;
}

.tile.chosen {
  border-color: #ffeb3b;
}

.tile.locked {
  cursor: default;
  opacity: 0.55;
}

.preview {
  width: 4.5em;
  height: 4.5em;
}

/* --- Online --- */
.online-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8em;
  margin-bottom: 0.8em;
}

.online-choices .setting {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

.online-choices .big-button {
  margin: 0;
}

.room-input {
  width: 7em;
  font: inherit;
  font-size: 1.6em;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
  padding: 0.15em 0.3em;
  border-radius: 0.4em;
  border: none;
}

.room-code {
  font-size: 3em;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: #ffeb3b;
  margin: 0.1em 0 0.3em;
}

.invite-link {
  width: 22em;
  max-width: 60vw;
  font: inherit;
  font-size: 0.85em;
  padding: 0.35em 0.5em;
  border-radius: 0.5em;
  border: none;
}

.online-status {
  font-size: 1.15em;
}

.online-status.error {
  color: #ffab91;
}

.online-hint {
  font-size: 0.85em;
  opacity: 0.8;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* --- Ranking --- */
.profile {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0.8em;
  padding: 0.5em 0.8em;
  margin-bottom: 0.6em;
}

.muted {
  opacity: 0.75;
}

.link-button {
  background: none;
  color: #ffeb3b;
  padding: 0.1em 0.4em;
}

.nickname-input {
  width: 12em;
  font: inherit;
  padding: 0.3em 0.6em;
  border-radius: 0.5em;
  border: none;
}

.table-wrap {
  max-height: 45vh;
  overflow-y: auto;
}

.leaderboard {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard th,
.leaderboard td {
  padding: 0.25em 0.5em;
}

.leaderboard th {
  position: sticky;
  top: 0;
  background: #37474f;
}

.leaderboard tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.04);
}

.leaderboard .name {
  text-align: left;
}

.leaderboard tr.me td {
  background: rgba(255, 235, 59, 0.25);
  font-weight: 700;
}

#ratingLine {
  font-size: 1.15em;
  margin-top: 0.3em;
}

/* --- Help --- */
.help {
  text-align: left;
  line-height: 1.5;
  padding-left: 1.2em;
}

/* --- Results --- */
#results h2 {
  margin: 0;
  font-size: 2.4em;
  color: #ffeb3b;
  text-shadow: 0 0.08em 0 #1b2a30, 0 0 0.5em rgba(255, 235, 59, 0.6);
  animation: pulse 1s ease-in-out infinite;
}

.final-score {
  display: flex;
  align-items: center;
  gap: 1.5em;
  margin: 1.2em 0 0.6em;
}

.score-box {
  position: relative;
  min-width: 10em;
  padding: 0.5em 1.4em 0.7em;
  border-radius: 1.2em;
  border: 0.3em solid white;
  box-shadow: 0 0.4em 0 rgba(0, 0, 0, 0.4);
  text-shadow: -2px -2px 0 #1b2a30, 2px -2px 0 #1b2a30, -2px 2px 0 #1b2a30, 2px 2px 0 #1b2a30;
}

.score-goals {
  font-size: 5em;
  font-weight: 700;
  line-height: 1;
}

.score-name {
  font-size: 1.3em;
  font-weight: 600;
}

.score-dash {
  font-size: 4em;
  font-weight: 700;
}

.crown {
  position: absolute;
  top: -1.1em;
  left: 50%;
  transform: translateX(-50%) rotate(-10deg);
  font-size: 2.4em;
  text-shadow: none;
  visibility: hidden;
}

.score-box.winner {
  animation: bigPulse 0.8s ease-in-out infinite;
  box-shadow: 0 0.4em 0 rgba(0, 0, 0, 0.4), 0 0 2em 0.5em rgba(255, 235, 59, 0.7);
}

.score-box.winner .crown {
  visibility: visible;
}

.score-box.loser {
  transform: scale(0.85);
  filter: saturate(0.6) brightness(0.8);
}

#resultExtra {
  font-size: 1.2em;
  min-height: 1.2em;
  color: #fff59d;
}

.result-buttons {
  display: flex;
  gap: 0.8em;
  align-items: center;
}

.result-buttons .big-button {
  margin: 0;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

@keyframes bigPulse {
  0%, 100% { transform: scale(1.08); }
  50%      { transform: scale(1.16); }
}

#confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -5%;
  width: 0.6em;
  height: 1em;
  border-radius: 0.15em;
  animation: fall linear infinite;
}

@keyframes fall {
  from { transform: translateY(0) rotate(0deg); }
  to   { transform: translateY(110vh) rotate(720deg); }
}

/* --- Phones held upright: ask to rotate --- */
#rotateHint {
  display: none;
  font-size: 1.6em;
  padding: 1em;
  z-index: 10;
}

@media (orientation: portrait) and (max-width: 900px) {
  #rotateHint {
    display: flex;
  }
}

@media (max-width: 700px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
