:root {
  --bg: #e6edf7;
  --bg2: #f8fafd;
  --text: #0f172a;
  --muted: #475569;
  --panel: rgba(255, 255, 255, 0.64);
  --border: rgba(148, 163, 184, 0.35);
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
  --accent: #2563eb;
}

body.dark {
  --bg: #020617;
  --bg2: #0b1225;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --panel: rgba(15, 23, 42, 0.55);
  --border: rgba(100, 116, 139, 0.34);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

/* Ultra-thin vertical scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.14) transparent;
}

*::-webkit-scrollbar {
  width: 4px;
  height: 0;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.16);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.28);
}

body.dark * {
  scrollbar-color: rgba(148, 163, 184, 0.18) transparent;
}

body.dark *::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.18);
}

body.dark *::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.32);
}

body {
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 18% 15%, var(--bg2), var(--bg));
}

.app-shell {
  width: min(1280px, 96%);
  margin: 1rem auto 2.25rem;
  display: grid;
  gap: 1rem;
}

.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 1rem;
  backdrop-filter: blur(16px);
}

.panel { padding: 1rem; }
.topbar {
  padding: 0.9rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
h1, h2, h3 { margin: 0 0 0.35rem; }
.sub { margin: 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.controls { max-height: 87vh; overflow: auto; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.grid { display: grid; gap: 0.75rem; margin-bottom: 0.75rem; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.field.checkbox { display: flex; gap: 0.5rem; align-items: center; }
.field.checkbox label { margin: 0; }

.input, input[type="range"] {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}
body.dark .input { background: rgba(2, 6, 23, 0.75); }
.input { padding: 0.68rem; }
.input.color { padding: 0.2rem; height: 2.6rem; }
input[type="range"] { accent-color: var(--accent); }

.btn {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.62rem 0.85rem;
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.2s ease;
}
body.dark .btn { background: rgba(15, 23, 42, 0.72); }
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(120deg, #2563eb, #4f46e5); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.top-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; justify-content: flex-end; }

.sticky-actions {
  position: sticky;
  bottom: -0.4rem;
  z-index: 5;
  display: flex;
  gap: 0.5rem;
  padding: 0.55rem;
  border-radius: 0.8rem;
  background: rgba(15, 23, 42, 0.08);
}
body.dark .sticky-actions { background: rgba(2, 6, 23, 0.72); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.kpi-card {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.56);
}
body.dark .kpi-card { background: rgba(2, 6, 23, 0.52); }
.kpi-card b { font-size: 1.1rem; }
.kpi-card span { display: block; color: var(--muted); font-size: 0.75rem; }

.result {
  min-height: 4rem;
  white-space: pre-line;
  padding: 0.72rem;
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
  margin-bottom: 0.8rem;
}

.canvas-wrap {
  position: relative;
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 10%, #dbeafe, #d9e3f5);
}
body.dark .canvas-wrap { background: radial-gradient(circle at 50% 10%, #102043, #0b1225); }
canvas#wheelCanvas {
  display: block;
  width: 100%;
  height: min(560px, 54vh);
}
.tooltip {
  position: absolute;
  pointer-events: none;
  display: none;
  background: rgba(2, 6, 23, 0.9);
  color: #fff;
  padding: 0.42rem 0.58rem;
  border-radius: 0.55rem;
  font-size: 0.76rem;
}

.export-row, .compare-actions { margin-top: 0.7rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.compare-output, .projects-list, .notes {
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.68rem;
}
.project-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  border-bottom: 1px dashed var(--border);
  padding: 0.45rem 0;
}
.project-actions { display: flex; gap: 0.3rem; }
.edu-grid {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}
.edu-grid article {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.72rem;
  background: rgba(255, 255, 255, 0.45);
}
body.dark .edu-grid article { background: rgba(2, 6, 23, 0.45); }
.seo-block p { color: var(--muted); }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: rgba(2, 6, 23, 0.92);
  color: #fff;
  padding: 0.7rem 0.9rem;
  border-radius: 0.75rem;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.popup-overlay {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(2, 6, 23, 0.62);
  z-index: 60;
  padding: 1rem;
}
.popup-overlay.active { display: flex; }
.popup-box {
  width: min(680px, 100%);
  padding: 1rem;
  border-radius: 1rem;
  position: relative;
}
.popup-close {
  position: absolute;
  right: 0.8rem;
  top: 0.8rem;
}
.embed-textarea {
  width: 100%;
  min-height: 150px;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
  color: #0f172a;
  padding: 0.7rem;
  margin-bottom: 0.6rem;
  font-family: Consolas, monospace;
}
body.dark .embed-textarea {
  background: rgba(2, 6, 23, 0.85);
  color: #dbeafe;
}
.similar-list { margin: 0.5rem 0 0; padding-left: 1.1rem; }
.similar-list li { margin-bottom: 0.45rem; }
.similar-list a { color: var(--text); }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .controls { max-height: unset; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app-shell { width: 95%; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1 1 calc(50% - 0.45rem); }
  .cols-2, .edu-grid { grid-template-columns: 1fr; }
  .sticky-actions { position: sticky; bottom: 0; }
}
