/* ==========================================================================
   Game: ChromaFlow  (connect matching dots with non-crossing pipes)
   Self-contained — every class is prefixed .cf-. Dark "stage" panel in both
   site themes. Uses site tokens from common.css.
   ========================================================================== */

.cf {
  --cf-bg: #11122a;
  --cf-card: rgba(255, 255, 255, .06);
  --cf-card-hover: rgba(255, 255, 255, .11);
  --cf-line: rgba(255, 255, 255, .12);
  --cf-text: #fff;
  --cf-sub: rgba(255, 255, 255, .72);
  --cf-good: #19c28f;
  --cf-bad: #ff5c8a;
  --cf-warn: #ffb547;
  --cf-accent: var(--hot);

  position: relative;
  margin: 10px 0 40px;
  padding: 36px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(100% 80% at 100% 0%, rgba(34, 211, 238, .22), transparent 55%),
    radial-gradient(90% 80% at 0% 100%, rgba(232, 67, 147, .3), transparent 60%),
    var(--cf-bg);
  color: var(--cf-text);
  isolation: isolate;
  min-height: 520px;
}
:root[data-theme="dark"] .cf { border: 1px solid var(--line); }

/* Decorative flowing ribbon */
.cf::before {
  content: "";
  position: absolute;
  right: -90px;
  bottom: -90px;
  z-index: -1;
  width: 300px;
  height: 300px;
  border: 22px solid transparent;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ff4d5e, #ffd84d, #2ecc71, #22d3ee, #3d7bff, #e84393, #ff4d5e) border-box;
  -webkit-mask: linear-gradient(#000 0 0) padding-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: .22;
  animation: cf-spin 24s linear infinite;
}
@keyframes cf-spin { to { transform: rotate(360deg); } }

.cf-screen[hidden] { display: none !important; }
.cf-screen { animation: cf-fade .35s var(--ease); }
@keyframes cf-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.cf-ico {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */
.cf-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border: 1px solid var(--cf-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--cf-text);
  font: 600 .875rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.cf-ghost:hover { background: var(--cf-card-hover); }
.cf-ghost--danger { color: var(--cf-sub); }
.cf-ghost.is-confirm { border-color: var(--cf-bad); color: var(--cf-bad); }
.cf-ghost .cf-ico--off { display: none; }
.cf-ghost.is-off .cf-ico--on { display: none; }
.cf-ghost.is-off .cf-ico--off { display: block; }

.cf-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--cf-line);
  border-radius: 50%;
  background: var(--cf-card);
  color: var(--cf-text);
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.cf-icon-btn:hover { background: var(--cf-card-hover); }

.cf .btn-pill { min-height: 46px; padding: 11px 24px; }
.cf .btn-pill:not(.btn-pill--hot) { background: var(--brand-soft); color: var(--night); }
.cf button:focus-visible { outline: 3px solid var(--cf-accent); outline-offset: 2px; }

/* ==========================================================================
   Home
   ========================================================================== */
.cf-home__head { display: flex; align-items: flex-start; gap: 22px; max-width: 760px; }
.cf-logo {
  flex: none;
  width: 76px;
  height: 76px;
  padding: 10px;
  border-radius: 20px;
  background: #0a0b1c;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35), inset 0 0 0 1px var(--cf-line);
}
.cf-logo picture, .cf-logo img { display: block; width: 100%; height: 100%; }

.cf-kicker {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 216, 77, .14);
  color: var(--cf-accent);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.cf-title { margin: 0 0 8px; font-size: clamp(2rem, 4.4vw, 3rem); letter-spacing: -.035em; line-height: 1.05; }
.cf-lead { margin: 0; color: var(--cf-sub); }

.cf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 28px 0 26px;
}
.cf-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.cf-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--cf-line);
  border-radius: var(--radius-pill);
  background: var(--cf-card);
}
.cf-chip__label { color: var(--cf-sub); font-size: .78rem; font-weight: 500; }
.cf-chip strong { color: var(--cf-accent); font-size: 1rem; }
.cf-toolbar__actions { display: flex; flex-wrap: wrap; gap: 10px; }

.cf-subtitle { margin: 0 0 14px; font-size: 1rem; letter-spacing: .06em; text-transform: uppercase; color: var(--cf-sub); }

.cf-stages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cf-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 18px;
  border: 1px solid var(--cf-line);
  border-radius: var(--radius-md);
  background: var(--cf-card);
  color: var(--cf-text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease);
}
.cf-stage:hover:not(:disabled) { transform: translateY(-3px); border-color: rgba(255, 216, 77, .55); background: var(--cf-card-hover); }
.cf-stage.is-cleared { border-color: rgba(25, 194, 143, .45); }
.cf-stage.is-locked { cursor: not-allowed; opacity: .5; }
.cf-stage__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cf-stage__num {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--cf-accent);
  color: var(--night);
  font-size: 1.1rem;
  font-weight: 700;
}
.cf-stage.is-locked .cf-stage__num { background: rgba(255, 255, 255, .14); color: var(--cf-text); }
.cf-stage__size {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .08);
  color: var(--cf-sub);
  font-size: .75rem;
  font-weight: 700;
}
.cf-stage__body { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.cf-stage__name { font-size: 1rem; font-weight: 700; line-height: 1.3; }
.cf-stage__blurb { color: var(--cf-sub); font-size: .82rem; line-height: 1.45; }
.cf-stage__bar { display: block; height: 5px; margin-top: 8px; overflow: hidden; border-radius: 5px; background: rgba(255, 255, 255, .1); }
.cf-stage__bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #22d3ee, #2ecc71); }
.cf-stage__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--cf-line);
}
.cf-stage__best { color: var(--cf-sub); font-size: .78rem; font-weight: 600; }

.cf-star { color: rgba(255, 255, 255, .22); font-size: 1.05rem; line-height: 1; }
.cf-star.is-on { color: var(--cf-accent); text-shadow: 0 0 12px rgba(255, 216, 77, .5); }

.cf-noscript { margin: 16px 0 0; padding: 14px 18px; border-radius: var(--radius-sm); background: rgba(255, 92, 138, .15); }

/* ==========================================================================
   Level select
   ========================================================================== */
.cf-levels__head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.cf-levels__head .cf-kicker { margin-bottom: 4px; }
.cf-levels__title { margin: 0; font-size: clamp(1.6rem, 3.4vw, 2.2rem); letter-spacing: -.02em; }
.cf-levels > .cf-lead { margin-bottom: 22px; }

.cf-levelgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cf-level {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--cf-line);
  border-radius: var(--radius-md);
  background: var(--cf-card);
  color: var(--cf-text);
  font-family: var(--font);
  cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease);
}
.cf-level:hover:not(:disabled) { transform: translateY(-3px); border-color: rgba(255, 216, 77, .55); background: var(--cf-card-hover); }
.cf-level.is-solved { border-color: rgba(25, 194, 143, .45); }
.cf-level.is-locked { cursor: not-allowed; opacity: .45; }
.cf-level__mini { display: block; width: 100%; aspect-ratio: 1; height: auto; }
.cf-mini__bg { fill: #0a0b1c; }
.cf-level__meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cf-level__name { font-weight: 700; font-size: .9rem; }
.cf-level__stars .cf-star { font-size: .9rem; }
.cf-level__lock {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -34px 0 0 -22px;
  border-radius: 50%;
  background: rgba(17, 18, 42, .9);
}

/* ==========================================================================
   Play
   ========================================================================== */
.cf-play { position: relative; }
.cf-hud { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 20px; }
.cf-hud__stage {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 216, 77, .14);
  color: var(--cf-accent);
  font-size: .8rem;
  font-weight: 700;
}
.cf-hud__stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-left: auto; }
.cf-stat { display: flex; flex-direction: column; line-height: 1.2; }
.cf-stat__label { color: var(--cf-sub); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.cf-stat strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.cf-arena {
  display: grid;
  grid-template-columns: minmax(0, 540px) minmax(220px, 280px);
  justify-content: center;
  align-items: start;
  gap: 28px;
}
.cf-boardwrap { position: relative; width: 100%; }

.cf-board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .4), 0 0 0 1px var(--cf-line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  outline: none;
}
.cf-board:focus-visible { box-shadow: 0 18px 40px rgba(0, 0, 0, .4), 0 0 0 3px var(--cf-accent); }
.cf-bg { fill: #07081a; }
.cf-l-grid line { stroke: rgba(255, 255, 255, .1); stroke-width: .025; }
.cf-fill { opacity: .14; transition: opacity .2s; }
.cf-fill.is-done { opacity: .26; }
.cf-pipe {
  fill: none;
  stroke-width: .3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .92;
}
.cf-pipe.is-done { opacity: 1; }
.cf-pipe.is-active { stroke-width: .34; }
.cf-pipe.is-hinted { animation: cf-hinted 1s ease-out; }
@keyframes cf-hinted { 0% { stroke-width: .6; opacity: .3; } 100% { stroke-width: .3; opacity: 1; } }

.cf-dot__halo { opacity: 0; transition: opacity .2s; }
.cf-dot.is-done .cf-dot__halo,
.cf-dot.is-active .cf-dot__halo { opacity: .35; }
.cf-dot__num {
  fill: #fff;
  font: 800 .38px/1 var(--font);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.cf-dot__num.is-dark { fill: #10112a; }

.cf-cursor { fill: none; stroke: transparent; stroke-width: .06; pointer-events: none; }
.cf-board:focus-visible .cf-cursor { stroke: rgba(255, 255, 255, .85); stroke-dasharray: .14 .1; }
.cf-board:focus-visible .cf-cursor.is-held { stroke: var(--cf-accent); stroke-dasharray: none; }

.cf-play.is-won .cf-board { animation: cf-win .9s var(--ease); }
.cf-play.is-won .cf-fill { opacity: .3; }
@keyframes cf-win { 40% { transform: scale(1.025); box-shadow: 0 0 0 3px var(--cf-good), 0 0 50px rgba(25, 194, 143, .5); } }

/* Side panel */
.cf-side { display: flex; flex-direction: column; gap: 14px; }
.cf-msg {
  min-height: 48px;
  margin: 0;
  padding: 12px 14px;
  border-left: 4px solid var(--brand-soft);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .07);
  color: var(--cf-sub);
  font-size: .88rem;
  line-height: 1.4;
}
.cf-msg.is-good { border-left-color: var(--cf-good); color: #b6f2dc; }
.cf-msg.is-warn { border-left-color: var(--cf-warn); color: #ffe0b0; }
.cf-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cf-tool {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  padding: 8px 6px;
  border: 1px solid var(--cf-line);
  border-radius: 14px;
  background: var(--cf-card);
  color: var(--cf-text);
  font: 600 .8rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color .2s var(--ease), opacity .2s var(--ease);
}
.cf-tool:hover:not(:disabled) { background: var(--cf-card-hover); }
.cf-tool:disabled { opacity: .4; cursor: not-allowed; }
.cf-tool--hint { border-color: rgba(255, 216, 77, .45); }
.cf-tool--hint .cf-ico { color: var(--cf-accent); }
.cf-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 2px;
  padding: 0 5px;
  border-radius: 9px;
  background: rgba(255, 216, 77, .18);
  color: var(--cf-accent);
  font-size: .7rem;
}
.cf-tip { margin: 0; color: var(--cf-sub); font-size: .82rem; line-height: 1.5; }

/* Pause */
.cf-play.is-paused .cf-arena { filter: blur(14px); pointer-events: none; user-select: none; }
.cf-paused { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px; }
.cf-paused[hidden] { display: none; }
.cf-paused__card {
  max-width: 400px;
  padding: 28px;
  border: 1px solid var(--cf-line);
  border-radius: var(--radius-md);
  background: rgba(17, 18, 42, .95);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  text-align: center;
}
.cf-paused__title { margin: 0 0 6px; font-size: 1.6rem; }
.cf-paused__card p { margin: 0 0 20px; color: var(--cf-sub); font-size: .9rem; }
.cf-paused__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ==========================================================================
   Results
   ========================================================================== */
.cf-result { max-width: 640px; margin: 0 auto; padding: 10px 0; text-align: center; }
.cf-result__stars { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.cf-star--big { font-size: clamp(3rem, 9vw, 4.25rem); opacity: 0; animation: cf-star-in .5s var(--ease) forwards; }
@keyframes cf-star-in {
  from { opacity: 0; transform: scale(.3) rotate(-30deg); }
  to { opacity: 1; transform: none; }
}
.cf-result__title { margin: 0 0 6px; font-size: clamp(1.8rem, 4vw, 2.5rem); }
.cf-result__new {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  background: var(--cf-accent);
  color: var(--night);
  font-size: .8rem;
  font-weight: 700;
}
.cf-result__new[hidden] { display: none; }
.cf-result__text { margin: 0 auto 24px; max-width: 460px; color: var(--cf-sub); }
.cf-result__stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 26px; }
.cf-result__stats div { padding: 14px 8px; border: 1px solid var(--cf-line); border-radius: var(--radius-sm); background: var(--cf-card); }
.cf-result__stats dt { color: var(--cf-sub); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.cf-result__stats dd { margin: 2px 0 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cf-result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.cf-result__actions [hidden] { display: none; }

/* ==========================================================================
   How to play
   ========================================================================== */
.cf-guide { margin: 0 0 56px; }
.cf-guide .section-head__title { margin-bottom: 22px; }
.cf-guide__item {
  height: 100%;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.cf-guide__item h3 { margin: 12px 0 6px; font-size: 1.05rem; }
.cf-guide__item p { margin: 0; color: var(--sub); font-size: .9rem; }
.cf-guide__num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand);
  color: var(--onbrand);
  font-weight: 700;
}
.cf-guide__back { margin: 24px 0 0; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 991.98px) {
  .cf-arena { grid-template-columns: minmax(0, 540px); }
}
@media (max-width: 767.98px) {
  .cf { padding: 24px 20px; min-height: 0; }
  .cf-result__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cf-hud__stats { margin-left: 0; order: 3; width: 100%; justify-content: space-between; }
  .cf-hud .cf-icon-btn { margin-left: auto; }
}
@media (max-width: 575.98px) {
  .cf { margin-left: -4px; margin-right: -4px; padding: 20px 12px; border-radius: var(--radius-md); }
  .cf-home__head { flex-direction: column; gap: 16px; }
  .cf-logo { width: 62px; height: 62px; padding: 8px; }
  .cf-toolbar { flex-direction: column; align-items: stretch; }
  .cf-toolbar__actions .cf-ghost { flex: 1; }
  .cf-stages { grid-template-columns: 1fr; }
  .cf-levelgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cf-hud { margin-bottom: 12px; }
  .cf-arena { gap: 12px; }
  .cf-board { border-radius: 10px; }
  .cf-side { gap: 10px; }
  .cf-msg { min-height: 0; padding: 8px 12px; font-size: .82rem; }
  .cf-tool { min-height: 52px; }
  .cf-tip { font-size: .76rem; }
}
@media (prefers-reduced-motion: reduce) {
  .cf::before, .cf-screen { animation: none; }
  .cf-play.is-won .cf-board, .cf-pipe.is-hinted { animation: none; }
  .cf-star--big { opacity: 1; animation: none; }
}

@media (min-width: 992px) {
  .cf-stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
