:root {
  --bg: #03070d;
  --panel: #081723;
  --panel-2: #0d2231;
  --text: #f3fbff;
  --muted: #91a9b6;
  --cyan: #22d6f7;
  --violet: #a06bff;
  --lime: #9cff5f;
  --orange: #ffad42;
  --magenta: #ff4fc8;
  --amber: #ffd166;
  --red: #ff4d35;
  --gap: clamp(5px, 1.6vw, 8px);
  --node-radius: 11px;
  --board-size: min(92vw, 58vh, 520px);
  --anim-fast: 160ms;
  --anim-med: 240ms;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(34, 214, 247, 0.22), transparent 30rem),
    radial-gradient(circle at 10% 100%, rgba(255, 79, 200, 0.13), transparent 24rem),
    linear-gradient(160deg, #020509 0%, #07101a 48%, #050912 100%);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
.node:focus-visible,
input:focus-visible + span {
  outline: 3px solid rgba(34, 214, 247, 0.7);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100dvh;
  padding: calc(14px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  display: grid;
  place-items: center;
  position: relative;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: #03070d;
  text-align: center;
}

.loading-screen.is-active {
  display: grid;
}

.loading-screen h1,
.brand-lockup h1 {
  margin: 0;
  font-size: clamp(2.3rem, 12vw, 5.4rem);
  line-height: 0.9;
  text-transform: uppercase;
  letter-spacing: 0;
}

.loading-screen p,
.brand-lockup p,
.offline-note {
  margin: 0;
  color: var(--muted);
}

.brand-mark {
  width: 96px;
  height: 54px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: center;
}

.brand-mark span {
  display: block;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(34, 214, 247, 0.7);
  background: linear-gradient(180deg, rgba(34, 214, 247, 0.45), rgba(160, 107, 255, 0.18));
  box-shadow: 0 0 26px rgba(34, 214, 247, 0.35);
  animation: pulseBar 950ms ease-in-out infinite alternate;
}

.brand-mark span:nth-child(2) {
  height: 50px;
  animation-delay: 110ms;
}

.brand-mark span:nth-child(3) {
  animation-delay: 220ms;
}

.game-frame {
  width: min(100%, 560px);
  min-height: min(820px, calc(100dvh - 24px));
  border: 1px solid rgba(145, 169, 182, 0.18);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(8, 23, 35, 0.92), rgba(5, 13, 22, 0.94));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.menu-screen,
.game-screen {
  min-height: min(820px, calc(100dvh - 24px));
}

.menu-content {
  min-height: inherit;
  padding: clamp(22px, 7vw, 42px);
  display: grid;
  align-content: center;
  gap: 22px;
  text-align: center;
}

.brand-lockup {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 46px;
  border-radius: 8px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 800;
  transition: transform var(--anim-fast) ease, filter var(--anim-fast) ease, border-color var(--anim-fast) ease;
}

.primary-button {
  width: 100%;
  background: linear-gradient(135deg, var(--cyan), #4c8cff 55%, var(--violet));
  box-shadow: 0 12px 34px rgba(34, 214, 247, 0.22);
}

.ghost-button,
.icon-button {
  background: rgba(145, 169, 182, 0.08);
  border: 1px solid rgba(145, 169, 182, 0.2);
}

.primary-button:active,
.ghost-button:active,
.icon-button:active {
  transform: scale(0.98);
}

.primary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled {
  cursor: default;
  opacity: 0.62;
  transform: none;
}

.menu-actions,
.settings-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-row.compact {
  margin: 4px 0;
}

.ghost-button {
  padding: 0 18px;
}

.menu-stats {
  display: grid;
  gap: 3px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 800;
}

.menu-stats strong {
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
}

.ad-status {
  margin: 0;
  min-height: 20px;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.toggle {
  position: relative;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid rgba(145, 169, 182, 0.22);
  color: var(--muted);
  background: rgba(145, 169, 182, 0.07);
  font-size: 0.86rem;
  font-weight: 800;
}

.toggle input:checked + span {
  border-color: rgba(34, 214, 247, 0.7);
  color: var(--text);
  background: rgba(34, 214, 247, 0.16);
}

.game-screen {
  padding: clamp(12px, 3vw, 18px);
  display: none;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 12px;
}

.game-screen.is-active {
  display: grid;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 48px;
  gap: 10px;
  align-items: stretch;
}

.sponsor-strip {
  min-height: 38px;
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(0, 1.22fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 209, 102, 0.08);
  border: 1px dashed rgba(255, 209, 102, 0.32);
}

.sponsor-strip span,
.ad-label {
  color: var(--amber);
  font-size: 0.66rem;
  font-weight: 950;
  text-transform: uppercase;
}

.sponsor-strip strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 0.82rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-block {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-block span,
.heat-copy span {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.69rem;
  font-weight: 900;
}

.stat-block strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: clamp(1.2rem, 6vw, 2rem);
  line-height: 1.05;
  text-overflow: ellipsis;
}

.icon-button {
  width: 48px;
  min-height: 48px;
}

.heat-panel {
  padding: 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(145, 169, 182, 0.16);
}

.heat-copy {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.heat-copy strong {
  font-size: 1.1rem;
}

.heat-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(145, 169, 182, 0.12);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45);
}

.heat-meter span {
  display: block;
  width: 15%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--lime));
  transition: width 260ms ease, background 260ms ease, box-shadow 260ms ease;
}

.heat-panel.elevated .heat-meter span {
  background: linear-gradient(90deg, var(--lime), var(--amber));
}

.heat-panel.critical .heat-meter span {
  background: linear-gradient(90deg, var(--amber), var(--orange));
  box-shadow: 0 0 18px rgba(255, 173, 66, 0.55);
}

.heat-panel.imminent .heat-meter span,
.heat-panel.shutdown .heat-meter span {
  background: linear-gradient(90deg, var(--orange), var(--red));
  box-shadow: 0 0 24px rgba(255, 77, 53, 0.68);
}

.game-screen.high-heat {
  animation: warningPulse 950ms ease-in-out infinite;
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: var(--board-size);
  align-self: center;
}

.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 18px;
  background:
    linear-gradient(rgba(34, 214, 247, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 214, 247, 0.08) 1px, transparent 1px),
    rgba(0, 0, 0, 0.26);
  background-size: 32px 32px;
  border: 1px solid rgba(34, 214, 247, 0.22);
  box-shadow: inset 0 0 34px rgba(0, 0, 0, 0.52), 0 16px 36px rgba(0, 0, 0, 0.34);
  touch-action: none;
}

.board.deadlock .node {
  animation: deadlock 420ms ease-in-out 2;
}

.node {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  border-radius: var(--node-radius);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 0 14px var(--node-glow);
  transform: translateZ(0);
  transition: transform var(--anim-fast) ease, box-shadow var(--anim-fast) ease, filter var(--anim-fast) ease;
  color: var(--node-color);
}

.node::before,
.mini-node::before {
  content: "";
  position: absolute;
  inset: 23%;
  margin: auto;
  background: currentColor;
  box-shadow: 0 0 18px currentColor;
}

.node::after {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 25%, rgba(255, 255, 255, 0.28), transparent 34%);
  pointer-events: none;
}

.node.is-selected {
  z-index: 2;
  transform: scale(1.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 0 0 3px rgba(255, 255, 255, 0.2), 0 0 28px var(--node-glow);
}

.node.is-clearing {
  animation: discharge 250ms ease forwards;
}

.node.is-new {
  animation: dropIn 260ms cubic-bezier(.2,.8,.2,1.15);
}

.node.is-invalid {
  animation: invalidSwap 320ms ease;
}

.node.is-special {
  border-color: rgba(255, 255, 255, 0.48);
}

.node.is-special .special-mark {
  position: absolute;
  inset: auto 12% 12% auto;
  width: 22%;
  height: 22%;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 13px #fff;
}

.node.is-special[data-special-direction="column"] .special-mark {
  width: 14%;
  height: 34%;
}

.node.is-special[data-special-direction="row"] .special-mark {
  width: 34%;
  height: 14%;
}

.type-cyan { --node-color: var(--cyan); --node-glow: rgba(34, 214, 247, 0.45); }
.type-violet { --node-color: var(--violet); --node-glow: rgba(160, 107, 255, 0.45); }
.type-lime { --node-color: var(--lime); --node-glow: rgba(156, 255, 95, 0.42); }
.type-orange { --node-color: var(--orange); --node-glow: rgba(255, 173, 66, 0.45); }
.type-magenta { --node-color: var(--magenta); --node-glow: rgba(255, 79, 200, 0.45); }

.shape-circle::before {
  border-radius: 50%;
}

.shape-diamond::before {
  transform: rotate(45deg);
  border-radius: 3px;
}

.shape-triangle::before {
  inset: 20% 21%;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.shape-hexagon::before {
  clip-path: polygon(25% 4%, 75% 4%, 100% 50%, 75% 96%, 25% 96%, 0 50%);
}

.shape-cross::before {
  clip-path: polygon(36% 0, 64% 0, 64% 36%, 100% 36%, 100% 64%, 64% 64%, 64% 100%, 36% 100%, 36% 64%, 0 64%, 0 36%, 36% 36%);
}

.run-status {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.combo-indicator,
.tutorial-tip,
.floating-score {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.combo-indicator {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text);
  font-size: clamp(1.1rem, 5vw, 1.8rem);
  font-weight: 950;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(34, 214, 247, 0.7);
  opacity: 0;
}

.combo-indicator.show {
  animation: comboPop 800ms ease forwards;
}

.tutorial-tip {
  left: 50%;
  bottom: calc(100% + 10px);
  width: min(92vw, 360px);
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(3, 7, 13, 0.92);
  border: 1px solid rgba(34, 214, 247, 0.35);
  color: var(--text);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.floating-score {
  color: var(--text);
  font-weight: 950;
  text-shadow: 0 0 14px rgba(34, 214, 247, 0.85);
  animation: scoreFloat 800ms ease forwards;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(1, 4, 9, 0.72);
  backdrop-filter: blur(8px);
}

.is-hidden {
  display: none !important;
}

.panel {
  width: min(100%, 400px);
  max-height: min(86dvh, 720px);
  overflow: auto;
  padding: 22px;
  display: grid;
  gap: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(13, 34, 49, 0.98), rgba(5, 13, 22, 0.98));
  border: 1px solid rgba(34, 214, 247, 0.22);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
}

.panel h2 {
  margin: 0;
  font-size: clamp(1.7rem, 8vw, 2.5rem);
  line-height: 0.95;
  text-transform: uppercase;
}

.panel p {
  margin: 0;
  color: var(--muted);
}

.help-panel ul {
  margin: 0;
  padding-left: 20px;
  color: #d8e9ef;
}

.help-panel li + li {
  margin-top: 8px;
}

.example-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 0;
}

.mini-node {
  position: relative;
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--node-color);
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 14px var(--node-glow);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  margin: 0;
}

.results-grid dt {
  color: var(--muted);
}

.results-grid dd {
  margin: 0;
  font-weight: 900;
}

.new-best {
  color: var(--lime) !important;
  font-weight: 900;
  text-transform: uppercase;
}

.ad-panel,
.purchase-panel {
  width: min(100%, 430px);
}

.ad-panel {
  text-align: center;
}

.ad-label {
  justify-self: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.28);
}

.ad-creative {
  min-height: 128px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.18), rgba(34, 214, 247, 0.08)),
    rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.ad-creative span {
  display: block;
  min-height: 58px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--amber), var(--orange));
  box-shadow: 0 0 22px rgba(255, 173, 66, 0.35);
  animation: adMeter 900ms ease-in-out infinite alternate;
}

.ad-creative span:nth-child(2) {
  min-height: 92px;
  background: linear-gradient(180deg, var(--cyan), #4c8cff);
  animation-delay: 120ms;
}

.ad-creative span:nth-child(3) {
  min-height: 72px;
  background: linear-gradient(180deg, var(--lime), var(--cyan));
  animation-delay: 240ms;
}

.overlay[data-variant="2"] .ad-creative span:nth-child(1) {
  background: linear-gradient(180deg, var(--magenta), var(--violet));
}

.overlay[data-variant="3"] .ad-creative span:nth-child(2) {
  background: linear-gradient(180deg, var(--red), var(--amber));
}

.ad-disclaimer {
  font-size: 0.82rem;
}

.purchase-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.purchase-grid dt {
  color: var(--muted);
}

.purchase-grid dd {
  margin: 0;
  color: var(--text);
  font-weight: 900;
}

@keyframes pulseBar {
  from { opacity: 0.55; transform: scaleY(0.82); }
  to { opacity: 1; transform: scaleY(1); }
}

@keyframes warningPulse {
  50% { filter: drop-shadow(0 0 12px rgba(255, 77, 53, 0.25)); }
}

@keyframes discharge {
  35% { transform: scale(1.12); filter: brightness(1.85); }
  100% { transform: scale(0.15) rotate(9deg); opacity: 0; filter: brightness(2.2); }
}

@keyframes dropIn {
  from { transform: translateY(-36%) scale(0.86); opacity: 0.3; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes invalidSwap {
  20% { transform: translateX(7%); }
  45% { transform: translateX(-7%); }
  70% { transform: translateX(4%); }
}

@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -8px) scale(0.9); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -18px) scale(1); }
}

@keyframes scoreFloat {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -42px) scale(1); }
}

@keyframes deadlock {
  50% { filter: brightness(1.8); transform: scale(0.94); }
}

@keyframes adMeter {
  from { transform: scaleY(0.78); filter: brightness(0.9); }
  to { transform: scaleY(1); filter: brightness(1.15); }
}

@media (max-width: 420px) {
  .sponsor-strip {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .sponsor-strip strong {
    text-align: left;
  }
}

@media (max-height: 710px) {
  :root {
    --board-size: min(91vw, 51vh, 500px);
  }

  .menu-content {
    gap: 14px;
  }

  .game-screen {
    gap: 8px;
  }

  .heat-panel,
  .stat-block {
    padding: 8px 10px;
  }
}

@media (min-width: 760px) {
  .app-shell {
    padding: 28px;
  }
}

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

.manual-reduced-effects *,
.manual-reduced-effects *::before,
.manual-reduced-effects *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
}
