:root {
  --bg: #050713;
  --panel: rgba(13, 18, 34, 0.76);
  --panel-strong: rgba(14, 22, 42, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f7ff;
  --muted: #96a2be;
  --cyan: #16ffd2;
  --blue: #73a7ff;
  --purple: #9b73ff;
  --gold: #ffd36a;
  --danger: #ff6f8f;
  --ok: #70ffb7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }
textarea { resize: vertical; }

.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 8%, rgba(22, 255, 210, 0.2), transparent 28%),
    radial-gradient(circle at 86% 18%, rgba(155, 115, 255, 0.18), transparent 32%),
    radial-gradient(circle at 48% 92%, rgba(255, 211, 106, 0.12), transparent 34%),
    linear-gradient(180deg, #060914 0%, #02030a 100%);
}

.ambient-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.34;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.75) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(255,255,255,0.45) 0 1px, transparent 1.5px);
  background-size: 110px 110px, 170px 170px;
  background-position: 20px 10px, 80px 60px;
}

.app-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 14px;
}

.glass-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.left-panel,
.right-panel {
  border-radius: 28px;
  padding: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sky-stage {
  position: relative;
  overflow: hidden;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: radial-gradient(circle at center, rgba(22, 255, 210, 0.05), rgba(3, 4, 12, 0.9));
}

#skyCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 0 28px rgba(22, 255, 210, 0.18);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; line-height: 1.12; }
h2 { margin-bottom: 10px; font-size: 19px; }
.lead { margin: 18px 0; color: #d9e2ff; line-height: 1.7; }
.hint, .muted { color: var(--muted); font-size: 13px; line-height: 1.65; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.stats-grid div {
  padding: 12px 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stats-grid strong {
  display: block;
  color: var(--gold);
  font-size: 24px;
}

.stats-grid span { color: var(--muted); font-size: 12px; }

.panel-section {
  margin-top: 16px;
  padding: 15px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.052);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.section-head h2 { margin: 0; }

.galaxy-list {
  display: grid;
  gap: 10px;
}

.galaxy-card {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 12px;
  color: var(--text);
  background: rgba(255,255,255,0.055);
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.galaxy-card:hover,
.galaxy-card.active {
  transform: translateY(-1px);
  border-color: rgba(22, 255, 210, 0.36);
  background: rgba(22, 255, 210, 0.09);
}

.galaxy-card strong { display: block; font-size: 15px; margin-bottom: 4px; }
.galaxy-card span { color: var(--muted); font-size: 12px; }

.topbar {
  position: absolute;
  z-index: 4;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 22px;
}

.topbar h2 { margin: 0; }
.top-actions, .control-grid { display: flex; gap: 10px; flex-wrap: wrap; }

.primary-btn, .ghost-btn {
  border: 0;
  border-radius: 15px;
  padding: 11px 13px;
  font-weight: 900;
  transition: transform .18s ease, filter .18s ease, border-color .18s ease;
}

.primary-btn {
  width: 100%;
  color: #02100d;
  background: linear-gradient(135deg, var(--cyan), var(--gold));
}

.ghost-btn {
  color: var(--text);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
}

.primary-btn:hover, .ghost-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.danger { color: #ffc7d2; border-color: rgba(255, 111, 143, 0.28); background: rgba(255, 111, 143, 0.1); }

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  color: #07120f;
  background: var(--cyan);
  font-size: 11px;
  font-weight: 900;
}

.muted-tag { color: var(--muted); background: rgba(255,255,255,0.08); }
.blackhole-card { background: radial-gradient(circle at top right, rgba(129, 77, 255, 0.18), rgba(255,255,255,0.052)); }

.sky-help {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 3;
  max-width: 520px;
  border-radius: 18px;
  padding: 12px 14px;
  color: #dce5ff;
  font-size: 13px;
}

.gesture-video {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 160px;
  height: 110px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.16);
  opacity: 0;
  pointer-events: none;
  transform: scaleX(-1);
  transition: opacity .2s ease;
}

.gesture-video.active { opacity: .64; }

.word-panel.empty-state {
  color: var(--muted);
  min-height: 210px;
  display: grid;
  align-content: center;
}

.word-panel h2 { font-size: 24px; }
.word-lao { font-size: 42px; line-height: 1.25; color: var(--gold); }
.word-meta { display: grid; gap: 8px; margin: 14px 0; }
.word-meta div { padding: 10px; border-radius: 15px; background: rgba(255,255,255,0.06); }

.spell-zone {
  margin-top: 14px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(22, 255, 210, 0.07);
  border: 1px solid rgba(22, 255, 210, 0.16);
}

.spell-pieces, .spell-target {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  border-radius: 14px;
}

.spell-pieces { background: rgba(255,255,255,0.055); }
.spell-target { margin-top: 10px; background: rgba(0,0,0,0.22); border: 1px dashed rgba(255,255,255,0.18); }

.letter-chip {
  min-width: 34px;
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #06110f;
  background: linear-gradient(135deg, var(--cyan), #e9fff9);
  font-weight: 1000;
  cursor: grab;
  user-select: none;
}

.letter-chip.used { opacity: .35; pointer-events: none; }
textarea {
  width: 100%;
  min-height: 96px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.24);
  color: var(--text);
  padding: 12px;
  outline: none;
}

textarea:focus { border-color: rgba(22, 255, 210, 0.42); box-shadow: 0 0 0 4px rgba(22, 255, 210, 0.08); }

.ai-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(0,0,0,0.22);
  color: #dce5ff;
  line-height: 1.7;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 32px));
  padding: 13px 16px;
  border-radius: 18px;
  background: rgba(11, 17, 31, 0.96);
  border: 1px solid rgba(22, 255, 210, 0.22);
  color: var(--text);
  box-shadow: 0 18px 60px rgba(0,0,0,0.42);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  html, body { overflow: auto; }
  .app-shell {
    min-height: 100vh;
    height: auto;
    grid-template-columns: 1fr;
  }
  .left-panel, .right-panel { overflow: visible; }
  .sky-stage { height: 68vh; min-height: 520px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; gap: 10px; }
  .left-panel, .right-panel { border-radius: 22px; padding: 14px; }
  .topbar { position: static; margin: 10px; flex-direction: column; align-items: flex-start; }
  .sky-stage { min-height: 560px; height: 72vh; }
  .sky-help { left: 12px; right: 12px; bottom: 12px; }
  .gesture-video { width: 116px; height: 84px; }
  h1 { font-size: 23px; }
}
