:root {
  --ink: #2b2d42;
  --muted: #6b6f88;
  --card: rgba(255, 255, 255, 0.92);
  --accent: #ff7a59;
  --accent-dark: #e05a3a;
  --ok: #35c46a;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #ffe3c2;
  -webkit-user-select: none;
  user-select: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 10px 0 rgba(43, 45, 66, 0.12), 0 20px 40px rgba(43, 45, 66, 0.12);
  padding: 22px 26px;
  backdrop-filter: blur(4px);
}

h1, h2 { margin: 0 0 10px; }
h2 { font-size: 1.25rem; }

.logo {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.logo span {
  color: var(--accent);
  font-size: 1.2rem;
  vertical-align: middle;
  background: #fff1ea;
  padding: 2px 8px;
  border-radius: 8px;
}

.join { width: min(440px, 100%); display: flex; flex-direction: column; gap: 8px; }
.join label, .my-color label { font-weight: 700; font-size: 0.9rem; margin-top: 6px; }

input#join-name {
  font: inherit;
  font-size: 1.15rem;
  padding: 10px 14px;
  border-radius: 12px;
  border: 3px solid #e4e1f0;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
input#join-name:focus { border-color: var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.1s;
}
.swatches.small .swatch { width: 30px; height: 30px; border-radius: 9px; }
.swatch:hover:not(:disabled) { transform: translateY(-2px); }
.swatch.selected { border-color: var(--ink); transform: scale(1.08); }
.swatch:disabled { opacity: 0.25; cursor: not-allowed; }
.swatch:disabled::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
}

.btn {
  font: inherit;
  font-weight: 800;
  border: none;
  border-radius: 14px;
  padding: 10px 18px;
  background: #ece9f6;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(43, 45, 66, 0.18);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(43, 45, 66, 0.18); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }
.btn.big { font-size: 1.15rem; padding: 12px 22px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.error { color: #d63031; font-weight: 700; margin: 4px 0; }
.welcome { color: #249a50; font-weight: 700; margin: 4px 0; }

kbd {
  display: inline-block;
  font: 700 0.75rem system-ui, sans-serif;
  background: #f3f1fa;
  border: 1px solid #d9d5ea;
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 1px 6px;
  margin: 0 1px;
}
.controls-mini {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Lobby */
.lobby {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(300px, 640px);
  gap: 16px;
  width: min(980px, 100%);
  max-height: 100%;
}
@media (max-width: 760px) {
  .lobby { grid-template-columns: 1fr; }
}
.pill {
  background: #ece9f6;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
  vertical-align: middle;
}
.player-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #f7f5fc;
  font-weight: 700;
}
.player-list li.me { outline: 3px solid #ffd2c4; }
.player-list li.offline { opacity: 0.45; }
.player-dot {
  width: 26px;
  height: 26px;
  border-radius: 9px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  flex: none;
}
.player-list .tag { margin-left: auto; font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.player-list .empty { background: transparent; border: 2px dashed #e0dcef; color: #b4b0c8; font-weight: 600; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 4px;
}
.level-tile {
  font: inherit;
  text-align: left;
  border: 3px solid transparent;
  border-radius: 14px;
  background: #f7f5fc;
  padding: 8px 10px;
  cursor: pointer;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(43, 45, 66, 0.1);
}
.level-tile .num { font-weight: 900; font-size: 1.1rem; }
.level-tile .name { font-weight: 700; font-size: 0.8rem; line-height: 1.15; }
.level-tile .best { font-size: 0.72rem; color: #249a50; font-weight: 700; margin-top: auto; }
.level-tile.locked { opacity: 0.45; cursor: not-allowed; }
.level-tile.selected { border-color: var(--accent); background: #fff1ea; }
.level-tile.readonly { cursor: default; }
.lobby-footer { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.selected-info { flex: 1; font-weight: 700; min-width: 160px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-left, .hud-right, .hud-center {
  position: absolute;
  top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.hud-left { left: 10px; }
.hud-right { right: 10px; }
.hud-center { left: 50%; transform: translateX(-50%); }
.hud-bottom { position: absolute; left: 12px; bottom: 8px; opacity: 0.7; }
.hud-chip {
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  padding: 6px 12px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(43, 45, 66, 0.12);
  font-variant-numeric: tabular-nums;
}
.hud-chip.vote { background: #fff3c4; }
.hud-chip.hostnote { font-size: 0.78rem; font-weight: 700; opacity: 0.85; }
.btn-icon { border: none; font: inherit; font-weight: 800; cursor: pointer; pointer-events: auto; }

#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 22%;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.banner-inner {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 22px;
  padding: 16px 34px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(43, 45, 66, 0.12);
  animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
  max-width: min(640px, 92vw);
}
.banner-num { font-weight: 800; color: var(--accent); letter-spacing: 0.1em; }
.banner-name { font-size: 2.2rem; font-weight: 900; }
.banner-hint { color: var(--muted); margin-top: 6px; }

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(43, 45, 66, 0.18);
}
.clear-card { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); min-width: min(360px, 92vw); }
.clear-title {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-shadow: 0 4px 0 #ffd2c4;
}
.clear-time { font-size: 1.8rem; font-weight: 900; margin: 6px 0; font-variant-numeric: tabular-nums; }
.record { font-weight: 900; color: #c78a00; margin-top: 6px; animation: pop 0.6s; }
.clear-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.menu-card { display: flex; flex-direction: column; gap: 10px; min-width: min(360px, 92vw); }

#toasts {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 50;
}
.toast {
  background: rgba(43, 45, 66, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 12px;
  font-weight: 700;
  animation: toast-in 0.25s ease-out;
  max-width: 90vw;
  text-align: center;
}
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
