/* Colours of the original game: dark slate, light text, blue while dragging, green for success. */
:root {
  --bg: rgb(30, 30, 40);
  --panel: rgb(44, 44, 60);
  --button: rgb(60, 60, 80);
  --button-hover: rgb(80, 80, 120);
  --text: rgb(255, 255, 255);
  --muted: rgb(176, 178, 196);
  --accent: rgb(100, 200, 255);
  --success: rgb(50, 200, 100);
  --danger: rgb(255, 110, 110);
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
p,
figure,
dl,
dd {
  margin: 0;
}

a {
  color: var(--accent);
}

.screen {
  max-width: 1180px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn,
.chip {
  font: inherit;
  color: var(--text);
  background: var(--button);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: background-color 0.12s;
}

.btn:hover,
.chip:hover {
  background: var(--button-hover);
  color: var(--accent);
}

.btn:focus-visible,
.chip:focus-visible,
.card-open:focus-visible,
.card-remove:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  color: rgb(14, 30, 44);
  font-weight: 600;
}

.btn.primary:hover {
  background: rgb(150, 220, 255);
  color: rgb(14, 30, 44);
}

.btn.quiet {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--button-hover);
}

.btn.armed {
  background: var(--danger);
  color: rgb(40, 10, 10);
}

.btn[aria-pressed="true"],
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: rgb(14, 30, 44);
}

.chip {
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
}

.chips,
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row {
  align-items: center;
}

.status {
  color: var(--muted);
  min-height: 1.45em;
}

.status .btn {
  min-height: 36px;
  padding: 6px 12px;
}

/* Menu */

.masthead h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.masthead em {
  font-style: normal;
  color: var(--accent);
}

.masthead p {
  color: var(--muted);
  max-width: 62ch;
  margin-top: 6px;
}

.resume {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
}

.resume img {
  width: 96px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  flex: none;
}

.resume div {
  flex: 1;
  min-width: 0;
}

.resume h2 {
  font-size: 1rem;
}

.resume p {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search {
  display: flex;
  gap: 8px;
}

input[type="search"],
input[type="number"] {
  font: inherit;
  color: var(--text);
  background: rgb(70, 70, 90);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: 44px;
  min-width: 0;
}

.search input {
  flex: 1;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
}

.card {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card-open img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  background: rgb(20, 20, 28);
  transition: transform 0.2s;
}

.card-open:hover img {
  transform: scale(1.04);
}

.card-title {
  display: block;
  padding: 8px 10px 10px;
  font-size: 0.9rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-open:hover .card-title {
  color: var(--accent);
}

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--success);
  color: rgb(8, 36, 18);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.card-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 20, 28, 0.8);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.card-remove:hover {
  background: var(--danger);
  color: rgb(40, 10, 10);
}

.about {
  color: var(--muted);
  font-size: 0.88rem;
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

/* Shared bar of the setup and game screens */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar h2 {
  flex: 1;
  min-width: 0;
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.credit {
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

/* Setup */

.setup {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.preview img {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: rgb(20, 20, 28);
}

.preview figcaption {
  margin-top: 8px;
}

.choices {
  display: grid;
  gap: 12px;
}

.choices h3 {
  font-size: 1rem;
  font-weight: 600;
}

.sizes {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  align-items: center;
}

.stepper {
  display: inline-flex;
  gap: 6px;
}

.stepper .btn {
  width: 44px;
  padding: 0;
  font-size: 1.3rem;
}

.stepper input {
  width: 4.5em;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.choices .primary {
  font-size: 1.1rem;
  min-height: 52px;
}

/* Game: the screen is exactly as tall as the window, the board takes what the bars leave. */

.screen.play {
  max-width: none;
  height: 100vh;
  height: 100dvh;
  gap: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.stats {
  display: flex;
  gap: 16px;
  flex: none;
}

.stats div {
  text-align: center;
}

.stats dt {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats dd {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

.stage canvas:active {
  cursor: grabbing;
}

.notice {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.win {
  position: absolute;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);
  width: min(92%, 420px);
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  padding: 18px;
  border-radius: var(--radius);
  background: rgba(24, 60, 38, 0.94);
  box-shadow: 0 0 0 2px var(--success), 0 14px 40px rgba(0, 0, 0, 0.5);
  animation: rise 0.35s ease-out;
}

.win h2 {
  color: var(--success);
  font-size: 1.6rem;
}

.win .row {
  justify-content: center;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translate(-50%, 16px);
  }
}

.controls {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}

.controls .row {
  justify-content: center;
}

@media (max-width: 720px) {
  .setup {
    grid-template-columns: 1fr;
  }

  .preview img {
    max-height: 36vh;
  }

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

  .bar h2 {
    font-size: 0.95rem;
  }

  .stats {
    gap: 10px;
  }

  /* The four game controls on one row of a phone held upright. */
  .controls .row {
    width: 100%;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .controls .btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 6px;
    font-size: 0.88rem;
  }

  .resume {
    flex-wrap: wrap;
  }
}

@media (max-height: 480px) {
  /* A phone held sideways: the board needs the height. */
  .controls .credit {
    display: none;
  }

  .controls .btn,
  .bar .btn {
    min-height: 36px;
    padding: 4px 12px;
  }
}

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