* {
  margin: 0;
  padding: 0;
  box-sizing: border-box
}

/* ===== THEME SYSTEM ===== */
:root {
  --font: system-ui, -apple-system, sans-serif;
  --sans: var(--font);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", monospace;
  --bw: 3px;
  --rad: 8px;
  --shadow: 4px 4px 0;
  --shadow-sm: 2px 2px 0;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg2: #141414;
  --bg3: #1e1e1e;
  --bg4: #2a2a2a;
  --bg5: #333;
  --tx: #f0f0f0;
  --tx1: #d0d0d0;
  --tx2: #a0a0a0;
  --tx3: #666;
  --bdr: #333;
  --bdr2: #444;
  --ac: #c8ff00;
  --ac2: #e2ff66;
  --ac-tx: #0a0a0a;
  --ac-sh: var(--shadow) #4a5c00;
  --ac-sh-sm: var(--shadow-sm) #4a5c00;
  --gn: #00ff88;
  --gn-bg: rgba(0, 255, 136, .08);
  --gn-bdr: #00ff88;
  --rd: #ff3b3b;
  --rd-bg: rgba(255, 59, 59, .08);
  --rd-bdr: #ff3b3b;
  --yl: #ffe14d;
  --cy: #00e5ff;
  --or: #ff9d00;
  --card-sh: var(--shadow) #1a1a1a;
  --card-sh-sm: var(--shadow-sm) #1a1a1a;
  --hover-bg: #1a1a1a;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #ffffff;
  --bg3: #f7f7f8;
  --bg4: #e8e8ec;
  --bg5: #d1d1d6;
  --tx: #1a1a1a;
  --tx1: #333;
  --tx2: #555;
  --tx3: #777;
  --bdr: #d4d4d8;
  --bdr2: #a1a1aa;
  --ac: #4400ff;
  --ac2: #6633ff;
  --ac-tx: #fff;
  --ac-sh: var(--shadow) #220088;
  --ac-sh-sm: var(--shadow-sm) #220088;
  --gn: #00994d;
  --gn-bg: rgba(0, 153, 77, .08);
  --gn-bdr: #00994d;
  --rd: #cc0000;
  --rd-bg: rgba(204, 0, 0, .06);
  --rd-bdr: #cc0000;
  --yl: #cc8800;
  --cy: #0077aa;
  --or: #cc6600;
  --card-sh: 0 2px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --card-sh-sm: 0 1px 6px rgba(0,0,0,.07);
  --hover-bg: #f0f0f4;
}

html {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--tx);
  line-height: 1.7;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  transition: background .3s, color .3s
}

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  border-radius: var(--rad)
}

button:focus-visible {
  outline: 3px solid var(--ac);
  outline-offset: 2px
}

input,
textarea {
  font-family: var(--mono);
  border-radius: var(--rad);
  border: var(--bw) solid var(--bdr);
  background: var(--bg);
  color: var(--tx);
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color .2s
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--ac)
}

::-webkit-scrollbar {
  width: 8px
}

::-webkit-scrollbar-track {
  background: var(--bg)
}

::-webkit-scrollbar-thumb {
  background: var(--bdr);
  border: 2px solid var(--bg)
}

/* ===== LAYOUT ===== */
#app {
  display: flex;
  height: 100%
}

/* Sidebar */
#sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg2);
  border-right: var(--bw) solid var(--bdr);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, width .3s, min-width .3s
}

#sidebar.collapsed {
  transform: translateX(-100%);
  width: 0;
  min-width: 0;
  overflow: hidden
}

.sb-head {
  padding: 14px 16px;
  border-bottom: var(--bw) solid var(--bdr);
  display: flex;
  align-items: center;
  gap: 12px
}

.sb-logo {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--ac);
  line-height: 1
}

.sb-head h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-transform: uppercase
}

.sb-progress {
  margin: 6px 10px 4px;
  padding: 6px 10px;
  background: var(--bg3);
  border: 2px solid var(--bdr);
  display: flex;
  align-items: center;
  gap: 8px
}

.pbar {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border: 2px solid var(--bdr)
}

.pfill {
  height: 100%;
  transition: width .4s
}

.pfill-main {
  background: var(--ac)
}

.pct-label {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--ac);
  min-width: 36px;
  text-align: right
}

#map {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px
}

.mi {
  margin-bottom: 4px
}

.mh {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--tx2);
  background: none;
  width: 100%;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 2px solid transparent;
  transition: all .15s
}

.mh:hover {
  color: var(--tx);
  background: var(--hover-bg);
  border-color: var(--bdr)
}

.mh.exp {
  color: var(--tx)
}

.mh .arr {
  font-size: 8px;
  transition: transform .2s;
  width: 12px;
  flex-shrink: 0;
  font-family: var(--mono)
}

.mh.exp .arr {
  transform: rotate(90deg)
}

.mt {
  flex: 1
}

.mp {
  width: 36px;
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--bdr);
  flex-shrink: 0
}

.mpf {
  height: 100%;
  background: var(--gn)
}

.ll {
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s
}

.ll.exp {
  max-height: 600px
}

.li {
  padding: 8px 12px 8px 38px;
  font-size: 12px;
  color: var(--tx3);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 3px solid transparent;
  margin-left: 12px;
  transition: all .12s
}

.li:hover {
  color: var(--tx);
  background: var(--hover-bg);
  border-left-color: var(--ac)
}

.li.act {
  color: var(--ac-tx);
  background: var(--ac);
  border-left-color: var(--ac);
  font-weight: 700
}

.sb-foot {
  padding: 6px;
  border-top: var(--bw) solid var(--bdr);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px
}

.sb-foot button {
  padding: 6px 4px;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--bg3);
  color: var(--tx2);
  border: 1px solid var(--bdr);
  transition: all .15s
}

.sb-foot button:hover {
  background: var(--ac);
  color: var(--ac-tx);
  border-color: var(--ac)
}

/* Main */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  padding-left: 80px;
  /* Push right to clear macOS window controls */
  border-bottom: var(--bw) solid var(--bdr);
  background: var(--bg2)
}

.tb-btn {
  background: none;
  color: var(--tx2);
  font-size: 18px;
  padding: 6px 10px;
  border: 2px solid transparent;
  transition: all .15s
}

.tb-btn:hover {
  color: var(--ac);
  border-color: var(--ac)
}

#tbtitle {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  letter-spacing: -0.2px
}

.theme-toggle {
  background: var(--bg3);
  color: var(--tx);
  border: 2px solid var(--bdr);
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  transition: all .15s;
  cursor: pointer
}

.theme-toggle:hover {
  border-color: var(--ac);
  color: var(--ac)
}

#wrap {
  flex: 1;
  overflow-y: auto
}

#ct {
  padding: 40px;
  max-width: 880px;
  margin: 0 auto
}

/* ===== TYPOGRAPHY ===== */
.ls {
  margin-bottom: 36px
}

.ls h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: -1px;
  line-height: 1.2
}

.ls h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--ac);
  text-transform: uppercase;
  letter-spacing: 1px
}

.ls p,
.cb p,
.eb p {
  font-size: 14px;
  color: var(--tx2);
  margin-bottom: 10px;
  line-height: 1.7
}

/* Concept box */
.cb {
  background: var(--bg3);
  border: var(--bw) solid var(--bdr);
  padding: 20px 24px;
  margin: 20px 0;
  box-shadow: var(--card-sh);
  position: relative
}

.cb::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 6px;
  height: calc(100% + 2px);
  background: var(--ac)
}

.cb h4 {
  font-size: 11px;
  font-weight: 700;
  color: var(--ac);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px
}

/* Example box */
.eb {
  background: var(--bg2);
  border: var(--bw) solid var(--bdr);
  padding: 20px 24px;
  margin: 20px 0;
  box-shadow: var(--card-sh);
  position: relative
}

.eb::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 6px;
  height: calc(100% + 2px);
  background: var(--cy)
}

.eb h4 {
  font-size: 11px;
  font-weight: 700;
  color: var(--cy);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px
}

/* Step reveal */
.sr .st {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--tx3);
  border-left: 3px solid var(--bg4);
  margin: 4px 0;
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s
}

.sr .st.rev {
  border-left-color: var(--ac);
  color: var(--tx);
  background: var(--bg3)
}

.sr .st:not(.rev):hover {
  background: var(--hover-bg)
}

/* Buttons */
.btn {
  padding: 12px 24px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: var(--bw) solid var(--bdr);
  transition: all .15s
}

.btn1 {
  background: var(--ac);
  color: var(--ac-tx);
  border-color: var(--ac);
  box-shadow: var(--ac-sh)
}

.btn1:hover {
  box-shadow: none;
  transform: translate(3px, 3px)
}

.btn1:active {
  box-shadow: none;
  transform: translate(6px, 6px)
}

.btn2 {
  background: var(--bg3);
  color: var(--tx);
  box-shadow: var(--card-sh)
}

.btn2:hover {
  box-shadow: none;
  transform: translate(3px, 3px)
}

.btns {
  padding: 8px 16px;
  font-size: 11px;
  box-shadow: var(--card-sh-sm)
}

.btns:hover {
  box-shadow: none;
  transform: translate(2px, 2px)
}

.btng {
  background: var(--gn);
  color: #0a0a0a;
  border-color: var(--gn)
}

/* Graph */
.gc {
  background: var(--bg2);
  border: var(--bw) solid var(--bdr);
  margin: 20px 0;
  box-shadow: var(--card-sh);
  overflow: hidden
}

.gc canvas {
  display: block;
  width: 100%
}

.gcc {
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  align-items: center;
  background: var(--bg3);
  border-top: var(--bw) solid var(--bdr)
}

.gcc label {
  font-size: 12px;
  color: var(--tx2);
  font-family: var(--mono)
}

.gcc input[type=range] {
  width: 160px;
  accent-color: var(--ac)
}

/* ===== PRACTICE PANEL ===== */
#pp {
  position: fixed;
  right: 0;
  top: 0;
  width: 440px;
  height: 100vh;
  background: var(--bg2);
  border-left: var(--bw) solid var(--bdr);
  transform: translateX(100%);
  transition: transform .3s;
  z-index: 100;
  display: flex;
  flex-direction: column
}

#pp.open {
  transform: none
}

.pp-h {
  padding: 20px;
  border-bottom: var(--bw) solid var(--bdr);
  display: flex;
  align-items: center;
  justify-content: space-between
}

.pp-h h3 {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px
}

#pb {
  flex: 1;
  overflow-y: auto;
  padding: 20px
}

.pp-f {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: var(--bw) solid var(--bdr)
}

.pp-f button {
  flex: 1
}

.prp {
  font-size: 15px;
  color: var(--tx);
  margin-bottom: 16px;
  line-height: 1.8
}

.pri {
  display: flex;
  gap: 8px;
  margin-bottom: 12px
}

.pri input {
  flex: 1
}

.hb {
  background: var(--bg3);
  color: var(--tx2);
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border: 2px solid var(--bdr);
  margin: 3px 3px 3px 0;
  transition: all .15s
}

.hb:hover {
  border-color: var(--yl);
  color: var(--yl)
}

.hc {
  background: var(--bg3);
  padding: 12px 16px;
  margin: 10px 0;
  font-size: 13px;
  color: var(--tx2);
  border-left: 4px solid var(--yl);
  line-height: 1.7
}

.fb {
  padding: 14px 18px;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.6;
  border: var(--bw) solid;
  font-weight: 500
}

.fb-ok {
  background: var(--gn-bg);
  border-color: var(--gn-bdr);
  color: var(--gn)
}

.fb-no {
  background: var(--rd-bg);
  border-color: var(--rd-bdr);
  color: var(--rd)
}

.mbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0
}

.mbar label {
  font-size: 10px;
  font-weight: 700;
  color: var(--tx3);
  min-width: 80px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--mono)
}

.mtrk {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border: 2px solid var(--bdr)
}

.mfl {
  height: 100%;
  transition: width .5s
}

.mc0 {
  background: var(--rd)
}

.mc1 {
  background: var(--or)
}

.mc2 {
  background: var(--yl)
}

.mc3 {
  background: var(--gn)
}

/* ===== MODAL ===== */
.mo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px
}

[data-theme="light"] .mo {
  background: rgba(0, 0, 0, .4)
}

.md {
  background: var(--bg2);
  border: var(--bw) solid var(--bdr);
  max-width: 620px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 8px 8px 0 var(--bdr)
}

.md-h {
  padding: 28px 28px 0;
  text-align: center
}

.md-h h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -1px
}

.md-h p {
  font-size: 13px;
  color: var(--tx2)
}

.md-b {
  padding: 24px 28px
}

.md-f {
  padding: 0 28px 28px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap
}

/* Quiz */
.qp {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  justify-content: center
}

.qd {
  width: 10px;
  height: 10px;
  background: var(--bg4);
  border: 2px solid var(--bdr)
}

.qd.dn {
  background: var(--ac);
  border-color: var(--ac)
}

.qd.cu {
  background: var(--ac);
  border-color: var(--ac);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--ac)
}

.qo {
  padding: 12px 18px;
  background: var(--bg);
  border: var(--bw) solid var(--bdr);
  font-size: 14px;
  text-align: left;
  color: var(--tx2);
  width: 100%;
  margin-bottom: 8px;
  transition: all .15s;
  box-shadow: var(--card-sh-sm)
}

.qo:hover {
  border-color: var(--ac);
  color: var(--tx);
  box-shadow: none;
  transform: translate(2px, 2px)
}

/* Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 2px;
  border: 2px solid var(--ac);
  color: var(--ac);
  font-family: var(--mono)
}

/* Bookmark */
.bks {
  cursor: pointer;
  font-size: 22px;
  color: var(--tx3);
  background: none;
  padding: 2px 6px;
  transition: color .2s;
  border: none
}

.bks.on {
  color: var(--yl)
}

.bks:hover {
  color: var(--yl)
}

/* Notes */
.na textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  font-size: 13px;
  padding: 12px
}

/* Review item */
.ri {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 2px solid var(--bdr)
}

.ri span {
  font-size: 12px;
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600
}

/* Responsive */
@media(max-width:768px) {
  #sidebar {
    position: fixed;
    z-index: 50;
    height: 100vh;
    width: 85vw;
    min-width: 280px;
    max-width: 340px
  }

  /* Backdrop overlay when sidebar is open on mobile */
  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 49;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px)
  }

  #sidebar-backdrop.active {
    display: block
  }

  #pp {
    width: 100%
  }

  #ct {
    padding: 20px 16px
  }

  #topbar {
    padding: 8px 10px;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none
  }

  #topbar::-webkit-scrollbar {
    display: none
  }

  /* 44px minimum touch targets (Apple HIG) */
  .tb-btn {
    font-size: 16px;
    padding: 8px 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0
  }

  #tbtitle {
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1
  }

  .theme-toggle {
    padding: 6px 10px;
    font-size: 13px;
    min-height: 44px;
    flex-shrink: 0
  }

  /* Sidebar lesson items: 44px touch targets */
  .mh {
    min-height: 44px;
    padding: 10px 12px
  }

  .li {
    min-height: 44px;
    padding: 10px 12px 10px 38px
  }

  .sb-foot button {
    min-height: 40px
  }

  /* Hero section: compact on mobile */
  .dash-hero {
    margin-bottom: 32px !important
  }

  .dash-hero h1 {
    font-size: 36px !important
  }

  .dash-hero p {
    font-size: 15px !important
  }

  /* Cards: less padding on mobile */
  .dash-card {
    padding: 20px !important
  }

  .dash-card h3 {
    font-size: 18px !important
  }

  .dash-card p {
    font-size: 13px !important
  }

  /* Practice input: ensure not hidden by keyboard */
  .pri input {
    font-size: 16px
  }

  #b-sb-close {
    display: block !important
  }
}

@media(prefers-reduced-motion:reduce) {
  * {
    transition: none !important
  }
}

/* KaTeX */
.katex {
  font-size: 1.05em !important
}

.katex-display {
  margin: 12px 0 !important;
  overflow-x: auto
}

/* Diag review cards */
.diag-card {
  border: var(--bw) solid var(--bdr);
  padding: 16px 20px;
  margin-bottom: 14px;
  background: var(--bg3);
  box-shadow: var(--card-sh-sm)
}

.diag-card.card-ok {
  border-left: 6px solid var(--gn)
}

.diag-card.card-no {
  border-left: 6px solid var(--rd)
}

.diag-step {
  font-size: 12px;
  color: var(--tx2);
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--ac);
  margin-bottom: 4px;
  line-height: 1.6
}

/* ===== MODAL FADE-IN ===== */
.mo {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== SPLASH SCREEN ===== */
#splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#splash.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#splash .splash-logo {
  font-size: 72px;
  font-weight: 900;
  color: var(--ac);
  font-family: var(--mono);
  line-height: 1;
  animation: splashPulse 1.2s ease-in-out infinite;
}

#splash .splash-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--tx);
  margin-top: 12px;
  letter-spacing: -0.5px;
}

#splash .splash-bar {
  width: 120px;
  height: 3px;
  background: var(--bg4);
  margin-top: 24px;
  border-radius: 3px;
  overflow: hidden;
}

#splash .splash-bar-fill {
  height: 100%;
  background: var(--ac);
  animation: splashLoad 0.8s ease-out forwards;
}

@keyframes splashPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes splashLoad {
  from { width: 0; }
  to { width: 100%; }
}

/* ===== PULL-TO-REFRESH ===== */
#ptr-indicator {
  position: fixed;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--bdr);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  z-index: 200;
  transition: top 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

#ptr-indicator.pulling {
  top: 12px;
}

#ptr-indicator.refreshing {
  top: 12px;
  animation: ptrSpin 0.8s linear infinite;
}

@keyframes ptrSpin {
  from { transform: translateX(-50%) rotate(0deg); }
  to { transform: translateX(-50%) rotate(360deg); }
}

/* ===== AUTH / SYNC UI ===== */
.google-signin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: 6px;
  border: 1px solid var(--bdr);
  background: #fff;
  color: #3c4043;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  transition: all .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.google-signin-btn:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  border-color: #4285f4;
}

[data-theme="dark"] .google-signin-btn {
  background: #fff;
  color: #3c4043;
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--ac);
  object-fit: cover;
}

.sync-indicator {
  font-size: 12px;
  font-family: var(--mono);
  padding: 2px 0;
}

.sync-syncing { color: var(--yl); }
.sync-synced { color: var(--gn); }
.sync-error { color: var(--rd); }

/* ===== ENTRANCE ANIMATION ===== */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.dash-hero {
  animation: slideUp 0.5s ease-out both;
}

.dash-grid {
  animation: slideUp 0.5s ease-out 0.15s both;
}

.dash-card {
  transition: all 0.2s ease, transform 0.2s ease;
}

/* ===== BADGE CELEBRATION ===== */
@keyframes celebrate {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== SKELETON LOADING ===== */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--rad);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 1em;
  margin: 8px 0;
}

.skeleton-card {
  height: 120px;
  margin: 12px 0;
}

/* ===== SCREEN READER ONLY ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ===== SAFE AREA (NOTCHED PHONES) ===== */
body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ===== ADDITIONAL BREAKPOINTS ===== */
@media(max-width: 480px) {
  #ct {
    padding: 16px 12px;
  }

  body {
    font-size: 14px;
  }

  .ls h2 {
    font-size: 22px;
  }

  .sb-head h1 {
    font-size: 14px;
  }

  #pp {
    width: 100%;
  }

  .cb, .eb {
    padding: 14px 16px;
  }

  .md {
    max-width: 100%;
  }

  .md-h {
    padding: 20px 16px 0;
  }

  .md-b {
    padding: 16px;
  }

  .md-f {
    padding: 0 16px 20px;
  }
}

@media(max-width: 360px) {
  #ct {
    padding: 12px 10px;
  }

  .ls h2 {
    font-size: 20px;
  }

  .sb-foot {
    grid-template-columns: 1fr;
  }

  .pp-f {
    flex-direction: column;
  }

  .pp-f button {
    width: 100%;
  }

  #topbar {
    flex-wrap: wrap;
    padding: 8px 12px;
    padding-left: 12px;
    gap: 6px;
  }
}

@media(min-width: 1024px) {
  #ct {
    max-width: 1100px;
    padding: 40px 48px;
  }
}

@media(min-width: 1200px) {
  #ct {
    max-width: 1200px;
  }

  #sidebar {
    width: 340px;
    min-width: 340px;
  }
}

@media(min-width: 768px) {
  .dash-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media(min-width: 1200px) {
  .dash-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 32px !important;
  }
}

/* ===== TEXTBOOK LIBRARY ===== */
.tb-library {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  padding: 20px 0
}

.tb-book-card {
  background: var(--bg2);
  border: var(--bw) solid var(--bdr);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--card-sh);
  transition: all 0.2s ease
}

.tb-book-card:hover {
  transform: translateY(-4px);
  border-color: var(--ac);
  box-shadow: 6px 6px 0 var(--bdr)
}

.tb-book-card:focus-visible {
  outline: 3px solid var(--ac);
  outline-offset: 2px
}

.tb-book-card-header {
  padding: 32px 24px;
  text-align: center;
  position: relative
}

.tb-book-icon {
  font-size: 56px;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.3))
}

.tb-book-card-body {
  padding: 20px 24px 24px
}

.tb-book-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
  color: var(--tx)
}

.tb-book-author {
  font-size: 12px;
  color: var(--tx3);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px
}

.tb-book-desc {
  font-size: 13px;
  color: var(--tx2);
  line-height: 1.6;
  margin-bottom: 14px
}

.tb-book-meta {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--tx3);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--mono)
}

.tb-book-progress {
  display: flex;
  align-items: center;
  gap: 10px
}

.tb-book-progress .pbar {
  flex: 1;
  height: 8px
}

/* Book accent colors */
.tb-book-lang_basic_math .tb-book-title { color: #60a5fa }
.tb-book-velleman_proofs .tb-book-title { color: #4ade80 }
.tb-book-garrity_all_math .tb-book-title { color: #a78bfa }

[data-theme="light"] .tb-book-lang_basic_math .tb-book-title { color: #2563eb }
[data-theme="light"] .tb-book-velleman_proofs .tb-book-title { color: #16a34a }
[data-theme="light"] .tb-book-garrity_all_math .tb-book-title { color: #7c3aed }

/* Chapter list */
.tb-chapter-list {
  margin-top: 8px
}

.tb-chapter-item {
  margin-bottom: 4px
}

/* Section item */
.tb-section-item {
  position: relative
}

/* Breadcrumb */
.tb-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 24px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tx3);
  text-transform: uppercase;
  letter-spacing: 0.5px
}

.tb-breadcrumb a {
  color: var(--ac);
  text-decoration: none;
  transition: color 0.15s
}

.tb-breadcrumb a:hover {
  color: var(--ac2);
  text-decoration: underline
}

/* Prev/Next nav */
.tb-nav-buttons {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 2px solid var(--bdr)
}

.tb-nav-buttons .btn {
  max-width: 45%;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

/* Progress ring (circular) */
.tb-progress-ring {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0
}

.tb-progress-ring svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%
}

.tb-progress-ring circle {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round
}

.tb-progress-ring .ring-bg {
  stroke: var(--bg4)
}

.tb-progress-ring .ring-fg {
  transition: stroke-dashoffset 0.4s ease
}

.tb-progress-ring .ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--tx2)
}

/* Responsive adjustments */
@media(max-width:768px) {
  .tb-library {
    grid-template-columns: 1fr
  }

  .tb-nav-buttons {
    flex-direction: column
  }

  .tb-nav-buttons .btn {
    max-width: 100%
  }

  .tb-breadcrumb {
    font-size: 10px
  }
}

@media(max-width:480px) {
  .tb-book-card-header {
    padding: 24px 16px
  }

  .tb-book-card-body {
    padding: 16px
  }

  .tb-book-icon {
    font-size: 40px
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  #sidebar, #pp, .toolbar, #b-sb {
    display: none !important;
  }

  #ct {
    max-width: 100%;
    padding: 20px;
  }
}
