/* ICT Lessons – shared styles. Designed for iPad (touch) first, Mac second. */
:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1f2430;
  --ink-soft: #5b6273;
  --line: #e3ddd0;
  --brand: #2f6fde;
  --brand-dark: #1f55b3;
  --good: #1f9d63;
  --warn: #e08a00;
  --bad: #d64545;
  --star: #f5b301;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(31, 36, 48, .06), 0 8px 24px rgba(31, 36, 48, .06);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;

  --c-blue: #2f6fde; --c-purple: #7b4fd6; --c-pink: #d6418a; --c-green: #1f9d63;
  --c-orange: #e0701a; --c-teal: #0d9488; --c-grey: #8a8f9c;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
a { color: var(--brand); }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- Buttons ---------- */
button, .btn {
  font: inherit;
  border: 0;
  border-radius: 14px;
  padding: 12px 20px;
  min-height: 48px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: 0 3px 0 var(--brand-dark);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--brand-dark); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #9cc0ff; outline-offset: 2px;
}
.btn-ghost { background: #fff; color: var(--ink); box-shadow: 0 3px 0 var(--line); border: 2px solid var(--line); }
.btn-ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn-good { background: var(--good); box-shadow: 0 3px 0 #157a4b; }
.btn-bad { background: var(--bad); box-shadow: 0 3px 0 #a83232; }
.btn-warn { background: var(--warn); box-shadow: 0 3px 0 #b06c00; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn-big { min-height: 64px; font-size: 1.25rem; padding: 14px 28px; }
.link-btn { background: none; box-shadow: none; color: var(--brand); padding: 6px; min-height: 0; font-weight: 600; }
.link-btn:active { transform: none; box-shadow: none; }

/* ---------- Forms ---------- */
input[type=text], input[type=password], input[type=time], input[type=number], select, textarea {
  font: inherit;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  min-height: 48px;
}
textarea { min-height: 120px; width: 100%; resize: vertical; }
label { font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 2px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .logo { font-size: 1.8rem; }
.topbar .title { font-weight: 800; font-size: 1.2rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.grid { display: grid; gap: 16px; }
.grid-tiles { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid-small { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: .85rem; font-weight: 700;
  background: #eef1f6; color: var(--ink-soft);
}
.pill.good { background: #e2f5ec; color: #157a4b; }
.pill.bad { background: #fde8e8; color: #a83232; }
.pill.warn { background: #fff1d9; color: #965c00; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c7ccd6; display: inline-block; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px #c9efdc; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.tab {
  background: #fff; color: var(--ink); box-shadow: none; border: 2px solid var(--line);
  min-height: 48px;
}
.tab[aria-selected=true] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab:active { box-shadow: none; }

/* ---------- Tiles (login + home) ---------- */
.tile {
  background: #fff;
  border: 3px solid transparent;
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 20px 14px;
  min-height: 130px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--ink);
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
}
.tile:active { transform: scale(.97); box-shadow: var(--shadow); }
.tile .emoji { font-size: 3rem; line-height: 1; }
.tile .sub { font-weight: 600; color: var(--ink-soft); font-size: .9rem; }
.tile.disabled { opacity: .55; cursor: default; }

/* Unit cards */
.unit {
  --c: var(--c-blue);
  background: #fff; border-radius: 22px; box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; text-align: left;
  align-items: stretch; justify-content: flex-start;
  color: var(--ink); padding: 0; min-height: 0; font-weight: 400;
}
.unit:active { transform: scale(.98); box-shadow: var(--shadow); }
.unit .band { background: var(--c); color: #fff; padding: 18px; display: flex; gap: 14px; align-items: center; min-height: 104px; }
.unit .band .emoji { font-size: 2.6rem; }
.unit .band h3 { margin: 0; font-size: 1.2rem; }
.unit .band .sub { opacity: .9; font-weight: 600; font-size: .9rem; }
.unit .foot { padding: 14px 18px; display: flex; flex-direction: column; gap: 8px; }
.bar { height: 12px; border-radius: 6px; background: #eef0f4; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--c); border-radius: 6px; }
.c-blue { --c: var(--c-blue); } .c-purple { --c: var(--c-purple); } .c-pink { --c: var(--c-pink); }
.c-green { --c: var(--c-green); } .c-orange { --c: var(--c-orange); } .c-teal { --c: var(--c-teal); } .c-grey { --c: var(--c-grey); }

/* Lesson list */
.lessons { display: grid; gap: 12px; }
.lesson {
  display: flex; align-items: center; gap: 16px;
  background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 14px 18px;
  color: var(--ink); text-decoration: none; min-height: 76px;
}
.lesson .num {
  width: 48px; height: 48px; border-radius: 14px; background: var(--c, var(--brand)); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; flex: none;
}
.lesson.soon { opacity: .6; }
.stars { color: var(--star); font-size: 1.4rem; letter-spacing: 2px; white-space: nowrap; }
.stars .off { color: #dfe2e8; }

/* ---------- Login ---------- */
.login-wrap { max-width: 900px; margin: 0 auto; padding: 32px 20px 60px; }
.login-head { text-align: center; margin-bottom: 28px; }
.login-head .logo { font-size: 3.4rem; }
.step-title { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.step-title h2 { margin: 0; flex: 1; }

.keypad { display: grid; grid-template-columns: repeat(3, 92px); gap: 14px; justify-content: center; }
.keypad button { min-height: 80px; font-size: 2rem; background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.keypad button:active { box-shadow: 0 1px 0 var(--line); }
.code-slots, .pic-slots { display: flex; gap: 12px; justify-content: center; margin: 12px 0 24px; }
.code-slots span, .pic-slots span {
  width: 64px; height: 72px; border-radius: 16px; background: #fff; border: 3px dashed var(--line);
  display: grid; place-items: center; font-size: 2rem; font-weight: 800;
}
.code-slots span.full, .pic-slots span.full { border-style: solid; border-color: var(--brand); }
.pic-slots span { width: 88px; height: 88px; font-size: 3rem; }

.pic-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; max-width: 560px; margin: 0 auto; }
.pic-grid button {
  min-height: 110px; font-size: 3.4rem; background: #fff; border: 3px solid var(--line);
  box-shadow: 0 4px 0 var(--line); border-radius: 22px;
}
.pic-grid button:active { box-shadow: 0 1px 0 var(--line); }
.pic-grid button.picked { border-color: var(--brand); background: #eef4ff; }

.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.names button {
  background: #fff; color: var(--ink); border: 3px solid var(--line); box-shadow: 0 4px 0 var(--line);
  min-height: 72px; font-size: 1.15rem;
}

.shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.error-msg { color: var(--bad); font-weight: 700; text-align: center; min-height: 1.5em; margin: 8px 0; }
.check { display: flex; align-items: center; gap: 10px; justify-content: center; font-weight: 600; margin-top: 16px; }
.check input { width: 26px; height: 26px; }

/* ---------- Lock / closed overlay ---------- */
.ict-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  text-align: center; padding: 30px;
  background: #1f2430; color: #fff;
  font-family: var(--font);
}
.ict-overlay.locked { background: radial-gradient(circle at 50% 40%, #3a4566, #1f2430 70%); }
.ict-overlay .big { font-size: 7rem; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.ict-overlay h1 { font-size: 2.6rem; margin: 0; max-width: 800px; }
.ict-overlay p { font-size: 1.3rem; margin: 0; opacity: .85; max-width: 700px; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@media (prefers-reduced-motion: reduce) { .ict-overlay .big, .shake { animation: none; } }

/* ---------- Modal / toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20, 24, 33, .45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 22px; padding: 24px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { max-width: 900px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; z-index: 2000;
  font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.bad { background: var(--bad); }

/* ---------- Tables (admin) ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .85rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.progress-grid td, .progress-grid th { text-align: center; white-space: nowrap; }
.progress-grid thead th { white-space: normal; min-width: 80px; max-width: 130px; vertical-align: bottom; }
.progress-grid td:first-child, .progress-grid th:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.typing-results td { line-height: 1.3; }
.spark { display: inline-block; vertical-align: middle; fill: var(--c-blue); }
.cell { display: inline-grid; place-items: center; min-width: 54px; height: 36px; border-radius: 10px; font-weight: 800; font-size: .95rem; }
.cell.none { background: #f2f3f6; color: #b6bbc6; }
.cell.started { background: #fff1d9; color: #965c00; }
.cell.completed { background: #e2f5ec; color: #157a4b; }

/* Admin live cards */
.class-card { display: flex; flex-direction: column; gap: 12px; border: 3px solid transparent; }
.class-card.is-locked { border-color: var(--warn); }
.class-card.is-closed { opacity: .8; }
.class-card .head { display: flex; align-items: center; gap: 12px; }
.class-card .head .emoji { font-size: 2.4rem; }
.class-key { font-family: ui-monospace, Menlo, monospace; font-size: 1.3rem; font-weight: 800; letter-spacing: .15em; }
.banner {
  padding: 14px 18px; border-radius: 16px; font-weight: 700; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.banner.warn { background: #fff1d9; color: #7a4a00; }
.banner.bad { background: #fde8e8; color: #8a2424; }
.banner.info { background: #e7efff; color: #1f3f80; }

.window-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---------- Print: login cards ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .login-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8mm; }
  .login-card { border: 2px dashed #999; border-radius: 6mm; padding: 6mm; break-inside: avoid; font-family: var(--font); }
  .login-card .name { font-size: 18pt; font-weight: 800; }
  .login-card .pics { font-size: 34pt; letter-spacing: 6mm; margin: 3mm 0; }
  .login-card .meta { font-size: 10pt; color: #444; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 1.6rem; }
  .pic-grid button { min-height: 80px; font-size: 2.6rem; }
  .keypad { grid-template-columns: repeat(3, 76px); }
}

/* "📱 iPad needed" labels for units that use the iPad's sensors (curriculum "needs": "ipad"). */
.needs-badge { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.9); color: #965c00; font-size: .8rem; font-weight: 700; }
.needs-note { background: #fff1d9; color: #6b4200; border-radius: 12px; padding: 10px 14px; font-weight: 600; margin: 8px 0 16px; }

/* Staff: groups and documents */
.group-card { border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.tick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 12px; max-height: 46vh; overflow-y: auto; padding: 4px; }
.tick { display: block; padding: 6px 0; font-weight: 600; cursor: pointer; line-height: 1.4; }
.tick input { width: 20px; height: 20px; vertical-align: -4px; margin: 0 8px 0 0; }
.kind-pick { border: 2px solid var(--line); border-radius: 10px; padding: 6px 12px; }

/* Hints (/js/hints.js): unlock one at a time after a minute. */
.hints { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 4px 0 10px; }
.hint-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; width: 100%; }
.hint { background: #fff8d9; border: 2px solid #f0dc8a; border-radius: 12px; padding: 8px 12px; line-height: 1.45; }
.hint-num { font-weight: 800; color: #965c00; margin-right: 4px; }
.hint-code { font: 700 .95em ui-monospace, Menlo, monospace; background: #fff; border: 1px solid #ecd27a; border-radius: 6px; padding: 1px 6px; }
pre.hint-code { display: block; margin: 6px 0 0; padding: 6px 10px; white-space: pre-wrap; }
.hint-btn { min-height: 40px; font-weight: 800; }
.hint-btn:disabled { opacity: .75; cursor: default; font-variant-numeric: tabular-nums; }

/* ---------- EN / 中文 language switch (/js/i18n.js) ---------- */
html.lang-zh { --font: ui-rounded, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif; }
html.i18n-wait body { visibility: hidden; }
.lang-switch {
  display: inline-flex; align-items: stretch; flex: none; padding: 0; gap: 0; min-height: 44px;
  border: 2px solid var(--line, #d6dbe4); border-radius: 999px; background: #fff; overflow: hidden; cursor: pointer;
  font: 800 .95rem var(--font); color: #556; box-shadow: none;
}
.lang-switch span { display: flex; align-items: center; padding: 0 12px; }
.lang-switch span.on { background: var(--brand, #2f6fde); color: #fff; }
.lang-switch .zh { font-family: "PingFang SC", "Hiragino Sans GB", "Heiti SC", sans-serif; }
.lang-switch:focus-visible { outline: 3px solid var(--brand, #2f6fde); outline-offset: 2px; }
.lang-switch.floating { position: fixed; top: 12px; right: 12px; z-index: 900; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }
@media print { .lang-switch { display: none !important; } }
