/* Echo Architect — premium light puzzle UI */
:root {
  --bg: #050510;
  --panel: #0c0e1a;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f0ff;
  --muted: #9b93b0;
  --gold: #f5d07a;
  --gold2: #e8a84a;
  --cyan: #5eead4;
  --violet: #a78bfa;
  --pink: #f472b6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tray-h: 128px;
  --chrome-top: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

.back-link {
  position: fixed;
  z-index: 80;
  top: max(10px, var(--safe-top));
  left: 12px;
  color: rgba(244, 240, 255, 0.75);
  font: 700 12px system-ui;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(167, 139, 250, 0.3);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.screen.active {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

/* Boot */
#screen-boot {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(167, 139, 250, 0.2), transparent),
    var(--bg);
}
.boot-orb {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e8, var(--gold) 40%, var(--violet) 70%, transparent 72%);
  box-shadow: 0 0 40px rgba(245, 208, 122, 0.5), 0 0 80px rgba(167, 139, 250, 0.35);
  animation: pulse 1.4s ease-in-out infinite;
  margin-bottom: 24px;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}
.boot-sub { color: var(--muted); font-size: 14px; margin-top: 8px; }

.logo {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  letter-spacing: -0.02em;
  text-align: center;
}
.logo em {
  font-style: italic;
  background: linear-gradient(135deg, var(--gold), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Title */
#screen-title {
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.title-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(167, 139, 250, 0.28), transparent 55%),
    radial-gradient(ellipse 50% 40% at 80% 80%, rgba(94, 234, 212, 0.1), transparent),
    radial-gradient(ellipse 40% 30% at 10% 70%, rgba(245, 208, 122, 0.08), transparent),
    var(--bg);
  pointer-events: none;
}
.title-inner { position: relative; z-index: 1; max-width: 440px; }
.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--violet);
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: rgba(167, 139, 250, 0.1);
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.lede {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.55;
  margin: 14px 0 28px;
}
.title-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}
.hint-mute {
  margin-top: 20px;
  font-size: 12px;
  color: rgba(155, 147, 176, 0.7);
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 16px 22px;
  border-radius: 16px;
  min-height: 52px;
  transition: transform 0.12s, filter 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold2));
  color: #1a1005;
  box-shadow: 0 10px 32px rgba(245, 208, 122, 0.28);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-sm {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.88rem;
  border-radius: 12px;
  flex: 1;
}
.btn-fire {
  flex: 1.4;
  min-height: 48px;
  border-radius: 14px;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, #f472b6, #a78bfa 50%, #5eead4);
  color: #0a0612;
  box-shadow: 0 8px 28px rgba(167, 139, 250, 0.4);
  border: none;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
.btn-fire:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.3);
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Levels */
#screen-levels {
  padding: calc(12px + var(--safe-top)) 14px calc(20px + var(--safe-bot));
  overflow: auto;
  touch-action: pan-y;
}
.panel {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
@media (max-width: 780px) {
  /* On a narrow viewport the panel is full-bleed, so ← sits under ← Games */
  .panel-head { padding-left: 96px; }
}
.panel-head h2 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: 1.6rem;
}
.panel-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 18px;
  text-align: center;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}
.level-cell {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s, transform 0.12s;
}
.level-cell:hover:not(:disabled) {
  border-color: rgba(245, 208, 122, 0.45);
  transform: translateY(-2px);
}
.level-cell:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.level-cell .stars {
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 1px;
  min-height: 12px;
}
.level-cell.cleared {
  border-color: rgba(94, 234, 212, 0.35);
  background: linear-gradient(160deg, rgba(94, 234, 212, 0.08), var(--panel));
}
.level-cell.current {
  box-shadow: 0 0 0 2px rgba(245, 208, 122, 0.5);
}

/* Play */
#screen-play {
  background: var(--bg);
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.play-chrome.top {
  height: calc(var(--chrome-top) + var(--safe-top));
  padding: var(--safe-top) 10px 0 108px; /* lane for fixed ← Games chip */
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 5;
}
.play-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#level-label {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#star-hint {
  font-size: 11px;
  color: var(--muted);
}
#board {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  touch-action: none;
  cursor: crosshair;
  background: transparent;
}
.play-chrome.bottom {
  flex-shrink: 0;
  padding: 8px 10px calc(10px + var(--safe-bot));
  background: linear-gradient(180deg, transparent, rgba(5, 5, 16, 0.95) 20%);
  border-top: 1px solid var(--border);
  z-index: 5;
}
.gadget-tray {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}
.gadget-tray::-webkit-scrollbar { display: none; }
.gad-btn {
  flex: 0 0 auto;
  min-width: 76px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.12s, background 0.12s;
}
.gad-btn .count {
  font-size: 11px;
  color: var(--muted);
}
.gad-btn.selected {
  border-color: rgba(245, 208, 122, 0.65);
  background: rgba(245, 208, 122, 0.12);
  box-shadow: 0 0 20px rgba(245, 208, 122, 0.15);
}
.gad-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.gad-btn .swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}
.gad-btn .swatch.mirror {
  background: linear-gradient(135deg, #e2e8f0, #94a3b8);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.4);
}
.gad-btn .swatch.crystal {
  background: linear-gradient(135deg, #c4b5fd, #5eead4);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.gad-btn .swatch.split {
  background: linear-gradient(90deg, #f472b6, #f5d07a);
  border-radius: 4px;
}
.gad-btn .swatch.portal {
  background: radial-gradient(circle, #5eead4, #312e81);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(94, 234, 212, 0.5);
}
.action-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 5, 16, 0.72);
  backdrop-filter: blur(8px);
  touch-action: auto;
}
.modal.hidden { display: none; }
.modal-card {
  position: relative;
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 22px 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}
.modal-x {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}
.modal-card h2 {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: 1.7rem;
  margin-bottom: 14px;
  text-align: center;
}
.how-list {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
  padding-left: 18px;
  margin-bottom: 16px;
}
.how-list strong { color: var(--text); }
.how-list em { color: var(--gold); font-style: normal; }
.how-gadgets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
}
.how-gadgets .g-ico {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 2px;
}
.g-ico.mirror { background: #94a3b8; }
.g-ico.crystal { background: linear-gradient(135deg, #c4b5fd, #5eead4); border-radius: 50%; }
.g-ico.split { background: #f472b6; }
.g-ico.portal { background: #5eead4; border-radius: 50%; }
.modal-card .btn { width: 100%; }

.result-card { text-align: center; }
.result-stars {
  font-size: 2rem;
  color: var(--gold);
  letter-spacing: 6px;
  margin: 8px 0 12px;
  text-shadow: 0 0 24px rgba(245, 208, 122, 0.5);
}
#result-sub {
  color: var(--muted);
  margin-bottom: 20px;
  font-size: 0.95rem;
}
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 720px) {
  .title-actions { flex-direction: row; justify-content: center; }
  .title-actions .btn { min-width: 200px; }
  .level-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-height: 560px) {
  .play-chrome.bottom { padding-top: 4px; }
  .gad-btn { min-width: 64px; padding: 6px 8px; }
}
