/* Mindwave — Claude-inspired warm UI */
:root {
  --bg: #faf9f5;
  --bg-elev: #ffffff;
  --sidebar: #f0eee6;
  --accent: #d97757;
  --accent-hover: #c76647;
  --accent-soft: #f5e7df;
  --text: #1f1e1d;
  --text-muted: #6e6a5e;
  --border: #e8e6dc;
  --border-strong: #d9d6cb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --green: #2f7d5a;
  --red: #b4433d;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 12px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 18px; font-size: 17px; font-weight: 600; letter-spacing: -0.3px; }
.spark { color: var(--accent); font-size: 18px; }
.side-section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); padding: 0 10px; margin: 6px 0 8px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border: none; background: none; border-radius: 9px;
  font-size: 14.5px; color: var(--text); cursor: pointer; text-align: left;
  font-family: inherit; transition: background 0.12s;
}
.nav-item:hover { background: rgba(0,0,0,0.05); }
.nav-item.active { background: var(--bg-elev); box-shadow: var(--shadow-sm); font-weight: 600; }
.nav-ico { color: var(--accent); width: 16px; text-align: center; }
.side-foot { margin-top: auto; padding: 10px; }
.side-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.dot.busy { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.side-note { font-size: 11.5px; color: var(--text-muted); margin-top: 12px; line-height: 1.5; }

.key-box { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.key-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); display: block; margin-bottom: 6px; }
.key-row { display: flex; gap: 6px; }
.key-row input {
  flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 9px; font-size: 12.5px; font-family: inherit; background: var(--bg-elev); color: var(--text); outline: none;
}
.key-row input:focus { border-color: var(--accent); }
.key-hint { font-size: 11px; color: var(--text-muted); margin-top: 5px; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(250,249,245,0.9); backdrop-filter: blur(8px); z-index: 5;
}
.menu-btn { display: none; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text); }
.crumb { font-size: 14px; font-weight: 600; }
.spacer { flex: 1; }

.content { width: 100%; max-width: 860px; margin: 0 auto; padding: 40px 32px 80px; }

.panel { display: none; }
.panel.active { display: block; animation: fade 0.28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Build ---------- */
.hero h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 5vw, 44px); line-height: 1.12; margin: 6px 0 16px;
  letter-spacing: -0.5px; font-weight: 500;
}
.hero h1 em { font-style: italic; color: var(--accent); }
.sub { color: var(--text-muted); font-size: 16px; line-height: 1.65; max-width: 620px; margin: 0 0 28px; }

.composer {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 16px 16px 12px;
}
textarea {
  width: 100%; min-height: 240px; border: none; outline: none; resize: vertical;
  font-family: inherit; font-size: 15px; line-height: 1.6; color: var(--text);
  background: transparent; padding: 6px 4px;
}
textarea::placeholder { color: #b6b2a4; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.composer-right { display: flex; align-items: center; gap: 12px; }

.btn {
  border: none; border-radius: 11px; padding: 11px 20px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.13s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(217,119,87,0.35); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border-strong); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 8px 14px; font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12.5px; }
.hint.center { text-align: center; margin-top: 16px; }

.loading { display: flex; align-items: center; gap: 12px; margin-top: 20px; color: var(--text-muted); font-size: 15px; }
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.feature-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 26px; }
@media (max-width: 720px) { .feature-row { grid-template-columns: 1fr; } }
.feature {
  display: flex; gap: 12px; padding: 16px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 14px; align-items: flex-start;
}
.f-ico { color: var(--accent); font-size: 20px; line-height: 1.3; }
.feature b { font-size: 14.5px; }
.feature p { margin: 4px 0 0; font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ---------- Section heads ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-family: Georgia, "Times New Roman", serif; font-size: 26px; font-weight: 500; margin: 0; letter-spacing: -0.3px; }
.controls { display: flex; gap: 8px; align-items: center; }
.count-pill {
  font-size: 13px; color: var(--text-muted); border: 1px solid var(--border-strong);
  padding: 6px 13px; border-radius: 999px; background: var(--bg-elev);
}

/* ---------- Constellation ---------- */
.map-wrap {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); height: min(62vh, 600px); min-height: 420px; overflow: hidden;
}
#map { width: 100%; height: 100%; }

.edge { stroke-linecap: round; opacity: 0.28; animation: fadein 0.6s ease both; }
@keyframes fadein { from { opacity: 0; } to { opacity: 0.28; } }

.node { cursor: pointer; }
.node .core {
  transform-box: fill-box; transform-origin: center;
  animation: pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; animation-delay: var(--d);
}
@keyframes pop { from { opacity: 0; transform: scale(0); } to { opacity: 1; transform: scale(1); } }
.node .glow { animation: fadein 0.8s ease both; animation-delay: var(--d); }
.node .label { animation: fadein 0.5s ease both; animation-delay: calc(var(--d) + 0.12s); }
.node:hover .core { filter: brightness(0.92); }
.node:hover .label { font-weight: 700; }

.map-wrap.dim .node { opacity: 0.15; transition: opacity 0.25s; }
.map-wrap.dim .node.hl { opacity: 1; }

.detail {
  position: fixed; right: 28px; bottom: 28px; z-index: 20;
  width: min(360px, calc(100vw - 56px));
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 12px 40px rgba(0,0,0,0.12);
  animation: fade 0.2s ease;
}
.detail h3 { margin: 0 0 8px; font-size: 18px; font-family: Georgia, serif; font-weight: 600; }
.detail p { margin: 0; color: var(--text-muted); line-height: 1.6; font-size: 14.5px; }
.detail-close { position: absolute; top: 8px; right: 12px; background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; }

/* ---------- Flashcards ---------- */
.flashcard { width: 100%; max-width: 620px; min-height: 280px; margin: 6px auto 18px; perspective: 1400px; cursor: pointer; outline: none; }
.card-inner {
  position: relative; width: 100%; min-height: 280px; transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.flashcard.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 16px; border: 1px solid var(--border); padding: 28px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 14px; text-align: center;
  background: var(--bg-elev); box-shadow: var(--shadow-md);
}
.card-back { background: linear-gradient(135deg, #fdf6f1, #fdf0e8); transform: rotateY(180deg); }
.tag { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.card-text { font-size: clamp(18px, 3vw, 24px); line-height: 1.45; margin: 0; }
.card-actions { display: flex; justify-content: center; align-items: center; gap: 14px; }
.card-pos { font-size: 13px; color: var(--text-muted); min-width: 52px; text-align: center; }

/* ---------- Quiz ---------- */
.quiz-box { display: flex; flex-direction: column; gap: 16px; }
.quiz-q { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); }
.quiz-q h3 { margin: 0 0 14px; font-size: 16px; line-height: 1.5; font-weight: 600; }
.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  text-align: left; background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; color: var(--text); font-size: 14.5px; cursor: pointer; font-family: inherit;
  transition: all 0.12s;
}
.opt:hover { border-color: var(--accent); }
.opt.correct { border-color: var(--green); background: #eef6f1; color: var(--green); font-weight: 600; }
.opt.wrong { border-color: var(--red); background: #fbeeec; color: var(--red); }
.opt:disabled { cursor: default; }
.quiz-empty { text-align: center; color: var(--text-muted); padding: 40px; }

/* ---------- Summary ---------- */
.summary-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 28px 30px; line-height: 1.75; font-size: 15.5px;
}
.summary-card ul { margin: 10px 0; padding-left: 20px; }
.summary-card li { margin: 8px 0; }
.summary-card p { margin: 12px 0; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 50; transition: left 0.25s; }
  .sidebar.open { left: 0; box-shadow: 0 0 60px rgba(0,0,0,0.25); }
  .menu-btn { display: block; }
  .content { padding: 24px 18px 60px; }
}
