/*!
 * nalyx.games.css — opt-in game-shell kit for nalyx.
 *
 * Requires nalyx.css. Provides the full-screen shell shared by the lab
 * games: .app-shell, .ambient orbs, .game-panel, .hero + .eyebrow header,
 * .icon-button / .ghost-button, .mode-row + .mode-picker + .mode-context +
 * .context-dot + .daily-best, .control-row + .difficulty-picker,
 * .status-strip + .status-copy + .status-signal + .metric,
 * .streak-row + .streak-copy + .week-strip + .week-day,
 * .play-layout + .board-wrap + .board-scroll + .board-actions + .side-panel
 * + .help-card + .tool-list, .result-banner + .result-actions +
 * .share-status, .game-footer, and an accent-tinted scoped kbd.
 *
 * Every class is scoped under .app-shell — load the file, keep the markup,
 * delete the local copy. Inside .app-shell the kit's .hero (a flex header)
 * wins over the core .hero effect class.
 *
 * Dark-first: the palette defaults to dark, flips to light via
 * prefers-color-scheme or <html data-shade="light|dark">. Retheme a game by
 * overriding --gx-accent/--gx-accent-2 (and optionally --gx-bg/--gx-bg-2):
 *
 *   :root { --gx-accent: #6fd8c8; --gx-accent-2: #dca85a; }
 *
 * or by selecting a family from nalyx.themes.css:
 *   <html data-theme="lagoon"> / Nalyx.setTheme('lagoon')
 */

/* ---------- shell palette ----------
 * Dark-first defaults re-tint the nalyx core tokens so .btn/.card/kbd match
 * the shell, then --gx-* aliases let the shell classes (and games) read a
 * single source of truth. Theme families override the nalyx tokens, which
 * the --gx-* aliases follow automatically. */
:root {
  --bg: #0a1018;
  --surface: rgba(12, 18, 27, 0.84);
  --surface-2: rgba(2, 8, 18, 0.38);
  --surface-3: rgba(255, 255, 255, 0.05);
  --text: #eef4ff;
  --text-muted: #8e9cb8;
  --text-dim: #72819c;
  --accent: #c8b27a;
  --accent-strong: color-mix(in srgb, var(--accent) 72%, #000);
  --accent-text: color-mix(in srgb, var(--accent) 72%, #fff);
  --accent-bg: color-mix(in srgb, var(--accent) 13%, transparent);
  --hover: color-mix(in srgb, var(--accent) 10%, transparent);
  --border: color-mix(in srgb, var(--accent) 10%, transparent);
  --border-strong: color-mix(in srgb, var(--accent) 30%, transparent);
  --success: #9df57a;
  --error: #ff8d7a;
  --shadow-color: rgba(0, 0, 0, 0.45);
  color-scheme: dark;

  --gx-bg: var(--bg);
  --gx-bg-2: #121a24;
  --gx-panel: var(--surface);
  --gx-well: var(--surface-2);
  --gx-chip: rgba(255, 255, 255, 0.025);
  --gx-text: var(--text);
  --gx-text-strong: #f4f7ff;
  --gx-muted: var(--text-muted);
  --gx-faint: var(--text-dim);
  --gx-accent: var(--accent);
  --gx-accent-2: #4d7dff;
  --gx-accent-soft: color-mix(in srgb, var(--accent) 40%, var(--gx-text));
  --gx-win: var(--success);
  --gx-lose: var(--error);
  --gx-line: var(--border);
  --gx-radius: 30px;
  --gx-panel-max: 1040px;
  --gx-side: 280px;
  --gx-orb: 420px;
}

/* Counter nalyx's own auto-dark block (specificity 0,3,0) when no family
 * is active — without this the shell would fall back to nalyx's indigo
 * dark palette for OS-dark users. */
@media (prefers-color-scheme: dark) {
  :root:not([data-shade]):not([data-theme]) {
    --bg: #0a1018;
    --surface: rgba(12, 18, 27, 0.84);
    --surface-2: rgba(2, 8, 18, 0.38);
    --surface-3: rgba(255, 255, 255, 0.05);
    --text: #eef4ff;
    --text-muted: #8e9cb8;
    --text-dim: #72819c;
    --accent: #c8b27a;
    --accent-strong: color-mix(in srgb, var(--accent) 72%, #000);
    --accent-text: color-mix(in srgb, var(--accent) 72%, #fff);
    --accent-bg: color-mix(in srgb, var(--accent) 13%, transparent);
    --hover: color-mix(in srgb, var(--accent) 10%, transparent);
    --border: color-mix(in srgb, var(--accent) 10%, transparent);
    --border-strong: color-mix(in srgb, var(--accent) 30%, transparent);
    --success: #9df57a;
    --error: #ff8d7a;
    --shadow-color: rgba(0, 0, 0, 0.45);
    color-scheme: dark;

    --gx-bg-2: #121a24;
    --gx-chip: rgba(255, 255, 255, 0.025);
    --gx-text-strong: #f4f7ff;
  }
}

@media (prefers-color-scheme: light) {
  :root:not([data-shade='dark']):not([data-theme]) {
    --bg: #eef3fb;
    --surface: rgba(255, 255, 255, 0.84);
    --surface-2: rgba(28, 55, 102, 0.05);
    --surface-3: rgba(28, 55, 102, 0.08);
    --text: #132033;
    --text-muted: #5d6d86;
    --text-dim: #7c8aa0;
    --accent-text: color-mix(in srgb, var(--accent) 60%, #241a06);
    --success: #177245;
    --error: #b42318;
    --shadow-color: rgba(36, 61, 112, 0.14);
    color-scheme: light;

    --gx-bg-2: #f7f9fd;
    --gx-chip: rgba(28, 55, 102, 0.04);
    --gx-text-strong: #122033;
  }
}

:root[data-shade='light']:not([data-theme]) {
  --bg: #eef3fb;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-2: rgba(28, 55, 102, 0.05);
  --surface-3: rgba(28, 55, 102, 0.08);
  --text: #132033;
  --text-muted: #5d6d86;
  --text-dim: #7c8aa0;
  --accent-text: color-mix(in srgb, var(--accent) 60%, #241a06);
  --success: #177245;
  --error: #b42318;
  --shadow-color: rgba(36, 61, 112, 0.14);
  color-scheme: light;

  --gx-bg-2: #f7f9fd;
  --gx-chip: rgba(28, 55, 102, 0.04);
  --gx-text-strong: #122033;
}

/* ---------- shell ---------- */

.app-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  overflow: hidden;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 16% -8%, color-mix(in srgb, var(--gx-accent) 18%, transparent), transparent 30rem),
    radial-gradient(circle at 92% 108%, color-mix(in srgb, var(--gx-accent-2) 14%, transparent), transparent 28rem),
    linear-gradient(180deg, var(--gx-bg-2) 0%, var(--gx-bg) 72%);
}

.app-shell :focus-visible {
  outline: 3px solid var(--gx-accent);
  outline-offset: 3px;
}

.ambient {
  position: absolute;
  width: var(--gx-orb);
  height: var(--gx-orb);
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.16;
  pointer-events: none;
}

.ambient-left {
  top: -180px;
  left: -180px;
  background: var(--gx-accent);
}

.ambient-right {
  right: -180px;
  bottom: -220px;
  background: var(--gx-accent-2);
}

.game-panel {
  position: relative;
  z-index: 1;
  width: min(100%, var(--gx-panel-max));
  padding: clamp(22px, 4vw, 40px);
  border: 1px solid var(--gx-line);
  border-radius: var(--gx-radius);
  background: var(--gx-panel);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.45), inset 0 1px rgba(255, 255, 255, 0.04);
  -webkit-backdrop-filter: blur(26px);
  backdrop-filter: blur(26px);
}

.app-shell .hero,
.app-shell .mode-row,
.app-shell .control-row,
.app-shell .status-strip,
.app-shell .result-banner,
.app-shell .game-footer,
.app-shell .streak-row {
  display: flex;
  align-items: center;
}

/* .hero inside .app-shell is the game header — reset the core .hero
 * effect class (padding/centered text/accent wash) it collides with. */
.app-shell .hero {
  justify-content: space-between;
  gap: 24px;
  padding: 0;
  text-align: start;
  background: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--gx-accent-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow span {
  width: 18px;
  height: 1px;
  background: currentColor;
}

.app-shell .hero h1 {
  margin: 0;
  font-size: clamp(36px, 6vw, 56px);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

.app-shell .hero p:not(.eyebrow) {
  margin: 12px 0 0;
  max-width: 46ch;
  color: var(--gx-muted);
  font-size: 14px;
}

/* ---------- shell buttons ---------- */

.app-shell .icon-button,
.app-shell .ghost-button,
.app-shell .result-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid color-mix(in srgb, var(--gx-accent) 12%, transparent);
  border-radius: 14px;
  color: var(--gx-text);
  background: color-mix(in srgb, var(--gx-accent) 7%, transparent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: border-color 180ms, background 180ms, transform 180ms, opacity 180ms;
}

.app-shell .ghost-button {
  min-height: 44px;
}

.app-shell .icon-button:hover,
.app-shell .ghost-button:hover,
.app-shell .result-actions button:hover,
.app-shell .difficulty-picker button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--gx-accent) 48%, transparent);
  background: color-mix(in srgb, var(--gx-accent) 16%, transparent);
  transform: translateY(-1px);
}

.app-shell .icon-button:disabled,
.app-shell .ghost-button:disabled,
.app-shell .difficulty-picker button:disabled {
  cursor: not-allowed;
  opacity: 0.34;
  transform: none;
}

.app-shell .icon-button svg,
.app-shell .ghost-button svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- mode & difficulty pickers ---------- */

.app-shell .mode-row {
  gap: 14px;
  margin-top: 28px;
  padding: 7px;
  border: 1px solid var(--gx-line);
  border-radius: 18px;
  background: var(--gx-well);
}

.app-shell .mode-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  flex: none;
  width: 190px;
  padding: 3px;
  border-radius: 12px;
  background: var(--gx-chip);
}

.app-shell .mode-picker button,
.app-shell .difficulty-picker button {
  border: 0;
  color: var(--gx-faint);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  transition: color 180ms, background 180ms, box-shadow 180ms, opacity 180ms;
}

.app-shell .mode-picker button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
}

.app-shell .mode-picker button[aria-pressed="true"],
.app-shell .difficulty-picker button[aria-pressed="true"] {
  color: var(--gx-text);
  background: color-mix(in srgb, var(--gx-accent) 15%, var(--gx-bg));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gx-accent) 18%, transparent),
              0 4px 18px rgba(0, 0, 0, 0.2);
}

.app-shell .mode-context {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-shell .context-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gx-faint);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--gx-faint) 8%, transparent);
}

.app-shell .context-dot.daily {
  background: var(--gx-accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--gx-accent) 10%, transparent),
              0 0 18px color-mix(in srgb, var(--gx-accent) 50%, transparent);
}

.app-shell .mode-context div,
.app-shell .result-banner > div:first-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.app-shell .mode-context strong {
  color: var(--gx-accent-soft);
  font-size: 12px;
  font-weight: 750;
}

.app-shell .mode-context span:not(.context-dot) {
  overflow: hidden;
  color: var(--gx-faint);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .daily-best {
  display: flex;
  min-width: 118px;
  margin-left: auto;
  padding: 6px 12px;
  border-left: 1px solid var(--gx-line);
  flex-direction: column;
  text-align: right;
}

.app-shell .daily-best span {
  color: var(--gx-faint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-shell .daily-best strong {
  color: var(--gx-muted);
  font-size: 12px;
}

.app-shell .daily-best.complete strong {
  color: var(--gx-accent-soft);
}

/* ---------- streak & week strip ---------- */

.app-shell .streak-row {
  gap: 16px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--gx-line);
  border-radius: 16px;
  background: var(--gx-well);
}

.app-shell .streak-copy {
  display: flex;
  min-width: 132px;
  flex-direction: column;
}

.app-shell .streak-copy span {
  color: var(--gx-faint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-shell .streak-copy strong {
  color: var(--gx-text);
  font-size: 18px;
}

.app-shell .streak-copy p {
  margin: 2px 0 0;
  color: var(--gx-muted);
  font-size: 11px;
}

.app-shell .week-strip {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.app-shell .week-day {
  display: flex;
  min-height: 56px;
  padding: 7px 4px;
  border: 1px solid var(--gx-line);
  border-radius: 12px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--gx-faint);
  background: var(--gx-chip);
}

.app-shell .week-day span {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-shell .week-day i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--gx-faint) 45%, var(--gx-bg));
  font-style: normal;
}

.app-shell .week-day.completed {
  color: var(--gx-accent-soft);
  background: color-mix(in srgb, var(--gx-accent) 10%, transparent);
}

.app-shell .week-day.completed i {
  background: var(--gx-accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--gx-accent) 55%, transparent);
}

.app-shell .week-day.today {
  border-color: color-mix(in srgb, var(--gx-accent) 38%, transparent);
}

.app-shell .week-day.missed i {
  background: color-mix(in srgb, var(--gx-lose) 30%, var(--gx-bg));
}

/* ---------- controls & status ---------- */

.app-shell .control-row {
  justify-content: space-between;
  gap: 18px;
  margin: 18px 0;
}

.app-shell .difficulty-picker {
  display: flex;
  flex: 1;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--gx-line);
  border-radius: 14px;
  background: var(--gx-chip);
}

.app-shell .difficulty-picker button {
  min-width: 86px;
  min-height: 52px;
  padding: 5px 12px;
  border-radius: 10px;
  flex: 1;
}

.app-shell .difficulty-picker button span {
  display: block;
  margin-top: 1px;
  color: var(--gx-faint);
  font-size: 9px;
  font-weight: 650;
}

.app-shell .status-strip {
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--gx-line);
  border-radius: 18px;
  background: var(--gx-well);
}

.app-shell .status-copy {
  display: flex;
  min-width: 0;
  margin-right: auto;
  align-items: center;
  gap: 12px;
}

.app-shell .status-signal {
  position: relative;
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gx-faint);
}

.app-shell .status-signal::after {
  position: absolute;
  inset: -5px;
  border: 1px solid currentColor;
  border-radius: inherit;
  content: "";
  opacity: 0.18;
}

.app-shell .status-playing {
  color: var(--gx-accent);
  background: currentColor;
  box-shadow: 0 0 18px color-mix(in srgb, var(--gx-accent) 55%, transparent);
  animation: nx-signal-pulse 1.8s ease-in-out infinite;
}

.app-shell .status-won {
  color: var(--gx-win);
  background: currentColor;
}

.app-shell .status-lost {
  color: var(--gx-lose);
  background: currentColor;
}

.app-shell .status-copy div {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.app-shell .status-copy strong {
  color: var(--gx-text);
  font-size: 13px;
}

.app-shell .status-copy span:last-child {
  overflow: hidden;
  max-width: 460px;
  color: var(--gx-faint);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell .metric {
  display: flex;
  min-width: 76px;
  min-height: 50px;
  padding: 6px 12px;
  border-left: 1px solid var(--gx-line);
  flex-direction: column;
  justify-content: center;
  text-align: right;
}

.app-shell .metric span {
  color: var(--gx-faint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-shell .metric strong {
  color: var(--gx-text-strong);
  font-family: var(--mono);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

/* ---------- layout ---------- */

.app-shell .play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--gx-side);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.app-shell .board-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.app-shell .board-scroll {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: auto;
  padding: 6px;
}

.app-shell .board-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.app-shell .side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-shell .help-card {
  padding: 12px 14px;
  border: 1px solid var(--gx-line);
  border-radius: 14px;
  color: var(--gx-muted);
  background: var(--gx-chip);
  font-size: 11px;
  line-height: 1.45;
}

.app-shell .help-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--gx-accent-soft);
  font-size: 11px;
}

.app-shell .tool-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.app-shell .tool-list span {
  white-space: nowrap;
}

.app-shell .legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.app-shell .legend-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--gx-bg);
  box-shadow: 0 0 0 2px currentColor;
}

/* ---------- result ---------- */

.app-shell .result-banner {
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--gx-win) 18%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--gx-win) 8%, transparent);
}

.app-shell .result-banner.lost {
  border-color: color-mix(in srgb, var(--gx-lose) 20%, transparent);
  background: color-mix(in srgb, var(--gx-lose) 7%, transparent);
}

.app-shell .result-banner span {
  color: color-mix(in srgb, var(--gx-win) 45%, var(--gx-muted));
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.app-shell .result-banner.lost span {
  color: color-mix(in srgb, var(--gx-lose) 45%, var(--gx-muted));
}

.app-shell .result-banner strong {
  color: color-mix(in srgb, var(--gx-win) 14%, var(--gx-text-strong));
  font-size: 13px;
}

.app-shell .result-banner.lost strong {
  color: color-mix(in srgb, var(--gx-lose) 14%, var(--gx-text-strong));
}

.app-shell .result-actions {
  display: flex;
  gap: 8px;
}

.app-shell .result-actions button {
  min-height: 38px;
  padding: 0 13px;
}

.app-shell .share-status {
  min-height: 17px;
  margin: 2px 0 0;
  color: var(--gx-accent-soft);
  font-size: 10px;
  text-align: right;
}

/* ---------- footer & kbd ---------- */

.app-shell .game-footer {
  justify-content: center;
  gap: 22px;
  margin-top: 16px;
  color: var(--gx-faint);
  font-size: 10px;
}

.app-shell .game-footer span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-shell kbd {
  padding: 2px 6px;
  border: 1px solid color-mix(in srgb, var(--gx-accent) 12%, transparent);
  border-radius: 5px;
  color: var(--gx-accent);
  background: var(--gx-chip);
  font-family: inherit;
  font-size: 9px;
}

@keyframes nx-signal-pulse {
  50% { box-shadow: 0 0 25px color-mix(in srgb, var(--gx-accent) 80%, transparent); }
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .app-shell .play-layout {
    grid-template-columns: 1fr;
  }

  .app-shell .side-panel {
    max-width: 420px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px 10px;
    place-items: start center;
  }

  .app-shell .game-panel {
    padding: 22px 14px;
    border-radius: 24px;
  }

  .app-shell .hero {
    align-items: flex-start;
  }

  .app-shell .icon-button.restart {
    min-width: 46px;
    padding: 0 13px;
  }

  .app-shell .mode-row,
  .app-shell .control-row,
  .app-shell .streak-row {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell .mode-picker,
  .app-shell .daily-best,
  .app-shell .difficulty-picker {
    width: 100%;
  }

  .app-shell .daily-best {
    margin: 0;
    padding: 5px 8px;
    border-top: 1px solid var(--gx-line);
    border-left: 0;
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }

  .app-shell .difficulty-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .app-shell .difficulty-picker button {
    min-width: 0;
    padding: 5px;
  }

  .app-shell .status-strip {
    flex-wrap: wrap;
  }

  .app-shell .status-copy {
    width: 100%;
    padding: 4px 3px 7px;
  }

  .app-shell .status-copy span:last-child {
    white-space: normal;
  }

  .app-shell .metric {
    min-width: 0;
    flex: 1;
    border-top: 1px solid var(--gx-line);
    border-left: 0;
    text-align: left;
  }

  .app-shell .result-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell .result-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .app-shell .game-footer {
    gap: 10px 16px;
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .status-playing {
    animation: none;
  }
  .app-shell .icon-button,
  .app-shell .ghost-button,
  .app-shell .result-actions button,
  .app-shell .mode-picker button,
  .app-shell .difficulty-picker button {
    transition: none;
  }
}
