/* Life: a dark, full-window sandbox. A toolbar across the top, the patterns down the left (a
   drawer over the grid when narrow), the grid filling the rest, and a line of stats below. */

:root {
  --bg: #0b1020;
  --panel: #121a33;
  --panel-2: #1a2447;
  --edge: #2a3766;
  --text: #e6ecff;
  --muted: #8f9cc8;
  --cyan: #8cf6ff;
  --gold: #ffd75a;
}
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* The toolbar */
.bar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--edge);
}
.brand { display: flex; align-items: center; gap: 8px; margin-right: 4px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.04em; color: var(--cyan); }
.back { color: var(--muted); text-decoration: none; font-size: 24px; line-height: 1; padding: 0 4px; }
.back:hover { color: var(--text); }
.group { display: flex; align-items: center; gap: 4px; }
.label { color: var(--muted); font-size: 12px; margin-right: 2px; }
.value { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; }
.bar button, .placing button, .square {
  height: 32px; padding: 0 12px; border: 1px solid var(--edge); border-radius: 8px;
  background: var(--panel-2); transition: background 0.15s, border-color 0.15s;
}
.bar button:hover:not(:disabled), .placing button:hover, .square:hover { background: #24305c; border-color: #3c4d8a; }
.bar button:disabled { opacity: 0.4; cursor: default; }
.square { width: 32px; padding: 0; font-size: 18px; line-height: 1; }
button.primary { min-width: 72px; background: #1d6b4a; border-color: #2b8f63; font-weight: 600; }
button.primary:hover { background: #23805a !important; }
button.primary.running { background: #8a2b3a; border-color: #b33d50; }
button.primary.running:hover { background: #a1323f !important; }
button.toggle[aria-pressed="true"] { background: #2b3f86; border-color: #5a74d6; color: #fff; }

/* The patterns */
.main { flex: 1; min-height: 0; display: flex; position: relative; }
.patterns {
  flex: none; width: 270px; overflow-y: auto; padding: 10px 12px 14px;
  background: var(--panel); border-right: 1px solid var(--edge);
  scrollbar-color: var(--edge) transparent; scrollbar-width: thin;
}
.patterns[hidden] { display: none; }
.patterns-head { display: flex; align-items: center; justify-content: space-between; }
.patterns h2 { margin: 0; font-size: 16px; }
.hint, .keys { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.keys { margin-top: 14px; line-height: 1.5; }
.patterns h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--cyan); }
.patterns h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: normal; margin-left: 4px; }
.pattern {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 4px; padding: 6px;
  text-align: left; border: 1px solid transparent; border-radius: 8px; background: none;
}
.pattern:hover { background: var(--panel-2); }
.pattern[aria-pressed="true"] { background: #2b3f86; border-color: #5a74d6; }
.pattern .pic {
  flex: none; width: 60px; height: 44px; display: flex; align-items: center; justify-content: center;
  background: var(--bg); border-radius: 6px;
}
.pattern canvas { image-rendering: pixelated; max-width: 56px; max-height: 40px; }
.pattern b { display: block; font-weight: 600; }
.pattern small { display: block; color: var(--muted); font-size: 12px; }

/* The grid */
.viewport { flex: 1; min-width: 0; position: relative; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { touch-action: none; cursor: grab; }
#overlay:active { cursor: grabbing; }
#overlay[data-tool="draw"], #overlay[data-tool="place"] { cursor: crosshair; }
.placing {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; max-width: calc(100% - 24px);
  padding: 8px 10px; border-radius: 12px; background: rgba(18, 26, 51, 0.92); border: 1px solid var(--edge);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.placing[hidden] { display: none; }
.placing b { color: var(--gold); }
.message { position: absolute; inset: 40% 20px auto; text-align: center; color: var(--muted); }

/* The stats */
.stats {
  flex: none; display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center;
  padding: 6px 12px; background: var(--panel); border-top: 1px solid var(--edge); color: var(--muted); font-size: 13px;
}
.stats b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.spacer { flex: 1; }
.account a { color: var(--cyan); }

/* Narrow: the patterns slide over the grid */
@media (max-width: 800px) {
  .patterns { position: absolute; z-index: 2; inset: 0 auto 0 0; width: min(300px, 85vw); box-shadow: 8px 0 30px rgba(0, 0, 0, 0.5); }
  .grid-size { display: none; }
  .label { display: none; }
  /* The toolbar one row, scrolled sideways */
  .bar { flex-wrap: nowrap; overflow-x: auto; gap: 10px; padding: 6px 8px; scrollbar-width: none; }
  .bar::-webkit-scrollbar { display: none; }
  .bar > * { flex: none; }
  .bar button { height: 34px; padding: 0 10px; }
  .bar .square { width: 34px; padding: 0; }
  .value { min-width: 38px; }
  .brand h1 { font-size: 18px; }
  .stats { gap: 2px 12px; font-size: 12px; }
}
