/*
 * Chain Reaction Puzzle — Game Anything
 * Shell: /play/shared/ga-casual-shell.css · scope: .ga-casual-scope on #cr-app
 * AI: emit levels as JSON (see js/schema.js); theme via --cr-* on .cr-app
 */
:root {
  --cr-bg0: #070b14;
  --cr-bg1: #111b2d;
  --cr-panel: rgba(15, 23, 42, 0.78);
  --cr-border: rgba(56, 189, 248, 0.22);
  --cr-text: #f1f5f9;
  --cr-muted: #94a3b8;
  --cr-accent: #3b82f6;
  --cr-accent2: #38bdf8;
  --cr-radius: 20px;
  --cr-shadow: 0 24px 56px rgba(2, 6, 23, 0.55);
}

.ga-casual-scope.cr-app {
  --cr-bg0: var(--ga-bg-abyss);
  --cr-bg1: var(--ga-bg-mid);
  --cr-panel: var(--ga-surface);
  --cr-border: var(--ga-border);
  --cr-text: var(--ga-text);
  --cr-muted: var(--ga-muted);
  --cr-accent: var(--ga-blue);
  --cr-accent2: var(--ga-sky);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: #000000;
  color: var(--cr-text);
  font-family: Outfit, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

code {
  font-size: 0.88em;
  color: var(--cr-accent2);
  background: rgba(56, 189, 248, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.cr-app {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: 100dvh;
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
}

/* Play chrome: out of flow like block-puzzle (menu overlay sits above; no in-flow min-height stretch) */
.cr-game-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  box-sizing: border-box;
  padding: 0;
  transition:
    opacity 0.35s ease,
    filter 0.35s ease;
}

.cr-game-layer--backdrop {
  opacity: 0.4;
  filter: saturate(0.88) brightness(0.94);
  pointer-events: none;
}

.cr-game-layer--playing {
  opacity: 1;
  filter: none;
  pointer-events: auto;
}

/* Menu / levels / daily: maze-style scrim + setting box only */
.cr-ui-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0px, env(safe-area-inset-top)) max(0px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
  background: rgba(2, 6, 23, 0.4);
  backdrop-filter: blur(10px) saturate(1.05);
  -webkit-backdrop-filter: blur(10px) saturate(1.05);
}

.cr-ui-overlay[hidden] {
  display: none !important;
}

.cr-ui-overlay-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.cr-ui-overlay-stack--wide {
  max-width: min(440px, 100%);
}

.cr-ui-overlay[data-cr-screen="menu"] .ga-game-setting-box.cr-menu-setting {
  width: min(var(--ga-puzzle-menu-max), 100%);
  max-width: min(var(--ga-puzzle-menu-max), 100%);
}

/* Level select — single-column list, full-width header (matches in-game level picker pattern) */
.cr-levels-setting.ga-game-setting-box {
  align-items: stretch;
  text-align: left;
  width: 100%;
  max-width: min(440px, 100%);
  padding: 24px 22px 22px;
  background: linear-gradient(165deg, rgba(12, 18, 36, 0.97) 0%, rgba(6, 10, 22, 0.98) 100%);
  border: 1px solid rgba(56, 189, 248, 0.32);
  box-shadow:
    0 24px 56px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.ga-casual-scope .ga-game-setting-box.cr-levels-setting .cr-levels-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 4.2vw, 1.65rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #f8fafc;
  text-shadow: 0 2px 16px rgba(56, 189, 248, 0.2);
}

.cr-levels-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(100, 116, 139, 0.22);
}

.cr-btn-menu-pill {
  flex-shrink: 0;
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(15, 23, 42, 0.75);
}

.cr-btn-menu-pill:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(56, 189, 248, 0.5);
}

.cr-ui-overlay[data-cr-screen="daily"] .ga-game-setting-box h2 {
  margin: 0 0 10px;
  font-size: clamp(1.1rem, 3.2vw, 1.35rem);
  font-weight: 700;
  line-height: 1.25;
  text-shadow: none;
  letter-spacing: normal;
}

.cr-panel {
  background: var(--cr-panel);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius);
  padding: clamp(24px, 5.5vw, 32px) clamp(22px, 5vw, 28px);
  box-shadow: var(--cr-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px);
}

.cr-panel-wide {
  padding-bottom: 16px;
}

.cr-kicker {
  margin: 0 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--cr-accent2);
}

.cr-lead {
  margin: 0 0 18px;
  line-height: 1.55;
  color: var(--cr-muted);
  font-size: 0.98rem;
}

.cr-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 11px;
  margin-bottom: 8px;
}

.cr-btn {
  appearance: none;
  border: 1px solid var(--cr-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--cr-text);
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  min-height: 48px;
  padding: 14px 16px;
  border-radius: 14px;
  cursor: pointer;
  transition:
    transform 0.2s cubic-bezier(0.34, 1.18, 0.64, 1),
    box-shadow 0.3s ease,
    border-color 0.25s ease,
    background 0.25s ease;
}

.cr-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(56, 189, 248, 0.32);
}

.cr-btn:active {
  transform: scale(0.98);
}

.cr-btn-primary {
  border-color: rgba(37, 99, 235, 0.55);
  background: linear-gradient(135deg, #2563eb, var(--cr-accent) 50%, var(--cr-accent2));
  color: #fff;
  box-shadow: 0 10px 32px rgba(37, 99, 235, 0.42);
}

.cr-btn-primary:hover {
  box-shadow: 0 14px 38px rgba(37, 99, 235, 0.5);
}

.cr-btn-ghost {
  background: transparent;
}

.cr-btn-sm {
  padding: 10px 12px;
  font-size: 0.88rem;
  min-height: 40px;
}

.cr-level-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(62vh, 520px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px 4px 10px 2px;
  margin-right: -2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.55) rgba(30, 41, 59, 0.95);
}

.cr-level-list::-webkit-scrollbar {
  width: 10px;
}

.cr-level-list::-webkit-scrollbar-track {
  background: rgba(30, 41, 59, 0.95);
  border-radius: 999px;
}

.cr-level-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
  border: 2px solid rgba(30, 41, 59, 0.95);
}

.cr-level-list::-webkit-scrollbar-thumb:hover {
  background: rgba(186, 198, 214, 0.55);
}

.cr-level-list-item {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cr-level-card {
  position: relative;
  width: 100%;
  text-align: left;
  padding: 18px 16px 14px;
  min-height: 88px;
  border-radius: 16px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  background: rgba(15, 23, 42, 0.72);
  cursor: pointer;
  font-family: inherit;
  color: var(--cr-text);
  transition:
    transform 0.18s cubic-bezier(0.34, 1.18, 0.64, 1),
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    background 0.22s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.cr-level-card:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(22, 33, 62, 0.88);
  box-shadow:
    0 10px 28px rgba(2, 6, 23, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.cr-level-card:active {
  transform: scale(0.99);
}

.cr-level-card:focus-visible {
  outline: 2px solid var(--cr-accent2);
  outline-offset: 2px;
}

.cr-lv-num {
  position: absolute;
  top: 14px;
  left: 16px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--cr-accent2);
  letter-spacing: 0.04em;
  line-height: 1;
}

.cr-lv-title {
  display: block;
  font-weight: 700;
  font-size: clamp(0.98rem, 2.8vw, 1.08rem);
  text-align: center;
  padding: 2px 36px 0;
  line-height: 1.3;
  color: #f8fafc;
}

.cr-lv-stars {
  display: block;
  margin-top: 12px;
  font-size: 0.92rem;
  letter-spacing: 0.18em;
  color: #e2e8f0;
  text-shadow: 0 0 14px rgba(56, 189, 248, 0.15);
}

.cr-muted {
  color: var(--cr-muted);
  line-height: 1.5;
}

.cr-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.cr-game-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* Top HUD — logic-puzzle style: one row, chips + toolbar (scroll if needed) */
.cr-hud {
  --cr-hud-pad-x: clamp(14px, 4vw, 20px);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-sizing: border-box;
  width: calc(100% + 2 * var(--cr-hud-pad-x));
  max-width: none;
  margin-left: calc(-1 * var(--cr-hud-pad-x));
  margin-right: calc(-1 * var(--cr-hud-pad-x));
  padding: 9px max(12px, var(--cr-hud-pad-x));
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.62);
  border: 1px solid rgba(148, 163, 184, 0.24);
  box-shadow: 0 10px 18px rgba(2, 6, 23, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.5) transparent;
}

.cr-hud::-webkit-scrollbar {
  height: 5px;
}

.cr-hud::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.45);
  border-radius: 999px;
}

.cr-hud-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.cr-hud-chip {
  font-size: 12px;
  color: #cbd5e1;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(125, 211, 252, 0.28);
}

.cr-hud-chip-l {
  color: var(--cr-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.65rem;
}

.cr-hud-chip strong {
  color: #f8fafc;
  font-weight: 800;
}

.cr-hud-chip-goal {
  color: var(--cr-accent2);
  font-weight: 600;
  max-width: 100%;
  white-space: nowrap;
}

.cr-hud-actions,
.cr-toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* Match logic-puzzle .lp-tool / .lp-tool-hud / .lp-hud-icon */
.cr-tool {
  appearance: none;
  margin: 0;
  font: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--cr-text);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color 0.2s ease,
    background 0.2s ease;
}

.cr-tool:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.cr-tool.cr-tool-hud {
  min-height: 0;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 10px;
}

.cr-tool-ghost {
  background: transparent;
}

.cr-icon-btn {
  appearance: none;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--cr-text);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.cr-icon-btn:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.cr-hud-icon {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 0.95rem;
}

@media (max-width: 520px) {
  .cr-toolbar {
    justify-content: flex-start;
  }
}

.cr-game-host {
  width: 100%;
  min-height: min(88vw, 500px);
  max-height: min(70vh, 520px);
  border-radius: 18px;
  overflow: hidden;
  background: #050508;
  border: 1px solid rgba(148, 163, 184, 0.24);
  box-shadow: 0 14px 36px rgba(2, 6, 23, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.cr-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.cr-modal-panel h3 {
  font-size: 1.35rem;
}

.cr-ui-overlay:not([hidden]) .ga-game-setting-box {
  animation: cr-panel-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.cr-ui-overlay:not([hidden])[data-cr-screen="menu"] .ga-game-setting-box {
  animation: none;
}

@keyframes cr-panel-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cr-ui-overlay:not([hidden]) .ga-game-setting-box {
    animation: none;
  }
}

.cr-modal[hidden] {
  display: none !important;
}

/*
 * Game Worlds: same play column height as block-puzzle / memory-card.
 * Standalone keeps min-height: 100dvh on .cr-app; embed must fill the fixed shell
 * and let #cr-game-host flex so Phaser matches the available area.
 */
.game-worlds-body .game-worlds-play-shell #cr-app.cr-app {
  flex: 1 1 auto;
  align-self: stretch;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

.game-worlds-body .game-worlds-play-shell .cr-game-layer {
  min-height: 0;
}

.game-worlds-body .game-worlds-play-shell .cr-game-shell {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.game-worlds-body .game-worlds-play-shell .cr-game-host {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: auto;
}
