* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #f2f4ff; --card: #ffffff; --ink: #1e214d; --muted: #6b7099;
  --brand: #4f46e5; --brand2: #7c3aed; --ok: #16a34a; --bad: #dc2626;
  --gold: #f59e0b; --radius: 20px;
  --grad: linear-gradient(135deg, #4f46e5, #7c3aed);
}
body.theme-vitenskap { --brand: #0d9488; --brand2: #0ea5e9; --grad: linear-gradient(135deg, #0d9488, #0ea5e9); }
body.theme-mattegeni { --brand: #ea580c; --brand2: #db2777; --grad: linear-gradient(135deg, #ea580c, #db2777); }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 760px; margin: 0 auto; padding: 16px; min-height: 100%; }
.loading { text-align: center; padding-top: 40vh; font-size: 22px; }

h1 { font-size: 26px; margin-bottom: 8px; }
h2 { font-size: 20px; margin: 18px 0 10px; }
.muted { color: var(--muted); font-size: 15px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: 0 4px 14px rgba(30,33,77,.08); margin-bottom: 14px;
}
.hero { background: var(--grad); color: #fff; }
.hero .muted { color: rgba(255,255,255,.85); }

button, .btn {
  font: inherit; border: 0; cursor: pointer; border-radius: 14px;
  padding: 13px 20px; font-weight: 700; font-size: 17px;
  background: var(--grad); color: #fff; display: inline-block; text-decoration: none;
  transition: transform .08s;
}
button:active { transform: scale(.96); }
.btn-ghost { background: #e8eaff; color: var(--brand); }
.btn-small { padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.btn-wide { width: 100%; text-align: center; margin-top: 10px; }

input, select {
  font: inherit; width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 2px solid #d9dcf0; background: #fff; margin: 6px 0 12px;
}
input:focus, select:focus { outline: none; border-color: var(--brand); }

/* profile picker */
.profiles { display: flex; flex-direction: column; gap: 14px; margin: 24px auto 0; max-width: 480px; }
.profile {
  width: 100%; display: flex; align-items: center; gap: 18px;
  padding: 18px 22px; border-radius: var(--radius);
  background: var(--card); box-shadow: 0 4px 14px rgba(30,33,77,.08); cursor: pointer;
}
.profile .avatar { font-size: 54px; line-height: 1; }
.profile .name { font-weight: 800; font-size: 22px; }
.profile:active { transform: scale(.98); }

/* PIN pad */
.pinpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; justify-content: center; margin-top: 18px; }
.pinpad button { height: 66px; font-size: 26px; background: var(--card); color: var(--ink); box-shadow: 0 3px 8px rgba(30,33,77,.1); }
.pindots { text-align: center; font-size: 34px; letter-spacing: 14px; min-height: 48px; margin-top: 12px; }

/* lessons */
.lesson-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  background: var(--card); border-radius: 14px; margin-bottom: 8px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(30,33,77,.06);
}
.lesson-row .pages { background: #eef0ff; color: var(--brand); font-weight: 700; border-radius: 9px; padding: 3px 9px; font-size: 13px; white-space: nowrap; }
.lesson-row .title { flex: 1; font-weight: 600; }
.lesson-row .stars { font-size: 15px; white-space: nowrap; }
.done { opacity: .85; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.topbar .who { font-weight: 800; font-size: 18px; }

/* quiz */
.progressbar { height: 10px; background: #e2e5f7; border-radius: 6px; overflow: hidden; margin: 10px 0 18px; }
.progressbar > div { height: 100%; background: var(--grad); border-radius: 6px; transition: width .3s; }
.q-text { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.q-pages { display: inline-block; background: #fff7e6; color: #b45309; font-weight: 800; border-radius: 10px; padding: 6px 12px; margin: 8px 0 14px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  text-align: left; background: var(--card); color: var(--ink); border: 2px solid #d9dcf0;
  border-radius: 14px; padding: 13px 16px; font-weight: 600;
}
.opt.sel { border-color: var(--brand); background: #eef0ff; }
.opt.right { border-color: var(--ok); background: #e9f9ee; }
.opt.wrong { border-color: var(--bad); background: #fdeaea; }
.feedback { border-radius: 14px; padding: 14px 16px; margin-top: 14px; font-weight: 600; }
.feedback.ok { background: #e9f9ee; color: #14532d; }
.feedback.bad { background: #fdeaea; color: #7f1d1d; }
.scaffold-note { background: #fff7e6; color: #92400e; border-radius: 14px; padding: 12px 16px; margin-top: 12px; font-weight: 600; }

/* flashcards */
.flashcard {
  background: var(--grad); color: #fff; border-radius: var(--radius); padding: 30px 20px;
  text-align: center; font-size: 20px; font-weight: 700; cursor: pointer; min-height: 140px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.flashcard.back { background: var(--card); color: var(--ink); border: 3px solid var(--brand); }

/* chat */
.chat-box { display: flex; flex-direction: column; gap: 10px; padding-bottom: 90px; }
.bubble { max-width: 85%; padding: 12px 16px; border-radius: 18px; }
.bubble.user { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; box-shadow: 0 2px 8px rgba(30,33,77,.07); }
.chat-input {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.chat-input .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; }
.chat-input input { margin: 0; flex: 1; }

/* dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: #eef0ff; border-radius: 14px; padding: 12px; text-align: center; }
.stat .big { font-size: 26px; font-weight: 800; color: var(--brand); }
.tag { display: inline-block; background: #fdeaea; color: #991b1b; border-radius: 9px; padding: 4px 10px; margin: 3px 4px 3px 0; font-size: 14px; font-weight: 700; }
.tag.good { background: #e9f9ee; color: #166534; }
.wrong-item { border-left: 4px solid var(--bad); padding: 6px 10px; margin: 8px 0; background: #fff; border-radius: 8px; font-size: 15px; }
.chatq { border-left: 4px solid var(--brand); padding: 6px 10px; margin: 8px 0; background: #fff; border-radius: 8px; font-size: 15px; }

/* celebration */
.celebrate { text-align: center; padding: 40px 20px; }
.celebrate .big { font-size: 70px; }
.celebrate h1 { margin: 10px 0; }

.fab-chat {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(79,70,229,.4); z-index: 5;
}
@media (max-width: 480px) { #app { padding: 12px; } h1 { font-size: 22px; } }
