:root {
  color-scheme: dark;
  --bg-a: #25122f;
  --bg-b: #101522;
  --panel: rgba(17, 21, 33, 0.84);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text: #f8f5ff;
  --muted: #d1c8e5;
  --accent: #ff6b6b;
  --accent-2: #ffd166;
  --good: #7df0b1;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 107, 107, 0.26), transparent 34%),
    radial-gradient(circle at bottom right, rgba(255, 209, 102, 0.18), transparent 26%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  filter: blur(10px);
  opacity: 0.2;
  pointer-events: none;
}

body::before {
  top: -40px;
  right: -60px;
  background: #ff6b6b;
}

body::after {
  bottom: -70px;
  left: -40px;
  background: #7df0b1;
}

.shell {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 36px;
}

.hero,
.stats,
.panel,
.legend,
.board-section,
.actions,
.support-strip,
.result {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
  align-items: flex-start;
}

.eyebrow,
.stats span,
.label,
.result-label {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.74rem;
  color: var(--accent-2);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.96;
  margin-top: 6px;
}

.subtitle {
  margin-top: 12px;
  max-width: 620px;
  line-height: 1.55;
  color: var(--muted);
}

.hub-link,
.support-strip a,
.card-link,
button {
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

.hub-link,
.support-strip a {
  color: var(--text);
  text-decoration: none;
}

.hub-link {
  white-space: nowrap;
  padding: 14px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.9), rgba(255, 209, 102, 0.9));
  font-weight: 700;
}

.stats {
  margin-top: 16px;
  padding: 16px 20px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats strong {
  font-size: 1.45rem;
}

.panel,
.legend,
.board-section,
.actions,
.support-strip,
.result {
  margin-top: 16px;
}

.panel,
.board-section,
.result {
  padding: 20px;
}

.message {
  font-size: 1rem;
  line-height: 1.5;
}

.goal-grid {
  margin-top: 18px;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.goal-card {
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
}

.goal-card strong {
  display: block;
  margin-top: 8px;
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.goal-card p {
  color: var(--muted);
  line-height: 1.45;
}

.legend {
  padding: 14px 18px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.legend-chip {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-weight: 800;
  color: #131722;
}

.legend-chip.up { background: #7df0b1; }
.legend-chip.right { background: #ffd166; }
.legend-chip.down { background: #7cc8ff; }
.legend-chip.left { background: #ff9ac0; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head p {
  color: var(--muted);
  max-width: 460px;
  line-height: 1.45;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 22px;
}

.cell.empty {
  border: 1px dashed rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.tile {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 22px;
  color: #101522;
  font: inherit;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  background: linear-gradient(180deg, #fff4de, #ffc870);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.15);
}

.tile.can-pop {
  background: linear-gradient(180deg, #d8ffe7, #7df0b1);
  transform: translateY(-2px);
}

.tile.pop-boost {
  animation: pulse 1.1s ease-in-out infinite;
}

.tile.up::after,
.tile.right::after,
.tile.down::after,
.tile.left::after {
  content: attr(data-arrow);
}

.tile:disabled {
  opacity: 0.72;
  cursor: default;
}

.actions {
  padding: 14px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

button {
  border: 0;
  border-radius: 16px;
  padding: 16px 18px;
  font: inherit;
  font-weight: 800;
}

button:hover:not(:disabled),
.hub-link:hover,
.support-strip a:hover {
  transform: translateY(-1px);
}

.primary {
  background: linear-gradient(135deg, var(--accent), #ff8f5c);
  color: white;
}

.hub-link:focus-visible,
.support-strip a:focus-visible,
button:focus-visible,
.tile:focus-visible {
  outline: 3px solid rgba(255, 209, 102, 0.92);
  outline-offset: 3px;
}

.ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

button:disabled {
  opacity: 0.4;
}

.support-strip {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.result {
  text-align: center;
}

.result strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(2rem, 8vw, 3.6rem);
}

.result p {
  margin-top: 10px;
  color: var(--muted);
}

@keyframes pulse {
  0%, 100% { box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.15), 0 0 0 rgba(125, 240, 177, 0.2); }
  50% { box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.15), 0 0 22px rgba(125, 240, 177, 0.4); }
}

@media (max-width: 720px) {
  #viewportState {
    display: inline;
  }

  .shell {
    width: min(100% - 16px, 720px);
    padding-top: 14px;
  }

  .hero,
  .section-head,
  .support-strip {
    flex-direction: column;
    align-items: stretch;
  }

  .stats,
  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .goal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .hero,
  .panel,
  .board-section,
  .result {
    padding: 16px;
  }

  .board {
    gap: 8px;
  }

  .tile {
    border-radius: 18px;
    font-size: 1.8rem;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }
}
