:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #17202a; --mute: #5f6b76; --line: #e2e6ea;
  --acc: #1f5fd1; --acc-ink: #ffffff; --ok: #1b8a4b; --ok-bg: #e5f4eb; --bad: #c0392b; --bad-bg: #fbe9e7;
  --warn: #a86400; --warn-bg: #fdf1dc; --idle: #8a949e; --idle-bg: #eef1f4; --late: #7b4fc9; --late-bg: #efe8fb;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101317; --card: #181c21; --ink: #e9edf1; --mute: #9aa5b0; --line: #2a3038;
    --acc: #6f9cff; --acc-ink: #0b1220; --ok: #4cc685; --ok-bg: #133022; --bad: #ff7a6b; --bad-bg: #3a1a17;
    --warn: #f0b04d; --warn-bg: #3a2a10; --idle: #7f8a95; --idle-bg: #1f252c; --late: #b593ff; --late-bg: #2a2140;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--acc); }

.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { color: var(--mute); font-size: 12px; font-weight: 400; display: block; }
.wrap { max-width: 980px; margin: 0 auto; padding: 14px 16px 120px; }
.narrow { max-width: 440px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--mute); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

label { display: block; font-size: 12.5px; color: var(--mute); margin: 10px 0 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
textarea { min-height: 140px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--acc); color: var(--acc-ink); font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--acc); border: 1px solid var(--line); }
.btn.quiet { background: var(--idle-bg); color: var(--ink); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--idle-bg); color: var(--mute); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }

/* teacher: class list */
.slotlist { display: grid; gap: 8px; }
.slot { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); cursor: pointer; text-align: left; width: 100%; }
.slot .big { font-size: 18px; font-weight: 700; min-width: 54px; }
.slot.now { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc) inset; }

/* teacher: marking */
.counts { display: flex; gap: 8px; }
.counts div { flex: 1; text-align: center; padding: 8px 4px; border-radius: 10px; background: var(--idle-bg); }
.counts b { display: block; font-size: 20px; }
.counts .p { background: var(--ok-bg); color: var(--ok); }
.counts .a { background: var(--bad-bg); color: var(--bad); }
.counts .l { background: var(--late-bg); color: var(--late); }
.students { display: grid; gap: 6px; margin-top: 10px; }
.stu { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; user-select: none; width: 100%; text-align: left; }
.av { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 700; flex: none; letter-spacing: .02em; position: relative; overflow: hidden; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#schoolLogo { width: 38px; height: 38px; border-radius: 9px; object-fit: contain; background: #fff; border: 1px solid var(--line); flex: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.photo-grid label { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 12px; cursor: pointer; padding: 8px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.photo-grid label input { display: none; }
.photo-grid .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.school-pic { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; display: block; }
.stu .roll { font-weight: 700; width: 30px; text-align: right; color: var(--mute); }
.stu .nm { flex: 1; min-width: 0; }
.stu .st { font-weight: 700; font-size: 13px; width: 70px; text-align: right; }
.stu.P .st { color: var(--ok); }
.stu.A { background: var(--bad-bg); border-color: transparent; }
.stu.A .st { color: var(--bad); }
.stu.L { background: var(--late-bg); border-color: transparent; }
.stu.L .st { color: var(--late); }
.bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px
  calc(10px + env(safe-area-inset-bottom)); z-index: 6; }
.bar .inner { max-width: 980px; margin: 0 auto; display: flex; gap: 8px; }

/* principal: board */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 24px; line-height: 1.15; }
.stat span { font-size: 12px; color: var(--mute); }
.stat.bad b { color: var(--bad); }
.stat.ok b { color: var(--ok); }
.board { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.board table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 520px; }
.board th, .board td { padding: 6px; border-bottom: 1px solid var(--line); text-align: center; font-size: 13px; }
.board th { color: var(--mute); font-weight: 500; position: sticky; top: 0; background: var(--card); }
.board td.sec { text-align: left; font-weight: 700; padding-left: 12px; white-space: nowrap; }
.board td.sec small { display: block; font-weight: 400; color: var(--mute); }
.cell { border: 0; border-radius: 8px; padding: 6px 4px; width: 100%; min-width: 62px; cursor: pointer; font-size: 12.5px;
  font-weight: 600; background: var(--idle-bg); color: var(--idle); line-height: 1.2; }
.cell small { display: block; font-weight: 500; font-size: 11px; opacity: .85; }
.cell.taken { background: var(--ok-bg); color: var(--ok); }
.cell.latestart { background: var(--warn-bg); color: var(--warn); }
.cell.missing { background: var(--bad-bg); color: var(--bad); }
.cell.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--acc); } 100% { box-shadow: 0 0 0 0 transparent; } }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin: 8px 2px 0; font-size: 12px; color: var(--mute); }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer .panel { width: min(440px, 100%); height: 100%; background: var(--card); padding: 16px; overflow-y: auto; }

/* admin */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
table.list { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.list th, table.list td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.list th { color: var(--mute); font-weight: 500; }
.scroll { overflow-x: auto; }
.codes td:last-child { font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: .08em; }

@media print {
  .top, .tabs, .btn, .noprint { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}

/* ---------- teacher app: hardware feel ---------- */
.led { position: absolute; left: 0; right: 0; bottom: -1px; height: 4px; background: var(--idle); transition: background .3s; }
.led.ok { background: var(--ok); } .led.warn { background: var(--warn); } .led.bad { background: var(--bad); }
.led.flash { animation: ledflash .9s ease-out 2; }
@keyframes ledflash { 0%, 100% { opacity: 1; } 50% { opacity: .15; } }

.modes { display: flex; background: var(--idle-bg); border-radius: 12px; padding: 4px; gap: 4px; margin: 10px 0 4px; }
.modes button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; color: var(--mute); cursor: pointer; }
.modes button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.lcd { background: #10261a; color: #7dff9e; border-radius: 14px; padding: 12px 16px; margin-top: 10px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.45); min-height: 96px; }
.lcd-num { font-size: 40px; font-weight: 700; line-height: 1.1; letter-spacing: .04em; }
.lcd-name { font-size: 15px; opacity: .9; min-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lcd.A { color: #ff8a80; } .lcd.L { color: #d1b3ff; } .lcd.err { color: #ffcc66; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.key { border: 0; border-radius: 14px; padding: 0; height: 62px; font-size: 26px; font-weight: 700; cursor: pointer; user-select: none;
  background: var(--card); color: var(--ink); border-bottom: 4px solid var(--line); box-shadow: var(--shadow); touch-action: manipulation; }
.key:active, .key.down { transform: translateY(3px); border-bottom-width: 1px; }
.key.small { font-size: 15px; }
.key.abs { background: var(--bad-bg); color: var(--bad); }
.key.late { background: var(--late-bg); color: var(--late); }
.key.pres { background: var(--ok-bg); color: var(--ok); }
.key.send { background: var(--acc); color: var(--acc-ink); font-size: 16px; }
.key.send.armed { background: var(--ok); color: #fff; }
.mchips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.mchip { border: 0; border-radius: 999px; padding: 6px 10px; font-weight: 600; font-size: 13px; cursor: pointer; }
.mchip.A { background: var(--bad-bg); color: var(--bad); } .mchip.L { background: var(--late-bg); color: var(--late); }

.rc-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 26px 16px 20px; margin-top: 12px; text-align: center;
  box-shadow: var(--shadow); touch-action: pan-y; transition: transform .18s ease, opacity .18s ease; user-select: none; }
.rc-card.go-right { transform: translateX(110%) rotate(8deg); opacity: 0; }
.rc-card.go-left { transform: translateX(-110%) rotate(-8deg); opacity: 0; }
.rc-card.go-up { transform: translateY(-60%); opacity: 0; }
.rc-roll { font-size: 15px; color: var(--mute); margin-top: 10px; }
.rc-name { font-size: 26px; font-weight: 700; margin: 2px 0 10px; }
.rc-prog { text-align: center; color: var(--mute); font-size: 13px; margin-top: 8px; }
.rc-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.rc-btns .key { height: 72px; font-size: 17px; }
.rc-help { text-align: center; font-size: 12px; color: var(--mute); margin-top: 8px; }

label.link { display: inline; color: var(--acc); text-decoration: underline; cursor: pointer; }
.rc-cam { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--acc); cursor: pointer; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; }
.clock { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.daybtn { padding: 6px 12px; font-size: 20px; line-height: 1; }
.daybtn:disabled { opacity: .35; }
.daypick { width: auto; padding: 6px 8px; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }
.edit-note { display: block; color: var(--warn); font-size: 12px; line-height: 1.35; margin-top: 2px; }
.edit-note:empty { display: none; }
.reason-box { display: block; margin: 10px 2px 0; padding: 10px 12px; border: 1px solid var(--warn); background: var(--warn-bg); color: var(--warn); border-radius: 10px; font-size: 13px; }
.reason-box.hidden { display: none; }
.reason-box input { margin-top: 6px; }

/* admin forms */
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 12px; align-items: end; }
.formgrid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--mute); margin: 0; }
.formgrid .formbtns { grid-column: 1 / -1; }
.checklist { margin: 6px 0 0; padding-left: 20px; }
.checklist li { margin: 6px 0; }
.checklist li.done a { color: var(--ok); }
.tt { border-collapse: collapse; font-size: 13px; }
.tt th, .tt td { border: 1px solid var(--line); padding: 6px; vertical-align: top; }
.tt th small { display: block; color: var(--mute); font-weight: 400; }
.tt td { min-width: 130px; }
.tt td select, .tt td input { width: 100%; padding: 6px; font-size: 13px; }
.tt td input { margin-top: 4px; }
input[readonly] { opacity: .7; }
.cell small.by { font-size: 10.5px; opacity: .8; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
