:root {
  color-scheme: dark;
  font-family: "Inter", "Noto Sans JP", system-ui, sans-serif;
  color: #e5ebe4;
  background: #101613;
  --panel: #191f1b;
  --surface: #141a16;
  --line: #303b32;
  --muted: #aab7ab;
  --accent: #c0ed9f;
  --mono: ui-monospace, "Cascadia Code", "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }

.masthead { background: #131a15; border-bottom: 1px solid #29332b; }
.masthead-inner, .workspace { width: min(100% - 64px, 1280px); margin-inline: auto; }
.masthead-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand {
  display: inline-flex; align-items: center; gap: 11px;
  color: #e7eee3; text-decoration: none; font-weight: 750;
  letter-spacing: .08em; white-space: nowrap;
}
.brand-mark {
  position: relative; width: 31px; height: 31px; border-radius: 50%;
  border: 1px solid #8ab66e; background: #233226;
  box-shadow: inset 0 0 0 3px #19251b;
}
.brand-mark i { position: absolute; background: var(--accent); border-radius: 50%; }
.brand-mark i:nth-child(1) { width: 7px; height: 7px; top: 7px; left: 8px; }
.brand-mark i:nth-child(2) { width: 5px; height: 5px; top: 14px; left: 17px; }
.brand-mark i:nth-child(3) { width: 3px; height: 3px; top: 19px; left: 11px; }

.workspace { padding-block: 34px 44px; }
.intro { margin-bottom: 25px; }
.intro h1 { font-size: clamp(1.65rem, 4vw, 2.45rem); line-height: 1.25; letter-spacing: -.045em; }
.intro p { margin-top: 9px; color: var(--muted); line-height: 1.65; }
.panels {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(335px, .52fr);
  grid-template-areas: "culture rules" "culture observations"; gap: 16px;
  align-items: start; grid-template-rows: auto 1fr;
}
.panel {
  min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); box-shadow: 0 14px 28px -24px #000b;
}
.culture { grid-area: culture; }
.rules { grid-area: rules; }
.observations { grid-area: observations; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 15px; }
.panel-heading h2 { font-size: 1.12rem; line-height: 1.35; letter-spacing: .015em; }
.culture-status { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px 14px; }
#culture-generation { color: #dbe8d7; font: .875rem var(--mono); }
.run-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .875rem; }
.run-status > span:first-child { width: 7px; height: 7px; background: #8e9a8e; border-radius: 50%; }
.run-status.running { color: var(--accent); }
.run-status.running > span:first-child { background: var(--accent); box-shadow: 0 0 9px #b9ee95a0; }
.scope { background: #0d1813; border: 1px solid #3a5140; border-radius: 10px; overflow: hidden; }
.scope:focus-within { border-color: var(--accent); }
.scope-labels {
  display: flex; justify-content: space-between; gap: 8px; padding: 9px 12px;
  background: #17251c; border-bottom: 1px solid #34483a; color: #b6c8b8;
  font: .875rem/1.35 var(--mono);
}
#board-rule { color: var(--accent); overflow-wrap: anywhere; text-align: right; }
#board { display: block; width: 100%; aspect-ratio: 8 / 5; touch-action: none; cursor: crosshair; }
#board:focus-visible { outline: none; }

.playback { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.primary, .secondary, .quiet {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 39px; padding: 6px 12px; border-radius: 7px;
  font-size: .875rem; line-height: 1.3; white-space: nowrap;
}
.primary { color: #1a2815; background: var(--accent); border: 1px solid var(--accent); font-weight: 750; min-width: 82px; }
.primary:hover { background: #d5f5be; }
.secondary { color: #e0e9df; background: #252e27; border: 1px solid #414f43; }
.secondary:hover:not(:disabled) { background: #313e33; border-color: #677f66; }
.quiet { padding-inline: 5px; min-height: 32px; background: transparent; border: 1px solid transparent; color: #bacbb8; }
.quiet:hover { color: var(--accent); background: #263127; }
.run-icon { width: 0; height: 0; border: 5px solid transparent; border-right: 0; border-left: 8px solid currentColor; }
.running .run-icon { width: 8px; height: 10px; border: solid currentColor; border-width: 0 2px; }
.speed { display: flex; align-items: center; gap: 9px; margin-left: auto; color: var(--muted); font-size: .875rem; white-space: nowrap; }
.speed input { width: clamp(70px, 8vw, 115px); margin: 0; accent-color: var(--accent); }
.speed output { min-width: 5.8em; text-align: right; color: #dbe8d7; font-variant-numeric: tabular-nums; }

.setup { border-top: 1px solid var(--line); margin-top: 17px; padding-top: 14px; }
.setup-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 14px; margin-bottom: 10px; }
.setup h3 { font-size: 1rem; }
.setup p, .formula-help, .rule-help { color: var(--muted); font-size: .875rem; line-height: 1.65; }
.setup-controls { display: grid; grid-template-columns: .85fr 1.2fr 1.1fr auto; gap: 9px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; color: #c7d3c7; font-size: .875rem; }
.seed-field { min-width: 0; display: flex; gap: 4px; }
.seed-field button { padding-inline: 7px; }
.field input, .field select, #share-url {
  width: 100%; min-width: 0; min-height: 39px; padding: 6px 9px;
  background: var(--surface); color: #e5ebe4; border: 1px solid #414f43; border-radius: 7px;
}
.field select {
  appearance: none; padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, #abc1ab 50%), linear-gradient(135deg, #abc1ab 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px; background-repeat: no-repeat;
}
.patterns { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.patterns button { min-height: 33px; }
.clear-button { color: var(--muted); background: transparent; }

.formula {
  display: flex; align-items: center; justify-content: center; gap: 12px; padding: 13px 9px;
  color: #dfecd9; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  font: .945rem/1.65 var(--mono);
}
.formula i, .formula-help i { font-family: Georgia, serif; }
.formula sub, .formula-help sub { line-height: 0; }
.formula-state { white-space: nowrap; font-size: 1.2rem; }
.formula-state span { color: #a3b99e; }
.formula dl { border-left: 1px solid #759871; border-radius: 8px 0 0 8px; padding-left: 10px; }
.formula dl > div { display: flex; gap: 10px; }
.formula dt { color: var(--accent); }
.formula-help { margin-top: 8px; }
.rules fieldset { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
.rules legend { padding: 0 0 5px; color: #dce6da; font-size: .875rem; }
.rules legend i { color: var(--accent); font-family: Georgia, serif; margin-left: 3px; }
.counts { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.count { position: relative; cursor: pointer; }
.count input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.count span {
  display: grid; place-items: center; min-height: 34px; border: 1px solid #3b493e; border-radius: 5px;
  color: #bdc9be; background: var(--surface); font: .9rem var(--mono);
}
.count input:checked + span { color: #e1f7d1; background: #3b5839; border-color: #82ae6c; font-weight: 750; }
.count input:hover + span { border-color: #8eab88; }
.count input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.rule-help { margin-top: 12px; }

.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.metrics > div { padding: 8px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.metrics dt { color: var(--muted); font-size: .875rem; }
.metrics dd { color: #e3f0dd; font: 1.3rem/1.3 var(--mono); overflow-wrap: anywhere; }
.history { margin-top: 12px; }
.history figcaption { color: #c7d3c7; font-size: .875rem; margin-bottom: 6px; }
#history { width: 100%; height: 118px; display: block; }

.notice {
  position: fixed; right: 18px; bottom: 18px; z-index: 1;
  max-width: min(400px, calc(100% - 36px)); padding: 11px 48px 11px 12px;
  border: 1px solid #71936a; border-radius: 9px; background: #243627;
  box-shadow: 0 4px 30px #0007;
}
.notice p { font-size: .875rem; line-height: 1.5; }
.notice button { position: absolute; top: 4px; right: 7px; width: 32px; }
#share-url { margin-top: 7px; font: .875rem var(--mono); }

@media (max-width: 1060px) {
  .setup-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .masthead-inner, .workspace { width: min(100% - 40px, 680px); }
  .panels { grid-template-columns: minmax(0, 1fr); grid-template-areas: "culture" "rules" "observations"; grid-template-rows: none; }
  .setup-controls { grid-template-columns: .85fr 1.2fr 1.1fr auto; }
}
@media (max-width: 540px) {
  .masthead-inner, .workspace { width: calc(100% - 24px); }
  .masthead-inner { min-height: 58px; }
  .workspace { padding-block: 22px 28px; }
  .intro { margin-bottom: 16px; }
  .panel { padding: 12px; }
  .panels { gap: 12px; }
  .setup-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field input, .field select { font-size: 1rem; }
  .speed { width: 100%; margin: 2px 0 0; }
  .speed input { flex: 1; }
}

.breadcrumb { display: flex; align-items: baseline; flex-wrap: wrap; gap: .55em; margin-bottom: 8px; font-size: .85rem; }
.breadcrumb a { display: inline-flex; align-items: center; min-height: 44px; padding-inline: 4px; color: var(--accent); text-underline-offset: 3px; }
