:root {
  --bg: #0c1218;
  --bg-panel: #15202b;
  --bg-card: #1c2a38;
  --bg-hover: #243447;
  --border: #2a3a4d;
  --text: #e8eef4;
  --text-muted: #8fa3b8;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --global: #a78bfa;
  --universal: #34d399;
  --domainlocal: #fbbf24;
  --tree-green: #2d6a4f;
  --tree-dark: #1b4332;
  --ground: #1a2f23;
  --sky-top: #0a1628;
  --sky-bottom: #132337;
  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app { min-height: 100vh; }

.mono { font-family: var(--mono); font-size: 0.92em; }

/* ---------- Screens ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen[hidden] { display: none !important; }

/* ---------- Intro ---------- */
.screen-intro {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, #1a3a2a 0%, transparent 55%),
    linear-gradient(180deg, var(--sky-top), var(--bg));
  padding: 24px;
}

.intro-card {
  max-width: 520px;
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}

.intro-icon { font-size: 3.2rem; margin-bottom: 12px; }

.intro-card h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.intro-lead {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 28px;
}

.intro-mission {
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 28px;
}

.intro-mission h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.intro-mission p {
  font-size: 0.92rem;
  margin-bottom: 8px;
  color: var(--text);
}

.intro-mission p:last-child { margin-bottom: 0; }

.intro-meta {
  margin-top: 20px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-lg { padding: 12px 28px; font-size: 1rem; font-weight: 600; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: #2563eb; transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: white;
  font-weight: 600;
  width: 100%;
  padding: 11px 16px;
}
.btn-danger:hover { background: #dc2626; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(15, 22, 32, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-title { font-size: 1.05rem; font-weight: 600; }
.attempts-pill {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
}

/* ---------- Forest map ---------- */
.screen-map { background: var(--sky-top); }

.forest-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.forest-sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(45, 106, 79, 0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 10%, rgba(30, 60, 90, 0.3) 0%, transparent 45%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 55%, var(--ground) 100%);
  pointer-events: none;
}

.forest-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28%;
  background:
    linear-gradient(180deg, transparent, rgba(26, 47, 35, 0.7) 30%, #152820 100%);
  pointer-events: none;
}

.forest-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(20px, 4vw, 48px);
  padding: 40px 24px 80px;
  z-index: 2;
  flex-wrap: wrap;
}

.forest-hint {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  z-index: 3;
  pointer-events: none;
}

/* Tree card (domain) */
.tree-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s;
  user-select: none;
  width: 140px;
}

.tree-card:hover {
  transform: translateY(-10px) scale(1.04);
  filter: brightness(1.12);
}

.tree-visual {
  width: 110px;
  height: 140px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.tree-crown {
  width: 90px;
  height: 90px;
  border-radius: 50% 50% 45% 45%;
  background:
    radial-gradient(circle at 35% 30%, #52b788, transparent 50%),
    radial-gradient(circle at 65% 40%, #2d6a4f, #1b4332 70%);
  box-shadow:
    inset -8px -12px 20px rgba(0,0,0,0.25),
    0 8px 24px rgba(0,0,0,0.35);
  position: relative;
  z-index: 2;
}

.tree-crown::before {
  content: '';
  position: absolute;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #74c69d, #40916c 70%);
  top: -18px;
  left: 18px;
  opacity: 0.85;
}

.tree-trunk {
  width: 18px;
  height: 42px;
  background: linear-gradient(90deg, #5c4033, #8b6914 40%, #5c4033);
  border-radius: 3px 3px 2px 2px;
  margin-top: -8px;
  z-index: 1;
  box-shadow: 2px 0 6px rgba(0,0,0,0.3);
}

.tree-card.root .tree-crown {
  background:
    radial-gradient(circle at 35% 30%, #95d5b2, transparent 50%),
    radial-gradient(circle at 65% 40%, #40916c, #1b4332 70%);
  width: 100px;
  height: 100px;
}

.tree-card.root .tree-visual { height: 155px; }

.tree-label {
  margin-top: 12px;
  text-align: center;
}

.tree-label .name {
  font-weight: 600;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--text);
  display: block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-label .tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

/* ---------- Domain interior ---------- */
.screen-domain { background: var(--bg); }

.domain-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  min-height: 0;
  overflow: hidden;
}

.domain-sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}

.sidebar-section { margin-bottom: 24px; }

.sidebar-section h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.domain-info-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 0.875rem;
}

.domain-info-block p { margin-bottom: 8px; color: var(--text-muted); }
.domain-info-block p:last-child { margin-bottom: 0; }
.domain-info-block strong { color: var(--text); }

.ou-list { display: flex; flex-direction: column; gap: 6px; }

.ou-btn {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  transition: background 0.12s, border-color 0.12s;
}

.ou-btn:hover { background: var(--bg-hover); }
.ou-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.domain-main {
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
}

.panel-header-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.panel-header-inline h2 { font-size: 1rem; font-weight: 600; }

.badge {
  font-size: 0.75rem;
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.objects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.object-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.object-card:hover {
  border-color: #3d5270;
  background: var(--bg-card);
  transform: translateY(-2px);
}

.object-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.object-card .oc-icon { font-size: 1.4rem; margin-bottom: 6px; }
.object-card .oc-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  word-break: break-word;
}
.object-card .oc-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.scope-pill {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.scope-global { background: rgba(167,139,250,0.2); color: var(--global); }
.scope-universal { background: rgba(52,211,153,0.2); color: var(--universal); }
.scope-domainlocal { background: rgba(251,191,36,0.2); color: var(--domainlocal); }

/* Detail panel */
.detail-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  gap: 10px;
}

.detail-empty .empty-icon { font-size: 2rem; opacity: 0.5; }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.detail-body h3 {
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.detail-type {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.detail-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.meta-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.meta-chip strong {
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 4px;
}

.detail-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.55;
}

.detail-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
  margin-top: 4px;
}

.members-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.members-list li {
  background: var(--bg-card);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-family: var(--mono);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.member-side {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font);
  white-space: nowrap;
}

.detail-actions {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.action-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 24px 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.result-success, .result-fail { text-align: center; }
.result-success .big-icon,
.result-fail .big-icon { font-size: 2.8rem; margin-bottom: 10px; }
.result-success h4 { color: var(--success); font-size: 1.2rem; margin-bottom: 8px; }
.result-fail h4 { color: var(--danger); font-size: 1.15rem; margin-bottom: 8px; }
.result-success p, .result-fail p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Responsive */
@media (max-width: 960px) {
  .domain-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .domain-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .detail-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 280px;
  }
}

@media (max-width: 600px) {
  .forest-stage { gap: 16px; padding-bottom: 70px; }
  .tree-card { width: 110px; }
  .tree-visual { width: 90px; height: 120px; }
  .tree-crown { width: 72px; height: 72px; }
}
