:root {
  --bg: #121213;
  --panel: #1a1a1b;
  --text: #f8f8f8;
  --muted: #818384;
  --border: #3a3a3c;
  --key: #818384;
  --empty: #121213;
  --green: #538d4e;
  --yellow: #b59f3b;
  --gray: #3a3a3c;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-strong: rgba(255, 255, 255, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  display: grid;
  place-items: center;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 40vmax;
  height: 40vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.22;
  z-index: -1;
  animation: float-glow 16s ease-in-out infinite;
}

body::before {
  background: var(--green);
  top: -18vmax;
  left: -12vmax;
}

body::after {
  background: var(--yellow);
  bottom: -20vmax;
  right: -12vmax;
  animation-delay: -7s;
}

.app {
  width: min(96vw, 520px);
  padding: 18px;
  display: grid;
  gap: 15px;
  background: linear-gradient(180deg, var(--surface) 0%, transparent 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.08);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.restart-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.restart-btn:hover {
  border-color: var(--muted);
  background: var(--surface-strong);
  transform: translateY(-1px);
}

.message {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  font-weight: 700;
  color: #f3f3f3;
  animation: fade-in 0.28s ease;
}

.player {
  display: flex;
  gap: 10px;
  align-items: end;
}

.player-field {
  display: grid;
  gap: 6px;
  flex: 1;
}

.player-field span {
  font-size: 0.85rem;
  color: #d8d8d8;
}

.player-field input {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.player-field input:focus,
.admin-field input:focus {
  outline: none;
  border-color: var(--muted);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.board {
  width: 100%;
  max-width: 360px;
  margin-inline: auto;
  display: grid;
  gap: 6px;
  position: relative;
}

.board.ui-locked,
.keyboard.ui-locked {
  pointer-events: none;
  opacity: 0.45;
  filter: grayscale(0.2);
}

.board.ui-locked::after {
  content: "Save your name to play";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 10px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(1.15rem, 4.6vw, 1.8rem);
  text-transform: uppercase;
  user-select: none;
  background: var(--empty);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.tile.filled {
  border-color: var(--muted);
}

.tile.active {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
  transform: translateY(-1px);
}

.tile.correct {
  background: var(--green);
  border-color: var(--green);
}

.tile.present {
  background: var(--yellow);
  border-color: var(--yellow);
}

.tile.absent {
  background: var(--gray);
  border-color: var(--gray);
}

.tile.reveal {
  animation: flip-reveal 0.45s ease;
}

.tile.smash {
  animation: smash-in 0.2s cubic-bezier(0.2, 1, 0.3, 1);
}

@keyframes flip-reveal {
  0% {
    transform: rotateX(0deg);
  }
  45% {
    transform: rotateX(90deg);
  }
  55% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

@keyframes smash-in {
  0% {
    transform: translateY(-10px) scale(1.25, 0.72);
    opacity: 0.7;
  }
  55% {
    transform: translateY(2px) scale(0.86, 1.18);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1, 1);
    opacity: 1;
  }
}

.keyboard-wrap {
  margin-top: 8px;
}

.admin {
  margin-top: 6px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: grid;
  gap: 10px;
  background: var(--surface);
  border-radius: 12px;
  padding-inline: 10px;
  padding-bottom: 10px;
}

.admin h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-login,
.admin-controls {
  display: grid;
  gap: 10px;
}

.hidden {
  display: none;
}

.admin-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.admin-field {
  display: grid;
  gap: 6px;
}

.admin-field span {
  font-size: 0.85rem;
  color: #d8d8d8;
}

.admin-field input {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.admin-actions {
  display: flex;
  gap: 8px;
}

.admin-actions button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.admin-actions button:hover {
  border-color: var(--muted);
  background: var(--surface-strong);
  transform: translateY(-1px);
}

.admin-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: #d8d8d8;
}

.admin-checkbox input {
  width: 16px;
  height: 16px;
}

.admin-status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: #d8d8d8;
}

.admin-results {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.admin-judge {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 8px;
}

.admin-judge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.admin-judge-head h3 {
  margin: 0;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-judge-meta {
  margin: 0;
  color: #d8d8d8;
  font-size: 0.84rem;
}

.judge-board {
  display: grid;
  gap: 10px;
}

.judge-empty {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: #d8d8d8;
  background: var(--panel);
}

.judge-player {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: var(--panel);
  animation: fade-in 0.24s ease;
}

.judge-player-header h4 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.06em;
}

.judge-player-header p {
  margin: 4px 0 0;
  color: #d8d8d8;
  font-size: 0.84rem;
}

.judge-rows {
  display: grid;
  gap: 6px;
}

.judge-row {
  display: flex;
  gap: 5px;
  min-height: 30px;
  align-items: center;
}

.judge-row-empty {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 0.08em;
}

.judge-letter {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.92rem;
  text-transform: uppercase;
  background: var(--empty);
  color: var(--text);
}

.judge-letter.correct {
  background: var(--green);
  border-color: var(--green);
}

.judge-letter.present {
  background: var(--yellow);
  border-color: var(--yellow);
}

.judge-letter.absent {
  background: var(--gray);
  border-color: var(--gray);
}

.results-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.results-table th,
.results-table td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 7px 6px;
  white-space: nowrap;
}

.results-table th {
  color: #d8d8d8;
  font-weight: 700;
}

.keyboard {
  display: grid;
  gap: 8px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  border: none;
  border-radius: 6px;
  min-width: 30px;
  height: 52px;
  padding: 0 8px;
  background: var(--key);
  color: white;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.key:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.key.wide {
  min-width: 58px;
  font-size: 0.78rem;
}

.key.correct {
  background: var(--green);
}

.key.present {
  background: var(--yellow);
}

.key.absent {
  background: var(--gray);
}

@keyframes float-glow {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(16px, -12px, 0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 420px) {
  .app {
    padding: 12px;
    gap: 12px;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .player {
    flex-direction: column;
    align-items: stretch;
  }

  .key {
    height: 48px;
    min-width: 28px;
    padding: 0 6px;
  }

  .key.wide {
    min-width: 52px;
  }
}
