*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; --tile: 86px; }

body {
  margin: 0;
  min-height: 100vh;
  background: #2a2a2a;
  color: #f3f3f3;
  font-family: "Segoe UI", Arial, sans-serif;
}

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: #8ecbff; }

#app { min-height: 100vh; }

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page:has(.game) {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.loading { padding: 48px 20px; text-align: center; color: #bbb; }

.top {
  flex: 0 0 auto;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: #000;
  border-bottom: 1px solid #1c1c1c;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.mark { width: 34px; height: 34px; display: block; }

.wordmark {
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 28px;
  letter-spacing: 0.5px;
  color: #fff;
  line-height: 1;
}

.wordmark span { color: #ff7f7f; }

.spacer { flex: 1; }

.conn { color: #ffd43b; font-size: 13px; }

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 2px;
  font-weight: 700;
  border: 1px solid #444;
  padding: 6px 10px;
  border-radius: 6px;
}

.ghost {
  background: transparent;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 6px 10px;
}

.ghost:hover { border-color: #aaa; }

.ghost.tiny { padding: 4px 8px; font-size: 13px; }

.primary {
  background: #3d8bfd;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 800;
  width: 100%;
}

.primary:hover { filter: brightness(1.06); }

.primary:disabled { opacity: 0.55; cursor: default; }

.primary.slim { width: auto; padding: 8px 12px; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.card:focus-visible,
.row:focus-visible {
  outline: 2px solid #7fbfff;
  outline-offset: 2px;
}

.home {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 460px);
  gap: 28px;
  padding: 28px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

.board {
  background: #141414;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.panel {
  background: #1b1b1b;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 16px 16px 18px;
}

h1 { margin: 0.15em 0 0.35em; font-size: 32px; line-height: 1.1; }

h2 { margin: 18px 0 8px; font-size: 16px; }

.blurb { color: #cfcfcf; line-height: 1.45; margin: 0 0 8px; }

.kicker {
  margin: 0;
  color: #9a9a9a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fine { color: #aaa; font-size: 13px; line-height: 1.4; }

.center { text-align: center; }

.field-label {
  display: block;
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: #ddd;
}

input[type="text"],
input:not([type]),
input[type="color"],
textarea,
select,
#invite-url,
#name,
#title,
#join-name,
#room-title {
  background: #111;
  color: #fff;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 8px 10px;
}

#name, #title, #join-name, #room-title, #template, #card-lines, #invite-url {
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 160px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.mode,
.source {
  text-align: left;
  border: 2px solid #333;
  background: #141414;
  border-radius: 8px;
  padding: 10px;
  color: #fff;
}

.mode strong,
.source strong { display: block; }

.mode span,
.source span { display: block; margin-top: 4px; color: #bbb; font-size: 13px; font-weight: 400; }

.mode.selected,
.source.selected { border-color: #7fbfff; background: #1a2430; }

.custom-builder:not([hidden]) { display: grid; gap: 8px; margin-top: 12px; }

.custom-list { display: flex; flex-direction: column; gap: 8px; }

.custom-card {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-card img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: #fff;
  border-radius: 2px;
}

.custom-card span { flex: 1; font-weight: 700; }

.create-panel .primary { margin-top: 14px; }

.steps { margin: 14px 0 0; padding-left: 18px; color: #ccc; }

.steps li { margin: 4px 0; }

.tiers {
  border: 2px solid #000;
  background: #111;
}

.row {
  display: flex;
  border-bottom: 2px solid #000;
  min-height: calc(var(--tile) + 2px);
  background: #1a1a1a;
}

.row:last-child { border-bottom: none; min-height: var(--tile); }

.tier-label {
  width: var(--tile);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 28px;
  letter-spacing: 0.5px;
  line-height: 1;
  padding: 4px;
  overflow: hidden;
}

.slots {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  align-content: flex-start;
  flex: 1;
  min-height: 52px;
}

.row > .slots {
  padding: 0;
  min-height: 0;
}

.row.over .slots {
  background: rgba(255, 255, 255, 0.06);
  outline: 2px dashed rgba(255, 255, 255, 0.5);
  outline-offset: -4px;
}

.card {
  position: relative;
  width: var(--tile);
  height: var(--tile);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  user-select: none;
  border: 1px solid rgba(0, 0, 0, 0.7);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  overflow: hidden;
  padding: 0;
}

.card .logo {
  position: absolute;
  left: 4px;
  top: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.card.photo .logo {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card[draggable="true"] { cursor: grab; }

.card.dragging { opacity: 0.4; }

.card.selected {
  outline: 3px solid #fff;
  outline-offset: 1px;
  z-index: 1;
}

.emoji {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  pointer-events: none;
  line-height: 1;
}

.cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  display: block;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  padding: 2px 2px 3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
}

.card:hover .cap { opacity: 1; }

.pool { border-top: 2px solid #000; background: #101010; }

.showcase .pool { max-height: 168px; overflow: auto; }

.seat .tiers { flex: 1 1 auto; min-height: 0; overflow: auto; }

.seat .pool { flex: 0 0 auto; max-height: 120px; overflow: auto; }

.pool-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9a9a9a;
  padding: 6px 8px 0;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 480px);
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.pill {
  display: inline-block;
  margin: 0;
  background: #111;
  border: 1px solid #444;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 800;
}

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

.seat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.player-slot {
  min-height: 140px;
  border-radius: 10px;
  background: #161616;
  border: 2px dashed #3a3a3a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  text-align: center;
}

.player-slot.filled { border-style: solid; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: 0 0 auto;
}

.avatar.lg { width: 44px; height: 44px; font-size: 18px; }

.tier-head, .row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-actions { margin-top: 14px; }

.row-actions .primary { width: auto; flex: 1; }

.tier-edit {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.tier-edit .tier-name { flex: 1; }

.tier-color {
  width: 42px;
  height: 36px;
  padding: 2px;
  background: #111;
}

.mini-tier {
  display: inline-flex;
  min-width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  margin: 0 6px 6px 0;
  font-family: Impact, "Arial Black", sans-serif;
  border-radius: 4px;
  padding: 0 8px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; max-height: 220px; overflow: auto; }

.muted { color: #999; }

.warn { color: #ffb4b4; min-height: 1.2em; }

.join-panel { width: min(440px, calc(100% - 32px)); margin: 48px auto; }

.join-panel .primary { margin-top: 18px; }

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px 12px;
  gap: 8px;
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px 12px;
  flex-wrap: wrap;
}

.status strong { font-size: 16px; }

.hint { color: #9ecbff; font-size: 13px; min-height: 1.1em; }

.status-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.order { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

.chip {
  border-radius: 999px;
  padding: 3px 8px;
  background: #111;
  border: 2px solid transparent;
  font-size: 13px;
  font-weight: 800;
}

.chip.on { border-color: #fff; }

.arrow { color: #777; }

.latest { color: #aaa; font-size: 13px; max-width: 460px; text-align: right; }

.stage-row {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: 10px;
}

.stage-row.solo { grid-template-columns: minmax(0, 1fr); }

.rail {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mini-seat {
  flex: 0 0 auto;
  text-align: left;
  background: #121212;
  border: 2px solid #2c2c2c;
  border-radius: 8px;
  padding: 0;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
}

.mini-seat.turn,
.mini-seat:hover,
.mini-seat:focus-visible { border-color: var(--seat-color); }

.mini-seat .seat-head { position: static; padding: 4px 6px; }

.mini-seat .pname { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mini-seat .tiers { max-height: 148px; overflow: auto; }

.mini-seat { --tile: 16px; }

.mini-seat .tier-label { font-size: 9px; padding: 1px; }

.mini-seat .logo {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.mini-seat .cap { display: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45);
  padding: 0;
}

.swatch.on { outline: 2px solid #fff; outline-offset: 2px; }

.swatch:disabled { opacity: 0.28; cursor: default; }

.seat {
  --tile: 72px;
  min-height: 0;
  overflow: hidden;
  background: #121212;
  border-radius: 8px;
  border: 2px solid var(--seat-color, #2c2c2c);
  display: flex;
  flex-direction: column;
}

.seat.active {
  box-shadow: 0 0 0 1px var(--seat-color);
}

.seat-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0e0e0e;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid #222;
}

.pname { font-weight: 800; }

.count { color: #aaa; font-size: 12px; margin-left: auto; }

.badge {
  background: #fff;
  color: #111;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 6px;
}

.seat .tier-label { font-size: 26px; }

.supply .card,
.chips .card { width: 52px; height: 52px; }

.seat .emoji { font-size: 30px; }

.supply .emoji,
.chips .emoji { font-size: 20px; }

.seat .cap { font-size: 11px; }

.supply .cap,
.chips .cap { font-size: 8px; }

.seat .pool { max-height: 176px; }

.seat.empty {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-copy { padding: 16px; color: #aaa; }

.supply {
  background: #121212;
  border: 2px solid #2c2c2c;
  border-radius: 8px;
  padding: 8px;
  max-height: 132px;
  overflow: auto;
}

.supply.hot { border-color: #fff; }

.supply-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #bbb;
  margin-bottom: 6px;
}

#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #111;
  color: #fff;
  border: 1px solid #444;
  padding: 10px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 20;
  max-width: min(90vw, 440px);
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.seat::-webkit-scrollbar,
.supply::-webkit-scrollbar,
.pool::-webkit-scrollbar,
.tiers::-webkit-scrollbar { width: 8px; height: 8px; }

.seat::-webkit-scrollbar-thumb,
.supply::-webkit-scrollbar-thumb,
.pool::-webkit-scrollbar-thumb,
.tiers::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

@media (max-width: 900px) {
  .home, .lobby-grid { grid-template-columns: 1fr; padding: 16px; }
  .wordmark { font-size: 22px; }
}

@media (max-width: 680px) {
  .stage-row { grid-template-columns: 1fr; }
  .rail { flex-direction: row; overflow-x: auto; max-height: 190px; }
  .mini-seat { min-width: 200px; }
}

@media (max-width: 720px) {
  .modes { grid-template-columns: 1fr; }
  .seat { --tile: 64px; }
  .supply .card { width: 44px; height: 44px; }
  .top { gap: 6px; padding: 0 8px; }
  .code { letter-spacing: 1px; padding: 4px 6px; }
}

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