/* Kai — DSGVO Compliance Companion Widget */
:root {
  --bg: #0a0a0f;
  --bg-elev: #13131a;
  --bg-elev-2: #1a1a24;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f0f5;
  --text-dim: #a9a8b6;
  --text-mute: #6b6a78;
  --accent: #0891b2;
  --accent-2: #06b6d4;
  --accent-dim: rgba(5, 150, 105, 0.15);
  --accent-strong: rgba(5, 150, 105, 0.45);
  --success: #06b6d4;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

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

/* Layout */
.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  max-width: 980px;
  margin: 0 auto;
}

/* Header */
.topbar {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
.brand-icon {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #0891b2 0%, #047857 100%);
  border-radius: 9px;
  font-size: 1rem;
}
.brand small { font-weight: 500; color: var(--text-dim); font-size: 0.72rem; margin-left: .25rem; }
.spacer { flex: 1; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
  font-size: 0.7rem;
  font-weight: 500;
  border: 1px solid rgba(16, 185, 129, 0.28);
}
.status::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Tab bar */
.tabbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tab {
  padding: 0.75rem 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.02); }
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-dim);
}
.tab-kbd {
  font-size: 0.6rem;
  color: var(--text-mute);
  font-weight: 400;
}

/* Main + views */
.main {
  overflow: hidden;
  position: relative;
}
.view {
  position: absolute;
  inset: 0;
  padding: 1rem 1.25rem;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.view[data-active="true"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Chat */
.chat-box {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.25rem 0;
}
.msg {
  max-width: 88%;
  padding: 0.7rem 0.95rem;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.94rem;
  word-wrap: break-word;
}
.msg.user {
  background: var(--accent-dim);
  border: 1px solid var(--accent-strong);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.sys {
  align-self: center;
  color: var(--text-mute);
  font-size: 0.78rem;
  font-style: italic;
  padding: 0.15rem 0;
  background: none;
  border: none;
  max-width: 100%;
  text-align: center;
}
.msg h1, .msg h2, .msg h3 { margin: 0.45rem 0 0.3rem; font-size: 1.02rem; }
.msg p { margin: 0.3rem 0; }
.msg ul, .msg ol { margin: 0.25rem 0 0.3rem 1.2rem; }
.msg li { margin: 0.1rem 0; }
.msg strong { color: #a7f3d0; font-weight: 600; }
.msg em { color: #d6d3de; }
.msg code {
  font-family: ui-monospace, Menlo, monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: 0.85em;
}
.msg pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.35rem 0;
  border: 1px solid var(--border);
}
.msg pre code {
  background: none;
  padding: 0;
  font-size: 0.82em;
}
.msg a { color: var(--accent); text-dekaition: underline; }

.dots { display: inline-flex; gap: 0.28rem; padding: 0.3rem 0; }
.dots span {
  width: 7px; height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.3s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.75); }
  40% { opacity: 1; transform: scale(1); }
}

/* Composer */
.composer {
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  font: inherit;
  padding: 0.7rem 0.95rem;
  resize: none;
  min-height: 46px;
  max-height: 140px;
  line-height: 1.5;
}
.composer textarea:focus {
  outline: 2px solid var(--accent-strong);
  outline-offset: -1px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0 1.25rem;
  min-height: 46px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: #047857; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sec {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.btn-sec:hover { background: var(--bg-elev-2); }
.btn-ghost {
  background: none;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.82rem;
}
.btn-ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80%;
  padding: 1.5rem;
  text-align: center;
}
.welcome h2 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  background: linear-gradient(140deg, #0891b2, #06b6d4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.welcome p {
  color: var(--text-dim);
  margin-bottom: 1.25rem;
  max-width: 38rem;
  line-height: 1.55;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  width: 100%;
  max-width: 42rem;
  margin-bottom: 1rem;
}
.mode-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
  color: inherit;
}
.mode-card:hover {
  border-color: var(--accent-strong);
  background: var(--bg-elev-2);
  transform: translateY(-2px);
}
.mode-card strong { display: block; font-size: 0.95rem; margin-bottom: 0.2rem; }
.mode-card span { color: var(--text-dim); font-size: 0.8rem; }

/* Quiz */
.quiz-intro {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 640px;
  margin: 0 auto;
}
.topic-select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.topic-select h3 { margin-bottom: 0.5rem; font-size: 1rem; }
.topic-btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.topic-pill {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.topic-pill:hover {
  border-color: var(--accent-strong);
  background: var(--accent-dim);
}
.topic-pill[aria-selected="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.quiz-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 640px;
  margin: 0 auto;
}
.quiz-progress {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}
.quiz-q {
  font-size: 1.05rem;
  line-height: 1.55;
  margin-bottom: 1rem;
}
.quiz-options { display: flex; flex-direction: column; gap: 0.5rem; }
.quiz-option {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-align: left;
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.quiz-option:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-dim);
}
.quiz-option .opt-letter {
  width: 24px; height: 24px;
  display: inline-grid;
  place-items: center;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}
.quiz-option.correct {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.5);
  color: var(--success);
}
.quiz-option.correct .opt-letter { background: var(--success); color: #000; }
.quiz-option.wrong {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--danger);
}
.quiz-option.wrong .opt-letter { background: var(--danger); color: #fff; }
.quiz-option:disabled { cursor: default; }
.quiz-explain {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-dim);
}
.quiz-explain strong { color: var(--text); }
.quiz-next {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}
.quiz-done {
  text-align: center;
  padding: 1.5rem;
}
.quiz-done h3 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.quiz-done .score {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(140deg, #0891b2, #06b6d4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 1rem 0;
}
.quiz-done .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

/* Flashcards */
.flash-intro { max-width: 640px; margin: 0 auto; }
.flashcard {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  max-width: 640px;
  margin: 0 auto;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s ease, opacity 0.2s;
  user-select: none;
}
.flashcard:hover { border-color: var(--accent-strong); }
.flashcard.flipping { opacity: 0.6; transform: scale(0.98); }
.flashcard-front {
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.5;
}
.flashcard-back {
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--text-dim);
}
.flashcard-back strong { color: var(--text); display: block; margin-bottom: 0.5rem; }
.flashcard-hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-mute);
  font-style: italic;
}
.flash-controls {
  max-width: 640px;
  margin: 1rem auto 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}
.flash-btn {
  padding: 0.7rem 0.4rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.flash-btn:hover { background: var(--bg-elev-2); }
.flash-btn .label { display: block; font-size: 0.72rem; color: var(--text-mute); margin-top: 2px; }
.flash-btn[data-rating="0"]:hover { border-color: var(--danger); color: var(--danger); }
.flash-btn[data-rating="1"]:hover { border-color: var(--warn); color: var(--warn); }
.flash-btn[data-rating="2"]:hover { border-color: var(--accent); color: var(--accent); }
.flash-btn[data-rating="3"]:hover { border-color: var(--success); color: var(--success); }

.flash-meta {
  max-width: 640px;
  margin: 0.5rem auto 0;
  display: flex;
  justify-content: space-between;
  color: var(--text-mute);
  font-size: 0.78rem;
}

/* Progress */
.progress-grid {
  display: grid;
  gap: 1rem;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 1rem;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  text-align: center;
}
.stat-card .val {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat-card .lbl {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}
.stat-card.accent .val { color: var(--accent); }
.stat-card.streak .val { color: var(--warn); }
.stat-card.level .val { color: var(--success); font-size: 1.2rem; }

.section-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.section-card h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}
.mastery-row {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.mastery-bar {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mastery-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
}
.mastery-head .pct { color: var(--accent); font-weight: 600; }
.bar-bg {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fg {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, #06b6d4 100%);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
}
.badge {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  text-align: center;
  transition: all 0.2s;
}
.badge.earned {
  border-color: var(--accent-strong);
  background: var(--accent-dim);
}
.badge.locked { opacity: 0.4; }
.badge .icon {
  font-size: 1.6rem;
  margin-bottom: 0.35rem;
  display: block;
}
.badge .title { font-size: 0.78rem; font-weight: 600; }
.badge .desc { font-size: 0.7rem; color: var(--text-mute); margin-top: 0.15rem; line-height: 1.3; }

/* Curriculum tree */
.curr-tree { max-width: 720px; margin: 0 auto; }
.curr-root {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  overflow: hidden;
}
.curr-root-head {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  text-align: left;
}
.curr-root-head:hover { background: rgba(255, 255, 255, 0.02); }
.curr-root-head .ic {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}
.curr-root-head .txt { flex: 1; }
.curr-root-head .txt strong { display: block; }
.curr-root-head .txt small { color: var(--text-dim); font-size: 0.78rem; }
.curr-root-head .chev {
  transition: transform 0.2s;
  color: var(--text-dim);
}
.curr-root[open] .curr-root-head .chev { transform: rotate(180deg); }
.curr-mods {
  padding: 0.2rem 0 0.6rem;
  border-top: 1px solid var(--border);
}
.curr-mod {
  padding: 0.55rem 1rem 0.55rem 3.75rem;
  border-left: 2px solid transparent;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.15s;
}
.curr-mod:hover {
  background: rgba(5, 150, 105, 0.05);
  border-left-color: var(--accent);
}
.curr-mod .m-title {
  font-size: 0.88rem;
  line-height: 1.3;
}
.curr-mod .m-arrow {
  color: var(--text-mute);
  font-size: 0.9rem;
}
.mod-detail {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 720px;
  margin: 0 auto;
}
.mod-detail h3 { margin-bottom: 0.5rem; letter-spacing: -0.01em; }
.mod-detail .breadcrumb {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.mod-detail .breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  font-size: inherit;
}
.mod-detail h4 { margin: 1rem 0 0.35rem; font-size: 0.9rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.mod-detail ul { margin-left: 1.2rem; color: var(--text); }
.mod-detail li { margin: 0.25rem 0; line-height: 1.5; }
.mod-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

/* Footer */
.footer {
  padding: 0.55rem 1.25rem;
  text-align: center;
  color: var(--text-mute);
  font-size: 0.7rem;
  border-top: 1px solid var(--border);
}
.footer a { color: var(--accent); text-dekaition: none; }

/* Toast */
.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  max-width: 300px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  pointer-events: auto;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* XP gain animation */
.xp-gain {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(140deg, #0891b2, #06b6d4);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  pointer-events: none;
  animation: xp-fly 1.5s ease-out forwards;
  z-index: 50;
}
@keyframes xp-fly {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -40px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60px) scale(0.9); }
}

/* Responsive */
@media (max-width: 640px) {
  .topbar { padding: 0.7rem 0.9rem; }
  .brand { font-size: 0.95rem; }
  .brand small { display: none; }
  .tabbar { grid-template-columns: repeat(5, 1fr); }
  .tab { font-size: 0.75rem; padding: 0.6rem 0.2rem; }
  .tab-kbd { display: none; }
  .view { padding: 0.75rem 0.9rem; }
  .composer { padding: 0.6rem 0.9rem 0.75rem; }
  .msg { max-width: 92%; font-size: 0.9rem; }
  .quiz-card, .flashcard, .mod-detail { padding: 1rem; }
  .quiz-q { font-size: 0.98rem; }
  .flash-controls { grid-template-columns: repeat(2, 1fr); }
  .stat-card .val { font-size: 1.45rem; }
  .welcome h2 { font-size: 1.25rem; }
  .welcome p { font-size: 0.88rem; }
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Utility */
.hidden { display: none !important; }
.flex-row { display: flex; align-items: center; gap: 0.5rem; }
.mono { font-family: ui-monospace, Menlo, monospace; }
