/* Watermark behind the whole app */
.bgimage {
  margin: -10em;
  position: fixed;
  z-index: 0;
  opacity: 0.025;
  pointer-events: none;
}
/* opt out of the global img max-width, and light-up the dark artwork for the
   dark theme the way the source site does */
.bgimage img { max-width: none; filter: invert(1); }
:root[data-theme="light"] .bgimage img { filter: none; }

/* App shell layout: desktop sidebar, mobile bottom tabs */
#app {
  position: relative;   /* sit above the watermark */
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}
#app.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed-w) 1fr; }

/* ---------- Sidebar ---------- */
#sidebar {
  background: var(--bg-panel-75);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head .logo {
  width: 30px; height: 30px; flex: none;
  color: var(--accent);
}
.sidebar-head .title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  white-space: nowrap;
}
.sidebar-head .collapse-btn { margin-left: auto; }

#campaign-bar { padding: 10px 12px; border-bottom: 1px solid var(--border); }
#campaign-bar select { width: 100%; }

#nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.nav-group-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 12px 10px 4px;
  white-space: nowrap;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  text-decoration: none;
  font-size: 0.92rem;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-raised); color: var(--text); }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item .nav-logo {
  width: 18px; height: 18px; flex: none;
  background: currentColor;
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
}
.nav-item .ext { margin-left: auto; width: 12px; height: 12px; color: var(--text-faint); }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 8px;
}

#app.sidebar-collapsed .sidebar-head .title,
#app.sidebar-collapsed .nav-group-label,
#app.sidebar-collapsed .nav-item span,
#app.sidebar-collapsed .nav-item .ext,
#app.sidebar-collapsed #campaign-bar { display: none; }
#app.sidebar-collapsed .nav-item { justify-content: center; padding: 9px 0; }
#app.sidebar-collapsed .sidebar-head { justify-content: center; }
#app.sidebar-collapsed .sidebar-head .collapse-btn { margin-left: 0; }
#app.sidebar-collapsed .sidebar-head .logo { display: none; }

/* ---------- Main ---------- */
#main {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px clamp(14px, 3vw, 36px) 40px;
}
.tool-header { margin-bottom: 16px; }
.tool-header h1 { font-size: 1.6rem; color: var(--accent); }
.tool-header .sub { color: var(--text-dim); font-size: 0.9rem; }

/* ---------- Bottom tab bar (mobile) ---------- */
#tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.62rem;
  text-decoration: none;
}
.tab-item svg { width: 22px; height: 22px; }
.tab-item.active { color: var(--accent); }

/* ---------- "More" sheet (mobile) ---------- */
#more-sheet {
  display: none;
  position: fixed;
  inset: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: var(--bg);
  z-index: 30;
  overflow-y: auto;
  padding: 18px;
}
#more-sheet.open { display: block; }
#more-sheet .nav-group-label { padding-left: 4px; }
.more-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.more-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  text-align: center;
  text-decoration: none;
}
.more-tile svg { width: 24px; height: 24px; color: var(--accent); }
.more-tile:active { background: var(--bg-hover); }

@media (min-width: 900px) {
  .mobile-only { display: none !important; }
}

@media (max-width: 899px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  #tabbar { display: flex; }
  #main { padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
}

@media print {
  #sidebar, #tabbar, #more-sheet { display: none !important; }
  #app { display: block; height: auto; }
  #main { overflow: visible; }
}
