:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #172233;
  --deep: #155e75;
  --reef: #ed5f8c;
  --gold: #f7b94a;
  --foam: #f4fbff;
  --line: rgba(23, 34, 51, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: auto;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.88) 0 42px, transparent 43px),
    radial-gradient(circle at 84% 18%, rgba(255, 255, 255, 0.62) 0 56px, transparent 57px),
    linear-gradient(180deg, #dffaff 0%, #7bd9e8 46%, #1d6d89 100%);
  color: var(--ink);
}

.tournament-layout {
  width: min(100vw - 28px, 980px);
  min-height: min(100vh, 920px);
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(320px, 520px);
  align-items: stretch;
  justify-content: center;
  gap: 16px;
  padding: 10px 0;
}

.tournament-panel,
.admin-panel {
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: rgba(247, 253, 255, 0.86);
  box-shadow: 0 24px 70px rgba(13, 67, 88, 0.22);
  backdrop-filter: blur(14px);
}

.tournament-panel {
  align-self: center;
  max-height: calc(100vh - 20px);
  overflow: auto;
  padding: 12px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.panel-section h2,
.admin-panel h2 {
  margin: 0 0 8px;
  color: var(--deep);
  font-size: 18px;
  line-height: 1.1;
}

.panel-copy {
  margin: 0 0 12px;
  color: rgba(23, 34, 51, 0.68);
  font-weight: 700;
}

.stacked-form,
.score-form {
  display: grid;
  gap: 10px;
}

.stacked-form label,
.score-form label {
  display: grid;
  gap: 5px;
  color: rgba(23, 34, 51, 0.78);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.stacked-form input,
.stacked-form select,
.score-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(21, 94, 117, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 9px 11px;
}

.field-hint {
  margin: -2px 0 0;
  color: rgba(23, 34, 51, 0.62);
  font-size: 12px;
  font-weight: 800;
}

.stacked-form button,
.score-form button,
.text-button,
.warning-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--deep);
  color: white;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  background: rgba(21, 94, 117, 0.1);
  color: var(--deep);
}

.player-change-button {
  width: 100%;
  margin-top: 10px;
}

.warning-button {
  background: #b66b0e;
}

.danger-button {
  background: #b8325d;
}

.form-message {
  min-height: 19px;
  margin: 9px 0 0;
  color: #9c2851;
  font-weight: 800;
}

.form-message.is-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--deep);
}

.form-message.is-loading::before {
  width: 14px;
  height: 14px;
  border: 3px solid rgba(21, 94, 117, 0.18);
  border-top-color: var(--deep);
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

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

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-row small {
  display: block;
  color: rgba(23, 34, 51, 0.62);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-row strong {
  color: var(--deep);
  font-size: 22px;
}

.selected-character-name {
  max-width: 128px;
  overflow: hidden;
  color: rgba(23, 34, 51, 0.68);
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.character-preview {
  height: 122px;
  display: grid;
  place-items: center;
  margin-top: 10px;
  border: 1px solid rgba(21, 94, 117, 0.12);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(198, 247, 255, 0.72), rgba(255, 255, 255, 0.58));
  overflow: hidden;
}

.character-preview img {
  width: 156px;
  height: 112px;
  object-fit: contain;
  filter: drop-shadow(0 12px 16px rgba(13, 67, 88, 0.16));
}

.character-option {
  min-width: 0;
  min-height: 112px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  border: 2px solid rgba(21, 94, 117, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  padding: 8px;
  text-align: center;
}

.character-option img {
  width: 70px;
  height: 58px;
  object-fit: contain;
}

.character-option span {
  max-width: 100%;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-option[aria-checked="true"] {
  border-color: var(--character-accent, var(--deep));
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 22px rgba(13, 67, 88, 0.14);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 0;
  padding: 0 10px;
  border-radius: 8px;
  background: rgba(21, 94, 117, 0.12);
  color: var(--deep);
  font-weight: 900;
}

.countdown {
  margin: 10px 0 0;
  color: var(--ink);
  font-size: 30px;
  font-weight: 950;
  line-height: 1;
}

.leaderboard {
  margin: 0;
  padding: 0;
  list-style-position: inside;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 32px 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border-bottom: 1px solid rgba(23, 34, 51, 0.1);
  font-weight: 850;
}

.leaderboard li:last-child {
  border-bottom: 0;
}

.leaderboard .rank {
  color: rgba(23, 34, 51, 0.58);
}

.leaderboard .avatar,
.overlay-standings .overlay-avatar {
  width: 30px;
  height: 30px;
  display: block;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  object-fit: contain;
}

.leaderboard .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .score {
  color: var(--deep);
  font-weight: 950;
}

.game-shell {
  position: relative;
  width: min(100%, 520px);
  height: min(100vh, 920px);
  aspect-ratio: 7 / 12;
  max-height: calc(100vh - 20px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: #78d9e8;
  box-shadow: 0 24px 70px rgba(13, 67, 88, 0.28);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.score-strip {
  display: flex;
  gap: 8px;
}

.score-strip div {
  min-width: 68px;
  padding: 8px 9px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 24px rgba(13, 67, 88, 0.14);
  text-align: center;
}

.score-strip div:first-child {
  min-width: 82px;
  background: rgba(255, 255, 255, 0.92);
}

.score-strip span {
  display: block;
  color: var(--deep);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.score-strip div:first-child span {
  font-size: 30px;
}

.score-strip small {
  display: block;
  margin-top: 3px;
  color: rgba(23, 34, 51, 0.68);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-button {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--deep);
  box-shadow: 0 12px 24px rgba(13, 67, 88, 0.14);
  cursor: pointer;
}

.pause-icon,
.pause-icon::before {
  display: block;
  width: 6px;
  height: 20px;
  border-radius: 4px;
  background: currentColor;
  content: "";
}

.pause-icon {
  position: relative;
  transform: translateX(-5px);
}

.pause-icon::before {
  position: absolute;
  left: 11px;
  top: 0;
}

.sound-icon {
  position: relative;
  width: 24px;
  height: 22px;
  display: block;
}

.sound-icon::before,
.sound-icon::after {
  position: absolute;
  content: "";
}

.sound-icon::before {
  left: 1px;
  top: 2px;
  width: 15px;
  height: 18px;
  background: currentColor;
  clip-path: polygon(0 7px, 6px 7px, 15px 1px, 15px 21px, 6px 15px, 0 15px);
}

.sound-icon::after {
  left: 14px;
  top: 4px;
  width: 8px;
  height: 14px;
  border: 3px solid currentColor;
  border-left: 0;
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 0 16px 16px 0;
}

.sound-button.is-muted .sound-icon::after {
  left: 2px;
  top: 10px;
  width: 23px;
  height: 3px;
  border: 0;
  border-radius: 4px;
  background: currentColor;
  opacity: 1;
  transform: rotate(-42deg);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, rgba(14, 76, 100, 0.12), rgba(14, 76, 100, 0.32));
  transition: opacity 160ms ease, visibility 160ms ease;
}

.overlay.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.author-credit {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 3;
  pointer-events: none;
  color: rgba(244, 253, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: 0 2px 6px rgba(9, 50, 68, 0.34);
}

.menu-panel {
  width: min(340px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 24px 60px rgba(13, 67, 88, 0.22);
  text-align: center;
  backdrop-filter: blur(12px);
}

h1 {
  margin: 0;
  color: var(--deep);
  font-size: clamp(34px, 9vw, 52px);
  line-height: 0.95;
  letter-spacing: 0;
}

.result {
  min-height: 23px;
  margin: 10px 0 18px;
  color: rgba(23, 34, 51, 0.7);
  font-weight: 800;
}

.menu-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.menu-actions button {
  min-width: 112px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--deep);
  color: white;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 22px rgba(21, 94, 117, 0.24);
}

.menu-actions button:disabled,
.stacked-form button:disabled,
.score-form button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.menu-actions button:last-child {
  background: var(--gold);
  color: #422b08;
}

.overlay-standings {
  margin-top: 16px;
  text-align: left;
}

.overlay-standings h2 {
  margin: 0 0 8px;
  color: var(--deep);
  font-size: 16px;
}

.overlay-standings ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.overlay-standings li {
  display: grid;
  grid-template-columns: 34px 32px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 0 9px;
  border-radius: 8px;
  background: rgba(21, 94, 117, 0.09);
  color: rgba(23, 34, 51, 0.82);
  font-weight: 900;
}

.overlay-standings .overlay-rank {
  color: rgba(23, 34, 51, 0.58);
}

.overlay-standings .overlay-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overlay-standings .overlay-score {
  color: var(--deep);
}

button:focus-visible {
  outline: 3px solid rgba(247, 185, 74, 0.86);
  outline-offset: 3px;
}

.admin-body {
  align-items: start;
  overflow: auto;
  padding: 24px 12px;
}

.admin-shell {
  width: min(100%, 560px);
}

.wide-admin-shell {
  width: min(100%, 920px);
}

.admin-panel {
  padding: 22px;
}

.admin-panel h1 {
  margin-bottom: 8px;
}

.admin-actions {
  display: flex;
  gap: 10px;
}

.admin-actions button {
  flex: 1;
}

.score-form {
  grid-template-columns: 1fr 120px 1.2fr auto auto;
  align-items: end;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

.admin-list {
  border-top: 1px solid rgba(23, 34, 51, 0.1);
}

.audit-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.audit-list li {
  padding: 9px;
  border-radius: 8px;
  background: rgba(21, 94, 117, 0.08);
  color: rgba(23, 34, 51, 0.78);
  font-weight: 750;
}

@media (max-width: 460px) {
  body {
    place-items: stretch;
  }

  .tournament-layout {
    width: 100vw;
    min-height: 100vh;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .tournament-panel {
    order: 2;
    max-height: none;
    border-radius: 0;
  }

  .game-shell {
    width: 100vw;
    height: 100vh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .score-strip div {
    min-width: 58px;
    padding: 7px;
  }

  .score-strip span {
    font-size: 21px;
  }
}

@media (max-width: 760px) {
  .score-form,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    flex-direction: column;
  }
}
