/* Pupil (tablet) styles. Big targets, calm colours, one thing at a time. */

:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --ink: #23314d;
  --muted: #5c6b85;
  --line: #e7e0d2;
  --accent: #ff7a45;
  --accent-dark: #e05f2c;
  --ok: #1f9d6b;
  --ok-bg: #e3f6ee;
  --warm: #f2a33a;
  --warm-bg: #fff2dc;
  --blue: #3567d6;
  --key: #f4efe5;
  --key-dark: #ded5c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.screen[hidden] { display: none; }

.card {
  width: min(640px, 100%);
  background: var(--card);
  border-radius: 28px;
  box-shadow: 0 10px 30px rgba(35, 49, 77, 0.10);
}

/* ---------- home & summary ---------- */

.home-card { padding: 40px 28px; text-align: center; }

.badge {
  width: 84px; height: 84px; margin: 0 auto 12px; border-radius: 50%;
  display: grid; place-items: center; font-size: 44px; color: #fff; background: var(--accent);
}
.badge.big { background: var(--warm-bg); }

h1 { font-size: 2.4rem; margin: 0 0 8px; }
.lead { font-size: 1.3rem; color: var(--muted); margin: 0 0 16px; }
.streak { font-size: 1.15rem; font-weight: 600; color: var(--accent-dark); margin: 0 0 24px; }
.error { color: #b33; margin-top: 16px; }

.big-btn {
  font-size: 1.5rem; font-weight: 700;
  min-height: 72px; min-width: 240px; padding: 16px 32px;
  border: none; border-radius: 20px; color: #fff;
  background: var(--accent); box-shadow: 0 6px 0 var(--accent-dark);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }
.big-btn:disabled { opacity: .5; }

.stats { display: flex; justify-content: center; gap: 12px; margin: 20px 0; flex-wrap: wrap; }
.stat {
  background: var(--bg); border-radius: 18px; padding: 14px 18px; min-width: 120px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat b { font-size: 2.2rem; }
.stat span { color: var(--muted); }

/* ---------- question ---------- */

#question { justify-content: flex-start; }

.q-top {
  width: min(640px, 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ghost-btn {
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 14px; font-size: 1rem; min-height: 48px;
}
.dots { display: flex; gap: 8px; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--key-dark); }
.dot.now { background: var(--accent); transform: scale(1.25); }
.dot.ok { background: var(--ok); }
.dot.later { background: var(--warm); }

.q-card { padding: 22px 24px 18px; display: grid; gap: 18px; }
.q-head { display: flex; justify-content: space-between; color: var(--muted); font-weight: 600; }
.q-label { color: var(--blue); }

.q-prompt {
  min-height: 110px; display: grid; place-items: center;
  overflow: hidden; padding: 8px 0;
}
/* font size is set by fitPrompt() in practice.js so long sums always fit */
.q-prompt .sum, .q-prompt .column-sum, .q-prompt .bus-stop { font-size: 2.8rem; }

/* Missing-number box shows what she's typing */
.q-prompt .gap-box {
  min-width: 2.8em; width: auto; padding: 0 .25em; text-align: center;
  line-height: 1.2; color: var(--blue); font-weight: 700;
}
.q-prompt .gap-box.typing { background: #fff7f2; }

.answer-area { display: flex; justify-content: center; }
.answer-area.in-prompt #number-entry { display: none; }
.number-entry, .fraction-entry { display: flex; align-items: center; gap: 14px; }
.number-entry[hidden], .fraction-entry[hidden] { display: none; }
.entry-label { color: var(--muted); font-weight: 600; font-size: 1.1rem; }

.entry-box {
  min-width: 190px; min-height: 64px; padding: 6px 14px;
  border: 3px solid var(--line); border-radius: 16px;
  font-size: 2.2rem; font-weight: 700; color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums; cursor: pointer;
}
.entry-box.small { min-width: 84px; min-height: 56px; font-size: 1.8rem; }
.entry-box.active { border-color: var(--accent); background: #fff7f2; }
.frac-builder { display: flex; align-items: center; gap: 10px; }
.frac-stack { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.frac-line { width: 100%; height: 4px; border-radius: 2px; background: var(--ink); }

.tries { text-align: center; color: var(--muted); margin: 0; min-height: 1.4em; }

/* ---------- keypad ---------- */

.keypad {
  width: min(640px, 100%);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.keypad button {
  min-height: clamp(56px, 8.5vh, 104px); font-size: 1.8rem; font-weight: 600;
  border: none; border-radius: 16px; background: var(--key); box-shadow: 0 4px 0 var(--key-dark);
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--key-dark); }
.keypad .mode-btn { font-size: 1.2rem; background: #e8eefc; box-shadow: 0 4px 0 #c9d6f4; }
.keypad .check-btn {
  grid-column: span 2; color: #fff; background: var(--ok); box-shadow: 0 4px 0 #157a52;
}
.keypad .check-btn:disabled { opacity: .5; }

/* ---------- feedback ---------- */

.feedback {
  position: fixed; inset: 0; z-index: 20; background: rgba(35, 49, 77, .35);
  display: grid; place-items: center; padding: 16px;
}
.feedback[hidden] { display: none; }
.feedback-card {
  width: min(480px, 100%); background: var(--card); border-radius: 28px;
  padding: 32px 24px; text-align: center; animation: pop .25s ease-out;
}
.fb-icon { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.feedback-card h2 { font-size: 2rem; margin: 0 0 8px; }
.feedback-card p { font-size: 1.25rem; color: var(--muted); margin: 0 0 24px; }
.feedback.good .feedback-card h2 { color: var(--ok); }
.feedback.retry .feedback-card h2 { color: var(--accent-dark); }
.feedback.later .feedback-card h2 { color: var(--warm); }

@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- working-out pad ---------- */

.pad {
  position: fixed; inset: 0; z-index: 10; background: var(--card);
  display: flex; flex-direction: column;
}
.pad[hidden] { display: none; }
.pad-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; border-bottom: 2px solid var(--line);
  font-weight: 700; font-size: 1.2rem;
}
.pad-bar div { display: flex; gap: 8px; }
.pad-q { padding: 10px 16px; text-align: center; border-bottom: 1px solid var(--line); }
.pad-q .sum, .pad-q .column-sum, .pad-q .bus-stop { font-size: 1.8rem; }
#pad-canvas {
  flex: 1; width: 100%; touch-action: none;
  background-color: #fff;
  background-image:
    linear-gradient(#e9eef7 1px, transparent 1px),
    linear-gradient(90deg, #e9eef7 1px, transparent 1px);
  background-size: 32px 32px;
}

@media (max-height: 760px) {
  .q-prompt { min-height: 80px; }
}
@media (min-height: 1000px) {
  .q-card { padding: 30px 28px 24px; }
  .q-prompt { min-height: 170px; }
  .keypad button { font-size: 2.2rem; }
}

/* ---------- tutor ---------- */

.top-actions { display: flex; gap: 8px; }
.top-actions [hidden] { display: none; }
.help-btn { border-color: #c9d6f4; background: #eef3ff; color: var(--blue); font-weight: 700; }
.help-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.tutor {
  position: fixed; inset: 0; z-index: 9; background: rgba(35, 49, 77, .30);
  display: flex; align-items: flex-end; justify-content: center;
}
.tutor[hidden] { display: none; }
.tutor-sheet {
  width: min(760px, 100%); height: min(88dvh, 900px);
  background: var(--card); border-radius: 28px 28px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideup .25s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.tutor-bar {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px;
  border-bottom: 2px solid var(--line);
}
.tutor-title { font-weight: 800; font-size: 1.25rem; }
.tutor-step { flex: 1; color: var(--muted); font-size: .95rem; }
.tutor-q { padding: 10px 16px; text-align: center; background: var(--bg); overflow-x: auto; }
.tutor-q .sum, .tutor-q .column-sum, .tutor-q .bus-stop { font-size: 1.6rem; }

.tutor-msgs {
  position: relative;
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  -webkit-user-select: text; user-select: text;
}
.bubble {
  max-width: 85%; padding: 12px 16px; border-radius: 20px; font-size: 1.2rem; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word;
}
.bubble.from-tutor { align-self: flex-start; background: var(--warm-bg); border-bottom-left-radius: 6px; }
.bubble.from-pupil { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 6px; }
.bubble.from-answer { align-self: flex-end; background: #e8eefc; color: var(--ink); border-bottom-right-radius: 6px; }
.bubble.typing { color: var(--muted); }
.bubble.typing span { animation: blink 1.2s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .2s; }
.bubble.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.tutor-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px; }
.tutor-chips:empty { display: none; }
.tutor-chips button {
  border: 2px solid var(--blue); color: var(--blue); background: #fff; border-radius: 999px;
  padding: 10px 16px; font-size: 1.05rem; font-weight: 600; min-height: 48px;
}

.tutor-actions { display: flex; gap: 10px; padding: 12px 16px 0; }
.tutor-actions [hidden] { display: none; }
.soft-btn, .go-btn {
  flex: 1; min-height: 56px; border: none; border-radius: 16px; font-size: 1.15rem; font-weight: 700;
}
.soft-btn { background: #fff4cf; box-shadow: 0 4px 0 #ecd98f; }
.go-btn { background: var(--ok); color: #fff; box-shadow: 0 4px 0 #157a52; }
.soft-btn:active, .go-btn:active { transform: translateY(3px); box-shadow: none; }
.soft-btn:disabled, .go-btn:disabled, .tutor-chips button:disabled { opacity: .5; }

.tutor-form { display: flex; gap: 8px; padding: 12px 16px 16px; }
.tutor-form input {
  flex: 1; min-height: 52px; border: 2px solid var(--line); border-radius: 16px;
  padding: 0 14px; font: inherit; font-size: 1.1rem; -webkit-user-select: text; user-select: text;
}
.tutor-form input:focus { outline: none; border-color: var(--blue); }
.send-btn {
  width: 56px; border: none; border-radius: 16px; background: var(--blue); color: #fff; font-size: 1.3rem;
}

.with-help-note {
  width: min(640px, 100%); text-align: center; color: var(--blue); font-weight: 600; margin: -4px 0 0;
}

/* ---------- method walkthrough card (in the tutor chat) ---------- */

.mcard {
  align-self: stretch; background: #fff; border: 3px solid #c9d6f4; border-radius: 20px;
  padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 10px;
  -webkit-user-select: none; user-select: none;
}
.mcard-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mcard-badge {
  background: var(--blue); color: #fff; font-weight: 700; font-size: .9rem;
  padding: 4px 10px; border-radius: 999px;
}
.mcard-title { font-weight: 700; color: var(--ink); }
.mcard-stage {
  min-height: 150px; display: grid; place-items: center; padding: 10px 4px;
  background: #fafbff; border-radius: 14px; overflow-x: auto;
}
.mcard-caption { margin: 0; font-size: 1.15rem; line-height: 1.45; min-height: 3em; }
.mcard-controls { display: flex; align-items: center; gap: 10px; }
.mcard-controls button {
  min-height: 52px; min-width: 110px; border: none; border-radius: 14px; font-size: 1.1rem; font-weight: 700;
  background: var(--key); box-shadow: 0 3px 0 var(--key-dark);
}
.mcard-controls button:disabled { opacity: .4; }
.mcard-controls .mc-next { background: var(--blue); color: #fff; box-shadow: 0 3px 0 #2a50aa; margin-left: auto; }
.mcard-count { color: var(--muted); font-weight: 600; flex: 1; text-align: center; }

/* digit grid */
.mgrid { display: inline-flex; flex-direction: column; font-size: clamp(1.4rem, 4.2vw, 2rem);
         font-variant-numeric: tabular-nums; font-weight: 600; }
.mrow { display: grid; grid-template-columns: repeat(var(--cols), 1.4em); }
.mrow.k-rule { height: 0; border-top: 3px solid var(--ink); margin: 2px 0; grid-template-columns: none; }
/* small rows: shrink the cells, not the row, so the columns stay lined up */
.mrow.k-small { color: var(--accent-dark); }
.mrow.k-small .mcell { font-size: .55em; height: 1.3em; }
.mrow.k-head { color: var(--muted); font-weight: 700; }
.mrow.k-head .mcell { font-size: .5em; height: 2em; }
.mcell {
  position: relative; height: 1.45em; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: background .2s;
}
.mcell.hl { background: #fff1b8; box-shadow: inset 0 0 0 2px #f2c94c; }
.mcell.new { color: var(--blue); animation: mpop .35s ease-out; }
.mcell.struck { color: #9aa3b5; text-decoration: line-through; text-decoration-thickness: 2px; }
.mcell.pad { color: #9aa3b5; font-style: italic; }
.mcell.faint { color: #9aa3b5; }
.mcell.dp::after { content: "."; position: absolute; right: -.12em; bottom: .05em; font-weight: 800; }
.mcell.bus { border-top: 3px solid var(--ink); border-left: 3px solid var(--ink); border-radius: 8px 0 0 0; }
.mcell.top { border-top: 3px solid var(--ink); border-radius: 0; }
/* a carried digit (short division): small, in a soft bubble at the bottom-left of the digit it
   joins, so it can't be read as a power of the digit before it ("3³") */
.mcarry {
  position: absolute; bottom: .12em; left: .02em; font-size: .45em; line-height: 1.25; color: var(--accent-dark);
  font-weight: 800; background: #ffe9dc; border-radius: 999px; padding: 0 .3em;
}
.mcell.has-carry { justify-content: flex-end; padding-right: .08em; }
@keyframes mpop { from { transform: scale(1.5); } to { transform: scale(1); } }

/* lines (fractions, percentages ...) */
.mlines { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.mline { padding: 4px 10px; border-radius: 10px; color: var(--muted); }
.mline .sum { font-size: 1.35rem; white-space: normal; }
.mline.hl { background: #fff1b8; color: var(--ink); font-weight: 600; }
.mline .gap-box { width: 2em; height: 1.1em; }

/* ---------- start screen: suggestion + picker ---------- */

.home-wrap { width: min(640px, 100%); display: grid; gap: 16px; }
.home-wrap .card { width: 100%; }
.home-card .streak { margin-bottom: 16px; }

.suggest {
  background: var(--warm-bg); border-radius: 22px; padding: 18px 18px 14px; margin: 0 0 20px;
}
.suggest[hidden] { display: none; }
.suggest-emoji { font-size: 2.6rem; line-height: 1; }
.suggest-title { font-size: 1.5rem; font-weight: 700; margin: 8px 0 4px; }
.suggest-reason { font-size: 1.15rem; color: var(--muted); margin: 0; }

.picker { padding: 22px 20px 24px; }
.picker[hidden] { display: none; }
.pick-title { font-size: 1.35rem; margin: 0 0 14px; text-align: center; }
.pick-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.pick-head .pick-title { margin: 0; flex: 1; text-align: left; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tiles.two { grid-template-columns: 1fr 1fr; }
.tile {
  min-height: 76px; padding: 12px 14px; border-radius: 18px;
  border: 3px solid var(--line); background: var(--card);
  display: flex; align-items: center; gap: 10px; text-align: left;
  font-size: 1.2rem; font-weight: 700; color: var(--ink);
  box-shadow: 0 4px 0 var(--key-dark);
}
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--key-dark); }
.tile:disabled { opacity: .5; }
.tile .t-emoji { font-size: 1.8rem; flex: none; }
.tile.subject { justify-content: center; min-height: 92px; font-size: 1.45rem; }
.tile.mix { border-style: dashed; }
.tile.now { border-color: var(--accent); }

.q-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.q-topic { font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden;
           text-overflow: ellipsis; max-width: 100%; }
.q-topic[hidden] { display: none; }

/* landscape tablet: the suggestion and the picker side by side */
@media (orientation: landscape) and (min-width: 900px) {
  .home-wrap { width: min(1100px, 100%); grid-template-columns: 1fr 1fr; align-items: center; }
}
.home-wrap.picking { grid-template-columns: 1fr; width: min(760px, 100%); }
.home-wrap.picking .home-card { display: none; }
