/* Layout + components. All colours, radii, shadows and fonts come from the
   theme variables in themes.css, so every design shares this one stylesheet. */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: var(--ui-tracking);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html { background: var(--bg); }
body {
  background: var(--page-bg);
  background-attachment: fixed;
  min-height: 100vh;
}
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
/* Board size. --ar is the canvas height/width (set by game.js, 1 = square).
   Narrow screens: one column, up to 720px wide.
   Wide landscape screens: board on the left sized to the viewport height, controls in a side column. */
:root {
  --ar: 1;
  --side: 360px;
  --gap: 28px;
}
#app {
  max-width: 720px;
  margin: 0 auto;
  /* padding-top leaves room for the fixed .back-link */
  padding: 64px 18px 56px;
}
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
h1 {
  font-family: var(--font-display);
  font-size: var(--title-size);
  letter-spacing: var(--title-tracking);
  text-transform: var(--title-transform);
  font-weight: var(--title-weight);
  margin: 0;
  line-height: 1.1;
}
.tag {
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}
.stage-main { min-width: 0; }
.stage-side { min-width: 0; }
@media (min-width: 960px) and (min-aspect-ratio: 5/4) {
  :root {
    /* width of the board: what fits next to the side column, and what fits above the fold */
    --cv: max(360px, min(100vw - var(--side) - var(--gap) - 72px, (100vh - 150px) / var(--ar), 1200px));
  }
  #app { max-width: calc(var(--cv) + var(--gap) + var(--side) + 36px); }
  .stage { display: flex; align-items: flex-start; gap: var(--gap); }
  .stage-main { flex: none; width: var(--cv); }
  .stage-side { flex: none; width: var(--side); }
  .stage-side .status { margin-top: 0; }
}
#canvas-wrap {
  position: relative;
  border: var(--border-w) solid var(--hairline);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--board);
  line-height: 0;
  box-shadow: var(--wrap-shadow);
  touch-action: manipulation;
}
/* fullscreen games (Snake, Conway): the canvas is the whole screen */
#canvas-wrap.fs { border: 0; border-radius: 0; box-shadow: none; }
canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
}
.status {
  min-height: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin: 12px 4px 14px;
  font-variant-numeric: tabular-nums;
}
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dim);
  flex-shrink: 0;
  transition: background 0.2s, box-shadow 0.2s;
}
.status.solved { color: var(--mint); }
.status.solved .dot { background: var(--mint); box-shadow: 0 0 0 4px color-mix(in srgb, var(--mint) 20%, transparent); }
.status.dead { color: var(--rose); }
.status.dead .dot { background: var(--rose); box-shadow: 0 0 0 4px color-mix(in srgb, var(--rose) 20%, transparent); }
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.row.tight { margin-bottom: 12px; }
button {
  flex: 1;
  appearance: none;
  border: var(--border-w) solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 8px;
  border-radius: var(--r-sm);
  box-shadow: var(--btn-shadow);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s, color 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--panel-2); border-color: var(--edge-hover); }
button:active { transform: var(--btn-press); box-shadow: var(--btn-shadow-press); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  background: var(--primary-bg);
  color: var(--primary-fg);
  border-color: var(--primary-border);
  font-weight: 700;
  box-shadow: var(--primary-shadow);
}
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-border); }
button.active,
button.hint-confirm {
  background: color-mix(in srgb, var(--toggle) 15%, var(--panel));
  color: var(--toggle-fg);
  border-color: color-mix(in srgb, var(--toggle) 50%, transparent);
  font-weight: 700;
}
button.active:hover,
button.hint-confirm:hover { background: color-mix(in srgb, var(--toggle) 22%, var(--panel)); border-color: color-mix(in srgb, var(--toggle) 65%, transparent); }
.preset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.preset-row label {
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}
.preset-row select {
  flex: 1;
  min-width: 0;
  appearance: none;
  border: var(--border-w) solid var(--panel-edge);
  background: var(--panel);
  box-shadow: var(--btn-shadow);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 36px 10px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.preset-row { position: relative; }
.preset-row::after {
  /* dropdown chevron, drawn in the theme's muted colour */
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}
.preset-row select:hover { border-color: var(--edge-hover); background-color: var(--panel-2); }
.preset-row select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.preset-row select option { background: var(--panel); color: var(--ink); }
.controls {
  background: var(--panel);
  border: var(--border-w) solid var(--panel-edge);
  border-radius: var(--r-md);
  box-shadow: var(--btn-shadow);
  padding: 12px 16px 16px;
}
.ctl {
  display: grid;
  grid-template-columns: 96px 1fr 52px;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}
.ctl + .ctl { border-top: 1px solid var(--grid-line); }
.ctl label {
  font-size: 13px;
  color: var(--muted);
}
.ctl input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.ctl .val {
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.ctl .val.bad { color: var(--rose); }
.apply-row { margin-top: 12px; }
.hint-note {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 4px 12px;
  min-height: 16px;
}
/* Padding enlarges the clickable area without a visible background/border;
   negative margin compensates so the link still lines up the same as plain text. */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  margin: -10px;
  padding: 10px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--ink); }
.back-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-sm); }

/* Normal layout has no top bar, so pin the back-link fixed top-left there.
   The fullscreen overlay bars (Snake/Conway, Conway's custom bar) instead
   place it as a normal flex child so it vertically aligns with their buttons. */
#app > a.back-link {
  position: fixed;
  top: 20px;
  left: 22px;
  z-index: 11;
}

/* ---- info modal ---- */
.info-btn {
  flex: none !important;
  width: 40px;
  min-height: 40px;
  padding: 0 !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: info-fade 0.2s ease;
}
.info-modal {
  position: relative;
  background: var(--modal-bg);
  border: var(--border-w) solid var(--hairline);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--modal-shadow);
  animation: info-pop 0.28s var(--ease);
}
@keyframes info-fade { from { opacity: 0; } }
@keyframes info-pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
.info-title {
  margin: 0 44px 0 2px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: var(--title-weight);
  letter-spacing: var(--title-tracking);
  text-transform: var(--title-transform);
  color: var(--ink);
}
.info-text {
  margin: 0 2px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}
.info-modal canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
  border-radius: var(--r-md);
  border: var(--border-w) solid var(--hairline);
}
#info-close {
  position: absolute;
  top: 16px;
  right: 16px;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 420px) {
  #app { padding: 60px 12px 40px; }
  h1 { font-size: 22px; }
  .tag { font-size: 12px; }
  button { font-size: 13px; padding: 10px 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .info-backdrop, .info-modal { animation: none; }
}
