:root {
  color-scheme: dark;
  --smoke-950: #101116;
  --smoke-900: #17191f;
  --smoke-850: #1d2028;
  --smoke-800: #242832;
  --smoke-700: #343945;
  --paper: #f8f7fb;
  --muted: #aeb5c2;
  --cyan: #72eadc;
  --lime: #d4ff70;
  --coral: #ff7595;
  --violet: #b78aff;
  --blue: #6ca9ff;
  --gold: #ffc857;
  --navy: #071b3a;
  font-family: ui-rounded, "Arial Rounded MT Bold", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--smoke-950); }

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  background: #292b30;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: var(--smoke-950);
  font-weight: 800;
  background: var(--lime);
  border-radius: 10px;
  transform: translateY(-170%);
  transition: transform 160ms ease;
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  width: 100%;
  max-width: none;
  padding: 0;
  background: #fff;
  border-bottom: 1px solid #dfe3e8;
  box-shadow: 0 5px 20px rgba(0, 0, 0, .14);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 36px);
  max-width: 1040px;
  margin: 0 auto;
  padding: 10px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  padding: 0;
}
.brand img { display: block; width: 100px; height: auto; }

.header-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #4f5865;
  font-size: .7rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.header-note > span {
  width: 8px;
  height: 8px;
  background: var(--lime);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--lime);
  animation: status-pulse 1.8s ease-in-out infinite;
}

.game-page {
  width: calc(100% - 28px);
  max-width: 600px;
  margin: 0 auto;
  padding: clamp(14px, 3.6vw, 36px) 0 48px;
}

.intro { max-width: 610px; margin: 0 auto 22px; text-align: center; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--cyan);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .19em;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(114, 234, 220, .42);
}
h1 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(2.45rem, 10vw, 4.8rem);
  font-weight: 950;
  line-height: .94;
  letter-spacing: -.07em;
  text-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
h1 span { color: var(--lime); text-shadow: 0 0 24px rgba(212, 255, 112, .25); }
.intro > p:last-child {
  max-width: 545px;
  margin: 15px auto 0;
  color: #bdc3ce;
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(.92rem, 2.7vw, 1.05rem);
  line-height: 1.55;
}

.game-card {
  position: relative;
  padding: 0;
}

.game-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(100%, 520px);
  min-height: 48px;
  margin: 0 auto;
  padding: 0 4px 11px;
}
.score-block { display: flex; align-items: center; gap: 9px; }
.score-block span, .game-status {
  color: #9ca5b4;
  font-family: Inter, system-ui, sans-serif;
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.score-block strong {
  min-width: 38px;
  color: var(--lime);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 16px rgba(212, 255, 112, .42);
  transition: color 120ms ease, transform 120ms ease;
}
.score-block strong.score-pop { color: var(--coral); transform: scale(1.24) rotate(-4deg); }
.game-status { margin: 0; color: var(--cyan); text-align: center; }

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  justify-self: end;
  padding: 0;
  color: var(--cyan);
  background: #292d37;
  border: 1px solid rgba(114, 234, 220, .3);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 12px rgba(114, 234, 220, .06);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.icon-button:not(:disabled):hover { background: #343a44; border-color: var(--cyan); transform: translateY(-1px); }
.icon-button:disabled { cursor: default; opacity: .34; }
.icon-button svg { width: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.icon-button .play-icon, .icon-button.is-paused .pause-icon { display: none; }
.icon-button.is-paused .play-icon { display: block; }

.board-wrap {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  background: #111b20;
  border: 3px solid rgba(114, 234, 220, .9);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .035), 0 0 0 4px rgba(10, 12, 17, .72), 0 0 0 6px rgba(183, 138, 255, .2), 0 18px 40px -24px rgba(0, 0, 0, .9);
  touch-action: none;
  user-select: none;
}
.board-wrap::after { position: absolute; inset: 7px; border: 1px solid rgba(255, 255, 255, .08); border-radius: 50%; content: ""; pointer-events: none; }
#game-board { display: block; width: 100%; height: 100%; border-radius: 50%; }

.game-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 19, 24, .7);
  border-radius: 50%;
  backdrop-filter: blur(5px);
}
.game-overlay[hidden] { display: none; }
.overlay-panel {
  position: relative;
  width: min(100%, 360px);
  padding: 0 10px;
  color: #d9dee7;
  text-align: center;
}
.microbe-mascot {
  display: block;
  width: 108px;
  height: 108px;
  margin: -9px auto -16px;
  object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .42)) drop-shadow(0 0 10px rgba(183, 138, 255, .42));
  animation: mascot-float 2.6s ease-in-out infinite;
}
.microbe-mascot.is-unavailable { display: none; }
.overlay-kicker { color: var(--cyan); font-size: .61rem; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.overlay-panel h2 { margin: 5px 0 8px; color: #fff; font-size: clamp(1.35rem, 4.5vw, 1.8rem); line-height: 1.04; letter-spacing: -.035em; }
.base-key { display: flex; justify-content: center; gap: 6px; margin: 0 0 9px; }
.base-key span { display: grid; place-items: center; width: 23px; height: 23px; color: #17191f; font-size: .64rem; font-weight: 950; border: 1px solid rgba(255, 255, 255, .3); border-radius: 50%; }
.base-key .base-a { background: var(--cyan); }
.base-key .base-c { background: var(--blue); }
.base-key .base-g { background: var(--gold); }
.base-key .base-t { background: var(--coral); }
.overlay-panel p { margin: 0 auto 11px; color: #bec4cf; font-family: Inter, system-ui, sans-serif; font-size: clamp(.73rem, 2.35vw, .86rem); line-height: 1.42; }
.primary-button {
  position: relative;
  z-index: 1;
  min-height: 44px;
  padding: 10px 18px;
  color: #15171c;
  font-size: .85rem;
  font-weight: 950;
  background: var(--lime);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 11px 25px -11px rgba(212, 255, 112, .8), inset 0 1px 0 rgba(255, 255, 255, .7);
  transition: filter 140ms ease, transform 140ms ease, box-shadow 140ms ease;
  touch-action: manipulation;
}
.primary-button span { margin-right: 5px; font-size: .7rem; }
.primary-button:hover { filter: brightness(1.08) saturate(1.08); transform: translateY(-1px) scale(1.015); box-shadow: 0 15px 28px -11px rgba(212, 255, 112, .95); }

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}
.secondary-button {
  position: relative;
  z-index: 1;
  min-height: 44px;
  padding: 9px 17px;
  color: var(--cyan);
  font-size: .82rem;
  font-weight: 900;
  background: #272b34;
  border: 1px solid rgba(114, 234, 220, .52);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 7px 18px -12px rgba(114, 234, 220, .85);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
  touch-action: manipulation;
}
.secondary-button:hover { background: #303640; border-color: var(--cyan); transform: translateY(-1px); }
.secondary-button[hidden] { display: none; }

.mode-hint {
  position: absolute;
  z-index: 3;
  top: 31%;
  left: 50%;
  width: max-content;
  max-width: 68%;
  margin: 0;
  padding: 8px 13px;
  color: #17191f;
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(.65rem, 2.3vw, .78rem);
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
  background: var(--lime);
  border-radius: 999px;
  box-shadow: 0 9px 22px -12px rgba(0, 0, 0, .85);
  transform: translateX(-50%);
  pointer-events: none;
}
.mode-hint[hidden] { display: none; }
.mode-hint.is-leaving { opacity: 0; transform: translateX(-50%) translateY(-7px); transition: opacity 320ms ease, transform 320ms ease; }

.library-mode .board-wrap {
  cursor: grab;
  background: #151820;
  border-color: rgba(183, 138, 255, .9);
  border-radius: 32px;
}
.library-mode #page-title {
  max-width: 680px;
  margin-inline: auto;
  font-size: clamp(2rem, 8.2vw, 4rem);
  line-height: .98;
  letter-spacing: -.055em;
}
.library-mode .board-wrap:active { cursor: grabbing; }
.library-mode .board-wrap::after { border-radius: 26px; }
.library-mode #game-board, .library-mode .game-overlay { border-radius: 29px; }
.library-mode .score-block strong { min-width: 52px; color: var(--cyan); }
.library-mode .game-status { color: var(--coral); letter-spacing: .07em; }
.library-mode .base-key, .library-mode .direction-pad { display: none; }
.library-mode .controls { padding-top: 12px; }
.library-mode .controls > p { max-width: none; margin-bottom: 0; }
.library-mode .mode-hint {
  top: auto;
  bottom: 4.5%;
  max-width: 86%;
  color: #f7f8fb;
  line-height: 1.25;
  white-space: normal;
  background: rgba(23, 25, 31, .94);
  border: 1px solid rgba(114, 234, 220, .45);
}
.library-mode .mode-hint.is-error { color: var(--coral); border-color: rgba(255, 117, 149, .8); }
.library-mode .mode-hint.is-warning { color: var(--gold); border-color: rgba(255, 200, 87, .75); }
.library-mode .mode-hint.is-success { color: var(--lime); border-color: rgba(212, 255, 112, .72); }

.controls { padding: 15px 0 3px; }
.controls > p { margin: 0 0 10px; color: #9da6b4; font-family: Inter, system-ui, sans-serif; font-size: .7rem; font-weight: 800; text-align: center; }
.controls > p span { color: var(--violet); }
.direction-pad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); justify-content: center; gap: 6px; }
.direction-button {
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--control-color, var(--cyan));
  background: #282c35;
  background: color-mix(in srgb, var(--control-color, var(--cyan)) 10%, #242832);
  border: 1px solid #4a5060;
  border: 1px solid color-mix(in srgb, var(--control-color, var(--cyan)) 48%, #343945);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 0 #15171d, 0 0 17px -12px var(--control-color, var(--cyan));
  transition: transform 80ms ease, box-shadow 80ms ease, background 100ms ease, border-color 100ms ease;
}
.direction-button:hover { border-color: var(--control-color, var(--cyan)); background: color-mix(in srgb, var(--control-color, var(--cyan)) 17%, #242832); }
.direction-button:active, .direction-button.is-pressed { background: color-mix(in srgb, var(--control-color, var(--cyan)) 23%, #242832); box-shadow: 0 1px 0 #15171d, 0 0 20px -9px var(--control-color, var(--cyan)); transform: translateY(3px); }
.direction-button svg { width: 23px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.25; filter: drop-shadow(0 0 5px currentColor); }
.direction-button.up { grid-column: 2; grid-row: 1; --control-color: var(--cyan); }
.direction-button.left { grid-column: 1; grid-row: 2; --control-color: var(--blue); }
.direction-button.right { grid-column: 3; grid-row: 2; --control-color: var(--violet); }
.direction-button.down { grid-column: 2; grid-row: 3; --control-color: var(--gold); }
.pad-center { display: grid; grid-column: 2; grid-row: 2; grid-template-columns: repeat(2, 6px); place-content: center; gap: 5px; border: 1px solid rgba(255, 255, 255, .06); border-radius: 50%; }
.pad-center span { width: 5px; height: 5px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.pad-center span:nth-child(1) { color: var(--cyan); background: var(--cyan); }
.pad-center span:nth-child(2) { color: var(--blue); background: var(--blue); }
.pad-center span:nth-child(3) { color: var(--gold); background: var(--gold); }
.pad-center span:nth-child(4) { color: var(--coral); background: var(--coral); }

.lab-note { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 17px 0 0; color: #8e97a6; font-family: Inter, system-ui, sans-serif; font-size: .68rem; text-align: center; }
.lab-note span { color: var(--cyan); font-size: 1rem; }
footer { padding: 25px 20px calc(25px + env(safe-area-inset-bottom)); color: #929aa8; background: #111318; border-top: 1px solid rgba(114, 234, 220, .1); text-align: center; }
footer p { margin: 0; font-family: Inter, system-ui, sans-serif; font-size: .78rem; }
footer a { color: var(--cyan); font-weight: 800; text-underline-offset: 3px; }

@media (max-width: 440px) {
  .header-inner { width: calc(100% - 28px); padding: 12px 0; }
  .brand { padding: 0; }
  .brand img { width: 92px; }
  .header-note { font-size: .58rem; }
  .game-page { padding-top: 8px; }
  .intro { margin-bottom: 17px; }
  .intro > p:last-child { margin-top: 12px; }
  .game-bar { min-height: 46px; padding-bottom: 8px; }
  .game-overlay { padding: 14px; }
  .overlay-panel { padding: 0 7px; }
  .microbe-mascot { width: 72px; height: 72px; margin: -7px auto -10px; }
  .overlay-panel h2 { margin: 3px 0 6px; font-size: 1.28rem; }
  .base-key { margin-bottom: 6px; }
  .base-key span { width: 21px; height: 21px; }
  .overlay-panel p { margin-bottom: 8px; font-size: .72rem; line-height: 1.32; }
  .overlay-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: min(100%, 248px);
    margin: 0 auto;
    gap: 9px;
  }
  .primary-button, .secondary-button {
    width: 100%;
    min-height: 46px;
    padding: 9px 14px;
    font-size: .8rem;
  }
  .controls { padding: 13px 0 1px; }
  .controls > p { margin-bottom: 8px; }
  .direction-pad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); gap: 5px; }
}

@media (max-width: 350px) {
  .game-overlay { padding: 10px; }
  .microbe-mascot { display: none; }
  .overlay-panel h2 { font-size: 1.15rem; }
  .overlay-panel p { font-size: .68rem; }
  .primary-button, .secondary-button { min-height: 44px; }
}

@media (min-width: 720px) {
  .direction-pad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
}

@media (min-width: 900px) {
  .game-page { max-width: 760px; }
  .game-card {
    display: grid;
    grid-template-columns: 480px 170px;
    grid-template-rows: auto auto;
    justify-content: center;
    align-items: center;
    column-gap: 30px;
  }
  .game-bar {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
  }
  .board-wrap {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
  }
  .controls {
    grid-column: 2;
    grid-row: 2;
    padding: 0;
  }
  .controls > p {
    max-width: 138px;
    margin: 0 auto 16px;
    line-height: 1.45;
  }
  .library-mode .game-card { display: block; }
  .library-mode .game-bar, .library-mode .board-wrap { width: min(100%, 540px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@keyframes mascot-float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-5px) rotate(2deg); }
}
@keyframes status-pulse {
  0%, 100% { opacity: .58; transform: scale(.88); }
  50% { opacity: 1; transform: scale(1.08); }
}
