:root {
  --bg: #0a0a0f;
  --bg-sidebar: #0d0d15;
  --bg-card: #131320;
  --bg-hover: #1a1a2e;
  --border: #252540;
  --text: #e8e8f0;
  --text-dim: #9090a8;
  --accent: #a78bfa;
  --accent-bright: #c4b5fd;
  --success: #4ade80;
  --sidebar-w: 260px;
  --topbar-h: 48px;
  --bottombar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }

/* Layout */
.shell { display: flex; height: 100vh; }

/* Sidebar (desktop) */
.sidebar {
  width: var(--sidebar-w); background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
}
.sidebar__header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar__logo { font-size: 1.25rem; font-weight: 800; background: linear-gradient(135deg, #fff, var(--accent-bright)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sidebar__search {
  margin: 8px 12px; padding: 8px 12px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.85rem; outline: none; width: calc(100% - 24px);
}
.sidebar__search:focus { border-color: var(--accent); }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 4px 0; -webkit-overflow-scrolling: touch; }
.sidebar__nav::-webkit-scrollbar { width: 4px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Sidebar footer (Grid View, Source links) */
.sidebar__footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; flex-shrink: 0;
}
.sidebar__footer-link {
  flex: 1; padding: 8px 10px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-dim); text-decoration: none;
  font-size: 0.8rem; font-weight: 500; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.sidebar__footer-link:hover, .sidebar__footer-link:active { border-color: var(--accent); color: var(--text); }

/* Cluster groups */
.cluster { margin-bottom: 4px; }
.cluster__header {
  padding: 8px 16px; font-size: 0.75rem; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer;
  display: flex; align-items: center; gap: 6px; user-select: none;
}
.cluster__header:hover { color: var(--text); }
.cluster__arrow { transition: transform 0.2s; font-size: 0.6rem; }
.cluster.collapsed .cluster__arrow { transform: rotate(-90deg); }
.cluster.collapsed .cluster__items { display: none; }
.cluster__desc { font-size: 0.7rem; color: var(--text-dim); padding: 0 16px 4px; font-weight: 400; opacity: 0.7; }

/* Tool items */
.tool-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 16px; cursor: pointer;
  font-size: 0.88rem; color: var(--text-dim); transition: background 0.1s, color 0.1s;
  text-decoration: none; border-left: 3px solid transparent;
}
.tool-item:hover { background: var(--bg-hover); color: var(--text); }
.tool-item.active { background: rgba(167,139,250,0.1); color: var(--accent-bright); border-left-color: var(--accent); }
.tool-item__emoji { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.tool-item__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Main area */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Top bar */
.topbar {
  height: var(--topbar-h); background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 12px; gap: 10px; flex-shrink: 0;
  min-width: 0;
}
.topbar__burger { display: none; background: none; border: none; color: var(--text); font-size: 1.4rem; cursor: pointer; padding: 4px 8px; line-height: 1; -webkit-tap-highlight-color: transparent; min-width: 44px; min-height: 44px; }
.topbar__title { font-size: 0.95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.topbar__breadcrumb { font-size: 0.8rem; color: var(--text-dim); }
.topbar__actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.topbar__btn {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; cursor: pointer;
  white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center;
}
.topbar__btn:hover { border-color: var(--accent); color: var(--text); }

/* Iframe */
.iframe-wrap { flex: 1; position: relative; }
.iframe-wrap iframe { width: 100%; height: 100%; border: none; background: var(--bg); }

/* Welcome screen (no tool selected) */
.welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 32px 24px; text-align: center; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.welcome__inner { max-width: 720px; width: 100%; display: flex; flex-direction: column; align-items: center; }
.welcome h2 { font-size: 1.5rem; margin-bottom: 8px; line-height: 1.2; }
.welcome p { color: var(--text-dim); margin-bottom: 24px; max-width: 460px; line-height: 1.5; }
.welcome__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; width: 100%; }
.welcome__card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; cursor: pointer; text-align: left; transition: border-color 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent; display: block; text-decoration: none; color: inherit;
}
.welcome__card:hover, .welcome__card:active { border-color: var(--accent); transform: translateY(-2px); }
.welcome__card-emoji { font-size: 1.5rem; margin-bottom: 6px; line-height: 1; }
.welcome__card-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.welcome__card-desc { font-size: 0.8rem; color: var(--text-dim); line-height: 1.35; }

@media (max-width: 768px) {
  .welcome { padding: 24px 16px; }
  .welcome h2 { font-size: 1.35rem; }
  .welcome p { margin-bottom: 18px; }
  .welcome__grid { grid-template-columns: 1fr; gap: 10px; }
  .welcome__card { padding: 14px; }
}

/* Next step card (overlay at bottom of iframe area) */
.next-card {
  position: absolute; bottom: 16px; right: 16px; left: 16px; max-width: 400px; margin-left: auto;
  background: var(--bg-card); border: 1px solid var(--accent); border-radius: 12px;
  padding: 12px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s; z-index: 10; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.next-card:hover { transform: translateY(-2px); }
.next-card.hidden { display: none; }
.next-card__emoji { font-size: 1.25rem; }
.next-card__text { flex: 1; }
.next-card__label { font-size: 0.75rem; color: var(--accent-bright); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.next-card__title { font-size: 0.9rem; font-weight: 600; }
.next-card__arrow { color: var(--accent); font-size: 1.25rem; }
.next-card__close { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 0.9rem; padding: 2px 4px; }

/* Bottom bar (mobile only — fixed to viewport bottom, not inside flex shell) */
.bottombar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--bottombar-h); background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  z-index: 90;
  /* iOS safe area */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: content-box;
}
.bottombar__items { display: flex; height: var(--bottombar-h); width: 100%; }
.bottombar__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; color: var(--text-dim); font-size: 0.65rem; text-decoration: none;
  transition: color 0.1s; min-width: 0;
  -webkit-tap-highlight-color: transparent;
}
.bottombar__item.active { color: var(--accent-bright); }
.bottombar__item-icon { font-size: 1.25rem; line-height: 1; }
.bottombar__item-label { font-weight: 600; white-space: nowrap; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* Mobile */
@media (max-width: 768px) {
  /* Sidebar becomes a slide-in overlay */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    width: min(280px, 85vw);
    transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: 0 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }

  /* Burger visible; "Grid View" hidden on mobile (moved to sidebar) */
  .topbar__burger { display: inline-flex; align-items: center; justify-content: center; }
  .topbar__actions { display: none; }
  .topbar { padding: 0 8px; }
  .topbar__title { font-size: 0.9rem; }

  /* Bottom bar visible & fixed to viewport bottom */
  .bottombar { display: block; }

  /* Push iframe content above the bottom bar */
  .iframe-wrap, .welcome {
    padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px));
  }

  /* Next-step card sits above the bottom bar */
  .next-card {
    bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px) + 8px);
    left: 8px; right: 8px;
  }

  /* Iframe wrap should not overflow */
  .iframe-wrap { width: 100%; }
  .iframe-wrap iframe { width: 100%; }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .topbar__title { font-size: 0.85rem; }
  .bottombar__item-label { font-size: 0.6rem; }
}
