:root {
  --dark: #111827;
  --dark-btn: #1a1a2e;
  --white: #ffffff;
  --bg: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --answer-bg: #f3f4f6;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  transition: background 0.3s;
}
body.op-add  { background: #D1FAE5; }
body.op-sub  { background: #FFE4E4; }
body.op-mul  { background: #FFEDD5; }
body.op-div  { background: #FEFCE8; }
body.op-frac { background: #DBEAFE; }

/* SCREENS */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }
#screen-tracing-practice.active { display: flex; height: 100vh; }

/* HOME */
.home-wrap {
  min-height: 100vh;
  padding: 40px 32px 60px;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.home-header { text-align: center; padding: 8px 0 4px; }
.home-title {
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}
.title-noku { color: #6EE7B7; font-weight: 800; }
.title-dot  { color: #111827; font-weight: 800; }
.title-ai   { color: #6EE7B7; font-weight: 800; }
.home-sub { font-size: 17px; color: var(--muted); margin-top: 6px; }

.home-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  text-align: center;
}
.home-section { display: flex; flex-direction: column; align-items: center; }
.home-section .option-group { justify-content: center; }

/* Operation cards */
.home-op-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.home-op-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  border-radius: var(--radius);
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.home-op-btn.op-add  { background: #D1FAE5; border-color: #A7F3D0; }
.home-op-btn.op-sub  { background: #FFE4E4; border-color: #FCA5A5; }
.home-op-btn.op-mul  { background: #FFEDD5; border-color: #FDBA74; }
.home-op-btn.op-div  { background: #FEFCE8; border-color: #FDE047; }
.home-op-btn.op-frac { background: #DBEAFE; border-color: #93C5FD; }

.home-op-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
.home-op-btn.active { border-width: 3px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); transform: translateY(-2px); }
.home-op-btn.op-add.active  { border-color: #34d399; }
.home-op-btn.op-sub.active  { border-color: #f87171; }
.home-op-btn.op-mul.active  { border-color: #fb923c; }
.home-op-btn.op-div.active  { border-color: #facc15; }
.home-op-btn.op-frac.active { border-color: #60a5fa; }

.hop-icon {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}
.hop-name { font-size: 13px; font-weight: 600; color: var(--text); }

.home-start { align-items: center; gap: 12px; }
input.home-name-input {
  width: 100%;
  max-width: 360px;
  padding: 15px 18px;
  border: 2px solid #F9A8D4 !important;
  border-radius: var(--radius-sm);
  font-size: 18px;
  background: #FCE7F3 !important;
  color: #831843;
  outline: none;
  text-align: center;
}
input.home-name-input:focus { border-color: #ec4899 !important; }
input.home-name-input::placeholder { color: #F9A8D4; }
.btn-dark.home-start-btn { max-width: 360px; font-size: 18px; padding: 18px 32px; background: #DBEAFE; color: #1e3a6e; border: 2px solid #93C5FD; }
.btn-dark.home-start-btn:hover { background: #BFDBFE; opacity: 1; }

/* keep old login card for fallback */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 24px;
}

/* TYPOGRAPHY */
.app-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}
.app-sub {
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  margin-top: 6px;
}

/* PAGE LAYOUT */
.page-top {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px 0;
  max-width: 1400px;
  margin: 0 auto;
}
.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-title-row .app-title { text-align: left; }
.page-title-row .app-sub { text-align: left; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.student-badge {
  background: var(--answer-bg);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

/* SETTINGS CARD */
.settings-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.setting-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  min-width: 180px;
}
.option-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* OPTION BUTTONS */
.opt-btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--white);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
  min-height: 44px;
}
.opt-btn:hover { border-color: var(--dark); }
.opt-btn.active { background: var(--dark); color: var(--white); border-color: var(--dark); }
.opt-btn.op-add.active  { background: #A8F5D1; color: #1a5c3a; border-color: #A8F5D1; }
.opt-btn.op-sub.active  { background: #FF9494; color: #7a0000; border-color: #FF9494; }
.opt-btn.op-mul.active  { background: #FFB87A; color: #7a3800; border-color: #FFB87A; }
.opt-btn.op-div.active  { background: #FFF176; color: #5a4a00; border-color: #FFF176; }
.opt-btn.op-frac.active { background: #93C5FD; color: #1e3a6e; border-color: #93C5FD; }

/* Difficulty pastel colors */
.diff-btn[data-val="easy"]   { background: #D1FAE5; border-color: #6EE7B7; color: #065f46; }
.diff-btn[data-val="medium"] { background: #FFEDD5; border-color: #FDBA74; color: #7c2d12; }
.diff-btn[data-val="hard"]   { background: #DBEAFE; border-color: #93C5FD; color: #1e3a6e; }
.diff-btn[data-val="easy"].active   { background: #6EE7B7; border-color: #34d399; color: #064e3b; box-shadow: 0 2px 10px rgba(52,211,153,0.4); }
.diff-btn[data-val="medium"].active { background: #FDBA74; border-color: #fb923c; color: #7c2d12; box-shadow: 0 2px 10px rgba(251,146,60,0.4); }
.diff-btn[data-val="hard"].active   { background: #93C5FD; border-color: #60a5fa; color: #1e3a6e; box-shadow: 0 2px 10px rgba(96,165,250,0.4); }

/* Count pastel colors */
.count-btn[data-val="25"]  { background: #D1FAE5; border-color: #6EE7B7; color: #065f46; }
.count-btn[data-val="50"]  { background: #FCE7F3; border-color: #F9A8D4; color: #831843; }
.count-btn[data-val="75"]  { background: #FFEDD5; border-color: #FDBA74; color: #7c2d12; }
.count-btn[data-val="100"] { background: #FEFCE8; border-color: #FDE047; color: #713f12; }
.count-btn[data-val="25"].active  { background: #6EE7B7; border-color: #34d399; color: #064e3b; box-shadow: 0 2px 10px rgba(52,211,153,0.4); }
.count-btn[data-val="50"].active  { background: #F9A8D4; border-color: #ec4899; color: #831843; box-shadow: 0 2px 10px rgba(236,72,153,0.3); }
.count-btn[data-val="75"].active  { background: #FDBA74; border-color: #fb923c; color: #7c2d12; box-shadow: 0 2px 10px rgba(251,146,60,0.4); }
.count-btn[data-val="100"].active { background: #FDE047; border-color: #eab308; color: #713f12; box-shadow: 0 2px 10px rgba(234,179,8,0.4); }

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 24px;
  gap: 2px;
}
.diff-btn span { font-size: 16px; font-weight: 600; }
.diff-btn small { font-size: 12px; opacity: 0.7; }
.diff-btn.active small { opacity: 0.8; }

.count-btn {
  padding: 10px 20px;
  font-size: 16px;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.ws-info {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
  padding: 10px 0 16px;
}

/* PROBLEMS GRID */
.problems-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.problems-grid.frac-grid {
  grid-template-columns: repeat(5, 1fr);
}

.problem-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.op-add .problem-card  { background: #F0FDF7; border: 3px solid #6EE7B7; }
.op-sub .problem-card  { background: #FFF5F5; border: 3px solid #FCA5A5; }
.op-mul .problem-card  { background: #FFF8F0; border: 3px solid #FDBA74; }
.op-div .problem-card  { background: #FEFEF0; border: 3px solid #FDE047; }
.op-frac .problem-card { background: #F0F7FF; border: 3px solid #93C5FD; }
.problem-card.correct { border-color: var(--green); }
.problem-card.wrong { border-color: var(--red); }

.prob-numbers {
  text-align: right;
  line-height: 1.2;
  margin-bottom: 10px;
}
.prob-a {
  font-size: 32px;
  font-weight: 700;
  display: block;
  color: var(--text);
  font-family: 'Edu NSW ACT Foundation', cursive;
}
.prob-b {
  font-size: 32px;
  font-weight: 700;
  display: block;
  color: var(--text);
  font-family: 'Edu NSW ACT Foundation', cursive;
}
.prob-b .op {
  margin-right: 6px;
  font-weight: 400;
}
.prob-line {
  border: none;
  border-top: 2px solid var(--text);
  margin-bottom: 10px;
  width: 100%;
}

/* ANSWER INPUT — large for stylus writing */
.answer-input {
  background: rgba(255,255,255,0.75);
  border: none;
  border-radius: var(--radius-sm);
  width: 100%;
  padding: 14px 10px;
  font-size: 32px !important;
  font-weight: 700;
  font-family: 'Edu NSW ACT Foundation', cursive !important;
  text-align: center;
  color: var(--text);
  outline: none;
  cursor: text;
  min-height: 56px;
  -webkit-appearance: none;
  -webkit-user-select: text;
  user-select: text;
}
.answer-input::placeholder { color: #c0c4cc; font-weight: 400; font-size: 20px; }
.answer-input:focus { background: #ebebf0; }
.answer-input.correct-ans { background: #dcfce7; color: var(--green); }
.answer-input.wrong-ans { background: #fee2e2; color: var(--red); }

/* DIVISION CARDS */
.div-display { display: flex; justify-content: center; margin-bottom: 4px; }
.div-display .frac-n, .div-display .frac-d { font-size: 28px; font-weight: 700; }

/* FRACTION CARDS */
.frac-card {
  padding: 12px 8px;
}
.frac-equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: nowrap;
}
.frac-display {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.1;
}
.frac-n, .frac-d { display: block; text-align: center; min-width: 18px; font-family: 'Edu NSW ACT Foundation', cursive; font-weight: 700; }
.frac-bar-h {
  width: 100%;
  border-top: 2px solid var(--text);
  display: block;
  min-width: 20px;
}
.frac-op, .frac-eq {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  padding: 0 1px;
}
.frac-answer {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.frac-input {
  width: 34px;
  height: 28px;
  background: var(--answer-bg);
  border: none;
  border-radius: 5px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.frac-input::placeholder { color: #c0c4cc; font-size: 13px; }
.frac-input:focus { background: #ebebf0; }
.frac-input.correct-ans { background: #dcfce7; color: var(--green); }
.frac-input.wrong-ans { background: #fee2e2; color: var(--red); }
.frac-bar-ans {
  width: 34px;
  border-top: 2px solid var(--text);
  display: block;
}

.result-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  min-height: 18px;
}
.result-badge .correct-label { color: var(--green); }
.result-badge .wrong-label { color: var(--red); }
.result-badge .correct-val { color: var(--green); }

/* SUBMIT ROW */
.submit-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 32px 48px;
  max-width: 1400px;
  margin: 0 auto;
}

/* INPUTS */
input[type="text"], input[type="password"] {
  width: 100%;
  padding: 15px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 17px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--dark); }

/* BUTTONS */
.btn-dark {
  background: var(--dark);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 50px;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.btn-dark:hover { opacity: 0.85; }
.btn-dark:active { opacity: 0.7; }
.btn-green {
  background: #22C55E;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 50px;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.btn-green:hover { opacity: 0.85; }
.btn-green:active { opacity: 0.7; }
.btn-full { width: 100%; }
.btn-submit { min-width: 220px; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 50px;
  touch-action: manipulation;
}
.btn-outline:hover { border-color: var(--dark); }

.btn-outline-sm {
  background: #f3f4f6;
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
  touch-action: manipulation;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-outline-sm:hover { filter: brightness(0.93); }

/* Nav button colors */
.btn-home        { background: #D1FAE5; border-color: #6EE7B7; color: #065f46; }
.btn-progress    { background: #DBEAFE; border-color: #93C5FD; color: #1e3a6e; }
.btn-workbook    { background: #FFEDD5; border-color: #FDBA74; color: #7c2d12; }
.btn-logout      { background: #FFE4E4; border-color: #FCA5A5; color: #7f1d1d; }
.btn-draw-toggle { background: #F3E8FF; border-color: #C084FC; color: #6b21a8; }
.btn-draw-toggle.draw-active { background: #C084FC; border-color: #a855f7; color: #fff; }

/* Draw mode canvas */
.answer-canvas {
  width: 100%;
  height: 70px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1.5px solid var(--border);
  cursor: crosshair;
  touch-action: none;
  display: block;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.frac-canvas {
  width: 60px;
  height: 34px;
}

.btn-ghost {
  background: #FFEDD5;
  border: 2px solid #FDBA74;
  border-radius: var(--radius-sm);
  color: #7c2d12;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 24px;
  text-align: center;
  touch-action: manipulation;
  transition: all 0.15s;
}
.btn-ghost:hover { background: #FED7AA; }

/* RESULTS */
.results-wrap {
  max-width: 700px;
  margin: 0 auto;
  padding: 32px;
}
.score-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  margin-bottom: 24px;
}
.res-emoji { font-size: 56px; margin-bottom: 12px; }
.res-score { font-size: 52px; font-weight: 800; color: var(--text); }
.res-pct { font-size: 22px; color: var(--muted); margin-bottom: 8px; }
.res-msg { font-size: 20px; font-weight: 600; }

.res-review {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rev-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
}
.rev-icon { font-size: 18px; width: 24px; }
.rev-problem { font-weight: 600; flex: 1; }
.rev-answer { color: var(--muted); }
.rev-correct { color: var(--red); font-weight: 600; }
.res-actions { display: flex; gap: 12px; }

/* PROGRESS */
.inner-wrap { max-width: 900px; margin: 0 auto; padding: 28px 32px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 10px 20px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--white);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}
.tab.active { background: var(--dark); border-color: var(--dark); color: var(--white); }

.mastery-summary { font-size: 15px; color: var(--muted); margin-bottom: 16px; }
.mastery-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.fact-cell {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
.fact-cell.mastered { background: #f0fdf4; border-color: #86efac; color: #166534; }
.fact-cell.learning { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.fact-cell.weak { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }

.legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }
.dot.gray { background: var(--border); }

/* WORKBOOK */
.workbook-list { display: flex; flex-direction: column; gap: 12px; }
.wb-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wb-title { font-size: 16px; font-weight: 600; }
.wb-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.wb-pct { font-size: 24px; font-weight: 800; color: var(--text); }
.wb-pct.high { color: var(--green); }
.wb-pct.mid { color: var(--yellow); }
.wb-pct.low { color: var(--red); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 40px; display: block; margin-bottom: 12px; }

/* PARENT SIGN IN BUTTON */
.btn-parent-signin {
  background: #EDE9FE;
  border: 2px solid #C4B5FD;
  border-radius: var(--radius-sm);
  color: #4c1d95;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 11px 24px;
  text-align: center;
  touch-action: manipulation;
  transition: all 0.15s;
}
.btn-parent-signin:hover { background: #DDD6FE; }

.home-divider {
  width: 100%;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}
.home-divider::before,
.home-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}

/* CHILD SELECTED BADGE */
.child-selected-badge {
  background: #F0FDF4;
  border: 2px solid #86EFAC;
  border-radius: var(--radius);
  padding: 14px 24px;
  font-size: 18px;
  color: #14532d;
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.child-sel-avatar { font-size: 22px; }

/* AUTH SCREEN */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: #F5F3FF;
}
.auth-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.auth-logo { font-size: 56px; }
.auth-title { font-size: 26px; font-weight: 700; color: var(--text); }
.auth-desc { font-size: 15px; color: var(--muted); line-height: 1.5; }
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
  touch-action: manipulation;
}
.btn-google:hover { background: #f9fafb; border-color: #9ca3af; }
.google-g {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #4285F4, #34A853, #FBBC05, #EA4335);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

/* PROFILES SCREEN */
.profiles-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}
.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  width: 100%;
}
.profile-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.profile-card:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); border-color: #93C5FD; }
.profile-avatar { font-size: 52px; line-height: 1; }
.profile-name { font-size: 18px; font-weight: 700; color: var(--text); }
.profile-grade { font-size: 13px; color: var(--muted); font-weight: 500; }
.profiles-empty { text-align: center; color: var(--muted); font-size: 16px; line-height: 1.6; }
.btn-add-child {
  background: var(--dark);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.btn-add-child:hover { opacity: 0.85; }

/* ADD CHILD SCREEN */
.add-child-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.add-child-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 8px;
}
.avatar-btn {
  font-size: 28px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-btn:hover { border-color: #93C5FD; background: #EFF6FF; }
.avatar-btn.active { border-color: #3B82F6; background: #DBEAFE; box-shadow: 0 0 0 3px #BFDBFE; }
.grade-btn { min-width: 52px; font-size: 15px; font-weight: 700; }
.grade-btn.active { background: #6EE7B7; border-color: #34d399; color: #064e3b; }

/* PROGRESS STATS */
.progress-stats { margin-bottom: 20px; }
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 12px;
  text-align: center;
}
.stat-val { font-size: 30px; font-weight: 800; color: var(--text); }
.stat-lbl { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 4px; }

/* SCORE HISTORY CHART */
.score-history-wrap { margin-bottom: 24px; }
.sh-wrap {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.sh-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 16px; }
.sh-bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; }
.sh-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sh-pct { font-size: 10px; font-weight: 700; color: var(--text); }
.sh-bar-track { flex: 1; display: flex; align-items: flex-end; width: 100%; }
.sh-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 4px; }
.sh-bar.high { background: #16a34a; }
.sh-bar.mid  { background: #d97706; }
.sh-bar.low  { background: #dc2626; }
.sh-date { font-size: 9px; color: var(--muted); text-align: center; }

/* ADMIN */
.admin-parents-list { display: flex; flex-direction: column; gap: 12px; }
.admin-parent-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-parent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.admin-parent-header:hover { background: #f9fafb; }
.admin-parent-email { font-size: 16px; font-weight: 600; color: var(--text); }
.admin-parent-name  { font-size: 13px; color: var(--muted); margin-top: 2px; }
.admin-children-wrap { border-top: 1px solid var(--border); padding: 16px; background: #f9fafb; }
.admin-children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.admin-child-card { cursor: pointer; }
.admin-child-card:hover { border-color: #93C5FD; transform: translateY(-2px); }

/* WORKBOOK ENTRIES */
.wb-entry {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}
.wb-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.wb-entry-header:hover { background: #f9fafb; }
.wb-entry-left { flex: 1; }
.wb-entry-right { display: flex; align-items: center; gap: 12px; }
.wb-chevron { font-size: 13px; color: var(--muted); }

/* Workbook detail (hidden by default, shown when .open) */
.wb-detail { display: none; border-top: 1px solid var(--border); }
.wb-detail.open { display: block; }

/* Problem grid inside workbook entry */
.wb-prob-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  pointer-events: none;
}
.wb-prob-card { cursor: default; }
.wb-correct { border-color: var(--green) !important; background: #f0fdf4 !important; }
.wb-wrong   { border-color: var(--red)   !important; background: #fff5f5 !important; }
.wb-student-ans {
  font-size: 26px;
  font-weight: 700;
  font-family: 'Edu NSW ACT Foundation', cursive;
  text-align: center;
  padding: 8px 4px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wb-ans-ok  { color: var(--green); }
.wb-ans-bad { color: var(--red); }
.wb-frac-ans {
  font-size: 18px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

/* HOME TRACING BOX */
.home-tracing-section { padding: 0; flex-direction: row !important; display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.home-tracing-btn  { background: #FFF9C4 !important; border-color: #FFD166 !important; width: 140px; min-height: 110px; }
.home-notebook-btn { background: #E8F5E9 !important; border-color: #A5D6A7 !important; width: 140px; min-height: 110px; }
.home-drill-btn    { background: #FFE4E4 !important; border-color: #FCA5A5 !important; width: 140px; min-height: 110px; }
.drill-op-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.drill-op-btn { display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 20px; border: 2.5px solid transparent; font-size: 15px; font-weight: 700; cursor: pointer; transition: all 0.15s; }
.drill-op-btn.op-add  { background: #D1FAE5; border-color: #A7F3D0; }
.drill-op-btn.op-sub  { background: #FFE4E4; border-color: #FCA5A5; }
.drill-op-btn.op-mul  { background: #FFEDD5; border-color: #FDBA74; }
.drill-op-btn.op-div  { background: #FEFCE8; border-color: #FDE047; }
.drill-op-btn.op-frac { background: #DBEAFE; border-color: #93C5FD; }
.drill-op-btn.active  { border-width: 3px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); transform: translateY(-1px); }
.drill-horiz-grid { grid-template-columns: repeat(5, 1fr) !important; }
.drill-result-banner { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; background: linear-gradient(135deg,#A78BFA,#4DBFFF); color:#fff; border-radius: 12px; padding: 12px 20px; font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.drill-problems-grid { grid-template-columns: repeat(10, 1fr) !important; gap: 4px !important; }
.drill-problems-grid .problem-card { padding: 6px 4px; gap: 2px; }
.drill-problems-grid .prob-a, .drill-problems-grid .prob-b { font-size: 18px; }
.drill-problems-grid .prob-numbers { margin-bottom: 4px; }
.drill-problems-grid .answer-input { font-size: 18px !important; min-height: 32px; padding: 4px 2px; }
.drill-problems-grid .answer-canvas { height: 44px; }
.drill-problems-grid .result-badge { font-size: 9px; min-height: 10px; }
.drill-problems-grid .correct-label, .drill-problems-grid .wrong-label { font-size: 9px; }
.drill-problems-grid .correct-val { font-size: 9px; }
.drill-eraser-btn { font-size: 14px; padding: 1px 4px; background: #fff3cd; border: 1px solid #ffc107; border-radius: 4px; cursor: pointer; margin-top: 2px; }

/* PRACTICE NOTEBOOK */
#screen-notebook { background: #f0ebe3; min-height: 100vh; display: none; align-items: center; justify-content: center; padding: 24px 16px; }
#screen-notebook.active { display: flex; }
.notebook-outer { display: flex; align-items: stretch; width: 100%; max-width: 900px; }
.notebook-outer {
  display: flex;
  align-items: stretch;
  width: 100%;
  max-width: 860px;
  position: relative;
}
.notebook-wrap {
  display: flex;
  position: relative;
  background: #fff;
  border-radius: 4px 12px 12px 4px;
  box-shadow: -4px 4px 20px rgba(0,0,0,0.18), 4px 4px 20px rgba(0,0,0,0.1);
  min-height: 80vh;
  flex: 1;
  overflow: hidden;
}
.notebook-spiral {
  width: 28px;
  background: linear-gradient(180deg, #b0a8f8 0%, #7ec8f8 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  padding: 16px 0;
  flex-shrink: 0;
}
.spiral-ring {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #e8e0ff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.notebook-tabs {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  gap: 0;
  margin-left: 4px;
  flex-shrink: 0;
}
.nb-tab {
  flex: 1;
  width: 52px;
  padding: 4px 2px;
  border: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  text-align: center;
  opacity: 0.75;
  transition: all 0.15s;
  box-shadow: 2px 0 6px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.nb-tab .nb-tab-sym { font-size: 22px; font-weight: 900; line-height: 1; color: #000; margin-bottom: 6px; }
.nb-tab .nb-tab-word { font-size: 13px; font-weight: 900; line-height: 1; color: #000; writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 2px; }
.nb-tab { opacity: 1; }
.nb-tab.active { opacity: 1; width: 60px; box-shadow: 3px 0 10px rgba(0,0,0,0.2); }
.nb-tab-add  { background: #A8F5D1; color: #000; }
.nb-tab-sub  { background: #FF9494; color: #000; }
.nb-tab-mul  { background: #FFB87A; color: #000; }
.nb-tab-div  { background: #FFF176; color: #000; }
.nb-tab-frac { background: #93C5FD; color: #000; }
.notebook-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 56px 16px 12px;
  background: #fff;
  background-image: repeating-linear-gradient(transparent, transparent 31px, #e8f0fe 31px, #e8f0fe 32px);
  background-position: 0 40px;
}
.nb-submit-result {
  background: linear-gradient(135deg, #A78BFA, #4DBFFF);
  color: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.notebook-page-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.nb-page-info { font-size: 14px; font-weight: 700; color: #374151; flex: 1; }
.nb-fact-select { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.nb-fact-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid #d1d5db;
  background: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: 'Edu NSW ACT Foundation', cursive;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nb-fact-btn.active { background: #111827; color: #fff; border-color: #111827; }
.nb-problems-area { overflow-y: auto; }
.nb-card { break-inside: avoid; }
.nb-horiz-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.nb-horiz-card { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1.5px solid #e5e7eb; border-radius: 10px; background: #fff; }
.nb-horiz-row { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.nb-horiz-grid.op-add  .nb-horiz-card { background: #F0FDF7; border: 3px solid #6EE7B7; }
.nb-horiz-grid.op-sub  .nb-horiz-card { background: #FFF5F5; border: 3px solid #FCA5A5; }
.nb-horiz-grid.op-mul  .nb-horiz-card { background: #FFF8F0; border: 3px solid #FDBA74; }
.nb-horiz-grid.op-div  .nb-horiz-card { background: #FEFEF0; border: 3px solid #FDE047; }
.nb-horiz-grid.op-frac .nb-horiz-card { background: #F0F7FF; border: 3px solid #93C5FD; }
.nb-horiz-grid .nb-horiz-card.correct { border-color: #16a34a; }
.nb-horiz-grid .nb-horiz-card.wrong   { border-color: #dc2626; }
.nb-horiz-label { font-family: 'Edu NSW ACT Foundation', cursive; font-size: 42px; font-weight: 700; white-space: nowrap; }
.nb-horiz-canvas { border-bottom: 2px solid #111827; background: transparent; width: 70px; height: 50px; }
.nb-horiz-input { width: 60px; font-family: 'Edu NSW ACT Foundation', cursive; font-size: 28px !important; font-weight: 700; padding: 2px 4px; text-align: center; border-bottom: 2px solid #111827; border-top: none; border-left: none; border-right: none; background: transparent; }
.nb-horiz-badge { font-size: 12px; }
.nb-rec-label { font-family: 'Edu NSW ACT Foundation', cursive; font-size: 16px; font-weight: 700; }
.nb-frac-grid { grid-template-columns: repeat(3, 1fr) !important; }
.nb-frac-grid .frac-n, .nb-frac-grid .frac-d { font-size: 26px; min-width: 28px; }
.nb-frac-grid .frac-op, .nb-frac-grid .frac-eq { font-size: 24px; }
.nb-frac-grid .frac-bar-h { min-width: 28px; }
.nb-frac-grid .frac-input { width: 44px; height: 36px; font-size: 20px; }
.nb-frac-grid .frac-bar-ans { width: 44px; }
.nb-clear-btn { font-size: 11px; padding: 2px 8px; background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; border-radius: 6px; cursor: pointer; margin-top: 2px; }
.notebook-page-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
}

/* TRACING OPTIONS SCREEN */
.tracing-opts-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  gap: 24px;
}
.tracing-opts-sub { color: var(--muted); font-size: 15px; margin: 0; }
.tracing-opts-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 700px;
}
.tracing-opt-card {
  flex: 1;
  min-width: 160px;
  max-width: 220px;
  background: white;
  border: 2px solid var(--card-color, #ccc);
  border-radius: 20px;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  text-align: center;
}
.tracing-opt-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.toc-num {
  font-family: 'Edu NSW ACT Foundation', cursive;
  font-size: 52px;
  font-weight: 700;
  color: var(--card-color, #ccc);
  line-height: 1;
}
.toc-label { font-size: 16px; font-weight: 700; color: var(--text); }
.toc-sub   { font-size: 13px; color: var(--muted); line-height: 1.4; }

/* TRACING PRACTICE SCREEN */
.tracing-screen { background: #f4e3bb; flex-direction: column; }
.tracing-top { background: #f4e3bb; border-bottom: 1px solid #d4b896; }
.tracing-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.tracing-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 16px 24px;
  background: #f4e3bb;
  border-top: 1px solid #d4b896;
}

/* SINGLE NUMBER TRACING */
.tracing-single-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tracing-abs-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
  z-index: 1;
}
.tracing-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  z-index: 2;
}

/* WORKSHEET TRACING */
.tracing-sheet {
  padding: 20px 16px;
  background: #f4e3bb;
}
.tracing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px dashed #c4a87a;
}
.tr-label {
  font-family: 'Edu NSW ACT Foundation', cursive;
  font-size: 36px;
  font-weight: 700;
  width: 44px;
  text-align: center;
  flex-shrink: 0;
}
.tr-cells {
  display: flex;
  gap: 8px;
  flex: 1;
}
.tr-cell {
  position: relative;
  flex: 1;
  aspect-ratio: 1 / 1.1;
  background: rgba(255,255,255,0.5);
  border-radius: 10px;
  border: 1px solid #d4b896;
  overflow: hidden;
}
.tr-guide {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Edu NSW ACT Foundation', cursive;
  font-size: min(70px, 12vw);
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}
.tr-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  z-index: 2;
}

/* WORKBOOK FLIP VIEW */
.wb-flip-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.wb-flip-counter {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.wb-flip-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.wb-flip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.wb-flip-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.wb-flip-body {
  padding: 0;
}

/* PRINT */
@media print {
  .page-top, .top-actions, .submit-row, .btn-dark, .btn-outline, .btn-outline-sm { display: none !important; }
  .problems-grid { padding: 0; }
  .problem-card { break-inside: avoid; border: 1px solid #ccc; }
  .answer-input { background: white; border: none; border-radius: 0; }
}

/* HOME RESPONSIVE */
@media (max-width: 768px) {
  .home-wrap { padding: 28px 20px 48px; gap: 20px; }
  .home-title { font-size: 40px; }
  .home-op-grid { grid-template-columns: repeat(5, 1fr); }
  .home-row { flex-direction: column; }
}

/* RESPONSIVE — iPad portrait */
@media (max-width: 1024px) {
  .problems-grid { grid-template-columns: repeat(5, 1fr); padding: 20px 24px; }
  .page-top { padding: 20px 24px 0; }
}
@media (max-width: 768px) {
  .problems-grid { grid-template-columns: repeat(5, 1fr); padding: 6px 8px; gap: 5px; }
  .setting-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .setting-label { min-width: unset; }
  .page-top { padding: 6px 12px 0; }
  .app-title { font-size: 15px; }
  .app-sub { font-size: 12px; margin-top: 2px; }
  .page-title-row { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 8px; }
  .top-actions { gap: 4px; }
  .btn-outline-sm { padding: 5px 8px; font-size: 11px; }
  .ws-info { font-size: 12px; padding: 4px 0 6px; }
  .submit-row { padding: 6px 12px 10px; gap: 8px; }
  .btn-submit { font-size: 14px; padding: 10px 16px; min-height: 40px; }
  .btn-outline { font-size: 14px; padding: 10px 16px; min-height: 40px; }
  .problem-card { padding: 8px 8px 6px; align-items: center; }
  .prob-a, .prob-b { font-size: 26px; }
  .prob-line { margin-bottom: 5px; }
  .answer-input { font-size: 26px !important; padding: 7px 4px; min-height: 40px; }
  .result-badge { margin-top: 3px; min-height: 14px; font-size: 12px; }
  .prob-numbers { display: inline-block; text-align: right; margin-bottom: 4px; }
  .prob-line { width: 100%; }
}
@media (max-width: 480px) {
  .problems-grid { grid-template-columns: repeat(3, 1fr); }
  .home-op-grid { grid-template-columns: repeat(3, 1fr); }
  .home-wrap { padding: 20px 14px 40px; }
  .home-title { font-size: 32px; }
}
