:root {
  color-scheme: dark;
  --bg: #161616;
  --panel: #242422;
  --ink: #f6f0df;
  --muted: #b8b1a0;
  --line: #3d3a33;
  --accent: #e1b84b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(225, 184, 75, 0.12), transparent 24rem),
    linear-gradient(135deg, #171715 0%, #20201d 48%, #171a18 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  gap: 14px;
  padding: 18px 0;
}

.shell.in-game {
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar"
    "stage"
    "legend";
  align-content: stretch;
}

.shell.in-game #topbar { grid-area: topbar; }
.shell.in-game #game-stage { grid-area: stage; }
.shell.in-game #legend { grid-area: legend; }

.topbar,
.legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 54px);
  line-height: 0.95;
  letter-spacing: 0;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

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

.session-form {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.session-form input {
  width: 190px;
  height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  outline: none;
}

.session-form input:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.command {
  height: 42px;
  min-width: 42px;
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  transition:
    background 140ms ease,
    transform 140ms ease;
}

.command:hover {
  background: #34322c;
}

.command {
  background: var(--accent);
  color: #1a160f;
  font-weight: 800;
}

.command {
  padding: 0 16px;
}

.command.big {
  height: auto;
  min-height: 64px;
  padding: 18px 36px;
  font-size: 18px;
  min-width: 240px;
}

.main-menu {
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 80px 20px 40px;
  text-align: center;
}

.main-menu-title {
  margin: 0;
  font-size: 60px;
  letter-spacing: -1px;
}

.main-menu-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.online-count {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.solo-start {
  display: flex;
  justify-content: flex-start;
  padding: 4px 0;
}

.command.secondary {
  background: #34322c;
  color: var(--ink);
}

.lobby {
  display: grid;
  gap: 8px;
}

.lobby-create {
  align-self: start;
  width: 100%;
  max-width: 440px;
}

.lobby-create-label {
  flex: 0 0 auto;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.lobby-create input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.lobby-create .command {
  flex: 0 0 auto;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}

.lobby-header strong {
  color: var(--ink);
}

.sessions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile {
  display: grid;
  gap: 10px;
}

.profile-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.profile-header strong {
  color: var(--ink);
}

.profile-header span {
  color: var(--muted);
  font-size: 12px;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-name {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.profile-name > span {
  padding-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.profile-name input {
  height: 38px;
  width: 240px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  outline: none;
}

.profile-name input:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.profile-name #reroll-name {
  height: 38px;
  width: 38px;
  font-size: 18px;
  line-height: 1;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.preview-grid-small {
  grid-template-columns: repeat(auto-fill, 130px);
  justify-content: start;
}

.preview-cell {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.preview-cell:hover {
  border-color: var(--muted);
  transform: translateY(-1px);
}

.preview-cell[aria-checked="true"] {
  border-color: var(--accent);
  background: #181410;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.preview-cell canvas {
  display: block;
  background: #1a1a1a;
  border-radius: 6px;
  image-rendering: pixelated;
  pointer-events: none;
}

.preview-cell figcaption {
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.preview-cell[aria-checked="true"] figcaption {
  color: var(--ink);
}

.session-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 20, 18, 0.76);
}

.session-card.current {
  border-color: rgba(225, 184, 75, 0.72);
  background: rgba(225, 184, 75, 0.12);
}

.session-card strong,
.session-card span {
  display: block;
}

.session-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.session-card button {
  height: 36px;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--accent);
  color: #1a160f;
  font-weight: 800;
  cursor: pointer;
}

.session-card button:disabled {
  background: #34322c;
  color: var(--muted);
  cursor: default;
}

.empty {
  min-height: 56px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.game-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  container-type: size;
}

.is-hidden {
  display: none;
}

canvas {
  display: block;
  width: min(100cqw, calc(100cqh * 15 / 13));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 15 / 13;
  image-rendering: pixelated;
  border: 2px solid #060606;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
  background: #363124;
}

.legend {
  justify-content: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.legend div {
  min-height: 28px;
  display: flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(20, 20, 18, 0.76);
}

.legend b {
  color: var(--ink);
  margin-right: 6px;
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 18px, 1180px);
    padding: 10px 0;
    gap: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    justify-content: space-between;
  }

  .session-form {
    width: 100%;
  }

  .session-form input {
    width: 100%;
  }

  canvas {
    width: min(100cqw, calc(100cqh * 15 / 13));
    height: auto;
  }
}
