:root {
  --bg: #161b24;
  --panel: rgba(22, 27, 36, 0.92);
  --border: rgba(255, 255, 255, 0.1);
  --text: #e8ecf3;
  --muted: #9aa5b8;
  --accent: #ffb347;
  --accent-ink: #1a1206;
  --error: #ff6b6b;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  color: var(--text);
  background: var(--bg);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
}
button {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
button.primary:hover:not(:disabled) {
  background: #ffc46e;
}
.hidden {
  display: none !important;
}

/* ---------------- home */
body.home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 30% 20%, #23304a, var(--bg) 60%);
}
.home-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.home-card h1 {
  margin: 0 0 4px;
  font-size: 28px;
}
.sub {
  margin: 0 0 20px;
  color: var(--muted);
}
.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  height: 220px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  color: var(--muted);
}
.dropzone.over {
  border-color: var(--accent);
}
.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.dropzone img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  pointer-events: none;
}
.dropzone.has-image img {
  display: block;
}
.dropzone.has-image .hint {
  display: none;
}
fieldset {
  border: none;
  padding: 0;
  margin: 18px 0;
}
legend {
  color: var(--muted);
  margin-bottom: 8px;
}
.counts {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  /* up to ~45 choices: scroll inside the box instead of making the page long */
  max-height: 212px;
  overflow-y: auto;
  padding-right: 4px;
}
.counts.empty {
  display: none;
}
.grid-info {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted, #9aa4b2);
}
@media (max-width: 480px) {
  .counts {
    grid-template-columns: repeat(4, 1fr);
  }
}
.count input {
  display: none;
}
.count span {
  display: block;
  text-align: center;
  padding: 8px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.count input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
#create-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  border: none;
}
.status {
  min-height: 1.4em;
  color: var(--muted);
  margin: 12px 0 0;
}
.status.error,
.error {
  color: var(--error);
}

/* ---------------- room */
body.room {
  overflow: hidden;
  height: 100vh;
  /* the "table" around the felt board */
  background: radial-gradient(circle at 50% 40%, #2c3a4c, #161c26 75%);
}
#board {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: grab;
}
#board.grabbing {
  cursor: grabbing;
}
.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 252px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-wrap: wrap;
}
.logo {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}
.progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 140px;
}
.bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}
.fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #ffb347, #ffd166);
  transition: width 0.3s;
}
#progress-text {
  font-variant-numeric: tabular-nums;
  min-width: 3em;
  text-align: right;
}
.tools {
  display: flex;
  gap: 6px;
}
.panel {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 228px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.panel h2 {
  font-size: 15px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0 8px;
  font-size: 12px;
}
#players {
  list-style: none;
  padding: 0;
  margin: 0;
}
#players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
#players .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#players .me {
  margin-left: auto;
  font-size: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 700;
}
.latency {
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 0;
}
.preview {
  position: fixed;
  left: 12px;
  bottom: 12px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.preview img {
  display: block;
  /* big enough to actually use as a reference: up to ~45% of the screen width / 55% of the height */
  max-width: min(45vw, 720px);
  max-height: 55vh;
  width: auto;
  height: auto;
  border-radius: 6px;
}
@media (max-width: 700px) {
  .preview img {
    max-width: calc(100vw - 40px);
    max-height: 40vh;
  }
}
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, 0.6);
  padding: 16px;
  z-index: 10;
}
.modal-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-card.center {
  text-align: center;
  align-items: center;
}
.modal-card h1 {
  margin: 0;
  font-size: 22px;
}
.modal-card p {
  margin: 0;
  color: var(--muted);
}
.modal-card .error {
  color: var(--error);
  min-height: 1.2em;
}
#nick {
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
}
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
.notice {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 30;
}
.notice.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 720px) {
  .topbar {
    right: 12px;
  }
  .panel {
    top: auto;
    bottom: 12px;
    width: 180px;
    max-height: 30vh;
  }
  .tools button {
    padding: 6px 8px;
  }
}
