:root {
  color-scheme: dark;
  --ink: #f7f2e8;
  --muted: #b8afa1;
  --paper: #dfcfad;
  --paper-edge: #8d755b;
  --bg: #181512;
  --panel: #231f1a;
  --line: rgba(247, 242, 232, 0.16);
  --gold: #f0bd55;
  --red: #d34e3d;
  --teal: #55c7b0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(247, 242, 232, 0.035) 1px, transparent 1px) 0 0 / 68px 68px,
    linear-gradient(180deg, rgba(247, 242, 232, 0.03) 1px, transparent 1px) 0 0 / 68px 68px,
    linear-gradient(150deg, #0d1115 0%, #24151b 44%, #0e2a24 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 16px 0 20px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 16px;
  margin-bottom: 12px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(35, 31, 26, 0.74);
  color: var(--ink);
  text-decoration: none;
}

.home-link span {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: #181512;
  font-weight: 900;
}

.title-block p,
.start-card p {
  margin: 0 0 3px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 0.95;
}

h1 {
  font-size: clamp(2.25rem, 5vw, 4.6rem);
}

.stacked-title {
  display: grid;
  gap: 0.04em;
  line-height: 0.9;
  word-break: keep-all;
}

.stacked-title span {
  display: block;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(62px, 1fr));
  gap: 8px;
  min-width: min(640px, 100%);
}

.stats span {
  display: grid;
  gap: 2px;
  min-height: 50px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(35, 31, 26, 0.78);
  color: var(--muted);
  font-size: 0.78rem;
}

.stats strong {
  color: var(--ink);
  font-size: 1.15rem;
}

.stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 380px;
  max-height: calc(100vh - 146px);
  border: 1px solid rgba(247, 242, 232, 0.22);
  border-radius: 8px;
  background: #15120f;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.start-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 10, 8, 0.54);
  overflow: auto;
}

.start-panel[hidden] {
  display: none;
}

.start-card {
  display: grid;
  gap: 14px;
  justify-items: center;
  min-width: min(310px, 100%);
  padding: 24px;
  border: 1px solid rgba(247, 242, 232, 0.22);
  border-radius: 8px;
  background: rgba(35, 31, 26, 0.88);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.42);
}

.lobby-card {
  width: min(820px, 100%);
  padding: 20px;
}

.start-card h2 {
  font-size: clamp(2.4rem, 7vw, 4.8rem);
  text-align: center;
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) minmax(260px, 0.85fr);
  gap: 14px;
  width: 100%;
  align-items: stretch;
}

.lobby-preview {
  position: relative;
  overflow: hidden;
  min-height: 236px;
  margin: 0;
  border: 1px solid rgba(247, 242, 232, 0.18);
  border-radius: 8px;
  background: #11120f;
}

.lobby-preview img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 236px;
  object-fit: cover;
}

.lobby-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 34%, rgba(0, 0, 0, 0.16) 62%, rgba(0, 0, 0, 0.5) 100%),
    linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, 0.66));
  pointer-events: none;
}

.lobby-preview figcaption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 1;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.72);
}

.background-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.background-option {
  display: grid;
  gap: 6px;
  min-width: 0;
  min-height: 0;
  padding: 7px;
  border: 1px solid rgba(247, 242, 232, 0.18);
  border-radius: 8px;
  background: rgba(247, 242, 232, 0.07);
  color: var(--ink);
  cursor: pointer;
}

.background-option img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  filter: saturate(0.88) brightness(0.82);
}

.background-option span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.background-option[aria-pressed="true"] {
  border-color: rgba(240, 189, 85, 0.9);
  background: rgba(240, 189, 85, 0.14);
  box-shadow: 0 0 0 2px rgba(240, 189, 85, 0.12);
}

.background-option[aria-pressed="true"] img {
  filter: saturate(1.08) brightness(1);
}

.background-option[aria-pressed="true"] span {
  color: var(--gold);
}

.start-card button:not(.background-option) {
  min-width: 128px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #17120c;
  font-weight: 900;
  cursor: pointer;
}

.start-card button:focus-visible,
.start-card button:hover {
  outline: 2px solid rgba(247, 242, 232, 0.8);
  outline-offset: 3px;
}

.result-card strong {
  color: var(--gold);
  font-size: 2.2rem;
}

.pad {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 5px;
  padding: 8px;
  border: 1px solid rgba(247, 242, 232, 0.18);
  border-radius: 8px;
  background: rgba(16, 13, 10, 0.62);
  backdrop-filter: blur(8px);
}

.pad button,
.pad span {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.pad button {
  border: 1px solid rgba(247, 242, 232, 0.22);
  background: rgba(247, 242, 232, 0.1);
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.pad button:active,
.pad button.active {
  background: var(--gold);
  color: #17120c;
}

.message {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    min-width: 0;
  }

  .stage {
    aspect-ratio: 10 / 13;
    max-height: none;
  }

  .lobby-layout {
    grid-template-columns: 1fr;
  }

  .lobby-preview,
  .lobby-preview img {
    min-height: 190px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 14px, 560px);
    padding-top: 10px;
  }

  .home-link {
    width: fit-content;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pad {
    right: 8px;
    bottom: 8px;
    grid-template-columns: repeat(3, 38px);
  }

  .pad button,
  .pad span {
    width: 38px;
    height: 38px;
  }

  .lobby-card {
    padding: 14px;
  }

  .background-select {
    grid-template-columns: 1fr;
  }
}
