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

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", ui-rounded, sans-serif;
  background: #fdf6e3;
  background-image: radial-gradient(#f5e6c4 1.5px, transparent 1.5px);
  background-size: 26px 26px;
  min-height: 100vh;
  color: #3b3b3b;
  touch-action: pan-y;
}

header {
  text-align: center;
  padding: 14px 10px 6px;
}

h1 { color: #e76f51; font-size: 1.7rem; text-shadow: 1px 1px 0 #fff; }

.levels {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
  flex-wrap: wrap;
}

.level-btn {
  font-family: inherit;
  font-size: 1rem;
  padding: 8px 14px;
  border: 3px solid #e9c46a;
  border-radius: 16px;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
  transition: transform .1s;
}
.level-btn small { font-size: .7rem; color: #888; }
.level-btn:active { transform: scale(.95); }
.level-btn.active { background: #e9c46a; border-color: #e76f51; color: #fff; }
.level-btn.active small { color: #fff8ee; }

.progress { font-size: 1.6rem; letter-spacing: 4px; min-height: 2rem; }
.progress .dim { opacity: .25; filter: grayscale(1); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 6px 12px 60px;
}

.row {
  background: #fff;
  border: 3px solid #f0d9a8;
  border-radius: 20px;
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 3px 0 #ecd9ab;
}
.row.correct { border-color: #7fc96b; background: #f3fbef; }
.row.wrong { animation: shake .4s; border-color: #f4978e; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.q-num {
  background: #e76f51;
  color: #fff;
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.question {
  flex: 1;
  min-width: 130px;
}

.eq { font-size: 2.4rem; font-weight: bold; color: #264653; }

.dots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  font-size: 1.6rem;
  max-width: 190px;
}
.dots + .eq-mini { font-size: 1.3rem; color: #264653; margin-top: 4px; }

.answer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pad-wrap { position: relative; }

canvas.pad {
  background: #fff;
  border: 3px dashed #90bede;
  border-radius: 14px;
  width: 240px;
  height: 150px;
  cursor: crosshair;
  touch-action: none;
  display: block;
}
.row.correct canvas.pad { border-color: #7fc96b; border-style: solid; }

.pad-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c9dff0;
  font-size: 1rem;
  pointer-events: none;
}

.tools { display: flex; gap: 8px; align-items: center; }

.erase-btn {
  font-family: inherit;
  font-size: .95rem;
  border: 2px solid #f4a261;
  background: #fff;
  color: #e76f51;
  border-radius: 12px;
  padding: 4px 12px;
  cursor: pointer;
}
.erase-btn:active { transform: scale(.93); }

.status {
  font-size: 1rem;
  min-height: 1.4rem;
  color: #888;
}
.status.ok { color: #43a047; font-weight: bold; }
.status.no { color: #e76f51; font-weight: bold; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(60, 45, 20, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }

.overlay-card {
  background: #fff;
  border-radius: 24px;
  padding: 30px 40px;
  text-align: center;
  border: 4px solid #e9c46a;
  max-width: 90vw;
}
.overlay-card h2 { color: #e76f51; font-size: 2rem; margin: 8px 0; }
.big-stars { font-size: 2.4rem; animation: pop .6s; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

.big-btn {
  font-family: inherit;
  font-size: 1.2rem;
  margin-top: 14px;
  padding: 12px 24px;
  border: none;
  border-radius: 16px;
  background: #2a9d8f;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #1f7268;
}
.big-btn:active { transform: translateY(3px); box-shadow: none; }

.spinner {
  width: 44px; height: 44px;
  border: 5px solid #f0d9a8;
  border-top-color: #e76f51;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .row { justify-content: center; }
  .eq { font-size: 2rem; text-align: center; }
  canvas.pad { width: 220px; height: 140px; }
}

/* ===== Views & login ===== */

.view.hidden, .hidden { display: none !important; }

.lang-toggle {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 60;
  display: flex;
  gap: 4px;
}
.lang-btn {
  font-family: inherit;
  border: 2px solid #e9c46a;
  background: #fff;
  border-radius: 10px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: .85rem;
}
.lang-btn.active { background: #e9c46a; color: #fff; }

.login-card {
  max-width: 380px;
  margin: 14vh auto 0;
  background: #fff;
  border: 4px solid #e9c46a;
  border-radius: 24px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 4px 0 #ecd9ab;
}
.login-card h1 { color: #e76f51; font-size: 1.5rem; margin-bottom: 8px; }
.login-card p { margin-bottom: 14px; color: #666; }
.login-card input {
  font-family: inherit;
  font-size: 1.3rem;
  text-align: center;
  width: 100%;
  padding: 12px;
  border: 3px solid #90bede;
  border-radius: 14px;
  margin-bottom: 12px;
  outline: none;
}
.login-card input:focus { border-color: #2a9d8f; }

.error { color: #e63946; min-height: 1.3rem; margin-top: 8px; }
.ok-msg { color: #43a047; min-height: 1.3rem; margin-top: 8px; }

.big-btn.alt { background: #f4a261; box-shadow: 0 4px 0 #c77f43; }
.big-btn.sm { font-size: 1rem; padding: 8px 16px; margin-top: 0; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.count-line { margin-top: 8px; color: #2a9d8f; font-weight: bold; }

.small-btn {
  font-family: inherit;
  font-size: .9rem;
  border: 2px solid #ccc;
  background: #fff;
  border-radius: 10px;
  padding: 5px 12px;
  cursor: pointer;
  color: #666;
}
.small-btn:active { transform: scale(.95); }
.small-btn.danger { border-color: #f4978e; color: #e63946; }

/* ===== Home: senarai worksheet ===== */

#view-home header, #view-sheet header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 12px 6px;
}
#view-home h1, #view-sheet h1 { color: #e76f51; font-size: 1.4rem; text-shadow: 1px 1px 0 #fff; }

.level-sec { margin-bottom: 20px; }
.level-sec h2 {
  color: #264653;
  font-size: 1.1rem;
  margin: 10px 4px;
  border-bottom: 3px dotted #e9c46a;
  padding-bottom: 4px;
}

.level-sec.recommended h2 { border-bottom-color: #e76f51; }

/* ===== Lencana ===== */

.badge-shelf {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: #fff;
  border: 3px solid #f0d9a8;
  border-radius: 16px;
  padding: 10px 14px;
  margin-bottom: 18px;
  box-shadow: 0 3px 0 #ecd9ab;
}
.badge-title { font-size: .9rem; color: #b8860b; font-weight: bold; margin-right: 4px; }
.badge-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
  padding: 4px 6px;
  border-radius: 12px;
  opacity: .35;
  filter: grayscale(1);
}
.badge-item.earned {
  opacity: 1;
  filter: none;
  background: #fff6d9;
  animation: pop .4s;
}
.badge-icon { font-size: 1.4rem; }
.badge-name { font-size: .6rem; color: #886a2b; text-align: center; line-height: 1.2; }

.new-badge {
  margin-top: 8px;
  background: #fff6d9;
  border: 2px solid #ffd166;
  border-radius: 12px;
  padding: 8px 14px;
  color: #b8860b;
  animation: pop .5s;
}

.cert-btn {
  font-family: inherit;
  font-size: .78rem;
  border: 2px solid #ffd166;
  background: #fff6d9;
  color: #b8860b;
  border-radius: 10px;
  padding: 3px 10px;
  margin-left: 8px;
  cursor: pointer;
  vertical-align: middle;
}
.cert-btn:active { transform: scale(.95); }

/* ===== Sijil ===== */

.cert-wrap { max-width: 640px; width: 92vw; }

.cert-border {
  background: #fffdf5;
  border: 6px double #b8860b;
  border-radius: 12px;
  padding: 36px 28px;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  color: #3b3b3b;
}
.cert-stars { font-size: 1.6rem; margin-bottom: 8px; }
.cert-title { color: #b8860b; letter-spacing: 3px; font-size: 1.4rem; margin-bottom: 14px; }
.cert-sub { color: #888; font-size: .95rem; margin: 6px 0; }
.cert-name {
  font-size: 2.2rem;
  color: #264653;
  border-bottom: 2px solid #e9c46a;
  display: inline-block;
  padding: 0 24px 4px;
  margin: 6px 0;
}
.cert-phase { font-size: 1.2rem; color: #e76f51; font-weight: bold; margin: 8px 0 20px; }
.cert-foot {
  display: flex;
  justify-content: space-between;
  font-size: .85rem;
  color: #888;
  border-top: 1px solid #eee;
  padding-top: 12px;
  margin-top: 10px;
}
.cert-wrap .btn-row { margin-top: 14px; }

@media print {
  body * { visibility: hidden; }
  #cert-overlay, #cert-overlay .cert-wrap, #cert-overlay .cert-border,
  #cert-overlay .cert-border * { visibility: visible; }
  #cert-overlay { position: absolute; inset: 0; background: #fff; }
  .no-print { display: none !important; }
}
.for-you {
  font-size: .78rem;
  color: #fff;
  background: #e76f51;
  border-radius: 10px;
  padding: 3px 10px;
  margin-left: 8px;
  vertical-align: middle;
  white-space: nowrap;
  animation: pop .5s;
}

.ws-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.ws-card {
  font-family: inherit;
  position: relative;
  background: #fff;
  border: 3px solid #f0d9a8;
  border-radius: 18px;
  padding: 14px 12px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 3px 0 #ecd9ab;
  transition: transform .1s;
}
.ws-card:not(.locked):hover { transform: translateY(-2px); }
.ws-card:active { transform: scale(.97); }
.ws-title { font-size: 1.05rem; font-weight: bold; color: #264653; }
.ws-stars { font-size: 1rem; letter-spacing: 2px; }
.ws-card .badge {
  font-size: .8rem;
  color: #b8860b;
  background: #fff6d9;
  border-radius: 8px;
  padding: 2px 8px;
  align-self: flex-start;
}
.ws-card.mastered { border-color: #ffd166; background: #fffcf0; }
.ws-card.locked { opacity: .55; cursor: not-allowed; filter: grayscale(.6); }
.ws-card .lock { position: absolute; top: 8px; right: 10px; font-size: 1.1rem; }

/* ===== Misi harian & streak ===== */

.parent-link {
  display: block;
  margin-top: 16px;
  font-size: .85rem;
  color: #2a9d8f;
  text-decoration: none;
}
.parent-link:hover { text-decoration: underline; }

.mission-card {
  display: flex;
  gap: 14px;
  align-items: stretch;
  background: linear-gradient(135deg, #fff8e8, #fff);
  border: 3px solid #ffd166;
  border-radius: 20px;
  padding: 14px 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  box-shadow: 0 3px 0 #ecd9ab;
}

.streak {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  padding: 6px 14px;
  border-right: 3px dotted #f0d9a8;
  color: #999;
}
.streak b { font-size: 1.8rem; color: #264653; }
.streak span:last-child { font-size: .75rem; }
.streak .flame { font-size: 1.4rem; filter: grayscale(1); }
.streak.hot { color: #e76f51; }
.streak.hot .flame { filter: none; animation: flicker 1s infinite alternate; }
@keyframes flicker { from { transform: scale(1) rotate(-3deg); } to { transform: scale(1.15) rotate(3deg); } }

.mission { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.mission-top { display: flex; justify-content: space-between; gap: 8px; color: #264653; font-size: .95rem; }
.bar {
  height: 16px;
  background: #f1e6cd;
  border-radius: 10px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f4a261, #e9c46a);
  border-radius: 10px;
  transition: width .6s;
}
.bar-fill.full { background: linear-gradient(90deg, #2a9d8f, #52b788); }
.mission-msg { font-size: .85rem; color: #888; }
.mission-msg.done { color: #2a9d8f; font-weight: bold; }
.mission-hit { color: #e76f51 !important; animation: pop .5s; }

/* ===== Jalan kira ===== */

.help-btn {
  font-family: inherit;
  font-size: .95rem;
  border: 2px solid #90bede;
  background: #fff;
  color: #457b9d;
  border-radius: 12px;
  padding: 4px 12px;
  cursor: pointer;
}
.help-btn:active { transform: scale(.93); }

.jk-panel {
  flex-basis: 100%;
  background: #f0f7ff;
  border: 2px dashed #90bede;
  border-radius: 14px;
  padding: 12px 14px;
  margin-top: 4px;
}
.jk-title { font-size: .95rem; color: #457b9d; font-weight: bold; margin-bottom: 8px; }
.jk-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jk-item {
  position: relative;
  font-size: 1.7rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  animation: jkPop .35s both;
}
.jk-num {
  font-size: .8rem;
  color: #457b9d;
  background: #fff;
  border: 1.5px solid #90bede;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: jkPop .3s both;
}
.jk-item.crossed { opacity: .8; }
.jk-item.crossed::after {
  content: '✖';
  position: absolute;
  top: 2px;
  font-size: 1.6rem;
  color: #e63946;
}
.jk-item.crossed .jk-num { color: #e63946; border-color: #f4978e; }
.jk-op { font-size: 1.6rem; color: #264653; font-weight: bold; margin: 0 4px; }
.jk-eq {
  margin-top: 10px;
  font-size: 1.3rem;
  color: #264653;
  animation: jkPop .4s both;
}
.jk-eq b { color: #2a9d8f; font-size: 1.6rem; }
@keyframes jkPop {
  from { opacity: 0; transform: scale(.3) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.jk-circle {
  display: inline-flex;
  gap: 4px;
  padding: 6px 8px;
  border: 2px dashed #b8d4ea;
  border-radius: 14px;
  margin: 2px;
  position: relative;
}
.jk-circle .jk-gnum {
  position: absolute;
  top: -10px;
  left: -6px;
  font-size: .8rem;
  color: #fff;
  background: #457b9d;
  border-radius: 50%;
  min-width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: jkPop .3s both;
}

/* ===== Jenis soalan baru ===== */

.trace-ghost {
  font-size: 5rem;
  font-weight: bold;
  color: transparent;
  -webkit-text-stroke: 3px #b8d4ea;
  line-height: 1;
  letter-spacing: 6px;
}

.word-q {
  font-size: 1.15rem;
  color: #264653;
  line-height: 1.5;
  max-width: 340px;
}

.mcq-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 10px;
}
.mcq-btn {
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: bold;
  color: #264653;
  background: #fff;
  border: 3px solid #90bede;
  border-radius: 16px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform .1s;
}
.mcq-btn:not(:disabled):hover { transform: translateY(-2px); }
.mcq-btn:active { transform: scale(.95); }
.mcq-btn.right { background: #e8f7e4; border-color: #7fc96b; color: #2e7d32; }
.mcq-btn.wrong-choice { background: #fdecea; border-color: #f4978e; color: #c62828; opacity: .7; }
.mcq-btn:disabled { cursor: default; }
