:root {
  --bg: #07070f;
  --bg-2: #10121c;
  --ink: #f3f1ea;
  --muted: #9a97ab;
  --line: rgba(255, 255, 255, 0.1);
  --glass: rgba(12, 14, 24, 0.78);
  --glass-2: rgba(20, 22, 36, 0.92);
  --gold: #ffd36a;
  --gold-2: #e8891a;
  --accent: #7cd4ff;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --bar: calc(52px + env(safe-area-inset-top));
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}
button { font-family: inherit; }
img { display: block; }

.topbar {
  position: fixed;
  z-index: 20;
  top: 0; left: 0; right: 0;
  height: var(--bar);
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(7,7,15,0.78), rgba(7,7,15,0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(255, 211, 106, 0.35);
}
.brand-name {
  font-weight: 500;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease, color .2s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); color: white; }
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.stage {
  position: relative;
  z-index: 1;
  isolation: isolate;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 50% at 50% 42%, rgba(62, 48, 120, 0.22), transparent 70%),
    radial-gradient(ellipse 40% 30% at 18% 78%, rgba(20, 60, 110, 0.2), transparent 70%),
    radial-gradient(ellipse 35% 28% at 82% 22%, rgba(90, 30, 70, 0.16), transparent 70%),
    var(--bg);
}
#space {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.system {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.body {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  color: inherit;
  font: inherit;
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  z-index: 2;
  display: block;
  width: var(--size);
  height: var(--size);
}
.body .disc {
  display: block;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  position: relative;
  z-index: 1;
}
.body .label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translate(var(--ox, 0px), var(--oy, calc(var(--size) * 0.5 + 16px)));
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(243, 241, 234, 0.86);
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
  white-space: nowrap;
  font-weight: 500;
}
.body .role {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 400;
  text-transform: uppercase;
  margin-top: 1px;
}
.body.is-selected .label { color: #fff; }
.body:focus-visible { outline: none; }
.body:focus-visible .disc { box-shadow: 0 0 0 3px rgba(255,211,106,0.8), 0 0 30px rgba(255,211,106,0.4); }

/* Sun */
.sun .corona, .sun .halo {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
}
.sun .halo {
  width: 220%;
  height: 220%;
  background: radial-gradient(circle, rgba(255, 200, 90, 0.28) 0%, rgba(255, 150, 40, 0.1) 38%, transparent 70%);
  animation: breathe 6s ease-in-out infinite;
}
.sun .corona {
  width: 140%;
  height: 140%;
  background: radial-gradient(circle, rgba(255, 246, 208, 0.55) 0%, rgba(255, 180, 60, 0.18) 46%, transparent 72%);
  filter: blur(2px);
  animation: spin 36s linear infinite;
}
.sun .disc {
  width: var(--size);
  height: var(--size);
  background:
    radial-gradient(circle at 34% 30%, #fff8de 0 12%, #ffd36a 32%, #f0a02a 62%, #c45c10 100%);
  box-shadow:
    0 0 18px 6px rgba(255, 210, 100, 0.55),
    0 0 60px 16px rgba(255, 150, 40, 0.28),
    inset -8px -10px 20px rgba(140, 50, 0, 0.28);
}
.sun.is-working .disc {
  box-shadow:
    0 0 22px 8px rgba(255, 220, 130, 0.7),
    0 0 80px 22px rgba(255, 160, 50, 0.38),
    inset -8px -10px 20px rgba(140, 50, 0, 0.28);
}

@keyframes breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
  50% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
}
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes pulse-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}

.planet .disc {
  width: var(--size);
  height: var(--size);
  transition: box-shadow .3s ease, filter .3s ease;
}
.planet.is-working .disc { animation: pulse-glow 1.8s ease-in-out infinite; }
.planet.is-dim .disc { filter: brightness(0.7) saturate(0.8); }
.planet.is-selected .disc { filter: brightness(1.08); }

.planet[data-id="spark"] .disc {
  background:
    radial-gradient(circle at 30% 26%, #f2fffd 0 8%, transparent 16%),
    radial-gradient(circle at 62% 68%, rgba(10, 40, 50, 0.35), transparent 40%),
    radial-gradient(circle at 35% 32%, #9ff8ee, #2db8b4 46%, #0b4a55 100%);
  box-shadow: 0 0 22px rgba(80, 230, 220, 0.42), inset -8px -8px 16px rgba(0,20,30,0.4);
}
.planet[data-id="flux"] .disc {
  background:
    radial-gradient(circle at 30% 26%, #ffe9c8 0 7%, transparent 16%),
    repeating-linear-gradient(110deg, rgba(80, 30, 8, 0.18) 0 4px, transparent 4px 10px),
    radial-gradient(circle at 38% 32%, #f0b15a, #c26a28 50%, #5a2a10 100%);
  box-shadow: 0 0 22px rgba(230, 140, 60, 0.4), inset -8px -8px 16px rgba(40,10,0,0.4);
}
.planet[data-id="forge"] .disc {
  background:
    radial-gradient(circle at 30% 24%, #ffd8c4 0 7%, transparent 16%),
    radial-gradient(circle at 70% 70%, #3a0a08 0 16%, transparent 42%),
    radial-gradient(circle at 38% 32%, #ff8a5b, #e04522 52%, #6a120c 100%);
  box-shadow: 0 0 22px rgba(255, 90, 50, 0.42), inset -8px -8px 16px rgba(40,0,0,0.45);
}
.planet[data-id="pip"] .disc {
  background:
    radial-gradient(circle at 32% 26%, #ffe8f0 0 8%, transparent 16%),
    radial-gradient(circle at 68% 72%, rgba(90, 30, 50, 0.35), transparent 40%),
    radial-gradient(circle at 38% 32%, #f8c0d0, #e07898 50%, #7a3048 100%);
  box-shadow: 0 0 22px rgba(240, 140, 170, 0.4), inset -8px -8px 16px rgba(40,10,20,0.4);
}

/* Legend */
.settings-open .legend { opacity: 0; pointer-events: none; }
.legend {
  position: absolute;
  z-index: 8;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 12px;
  box-shadow: var(--shadow);
  min-width: 210px;
}
.legend h2 {
  margin: 0 0 8px;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.legend ul, .legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.legend li, .legend-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.78rem;
  color: rgba(243,241,234,0.9);
  line-height: 1.35;
  margin: 5px 0;
}

.lg {
  width: 22px;
  height: 12px;
  flex: 0 0 22px;
  display: inline-block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}
.lg-rocket {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 12'><path d='M3 8.5 L6 6 L3 3.5 Z' fill='%23ffb24a'/><path d='M6 6 L16 3.4 L18.5 6 L16 8.6 Z' fill='%23eef3ff'/><circle cx='11.5' cy='6' r='1.1' fill='%237cd4ff'/></svg>");
}
.lg-meteor {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 12'><path d='M2 8 L11 5' stroke='%23ff8a3a' stroke-width='1.6' stroke-linecap='round' opacity='.8'/><ellipse cx='14.5' cy='5.4' rx='4' ry='2.6' fill='%23c45a22'/><ellipse cx='15.4' cy='4.6' rx='1.4' ry='0.9' fill='%23ffd19a' opacity='.8'/></svg>");
}
.lg-star {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 12'><path d='M2 8 L15 4.5' stroke='white' stroke-width='1.3' stroke-linecap='round' opacity='.85'/><circle cx='16.5' cy='4.2' r='1.6' fill='white'/><path d='M16.5 1.2 V7.2 M13.6 4.2 H19.4' stroke='white' stroke-width='0.7' opacity='.9'/></svg>");
}
.lg-comet {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 12'><path d='M2 8.2 C8 7 12 5.2 16 4.2' stroke='%237cd4ff' stroke-width='1.6' fill='none' stroke-linecap='round' opacity='.85'/><circle cx='17.2' cy='4' r='2.1' fill='%23eef9ff'/></svg>");
}

/* Side panel */
.panel {
  position: fixed;
  z-index: 25;
  top: var(--bar);
  right: 0;
  bottom: 0;
  width: min(360px, 100%);
  pointer-events: none;
}
.panel:not([hidden]) { pointer-events: auto; }
.panel-inner {
  height: 100%;
  margin: 0 0 0 auto;
  background: var(--glass-2);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px 22px 28px;
  overflow: auto;
  transform: translateX(104%);
  transition: transform .35s cubic-bezier(.22,1,.36,1);
}
.panel.is-open .panel-inner { transform: translateX(0); }
.panel-close { position: absolute; top: 14px; right: 14px; }

.profile {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px 36px 18px 0;
}
.profile-orb {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex: 0 0 54px;
}
.profile h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}
.profile .meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.badge::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge.is-active { color: #8ef0c2; background: rgba(80, 200, 140, 0.12); }
.badge.is-working { color: var(--gold); background: rgba(255, 200, 80, 0.12); }
.badge.is-idle { color: #9aa0b8; }

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 16px 0 8px;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.meter {
  height: 6px;
  border-radius: 99px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e8891a, #ffd36a);
}

.section-title {
  margin: 22px 0 8px;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.task, .transfer-row {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0;
}
.task-name { font-size: 0.92rem; }
.task-status {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 3px;
  letter-spacing: 0.04em;
}
.transfer-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.84rem;
  color: rgba(243,241,234,0.9);
}
.transfer-row .lg { margin-top: 4px; }
.empty { color: var(--muted); font-size: 0.85rem; }

/* Settings modal */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}
.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: min(88vh, 820px);
  overflow: auto;
  background: var(--glass-2);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 8px 22px 26px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--glass-2), rgba(20,22,36,0.9) 70%, transparent);
  padding: 16px 0 10px;
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.settings-section { margin: 8px 0 22px; }
.settings-section h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint { margin: 0 0 14px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.settings-section.future { opacity: 0.85; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.theme-tile {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  border-radius: 16px;
  padding: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .2s ease, transform .2s ease, background .2s ease;
}
.theme-tile:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(255,255,255,0.22); }
.theme-tile.is-active {
  border-color: rgba(255, 211, 106, 0.8);
  box-shadow: 0 0 0 1px rgba(255, 211, 106, 0.35);
}
.theme-tile:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}
.theme-tile:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.theme-preview {
  height: 88px;
  position: relative;
  overflow: hidden;
}
.theme-preview.solar {
  background:
    radial-gradient(circle at 50% 54%, rgba(255,200,80,0.35), transparent 28%),
    #0b0b16;
}
.theme-preview.solar::before,
.theme-preview.solar::after {
  content: "";
  position: absolute;
  left: 50%; top: 54%;
  border: 1px solid rgba(255, 220, 140, 0.35);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.theme-preview.solar::before { width: 54px; height: 22px; }
.theme-preview.solar::after { width: 86px; height: 34px; }
.theme-preview.solar .sun-dot {
  position: absolute;
  left: 50%; top: 54%;
  width: 14px; height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #fff6d0, #ffb84a);
  box-shadow: 0 0 10px #ffc14a;
}
.theme-preview.office { background: linear-gradient(180deg, #d8dee8 0 38%, #bec6d4 38% 40%, #cfc8bb 40%); }
.theme-preview.office::after {
  content: "";
  position: absolute; left: 18px; bottom: 16px;
  width: 54px; height: 36px;
  background: #8b9bb0;
  clip-path: polygon(8% 100%, 8% 28%, 50% 8%, 92% 28%, 92% 100%);
  opacity: 0.85;
}
.theme-preview.farm { background: linear-gradient(180deg, #87b7e4 0 48%, #6aa84f 48%); }
.theme-preview.farm::after {
  content: "";
  position: absolute; left: 46px; bottom: 22px;
  width: 28px; height: 28px;
  background: #c44;
  clip-path: polygon(50% 0, 100% 40%, 82% 40%, 82% 100%, 18% 100%, 18% 40%, 0 40%);
}
.theme-preview.zoo { background: linear-gradient(180deg, #9fd67a 0 42%, #5e8f3d 42%); }
.theme-preview.zoo::after {
  content: "🐾";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 28px; opacity: 0.85;
}
.theme-preview.brain { background: radial-gradient(circle at 50% 50%, #3a2458, #12081d); }
.theme-preview.brain::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 34px;
  transform: translate(-50%, -50%);
  border: 2px solid #c9a0ff;
  border-radius: 50% 50% 45% 45%;
  box-shadow: inset 0 0 0 1px rgba(201,160,255,0.3), 0 0 12px rgba(180,120,255,0.4);
}
.theme-meta { padding: 10px 12px 12px; }
.theme-meta .name { display: block; font-weight: 500; font-size: 0.92rem; }
.theme-meta .state { display: block; margin-top: 2px; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; }

@media (max-width: 720px) {
  .theme-preview { height: 70px; }
  .modal {
    place-items: start center;
    padding: calc(var(--bar) + 6px) 12px 12px;
  }
  .modal-card {
    max-height: calc(100dvh - var(--bar) - 18px);
    overflow-y: auto;
  }
  .legend {
    min-width: 0;
    padding: 8px 10px;
  }
  .legend li span:last-child {
    font-size: 0.7rem;
  }
  .body .role { display: none; }
  .panel {
    top: auto;
    left: 0;
    width: 100%;
    height: min(58vh, 480px);
  }
  .panel-inner {
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    transform: translateY(104%);
  }
  .panel.is-open .panel-inner { transform: translateY(0); }
}

@media (max-width: 420px) {
  .legend h2 { display: none; }
  .legend li span:last-child {
    /* keep short labels visible */
  }
}

@media (prefers-reduced-motion: reduce) {
  .sun .halo, .sun .corona, .planet.is-working .disc { animation: none; }
  .panel-inner { transition: none; }
}
