/* ================================================================
   GAME OF LIFE — styles.css
   Calm by default: soft neutral surfaces, one accent colour taken
   from the active palette, and as little chrome over the board as
   possible. Palette colours (--bg, --accent, --accent-ink) are set
   from script.js; [data-theme="light"] switches the chrome for the
   light palette.
   ================================================================ */

:root {
  --bg: #111317;
  --accent: #d6c8a4;
  --accent-ink: #1a1813;

  --surface: rgba(22, 24, 29, 0.88);
  --surface-strong: rgba(20, 22, 27, 0.96);
  --raised: rgba(255, 255, 255, 0.05);
  --raised-2: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9e6df;
  --muted: #a9a69e;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);

  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "DM Serif Display", Georgia, serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --surface: rgba(250, 248, 243, 0.9);
  --surface-strong: rgba(250, 248, 243, 0.97);
  --raised: rgba(0, 0, 0, 0.04);
  --raised-2: rgba(0, 0, 0, 0.075);
  --line: rgba(0, 0, 0, 0.09);
  --text: #23262d;
  --muted: #565a63;
  --shadow: 0 12px 32px rgba(60, 50, 30, 0.12);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s var(--ease);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* Frosted pill used by the top-bar pieces. */
.pill {
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

/* ── Top bar ── */
#topbar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;   /* the gaps between pills stay drawable */
}
#topbar > * { pointer-events: auto; }

#backLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 15px 0 11px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.15s;
}
#backLink:hover { color: var(--text); }

#title {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 16px;
  min-width: 0;
}
#title h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.rule-code {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

#stats {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 38px;
  padding: 0 16px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.stat-val { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ── Dock ── */
#dock {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  transition: left 0.3s var(--ease);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  max-width: calc(100vw - 20px);
  border-radius: 16px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 10;
}

.dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s;
}
.dock-btn:hover { background: var(--raised-2); }
.dock-btn svg { flex: none; }

.dock-btn.primary {
  min-width: 92px;
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-ink);
}
.dock-btn.primary:hover { background: var(--accent); filter: brightness(1.07); }

#settingsBtn[aria-expanded="true"] { background: var(--raised-2); }

/* Keep the dock centred in the space left of the open drawer. */
@media (min-width: 901px) {
  body.drawer-open #dock { left: calc((100vw - 372px) / 2); }
  body.drawer-open #stats { visibility: hidden; }
}
@media (min-width: 901px) and (max-width: 1240px) {
  body.drawer-open .dock-btn:not(.primary) .dock-label { display: none; }
  body.drawer-open .dock-btn:not(.primary) { width: 40px; padding: 0; }
}

.dock-sep { flex: none; width: 1px; height: 22px; margin: 0 5px; background: var(--line); }

#speedCycle { display: none; min-width: 52px; font-variant-numeric: tabular-nums; }

/* Segmented control (speed, edges) */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--raised);
}
.seg button {
  height: 32px;
  min-width: 38px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: background-color 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  color: var(--text);
  background: var(--raised-2);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

/* ── Drawer ── */
#backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: none;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}

#drawer {
  position: fixed;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: 344px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transform: translateX(calc(100% + 28px));
  visibility: hidden;
  transition: transform 0.3s var(--ease), visibility 0s linear 0.3s;
}
#drawer.open {
  transform: none;
  visibility: visible;
  transition: transform 0.3s var(--ease), visibility 0s;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 8px 22px;
}
.drawer-head h2 { font-family: var(--serif); font-weight: 400; font-size: 21px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--raised-2); color: var(--text); }

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 22px 26px;
  scrollbar-width: thin;
  scrollbar-color: var(--raised-2) transparent;
}
.drawer-body section + section {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.drawer-body h3 {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.note { margin-top: 10px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }

.preset-list { display: grid; gap: 2px; margin: 0 -10px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin: 0 -10px; }
.preset {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 10px;
  text-align: left;
  transition: background-color 0.15s;
}
.preset:hover { background: var(--raised); }
.preset.active { background: var(--raised-2); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.preset-name { font-size: 14px; font-weight: 500; }
.preset-desc { font-size: 12.5px; line-height: 1.45; color: var(--muted); }

.bits { display: grid; gap: 8px; margin-top: 14px; }
.bit-line { display: flex; align-items: center; gap: 10px; }
.bit-lbl { flex: none; width: 56px; font-size: 13px; color: var(--muted); }
.bit-row { flex: 1; min-width: 0; display: flex; gap: 3px; }
.bit-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 30px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  background: var(--raised);
  font-variant-numeric: tabular-nums;
  transition: background-color 0.15s, color 0.15s;
}
.bit-btn:hover { background: var(--raised-2); color: var(--text); }
.bit-btn.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.swatch {
  display: grid;
  gap: 7px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 12.5px;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
}
.swatch:hover { color: var(--text); }
.swatch.active { border-color: var(--accent); color: var(--text); }
.chip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 7px;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip i { border-radius: 2px; }

.shortcuts dl { display: grid; gap: 7px; font-size: 13px; }
.shortcuts dl div { display: flex; justify-content: space-between; align-items: center; }
.shortcuts dd { color: var(--muted); }
kbd {
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--raised-2);
  border: 1px solid var(--line);
}

/* ── Hint ── */
#drawHint {
  position: fixed;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
  transform: translateX(-50%);
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
  transition: opacity 0.8s var(--ease);
}
#drawHint.hidden { opacity: 0; }

/* ── Tooltip ── */
#tooltip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s, transform 0.15s;
}
#tooltip.visible { opacity: 1; transform: none; }
#tooltip::after {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  bottom: -5px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  background: inherit;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
#tooltip.tip-below::after { bottom: auto; top: -5px; transform: rotate(225deg); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .dock-btn:not(.primary) .dock-label { display: none; }
  .dock-btn:not(.primary) { width: 40px; padding: 0; }
  #speedCycle { width: auto; padding: 0 10px; }

  /* The drawer becomes a bottom sheet over a dimmed board. */
  #backdrop { display: block; }
  #backdrop.visible { opacity: 1; pointer-events: auto; }
  #drawer {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-height: 80vh;
    border-radius: 20px;
    transform: translateY(calc(100% + 24px));
  }
}
@media (min-width: 641px) and (max-width: 900px) {
  #drawer { left: 50%; right: auto; width: min(560px, calc(100vw - 16px)); transform: translate(-50%, calc(100% + 24px)); }
  #drawer.open { transform: translateX(-50%); }
}

@media (max-width: 640px) {
  #topbar { top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; gap: 6px; }
  .back-text, .rule-code { display: none; }
  #backLink { width: 38px; padding: 0; justify-content: center; }
  #title { padding: 0 14px; }
  #title h1 { font-size: 17px; }
  #stats { gap: 10px; padding: 0 13px; font-size: 12.5px; }

  #dock { bottom: max(10px, env(safe-area-inset-bottom)); }
  .dock-label { display: none; }
  .dock-btn.primary { min-width: 0; width: 46px; padding: 0; }
  .dock-sep { margin: 0 3px; }
  #speedSeg { display: none; }
  #speedCycle { display: inline-flex; }
  #drawHint { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px); }

}

@media (max-width: 380px) {
  #stats .stat:first-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
