:root {
  --yellow: #f9c419;
  --yellow-hover: #ffd93b;
  --red: #e53935;
  --black: #111;
  --white: #fff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background-color: var(--black);
}

body::-webkit-scrollbar {
  display: none;
}

body {
  height: 100%;
  margin: 12px 24px;
  padding: 0;
  font-family: sans-serif;
  background-color: var(--black);
}

/* Layout & Main Screens */
.page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 0 12px;
  box-sizing: border-box;
  height: 100vh;
}

.top-spacer,
.bottom-spacer {
  flex: 1;
}

.logo {
  width: 160px;
  max-width: 50%;
  border-radius: 24px;
  margin-bottom: 30px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Menu Buttons */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
  width: 100%;
}

.styled-menu-button {
  width: 100%;
  max-width: 600px;
  text-align: center;
  padding: 16px;
  font-size: 3.2rem;
  font-weight: bold;
  text-decoration: none;
  color: var(--black);
  background-color: var(--yellow);
  border-radius: 20px;
  border: 3px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, background-color 0.3s ease;
  display: block;
  word-break: break-word;
}

.styled-menu-button:hover {
  transform: scale(1.02);
  background-color: var(--yellow-hover);
}

/* Responsive Font Scaling */
@media (max-width: 425px) {
  .styled-menu-button {
    font-size: 2.4rem;
    padding: 14px;
  }
  body {
    margin: 8px;
  }
}

@media (max-width: 375px) {
  .styled-menu-button {
    font-size: 2.2rem;
    padding: 12px;
  }
}

@media (max-width: 320px) {
  .styled-menu-button {
    font-size: 1.8rem;
    padding: 10px;
  }
}

/* Clock Display & Player Selection */
.clock-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(64px, 9vw, 104px) minmax(0, 1fr);
  align-items: stretch;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  padding: 0 0 max(24px, env(safe-area-inset-bottom));
  gap: 6px;
  box-sizing: border-box;
}

.control-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: clamp(4px, 1.2vh, 10px);
  padding: clamp(6px, 1.6vh, 14px) 4px max(clamp(18px, 4vh, 36px), env(safe-area-inset-bottom));
  margin-bottom: max(clamp(6px, 1.8vh, 12px), env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.clock-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  min-width: 0;
  padding: 0;
}

.clock-wrapper select {
  font-size: 1.5rem;
  padding: 10px 20px;
  border-radius: 10px;
  margin-bottom: 10px;
  background: white;
  color: var(--black);
}

.clock-wrapper select.hidden {
  display: none;
}

.player-name {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--yellow);
  margin-bottom: 10px;
  text-align: center;
}

/* Timer Style */
.clock-side {
  flex: 1;
  background-color: var(--yellow);
  color: var(--black);
  font-size: clamp(4rem, 10vw, 16rem); /* Maximize font */
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 24px;
  margin: 12px;
  padding: 20px;
  border: 6px solid transparent;
  box-sizing: border-box;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.clock-timeout-btn {
  position: absolute;
  inset: 0;
  margin: 16px;
  border-radius: 18px;
  border: none;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: bold;
  z-index: 3;
  cursor: pointer;
}

@media (max-width: 900px), (max-height: 450px) {
  body {
    margin: 6px 10px;
  }

  .clock-container {
    grid-template-columns: minmax(0, 1fr) clamp(58px, 8vw, 88px) minmax(0, 1fr);
    gap: 4px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .clock-side {
    margin: 6px;
    padding: 10px;
    font-size: clamp(2.8rem, 9vw, 10rem);
    border-radius: 18px;
  }

  .icon-button img,
  .bigger-icon-button img {
    width: clamp(24px, 5.4vh, 40px);
  }

  .bigger-icon-button img {
    width: clamp(34px, 8vh, 56px);
  }

  .control-buttons {
    gap: clamp(3px, 1vh, 8px);
    padding: clamp(6px, 1.4vh, 12px) 3px max(clamp(16px, 3.6vh, 30px), env(safe-area-inset-bottom));
    margin-bottom: max(clamp(6px, 1.6vh, 10px), env(safe-area-inset-bottom));
  }

  .player-name {
    font-size: 1.8rem;
    margin-bottom: 6px;
  }

  .clock-wrapper select {
    font-size: 1.1rem;
    padding: 6px 10px;
  }
}

@media (max-height: 430px) {
  .clock-container {
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }

  .control-buttons {
    padding-bottom: max(38px, env(safe-area-inset-bottom));
    margin-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-height: 360px) {
  .clock-container {
    grid-template-columns: minmax(0, 1fr) 54px minmax(0, 1fr);
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .icon-button img,
  .bigger-icon-button img {
    width: clamp(22px, 5vh, 32px);
  }

  .bigger-icon-button img {
    width: clamp(30px, 7.5vh, 44px);
  }

  .control-buttons {
    gap: clamp(2px, 0.9vh, 6px);
    padding: clamp(4px, 1.2vh, 8px) 2px max(clamp(12px, 3vh, 22px), env(safe-area-inset-bottom));
    margin-bottom: max(clamp(6px, 1.4vh, 10px), env(safe-area-inset-bottom));
  }

  .clock-side {
    margin: 4px;
    padding: 8px;
    font-size: clamp(2.2rem, 8vw, 8rem);
  }
}


.clock-side.active {
  border: 6px solid var(--white);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
}

.clock-side.timeout {
  background-color: var(--red);
  color: var(--white);
  border: 6px solid var(--white);
  box-shadow: 0 0 20px rgba(229, 57, 53, 0.7);
}

.clock-text-rotate-cw {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(0deg);
}

.clock-text-rotate-ccw {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.clock-time-text {
  position: relative;
  z-index: 3;
}

.conveyor-indicator {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.conveyor-svg {
  width: 100%;
  height: 100%;
}

.conveyor-track {
  stroke: #111;
  fill: none;
}

.conveyor-elapsed {
  stroke: #fff;
  fill: none;
}

.conveyor-belt-outline {
  stroke: #7d7d7d;
  fill: none;
  opacity: 0.7;
}

.conveyor-belt-lines {
  stroke: #7d7d7d;
  fill: none;
  opacity: 0.85;
}


.conveyor-tire {
  fill: #111;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 2;
}


/* Icon Buttons */
.icon-button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-button img {
  width: 60px;
  height: auto;
  max-width: 100%;
  border-radius: 12px;
}

.icon-button img,
.bigger-icon-button img {
  width: clamp(28px, 6vh, 52px);
  height: auto;
  border-radius: 12px;
}

.bigger-icon-button {
  background: none;
  border: none;
  padding: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
}

.bigger-icon-button img {
  width: clamp(40px, 9vh, 72px);
  height: auto;
  border-radius: 16px;
  transition: transform 0.2s ease;
}

.bigger-icon-button:hover img {
  transform: scale(1.05);
}

.huge-icon-button {
  background: none;
  border: none;
  padding: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
}

.huge-icon-button img {
  width: 240px;
  border: 5px solid var(--black);
  height: auto;
  border-radius: 20px;
  transition: transform 0.2s ease;
}

.huge-icon-button:hover img {
  transform: scale(1.07);
}

/* Orientation Warning */
.orientation-warning {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--black);
  color: var(--white);
  font-size: 1.8rem;
  font-weight: bold;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 20px;
  z-index: 9999;
}

.orientation-warning-landscape {
  position: fixed;
  inset: 0;
  background: var(--black);
  color: var(--white);
  font-size: 1.8rem;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 20px;
  z-index: 9999;
}

.orientation-home img {
  width: 64px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 16px;
}

.settings-panel {
  background: #111;
  color: var(--yellow);
  border-radius: 20px;
  padding: 16px;
  width: min(92vw, 520px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  text-align: center;
  position: relative;
}

.settings-title {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 0 0 12px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.settings-row.orientation-row {
  grid-template-columns: 1fr auto auto;
  align-items: center;
}

.settings-label {
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  text-align: right;
}

.settings-value {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: bold;
  background: var(--yellow);
  color: #111;
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 64px;
  text-align: center;
}

.settings-controls {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
}

.settings-row.orientation-row .settings-controls {
  justify-content: center;
}

.settings-spacer {
  min-width: 64px;
}

.settings-btn {
  background: var(--yellow);
  border: none;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: clamp(1.4rem, 3.6vw, 2rem);
  color: #111;
  font-weight: bold;
  cursor: pointer;
}

.settings-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.settings-close {
  margin-top: 12px;
  background: var(--yellow);
  color: #111;
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  font-size: clamp(1.4rem, 3.6vw, 1.8rem);
  font-weight: bold;
  cursor: pointer;
}

.settings-close-icon {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--yellow);
  font-size: clamp(1.8rem, 4vw, 2.2rem);
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}

.winner-close {
  position: absolute;
  top: 12px;
  right: 16px;
}

.orientation-selected {
  outline: 3px solid #fff;
}

.settings-orient {
  min-width: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.settings-orient.vertical {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  min-height: 58px;
}

body.portrait .orientation-warning {
  display: flex;
}

.rotate-icon {
  width: 100px;
  max-width: 40%;
  border-radius: 20px;
  margin-bottom: 20px;
}

.rotate-text {
  max-width: 90%;
  line-height: 1.4;
}


/* === Standings Page Styling === */
ul {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 0;
  margin: 2rem auto;
  flex-wrap: wrap;
}

ul li a {
  background-color: var(--black);
  color: var(--yellow);
  font-size: 2.5rem;
  padding: 1.2rem 2.4rem;
  border-radius: 20px;
  text-decoration: none;
  font-weight: bold;
  box-shadow: 0 6px 12px rgba(0,0,0,0.25);
  transition: background-color 0.3s ease;
}

ul li a:hover {
  background-color: #222;
}

section {
  background: var(--white);
  border-radius: 24px;
  padding: 2rem;
  margin-bottom: 3rem;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
}

section h2 {
  font-size: 3rem;
  color: var(--black);
  margin-bottom: 1.5rem;
  text-align: center;
}

section p {
  font-size: 2rem;
  color: var(--black);
  text-align: center;
  line-height: 1.4;
}

/* Responsive tweak for small screens */
@media (max-width: 480px) {
  ul li a {
    font-size: 1.8rem;
    padding: 1rem 1.6rem;
  }

  section h2 {
    font-size: 2.4rem;
  }

  section p {
    font-size: 1.6rem;
  }
}

.standings-table {
  width: 100%;
  max-width: 600px;
  margin: 2rem auto;
  border-collapse: collapse;
  font-size: 2rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  background: white;
  border-radius: 20px;
  overflow: hidden;
}

.standings-table thead {
  background: var(--yellow);
  color: var(--black);
  font-weight: bold;
}

.standings-table th, .standings-table td {
  padding: 1rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid #ddd;
}

.standings-table tr:last-child td {
  border-bottom: none;
}

.standings-table tbody tr:nth-child(even) {
  background-color: #fdf4bc;
}

.standings-table tbody tr:hover {
  background-color: var(--yellow-hover);
}

.match-history-table {
  max-width: 680px;
}

.match-history-table tbody tr:nth-child(even) {
  background-color: #ffffff;
}

.match-history-table tbody tr:hover {
  background-color: #f5f5f5;
}

.match-history-table .match-row-win td {
  background-color: #e3f4ea;
}

.match-history-table .match-row-draw td {
  background-color: #fff3d6;
}

.match-history-table .match-row-loss td {
  background-color: #fbe3e3;
}

.result-options {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  z-index: 10000;
  font-size: 2rem;
  color: white;
}
.result-options.hidden {
  display: none;
}
.result-options button {
  font-size: 2rem;
  padding: 1rem 2rem;
  background: var(--yellow);
  border: none;
  border-radius: 12px;
  color: var(--black);
  font-weight: bold;
  cursor: pointer;
}


@keyframes swapPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); background-color: rgba(255,255,255,0.1); }
  100% { transform: scale(1); }
}

.swap-animate {
  animation: swapPulse 0.4s ease-in-out;
}

/* Fade animation */
.fade-out {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.animated-msg {
  font-size: 3.5rem;
  font-weight: bold;
  text-align: center;
  opacity: 0;
  transform: translateY(-20px);
  animation: fadeInSlideDown 1s ease forwards;
  margin-top: 2rem;
}

.stats-bar {
  display: flex;
  width: 100%;
  max-width: 520px;
  height: 14px;
  margin: 12px auto;
  border-radius: 999px;
  overflow: hidden;
  background: #2b2b2b;
}

.stats-bar-win {
  background: #41b36d;
}

.stats-bar-draw {
  background: #e6c24a;
}

.stats-bar-loss {
  background: #d65656;
}

.stats-load-more {
  margin-top: 12px;
  background: var(--yellow);
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 1.6rem;
  font-weight: bold;
  color: #111;
  cursor: pointer;
}

@keyframes fadeInSlideDown {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
