/* ==========================================================================
   Planet Clicker

   The game lives in a fixed-shape box. Everything inside it is sized in
   container units (cqmin, cqw, cqh), so the whole interface scales with the box
   and keeps the same proportions on a phone, a laptop and in full screen.
   ========================================================================== */

[hidden] { display: none !important; }

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

:root {
  --page: #0a0f1d;
  --frame: #141b2d;
  --frame-line: #232c45;
  --text: #f4f7ff;
  --muted: #9aa6c4;
  --accent: #5aa9ff;
  --green-top: #4be58f;
  --green-bottom: #1fb865;
  --green-edge: #13894a;
  --red-top: #ff6f6f;
  --red-bottom: #e03e3e;
  --red-edge: #a42828;
  --card-top: #232b42;
  --card-bottom: #1a2034;
  --line: rgba(255, 255, 255, 0.09);
  --glass: rgba(255, 255, 255, 0.07);
  --glass-line: rgba(255, 255, 255, 0.13);
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  background:
    radial-gradient(1200px 700px at 50% 0%, #16213d 0%, rgba(10, 15, 29, 0) 70%),
    var(--page);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

p, h1, h2, h3, dl, dd { margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ==========================================================================
   The box
   ========================================================================== */

.frame {
  /* As wide as possible, but never taller than the screen. 76px is the bar. */
  width: min(1040px, calc(100vw - 32px), calc((100vh - 32px - 76px) * 4 / 3));
  width: min(1040px, calc(100vw - 32px), calc((100dvh - 32px - 76px) * 4 / 3));
  overflow: hidden;
  background: var(--frame);
  border: 1px solid var(--frame-line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 2px 0 rgba(255, 255, 255, 0.03) inset;
}

.game {
  /* The canvas; the globe itself is 90% of it, the rest is atmosphere. */
  --planet: min(49cqh, 69cqw);
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  container: game / size;
  background: #03050c;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.game:fullscreen {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.game:-webkit-full-screen {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

/* ---- Title bar under the game ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 12px 18px;
  border-top: 1px solid var(--frame-line);
}

.bar-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  padding: 5px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 50%, #0e1a36, #04060d);
  box-shadow: inset 0 0 0 1px var(--glass-line);
}

.bar-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bar-category {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.bar-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.bar-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border-radius: 12px;
  color: #d8def0;
  transition: background-color 0.15s, color 0.15s;
}

.bar-button:hover { background: var(--glass); color: #fff; }

.bar-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==========================================================================
   Space
   ========================================================================== */

.space {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 46%, #0b1633 0%, #050a19 45%, #02040a 100%);
}

.stars {
  position: absolute;
  inset: 0;
}

.stars i {
  position: absolute;
  border-radius: 50%;
  background: #fff;
}

/* ==========================================================================
   Energy counter
   ========================================================================== */

.counter {
  position: absolute;
  top: 4cqmin;
  /* Wide enough to clear the settings button, whose size has a pixel floor. */
  left: max(16cqmin, 64px);
  right: max(16cqmin, 64px);
  z-index: 2;
  text-align: center;
  pointer-events: none;
}

.energy {
  font-size: 8.4cqmin;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.01em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0.5cqmin 2.4cqmin rgba(0, 0, 0, 0.7);
}

/* Big numbers ("1.25 QUADRILLION") step down a size so they still fit. */
.energy.is-long { font-size: 6.2cqmin; }
.energy.is-longer { font-size: 5cqmin; }

.energy-unit {
  margin-left: 0.12em;
  font-size: 0.6em;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #cfd9f2;
}

.rate {
  margin-top: 0.8cqmin;
  font-size: 3.2cqmin;
  font-weight: 600;
  color: #8fd0ff;
  text-shadow: 0 0.3cqmin 1.2cqmin rgba(0, 0, 0, 0.7);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

/* Square glass buttons: settings, sound, stats, close. */
.icon-button {
  display: grid;
  place-items: center;
  width: clamp(40px, 9cqmin, 62px);
  height: clamp(40px, 9cqmin, 62px);
  border-radius: 24%;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--glass-line), 0 0.6cqmin 1.8cqmin rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  transition: background-color 0.15s, transform 0.1s;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.14); }
.icon-button:active { transform: scale(0.94); }

.icon-button svg {
  width: 54%;
  height: 54%;
  fill: currentColor;
}

.close svg,
.nav-arrow svg,
.exit-fullscreen svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-button {
  position: absolute;
  top: 3.2cqmin;
  right: 3.2cqmin;
  z-index: 3;
}

.exit-fullscreen {
  position: absolute;
  top: 3.2cqmin;
  left: 3.2cqmin;
  /* Under the overlays, whose own headers use this corner. */
  z-index: 4;
}

.exit-fullscreen:hover { background: rgba(224, 62, 62, 0.55); }

.side {
  position: absolute;
  top: 50%;
  left: 3.2cqmin;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2.2cqmin;
  transform: translateY(-50%);
}

/* Rounded text buttons: BUY, RESET, CANCEL. */
.button {
  padding: 1.1cqmin 4.4cqmin 1.3cqmin;
  border-radius: 999px;
  font-size: clamp(15px, 4cqmin, 30px);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.2;
  white-space: nowrap;
  color: #fff;
  transition: filter 0.15s, box-shadow 0.1s, background-color 0.15s;
}

.button:hover { filter: brightness(1.07); }

.button-buy {
  background: linear-gradient(180deg, var(--green-top), var(--green-bottom));
  color: #05301a;
  box-shadow: 0 0.6cqmin 0 var(--green-edge), 0 1.2cqmin 2.6cqmin rgba(31, 184, 101, 0.3);
}

.button-buy:active { box-shadow: 0 0.2cqmin 0 var(--green-edge); }

/* Not enough energy: still clickable, but plainly not ready. */
.button-buy.is-poor {
  background: #2a3149;
  color: #7f8aa8;
  box-shadow: 0 0.6cqmin 0 #191e30;
}

.button-danger {
  background: linear-gradient(180deg, var(--red-top), var(--red-bottom));
  box-shadow: 0 0.6cqmin 0 var(--red-edge), 0 1.2cqmin 2.6cqmin rgba(224, 62, 62, 0.28);
}

.button-danger:active { box-shadow: 0 0.2cqmin 0 var(--red-edge); }

.button-quiet {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px var(--glass-line);
}

.shop-button {
  position: absolute;
  right: 3.2cqmin;
  bottom: 3.2cqmin;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 1.4cqmin;
  padding: 1.7cqmin 3.2cqmin 1.7cqmin 2.6cqmin;
  border-radius: 2.4cqmin;
  background: linear-gradient(180deg, #2b3552, #1b2239);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0.8cqmin 2.6cqmin rgba(0, 0, 0, 0.45);
  font-size: clamp(16px, 4.6cqmin, 34px);
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: filter 0.15s, transform 0.1s;
}

.shop-button:hover { filter: brightness(1.15); }
.shop-button:active { transform: scale(0.96); }

.shop-button svg {
  width: 1.15em;
  height: 1.15em;
  fill: currentColor;
}

.is-shaking { animation: shake 0.32s; }

@keyframes shake {
  20% { transform: translateX(-1.2cqmin); }
  60% { transform: translateX(1.2cqmin); }
}

/* ==========================================================================
   Planet
   ========================================================================== */

.stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.planet-wrap {
  position: relative;
  width: var(--planet);
  aspect-ratio: 1;
  margin-top: -1cqh;
}

.halo {
  position: absolute;
  inset: -48%;
  border-radius: 50%;
  pointer-events: none;
  transition: background 0.4s;
}

.planet {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: auto;
  transition: transform 0.12s ease-out;
}

.planet canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.planet:focus-visible { outline-offset: 1cqmin; }

.stage.is-hit .planet { animation: hit 0.14s ease-out; }

@keyframes hit {
  45% { transform: scale(0.955); }
}

.stage.is-locked .planet { cursor: default; }

.lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #0a0e18;
  pointer-events: none;
}

.lock svg {
  width: 32%;
  height: auto;
  fill: currentColor;
  filter: drop-shadow(0 0 1.4cqmin rgba(255, 255, 255, 0.35));
}

.floats {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.float {
  position: absolute;
  font-size: 5cqmin;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 0 1.6cqmin rgba(120, 200, 255, 0.95), 0 0.3cqmin 0.6cqmin rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  animation: rise 0.9s ease-out forwards;
}

@keyframes rise {
  to { transform: translate(-50%, -190%); opacity: 0; }
}

.unlock {
  position: absolute;
  /* Hangs off the bottom of the planet, overlapping its lower edge. */
  top: calc(95% - 4.5cqmin);
  left: 50%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.8cqmin;
  transform: translateX(-50%);
  pointer-events: auto;
}

.unlock .button {
  font-size: clamp(16px, 4.6cqmin, 34px);
  padding-inline: 5.4cqmin;
}

.price {
  font-size: 4.2cqmin;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  text-shadow: 0 0.3cqmin 1.4cqmin rgba(0, 0, 0, 0.8);
}

.price strong { font-weight: 700; color: #ffd66b; }

/* ==========================================================================
   Planet switcher
   ========================================================================== */

.planet-nav {
  position: absolute;
  bottom: 4cqmin;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 1.6cqmin;
  transform: translateX(-50%);
}

.planet-name {
  width: 30cqmin;
  font-size: 7cqmin;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.06em;
  text-align: center;
  text-shadow: 0 0.4cqmin 2cqmin rgba(0, 0, 0, 0.7);
}

.nav-arrow {
  display: grid;
  place-items: center;
  width: clamp(36px, 8cqmin, 56px);
  height: clamp(36px, 8cqmin, 56px);
  border-radius: 50%;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--glass-line);
  color: #fff;
  transition: background-color 0.15s, transform 0.1s;
}

.nav-arrow:hover { background: rgba(255, 255, 255, 0.15); }
.nav-arrow:active { transform: scale(0.92); }

.nav-arrow svg {
  width: 50%;
  height: 50%;
}

/* ==========================================================================
   Overlays
   ========================================================================== */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 3.2cqmin;
  background: rgba(3, 6, 14, 0.8);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: appear 0.18s ease-out;
}

.overlay-solid {
  background: radial-gradient(ellipse 80% 70% at 50% 30%, #0e1731 0%, #050912 70%);
}

@keyframes appear {
  from { opacity: 0; }
}

.overlay-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 2cqmin;
  margin-bottom: 3cqmin;
}

.overlay-title {
  grid-column: 2;
  font-size: 7.6cqmin;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.close {
  grid-column: 3;
  justify-self: end;
}

.wallet {
  grid-column: 1;
  justify-self: start;
  display: flex;
  flex-direction: column;
  padding: 1.2cqmin 2.4cqmin;
  border-radius: 2cqmin;
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--glass-line);
}

.wallet-label {
  font-size: clamp(10px, 2.4cqmin, 16px);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.wallet-value {
  font-size: clamp(15px, 4.2cqmin, 30px);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.panel {
  width: min(100%, 76cqmin);
  margin: 0 auto;
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  border-radius: 2.8cqmin;
  box-shadow: inset 0 0 0 1px var(--line), 0 1.2cqmin 3.6cqmin rgba(0, 0, 0, 0.4);
}

/* ---- shop ---- */

.shop-list {
  flex: 1;
  width: min(100%, 86cqmin);
  margin: 0 auto;
  padding: 0.5cqmin 1.5cqmin 5cqmin;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5.6cqmin;
  scrollbar-width: thin;
  scrollbar-color: #3a4566 transparent;
}

.shop-list::-webkit-scrollbar { width: 8px; }
.shop-list::-webkit-scrollbar-thumb { background: #3a4566; border-radius: 8px; }

.card {
  position: relative;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 3cqmin;
  padding: 3cqmin 3.6cqmin 5.8cqmin;
  border-radius: 2.8cqmin;
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  box-shadow: inset 0 0 0 1px var(--line), 0 1.2cqmin 3cqmin rgba(0, 0, 0, 0.35);
}

.card-name {
  font-size: clamp(16px, 5.2cqmin, 38px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.02em;
}

.card-effect {
  margin-top: 0.8cqmin;
  font-size: clamp(12px, 3.5cqmin, 26px);
  font-weight: 600;
  color: #8fd0ff;
}

.card-owned {
  min-height: 1.3em;
  margin-top: 0.4cqmin;
  font-size: clamp(11px, 2.9cqmin, 21px);
  font-weight: 500;
  color: var(--muted);
}

.card-icon {
  display: grid;
  place-items: center;
  width: 15cqmin;
  height: 15cqmin;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #30406a, #111a2e 75%);
  box-shadow: 0 0 0 max(2px, 0.55cqmin) rgba(255, 255, 255, 0.92), 0 1cqmin 2.6cqmin rgba(0, 0, 0, 0.45);
}

.card-icon svg {
  width: 74%;
  height: 74%;
}

.card-buy {
  position: absolute;
  bottom: 0;
  left: 50%;
  /* `translate`, not `transform`, so the shake animation can use transform. */
  translate: -50% 50%;
}

/* ---- stats ---- */

.stats-list { padding: 0.6cqmin 4.4cqmin; }

.stats-list div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 3cqmin;
  padding: 2.8cqmin 0;
  border-bottom: 1px solid var(--line);
}

.stats-list div:last-child { border-bottom: 0; }

.stats-list dt {
  font-size: clamp(13px, 3.8cqmin, 28px);
  font-weight: 600;
  color: var(--muted);
}

.stats-list dd {
  font-size: clamp(14px, 4.2cqmin, 30px);
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---- settings ---- */

.settings-panel {
  padding: 4.6cqmin 4.4cqmin;
  text-align: center;
}

.panel-title {
  font-size: clamp(17px, 5.2cqmin, 36px);
  font-weight: 700;
}

.panel-text {
  max-width: 58cqmin;
  margin: 1.4cqmin auto 4cqmin;
  font-size: clamp(12px, 3.4cqmin, 24px);
  line-height: 1.4;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2.4cqmin;
}

.settings-rule {
  margin: 5cqmin 0 4cqmin;
  border: 0;
  border-top: 1px solid var(--line);
}

/* ---- leaderboard ---- */

.back {
  grid-column: 1;
  justify-self: start;
}

.back svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lb-input {
  display: block;
  width: min(100%, 52cqmin);
  margin: 0 auto;
  padding: 1.6cqmin 3cqmin;
  border: 0;
  border-radius: 2cqmin;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 0 0 1px var(--glass-line);
  color: var(--text);
  font: inherit;
  font-size: clamp(15px, 4.2cqmin, 30px);
  font-weight: 600;
  text-align: center;
  outline: none;
}

.lb-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.lb-input::placeholder { color: #5f6a88; }

.lb-error {
  min-height: 1.4em;
  margin: 1.4cqmin 0 2.4cqmin;
  font-size: clamp(12px, 3.2cqmin, 22px);
  font-weight: 500;
  color: #ff8a8a;
}

.lb-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: min(100%, 86cqmin);
  margin: 0 auto;
}

.lb-you {
  flex-shrink: 0;
  width: 100%;
  padding: 0 3.6cqmin;
  box-shadow: inset 0 0 0 max(2px, 0.4cqmin) rgba(75, 229, 143, 0.55), 0 1.2cqmin 3.6cqmin rgba(0, 0, 0, 0.4);
}

.lb-status {
  flex-shrink: 0;
  min-height: 1.4em;
  margin: 1.6cqmin 0;
  font-size: clamp(11px, 3cqmin, 21px);
  font-weight: 500;
  text-align: center;
  color: var(--muted);
}

.lb-list {
  flex: 0 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 0 3.6cqmin;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #3a4566 transparent;
}

.lb-list::-webkit-scrollbar { width: 8px; }
.lb-list::-webkit-scrollbar-thumb { background: #3a4566; border-radius: 8px; }

.lb-row {
  display: grid;
  grid-template-columns: 9cqmin 1fr auto;
  align-items: baseline;
  gap: 2cqmin;
  padding: 2.2cqmin 0;
  border-bottom: 1px solid var(--line);
}

.lb-list .lb-row:last-child,
.lb-you .lb-row { border-bottom: 0; }

.lb-rank {
  font-size: clamp(13px, 3.8cqmin, 28px);
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lb-row.is-top .lb-rank { color: #ffd66b; }

.lb-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(14px, 4cqmin, 29px);
  font-weight: 600;
}

.lb-row.is-you .lb-name { color: var(--green-top); }

.lb-score {
  font-size: clamp(13px, 3.8cqmin, 28px);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Tall screens (phones held upright): the box becomes portrait
   ========================================================================== */

@media (max-width: 640px) {
  body { padding: 10px; }

  .frame {
    width: min(100vw - 20px, (100vh - 20px - 68px) * 3 / 4);
    width: min(100vw - 20px, (100dvh - 20px - 68px) * 3 / 4);
    border-radius: 16px;
  }

  .game { aspect-ratio: 3 / 4; }

  .bar { min-height: 68px; padding: 10px 14px; gap: 12px; }
  .bar-icon { width: 42px; height: 42px; }
  .bar-category { font-size: 12px; }
  .bar-title { font-size: 19px; }
}

/* In a portrait box the switcher sits above the shop button, not beside it. */
@container game (orientation: portrait) {
  .game { --planet: min(44cqh, 66cqw); }
  .planet-wrap { margin-top: -5cqh; }
  .planet-nav { bottom: 17cqmin; }
  .energy.is-long { font-size: 7cqmin; }
  .energy.is-longer { font-size: 5.6cqmin; }
}

@media (prefers-reduced-motion: reduce) {
  .stage.is-hit .planet, .float, .is-shaking, .overlay { animation: none; }
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
}
