/* Shell styles. Every value derives from tokens.css — no raw colors here. */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.l1 { font-family: var(--font-ja); }
[data-lang="en"] .l1 { display: none !important; }
[data-lang="l1"] .en { display: none !important; }
button { font-family: var(--font-sans); cursor: pointer; }
:focus-visible { outline: 3px solid var(--brand-accent); outline-offset: 2px; }

.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--brand-deep); color: var(--on-brand);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: calc(15px * var(--scale)); letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-dot); box-shadow: 0 0 0 3px rgba(91,141,239,.25); flex-shrink: 0; }
.tb-spacer { margin-left: auto; }
.tb-btn {
  background: rgba(255,255,255,.12); border: none; color: var(--on-brand);
  font-weight: 600; font-size: calc(11px * var(--scale));
  padding: 7px 12px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 6px;
}
.tb-btn:hover { background: rgba(255,255,255,.22); }
.seg { display: flex; background: rgba(255,255,255,.10); border-radius: var(--r-pill); padding: 3px; }
.seg button {
  background: none; border: none; color: var(--on-brand-soft);
  font-size: calc(11px * var(--scale)); font-weight: 600;
  padding: 5px 10px; border-radius: var(--r-pill);
}
.seg button.on { background: var(--card); color: var(--brand); }

/* Main column */
.main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 20px 16px 90px; }
.main.wide { max-width: none; padding: 0; display: flex; flex-direction: column; }

.kicker { font-size: calc(11px * var(--scale)); font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--text-muted); }
h1.page-title { color: var(--brand); font-weight: 700; font-size: calc(26px * var(--scale)); line-height: 1.15; margin: 6px 0 2px; }
.page-sub { font-family: var(--font-serif); font-style: italic; color: var(--brand-light); font-size: calc(17px * var(--scale)); margin-bottom: 18px; }

/* Cards & list items */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-card);
  padding: 16px 18px; margin-bottom: 12px;
}
.item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 16px; margin-bottom: 10px;
  transition: .14s; color: var(--text);
}
.item:hover { border-color: var(--brand-mist-2); box-shadow: var(--shadow-pop); transform: translateY(-1px); }
.item .ph {
  flex-shrink: 0; width: calc(40px * var(--scale)); height: calc(40px * var(--scale));
  border-radius: var(--r-md); background: var(--brand-mist); color: var(--brand);
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  font-size: calc(15px * var(--scale));
}
.item.done .ph { background: var(--success-bg); color: var(--success); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 700; font-size: calc(15px * var(--scale)); }
.item .desc { font-size: calc(12px * var(--scale)); color: var(--text-muted); margin-top: 2px; }
.item .meta { flex-shrink: 0; font-size: calc(11px * var(--scale)); font-weight: 700; color: var(--brand-light); background: var(--brand-mist); border-radius: var(--r-pill); padding: 5px 11px; white-space: nowrap; }
.item .meta.done { color: var(--success); background: var(--success-bg); }
.item .arrow { flex-shrink: 0; color: var(--text-faint); font-size: calc(17px * var(--scale)); }

.group-lab { font-size: calc(11px * var(--scale)); font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); margin: 22px 0 11px; display: flex; align-items: center; gap: 10px; }
.group-lab .line { flex: 1; height: 1px; background: var(--border); }

/* Progress bar */
.pbar { height: 8px; background: var(--surface-100); border-radius: var(--r-pill); overflow: hidden; margin-top: 8px; }
.pbar > div { height: 100%; background: var(--brand-accent); border-radius: var(--r-pill); transition: width .3s; }

/* Unit viewer */
.viewerbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 8px 14px;
}
.viewerbar .vtitle { font-weight: 700; font-size: calc(13px * var(--scale)); color: var(--brand); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewerbar .pageinfo { font-size: calc(11px * var(--scale)); color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.vbtn {
  border: 1px solid var(--border); background: var(--surface-50); color: var(--brand);
  font-weight: 700; font-size: calc(12px * var(--scale));
  padding: 7px 12px; border-radius: var(--r-pill);
}
.vbtn:disabled { opacity: .4; cursor: default; }
.vbtn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.vbtn.primary.is-done { background: var(--success); border-color: var(--success); }
.frame-wrap { flex: 1; display: flex; }
.frame-wrap iframe { flex: 1; width: 100%; border: 0; background: var(--card); }

/* Toast + status */
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--brand-deep); color: var(--on-brand);
  border-radius: var(--r-pill); padding: 10px 18px;
  font-size: calc(12px * var(--scale)); font-weight: 600;
  box-shadow: var(--shadow-pop); z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.toast.show { opacity: 1; }
.sync-chip { font-size: calc(10px * var(--scale)); font-weight: 700; border-radius: var(--r-pill); padding: 3px 9px; }
.sync-chip.offline { background: var(--warn-bg); color: var(--warn); }
.sync-chip.online { background: var(--success-bg); color: var(--success); }
.sync-chip.warn { background: var(--danger-bg); color: var(--danger); }

.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; font-size: calc(13px * var(--scale)); }

@media (max-width: 640px) {
  .main { padding: 16px 12px 90px; }
  .item .desc { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Sign-in */
.login-card { max-width: 420px; }
.fld { display: block; font-size: calc(12px * var(--scale)); font-weight: 700; color: var(--text-2); margin-bottom: 14px; }
.fld input {
  display: block; width: 100%; margin-top: 6px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-50); color: var(--text);
  font-family: var(--font-sans); font-size: calc(15px * var(--scale));
  padding: 11px 12px;
}
.fld input:focus { border-color: var(--brand-accent); outline: none; box-shadow: 0 0 0 3px var(--brand-mist-2); }
.login-btn { display: block; width: 100%; margin-top: 10px; padding: 12px; }
.login-err { color: var(--danger); font-size: calc(12px * var(--scale)); font-weight: 600; min-height: 1em; margin-bottom: 4px; }

/* Effort + score strip (unit viewer) */
.syncrow { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin: 10px 0 12px; }
.syncrow .slab { font-size: calc(12px * var(--scale)); font-weight: 700; color: var(--text-2); margin-right: 2px; }
.syncrow .effort, .syncrow .scorebox { display: flex; align-items: center; gap: 6px; }
.syncrow .ebtn {
  width: 34px; height: 34px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface-50); color: var(--text-2);
  font-family: var(--font-sans); font-size: calc(13px * var(--scale)); font-weight: 700; cursor: pointer;
}
.syncrow .ebtn.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.syncrow .ebtn.on { filter: none; }
.syncrow .effort .ebtn { filter: grayscale(1); font-size: calc(16px * var(--scale)); }
.syncrow .effort .ebtn.on { filter: grayscale(0); }
.syncrow .ecap { font-size: calc(11px * var(--scale)); font-weight: 700; color: var(--brand); margin-left: 2px; }
.syncrow .ebtn.save { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.syncrow .scorebox input {
  width: 52px; height: 34px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-50); color: var(--text);
  font-family: var(--font-sans); font-size: calc(14px * var(--scale));
}
.syncrow .scorebox input:focus { border-color: var(--brand-accent); outline: none; }
.syncrow .slash { color: var(--text-muted); font-weight: 700; }

/* Effort pop-up */
.modal-ov {
  position: fixed; inset: 0; z-index: 60;
  background: var(--overlay);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  padding: 18px 16px; max-width: 440px; width: 100%;
}
.modal-card .mtitle {
  font-family: var(--font-sans); font-size: calc(14px * var(--scale)); font-weight: 700;
  color: var(--text); text-align: center; margin-bottom: 14px;
}
.modal-card .mrow { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.modal-card .mbtn {
  flex: 1; min-width: 68px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface-50); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 4px; cursor: pointer; font-family: var(--font-sans);
}
.modal-card .mbtn:hover { border-color: var(--brand-accent); background: var(--brand-mist); }
.modal-card .memoji { font-size: calc(24px * var(--scale)); }
.modal-card .mcap { font-size: calc(10px * var(--scale)); font-weight: 700; color: var(--text-2); text-align: center; }
.modal-card .mskip {
  display: block; margin: 14px auto 0; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-family: var(--font-sans); font-size: calc(12px * var(--scale)); font-weight: 600;
  text-decoration: underline;
}

/* Account screen */
.acct-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 0;
  font-size: calc(12px * var(--scale)); font-weight: 600; color: var(--text-2);
}
.acct-row strong { margin-left: auto; color: var(--text); font-size: calc(13px * var(--scale)); text-align: right; }
.acct-err { color: var(--danger); font-size: calc(11px * var(--scale)); font-weight: 600; padding-top: 6px; word-break: break-word; }

/* separator between Study Hub sign-in and student-code entry */
.code-sep { text-align: center; font-size: calc(11px * var(--scale)); font-weight: 700;
  color: var(--text-muted); margin: 18px 0 12px; }

/* One control row: back, title, effort, score, complete. Three stacked bars
   plus the course page's own header pushed real content below the fold on a
   phone — the student scrolled past the lesson to find the controls. */
.viewerbar .vbtn.primary { margin-left: auto; }
.viewerbar .effort, .viewerbar .scorebox { display: flex; align-items: center; gap: 5px; }
.viewerbar .slab { font-size: calc(11px * var(--scale)); font-weight: 700; color: var(--text-muted); }
.viewerbar .ebtn {
  border: 1px solid var(--border); background: var(--surface-50);
  border-radius: 50%; width: calc(26px * var(--scale)); height: calc(26px * var(--scale));
  font-size: calc(13px * var(--scale)); line-height: 1; cursor: pointer;
}
.viewerbar .effort .ebtn { filter: grayscale(1); opacity: .55; }
.viewerbar .effort .ebtn.on { filter: grayscale(0); opacity: 1; background: var(--brand-mist, var(--surface-100)); border-color: var(--brand); }
.viewerbar .ebtn.save { background: var(--success-bg); color: var(--success); border-color: var(--success); border-radius: var(--r-md); width: auto; padding: 0 9px; }
.viewerbar .ecap { font-size: calc(10px * var(--scale)); font-weight: 700; color: var(--brand); }
.viewerbar .slash { color: var(--text-muted); font-weight: 700; }
/* Editable fields need to look editable: a filled box with a visible border
   and a caret, not a number sitting on the page. */
.viewerbar .scorebox input {
  width: calc(46px * var(--scale)); padding: 4px 6px; text-align: center;
  font-family: inherit; font-size: calc(12px * var(--scale)); font-weight: 700;
  color: var(--brand); background: var(--card);
  border: 1px solid var(--brand-accent); border-radius: var(--r-md);
}
.viewerbar .scorebox input:focus { outline: none; box-shadow: 0 0 0 3px var(--brand-mist-2, rgba(45,93,186,.18)); }
.viewerbar .scorebox input::placeholder { color: var(--text-faint); font-weight: 400; }

/* Sign-in choices. Testing showed students scrolling past the code field
   and taking "Skip for now" without realising it made their work invisible
   to their teacher. Both paths are now numbered cards of equal weight, and
   the skip is a quiet link behind a confirmation. */
.login-card.choice { max-width: 460px; margin: 0 auto 4px; }
.choice-h {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: calc(15px * var(--scale)); color: var(--brand);
  margin-bottom: 2px;
}
.choice-h .n {
  flex: none; width: calc(22px * var(--scale)); height: calc(22px * var(--scale));
  border-radius: 50%; background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(12px * var(--scale)); font-weight: 700;
}
.choice-sub {
  font-size: calc(12px * var(--scale)); color: var(--text-muted);
  margin: 0 0 12px calc(30px * var(--scale));
}
.choice-or {
  text-align: center; max-width: 460px; margin: 10px auto;
  font-size: calc(12px * var(--scale)); font-weight: 700; color: var(--text-muted);
}
.linkish {
  display: block; margin: 20px auto 0; background: none; border: 0;
  color: var(--text-muted); font-family: inherit;
  font-size: calc(12px * var(--scale)); text-decoration: underline; cursor: pointer;
}
.linkish:hover { color: var(--text-2); }
