/* Shared shell: home, create, lobby and the frame around a game. Each game styles itself in
   games/<name>/<name>.css. */

:root {
  --bg: #1a1024;
  --bg-glow: #2c1640;
  --surface: #251733;
  --surface-2: #32204a;
  --line: #45305f;
  --text: #f7eefc;
  --muted: #b9a5c9;
  --pink: #ff5fb8;
  --pink-dark: #d93f95;
  --error: #ff8a8a;
  --ok: #6ee7a8;
  --warn: #ffcc66;
  --radius: 16px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background: radial-gradient(ellipse at top, var(--bg-glow), var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.5px;
}

h1 {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
}

h2 {
  font-size: 1.4rem;
  margin-bottom: 16px;
}

p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

.screen {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

#screen-game {
  max-width: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}

.center {
  text-align: center;
}

/* home */

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero-donuts {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.hero-donuts img {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  animation: bob 2.4s ease-in-out infinite;
}

.hero-donuts img:last-child {
  animation-delay: -1.2s;
}

@keyframes bob {
  50% {
    transform: translateY(-8px) rotate(8deg);
  }
}

.tagline {
  color: var(--muted);
  margin-top: 8px;
}

.game-list {
  display: grid;
  gap: 10px;
}

.game-row {
  position: relative;
}

.info-btn {
  font: inherit;
  font-weight: 700;
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 0.85rem;
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.info-btn:hover,
.info-btn:focus-visible {
  color: var(--text);
  border-color: var(--pink);
}

.game-row .info-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

.lobby-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.6);
}

.help-window {
  width: min(420px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}

.help-window p {
  margin: 0 0 10px;
  line-height: 1.45;
}

.help-window .help-big {
  font-size: clamp(3rem, 18vw, 5rem);
  font-weight: 700;
  text-align: center;
  color: var(--pink);
  margin: 16px 0 24px;
}

.help-window .btn {
  width: 100%;
}

.game-option {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 4px 14px;
  width: 100%;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.game-option:hover {
  border-color: var(--pink);
}

.game-option:active {
  transform: scale(0.98);
}

.game-option img {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.game-option .name {
  font-size: 1.15rem;
  font-weight: 700;
}

.game-option .meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.name-field {
  margin-bottom: 20px;
}

.name-field label {
  display: block;
  margin-bottom: 6px;
}

.name-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.name-input::placeholder {
  color: var(--line);
}

.name-input:focus {
  outline: none;
  border-color: var(--pink);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.join-row {
  display: flex;
  gap: 8px;
}

.code-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.code-input::placeholder {
  color: var(--line);
}

.code-input:focus {
  outline: none;
  border-color: var(--pink);
}

/* buttons */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.btn:hover {
  background: var(--line);
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible,
.game-option:focus-visible {
  outline: 3px solid var(--pink);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn-primary {
  background: var(--pink);
  border-color: var(--pink);
  color: #2a0a1c;
}

.btn-primary:hover:not(:disabled) {
  background: var(--pink-dark);
  border-color: var(--pink-dark);
}

.btn-ghost {
  background: transparent;
}

.actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.error {
  color: var(--error);
  margin-top: 12px;
}

/* create */

.setting {
  margin-bottom: 16px;
}

.setting label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.setting output {
  font-weight: 700;
  color: var(--pink);
}

.setting label.setting-toggle {
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.setting-toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--pink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--pink);
}

/* lobby */

.big-code {
  font-size: clamp(2.2rem, 11vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.15em;
  margin: 4px 0 20px;
  padding-left: 0.15em; /* balances the trailing letter-spacing */
  color: var(--pink);
  user-select: all; /* one click selects the whole code */
}

.copy-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.players-box {
  margin: 24px 0 12px;
  text-align: left;
}

.players-box h2 {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.lobby-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 500;
}

.badge {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--pink);
}

.you {
  color: var(--muted);
  font-weight: 400;
}

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
}

.dot.reconnecting {
  background: var(--warn);
}

.dot.left {
  background: var(--error);
}

.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  border: 4px solid var(--line);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.spinner.small {
  width: 18px;
  height: 18px;
  border-width: 3px;
  margin: 0;
}

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

/* around a game */

.banner {
  text-align: center;
  max-width: 640px;
  margin: 12px auto 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgb(255 204 102 / 0.12);
  color: var(--warn);
}

/* chat: a small window over the bottom right, so the game stays playable behind it */

.float-btn {
  position: fixed;
  bottom: 16px;
  z-index: 15;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.45);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.float-btn:hover {
  transform: scale(1.06);
}

.float-btn:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 3px;
}

.leave-btn {
  left: 16px;
  background: #e0334f;
}

.leave-btn:hover {
  background: #c22640;
}

.chat-open {
  right: 16px;
  background: var(--pink);
}

.chat-open:hover {
  background: var(--pink-dark);
}

/* Rematch sits between the two corner buttons */
#screen-game .game-actions {
  justify-content: center;
  padding: 0 64px;
}

.btn-danger {
  background: #e0334f;
  border-color: #e0334f;
  color: #fff;
}

.btn-danger:hover {
  background: #c22640;
}

.confirm-window {
  width: min(360px, 100%);
  text-align: center;
}

.confirm-window h2 {
  margin-top: 0;
}

.confirm-window .actions {
  justify-content: center;
}

.chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e0334f;
  border: 2px solid var(--bg);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.75rem;
  line-height: 18px;
}

.chat {
  position: fixed;
  right: 16px;
  bottom: 80px;
  z-index: 15;
  width: min(340px, calc(100vw - 32px));
  height: min(380px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.chat:not([hidden]) {
  display: flex;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.chat-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.chat-head .info-btn {
  font-style: normal;
  font-family: inherit;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.chat-log li {
  padding: 3px 0;
}

.chat-log li.mine b {
  color: var(--pink);
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
}

.turn-timer {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 700;
  font-size: 1.2rem;
}

.turn-timer.low {
  color: var(--error);
}

.game-actions {
  max-width: 640px;
  margin: 20px auto 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 18px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
}

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