:root {
  color-scheme: light;
  --paper: #f8fbff;
  --ink: #181817;
  --muted: #6e6e69;
  --line: #d8dce6;
  --grid-line: #d5dae2;
  --focus: #1667d9;
  --blue: #246be8;
  --wall: #4e5561;
  --wall-dark: #353b45;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 12%, rgba(66, 219, 245, .12), transparent 27%),
    radial-gradient(circle at 90% 18%, rgba(117, 70, 204, .09), transparent 30%),
    linear-gradient(145deg, #f7fcff 0%, #faf8ff 54%, #fffaf3 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

[hidden] {
  display: none !important;
}

.topbar {
  height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(248, 251, 255, .82);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .72);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: inherit;
  text-decoration: none;
  font-size: .95rem;
  font-weight: 650;
  letter-spacing: .025em;
}

.brand-logo {
  width: 2.4rem;
  height: 2.4rem;
  display: block;
  object-fit: contain;
  transition: transform 160ms ease;
}

.brand:hover .brand-logo {
  transform: translateY(-1px) rotate(-2deg);
}

.brand:focus-visible,
.board:focus-visible,
.access-form input:focus-visible,
.access-form button:focus-visible,
.design-rail button:focus-visible,
.design-rail input:focus-visible,
.design-rail select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 65%);
  outline-offset: 3px;
}

.game-name {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.page {
  min-height: calc(100svh - 4.5rem);
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.access-panel,
.game-panel {
  width: 100%;
  display: grid;
  place-items: center;
}

.game-workspace {
  display: grid;
  grid-template-columns: 12.5rem auto 12.5rem;
  align-items: start;
  justify-content: center;
  gap: 1.25rem;
  width: 100%;
}

.design-rail {
  width: 12.5rem;
}

.design-toggle,
.design-tools {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .84);
  box-shadow: 0 .8rem 2.5rem rgba(24, 24, 23, .055);
}

.design-toggle {
  min-height: 2.7rem;
  padding: .65rem 1rem;
  border-radius: .75rem;
  color: var(--ink);
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .035em;
  cursor: pointer;
}

.design-toggle[aria-expanded="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.design-tools {
  margin-top: .65rem;
  padding: 1rem;
  border-radius: 1rem;
}

.tool-group + .tool-group,
.pattern-form + .tool-group {
  margin-top: 1.15rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}

.tool-label,
.pattern-form label {
  display: block;
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.tile-choice {
  width: 100%;
  min-height: 3rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: .7rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .8rem;
  font-weight: 650;
  cursor: pointer;
}

.tile-choice.is-selected {
  border-color: color-mix(in srgb, var(--focus), white 20%);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus), transparent 82%);
}

.wall-swatch {
  width: 1.45rem;
  height: 1.45rem;
  flex: 0 0 auto;
  border: 1px solid var(--wall-dark);
  border-radius: .22rem;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .18), transparent 45%),
    var(--wall);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .08);
}

.pattern-form {
  margin-top: 1.15rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}

.pattern-form input,
.pattern-form button,
.design-tools select,
.pattern-actions button {
  width: 100%;
  min-height: 2.45rem;
  border: 1px solid var(--line);
  border-radius: .62rem;
  font: inherit;
  font-size: .76rem;
}

.pattern-form input,
.design-tools select {
  padding: .55rem .65rem;
  background: #fff;
  color: var(--ink);
}

.pattern-form input::placeholder {
  color: #989994;
}

.pattern-form button,
.pattern-actions button {
  padding: .55rem .65rem;
  background: #fff;
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
}

.pattern-form button {
  margin-top: .5rem;
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.pattern-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
  margin-top: .5rem;
}

.pattern-form button:disabled,
.pattern-actions button:disabled {
  cursor: default;
  opacity: .42;
}

.design-note,
.design-status {
  margin: .85rem 0 0;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.45;
}

.design-status {
  min-height: 2.9em;
  color: #3e403d;
}

.design-status.is-error {
  color: #a22d2d;
}

.access-form {
  width: min(20rem, 100%);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 1.25rem 4rem rgba(24, 24, 23, .08);
}

.access-form h1 {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
  font-weight: 650;
}

.access-form label {
  display: block;
  margin: 0 0 .45rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
}

.access-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .6rem;
}

.access-form input,
.access-form button {
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: .7rem;
  font: inherit;
}

.access-form input {
  min-width: 0;
  padding: .65rem .8rem;
  background: white;
  color: var(--ink);
  letter-spacing: .18em;
}

.access-form button {
  padding: .65rem 1rem;
  background: var(--ink);
  color: white;
  font-size: .82rem;
  font-weight: 650;
  cursor: pointer;
}

.access-error {
  min-height: 1rem;
  margin: .65rem 0 0;
  color: #a22d2d;
  font-size: .78rem;
}

.board {
  position: relative;
  width: min(calc(100vw - 29rem), calc(100svh - 8rem), 46rem);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--grid-line);
  background-color: #fbfcfe;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: calc(100% / 21) calc(100% / 21);
}

.board.design-active {
  border-color: color-mix(in srgb, var(--focus), white 35%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus), transparent 78%);
}

.tile-grid {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  grid-template-rows: repeat(21, 1fr);
}

.tile-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: crosshair;
}

.tile-cell:hover {
  background: color-mix(in srgb, var(--focus), transparent 88%);
}

.tile-cell:focus-visible {
  z-index: 2;
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.tile-cell[data-tile-type="wall"]::before {
  position: absolute;
  inset: 7%;
  border: 1px solid var(--wall-dark);
  border-radius: 8%;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .19), transparent 42%),
    linear-gradient(315deg, rgba(0, 0, 0, .12), transparent 48%),
    var(--wall);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .09),
    0 1px 2px rgba(24, 24, 23, .18);
  content: "";
}

.player {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: calc(100% / 21);
  height: calc(100% / 21);
  display: grid;
  place-items: center;
  pointer-events: none;
  will-change: transform;
}

.player::before {
  width: 70%;
  height: 70%;
  border-radius: 24%;
  background: var(--blue);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .32),
    0 2px 5px rgba(36, 107, 232, .22);
  content: "";
}

@media (max-width: 76rem) {
  .game-workspace {
    grid-template-columns: 12.5rem auto;
  }

  .workspace-balance {
    display: none;
  }

  .board {
    width: min(calc(100vw - 17rem), calc(100svh - 8rem), 46rem);
  }
}
