:root {
  --bg: #f3e9d2;
  --panel: #fdf8ec;
  --panel2: #f7efdc;
  --panel3: #efe1c4;
  --line: #ddc9a3;
  --text: #3f3427;
  --muted: #8b7a5e;
  --accent: #b07a3a;
  --accent2: #8f5f24;
  --gold: #a8671a;
  --green: #4f7d4a;
  --orange: #bf7a2a;
  --red: #b34a3a;
  --purple: #7d5a9e;
  --shadow: 0 8px 22px rgba(120,90,50,.2);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.5; overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d6c09a; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; background: var(--bg);
}

/* ---------- 布局 ---------- */
#app { height: 100%; display: grid; grid-template-rows: 58px 1fr; }
#layout { display: grid; grid-template-columns: 196px 1fr; min-height: 0; }
#view { overflow-y: auto; padding: 16px 18px 40px; min-width: 0; background: var(--bg); overscroll-behavior: contain; }
#view, #sidebar { -webkit-overflow-scrolling: touch; }
#sidebar { border-right: 1px solid var(--line); background: #f8efd9; overflow-y: auto; padding: 8px; }

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 12px; background: #fbf3e1; border-bottom: 1px solid var(--line); z-index: 20;
}
.tb-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#school-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.brand .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-clock { text-align: center; flex: 0 0 auto; }
.tb-clock .date { font-size: 12px; color: var(--muted); }
.tb-clock .time { font-size: 16px; font-weight: 600; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.tb-right { display: flex; align-items: center; gap: 12px; }
.tb-stat { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); line-height: 1.1; }
.tb-stat span { color: var(--text); font-size: 13px; font-weight: 600; }
.tb-stat .k { color: var(--muted); font-size: 10px; }
.speed-ctrl { display: flex; align-items: center; gap: 4px; background: var(--panel2); border-radius: 8px; padding: 2px 4px; }
#speed-label { min-width: 44px; text-align: center; font-size: 12px; color: var(--gold); font-weight: 600; }
.icon-btn {
  background: transparent; border: none; color: var(--text); font-size: 15px;
  width: 28px; height: 28px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(120,90,50,.1); }
#btn-menu { display: none; }

/* ---------- 侧栏 ---------- */
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-size: 13.5px; margin-bottom: 2px; cursor: pointer; user-select: none;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--panel2); color: var(--text); }
.nav-item.active { background: var(--panel3); color: var(--accent2); border-color: #d3b783; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 6px; }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10px; padding: 0 5px; border-radius: 8px; }

/* ---------- 通用组件 ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 19px; margin: 0; font-weight: 700; }
.page-head .desc { color: var(--muted); font-size: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
}
.card h2 { font-size: 14px; margin: 0 0 10px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card h2 .r { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .g3, .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.stat-box { background: var(--panel2); border-radius: 10px; padding: 11px 13px; }
.stat-box .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-box .l { font-size: 11px; color: var(--muted); margin-top: 1px; }
.stat-box .sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 500; transition: filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: var(--panel3); color: var(--text); border: 1px solid var(--line); }
.btn.green { background: #4f7d4a; }
.btn.red { background: #a8453a; }
.btn.gold { background: #a8671a; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select, input[type=text], input[type=number], input[type=date], input[type=time] {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 7px 9px; font-size: 13px; font-family: inherit; outline: none;
}
select:focus, input:focus { border-color: var(--accent); }
input[type=number] { width: 82px; }
input[type=text] { width: 100%; }
label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
label.fld > span { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 7px 8px; border-bottom: 1px solid rgba(160,130,90,.35); }
table.tbl tr:hover td { background: rgba(120,90,50,.05); }
table.tbl tr.clickable { cursor: pointer; }
.tbl-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; background: var(--panel3); color: var(--muted); }
.pill.green { background: rgba(63,191,127,.15); color: var(--green); }
.pill.red { background: rgba(224,91,91,.15); color: var(--red); }
.pill.gold { background: rgba(255,204,51,.14); color: var(--gold); }
.pill.blue { background: rgba(160,110,60,.18); color: var(--accent2); }
.pill.purple { background: rgba(155,111,224,.16); color: var(--purple); }
.pill.orange { background: rgba(232,163,61,.15); color: var(--orange); }

.bar { height: 6px; background: var(--panel3); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .3s; }
.bar.g > i { background: var(--green); }
.bar.r > i { background: var(--red); }
.bar.y > i { background: var(--gold); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 8px 13px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--accent2); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 28px 10px; }
.hint { color: var(--muted); font-size: 12px; }
.mini { font-size: 11px; color: var(--muted); }
.tag-line { display: flex; gap: 6px; flex-wrap: wrap; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed rgba(160,130,90,.35); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 500; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- 地图 ---------- */
.map-wrap { position: relative; background: #f4e7c9; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
#map-canvas { display: block; width: 100%; height: 440px; touch-action: none; }
.map-tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
.map-tools button {
  background: rgba(255,255,255,.9); border: 1px solid #cbb78f; color: #5a4a32;
  width: 34px; height: 30px; border-radius: 6px; font-size: 14px; cursor: pointer;
}
.map-tools button:last-child { width: auto; padding: 0 8px; font-size: 12px; }
.map-tools button:hover { background: #fff; }
.map-hint { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #7a6a4e; background: rgba(255,255,255,.7); padding: 2px 6px; border-radius: 4px; }
@media (max-width: 560px) { #map-canvas { height: 320px; } }
.map-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.map-tabs button { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); padding: 6px 12px; border-radius: 8px; font-size: 12.5px; }
.map-tabs button.active { background: var(--panel3); color: var(--accent2); border-color: #d3b783; }

/* ---------- 弹窗 ---------- */
#modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(70,50,25,.42); display: flex; align-items: center; justify-content: center;
  padding: 18px; pointer-events: auto; animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 86vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { max-width: 820px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.modal-body { padding: 14px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 20px; line-height: 1; }

.event-icon { font-size: 26px; margin-bottom: 4px; }
.event-desc { color: var(--text); font-size: 13.5px; line-height: 1.65; margin-bottom: 14px; white-space: pre-wrap; }
.event-opt { border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; margin-bottom: 9px; cursor: pointer; transition: border-color .15s, background .15s; }
.event-opt:hover { border-color: var(--accent); background: rgba(176,122,58,.08); }
.event-opt .t { font-weight: 600; font-size: 13.5px; }
.event-opt .d { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #fffdf6; border: 1px solid var(--line); color: var(--text); padding: 9px 16px;
  border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); max-width: 86vw; animation: toastIn .22s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

/* ---------- 开局与菜单 ---------- */
.setup {
  position: fixed; inset: 0; background: radial-gradient(circle at 30% 20%, #f9efd9, #e6d3ad 75%);
  z-index: 300; overflow-y: auto; padding: 26px 18px 50px;
}
.setup-inner { max-width: 640px; margin: 0 auto; }
.setup h1 { font-size: 26px; margin: 12px 0 4px; letter-spacing: 1px; }
.setup .lead { color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.setup .card { background: rgba(253,248,236,.92); }
.setup .steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.setup .step { flex: 1; min-width: 120px; background: var(--panel2); border-radius: 9px; padding: 9px 12px; font-size: 12px; color: var(--muted); border: 1px solid transparent; }
.setup .step.on { border-color: var(--accent); color: var(--text); }
.setup .step b { display: block; color: var(--accent2); font-size: 11px; margin-bottom: 2px; }
.preview-name { font-size: 20px; font-weight: 700; color: var(--gold); margin: 6px 0 2px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.checkline input { width: 16px; height: 16px; }
.menu-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.menu-btns .btn { padding: 12px; font-size: 14px; }
.version-tag { position: fixed; right: 14px; bottom: 12px; color: #a08c6a; font-size: 11px; }

/* ---------- 图表 ---------- */
.chart-wrap { position: relative; width: 100%; overflow-x: auto; }
canvas.chart { display: block; max-width: 100%; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  #app { grid-template-rows: 54px 1fr; }
  #layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #sidebar {
    grid-row: 2; border-right: none; border-top: 1px solid var(--line); background: #f8efd9;
    display: flex; overflow-x: auto; overflow-y: hidden; padding: 6px; gap: 4px;
    -webkit-overflow-scrolling: touch;
  }
  #sidebar .nav-item { flex-direction: column; gap: 2px; font-size: 10px; padding: 5px 8px; min-width: 54px; text-align: center; margin: 0; }
  #sidebar .nav-item .ico { font-size: 17px; }
  #sidebar .nav-sep { display: none; }
  #sidebar .nav-badge { position: absolute; }
  #view { grid-row: 1; padding: 12px 12px 84px; }
  #btn-menu { display: none; }
  .tb-stat { display: none; }
  .brand .sub { display: none; }
  #school-name { max-width: 120px; font-size: 14px; }
  .tb-clock .date { font-size: 10px; }
  .tb-clock .time { font-size: 14px; }
  .page-head h1 { font-size: 17px; }
  .modal { max-width: 100%; }
  #toast-root { bottom: 86px; }
}

/* ---------- 校园大屏与公告栏 ---------- */
.screen {
  background: linear-gradient(180deg, #241c13, #3a2c1c);
  border: 6px solid #6b5334; border-radius: 10px;
  padding: 16px 20px; color: #ffd27a; box-shadow: inset 0 0 40px rgba(0,0,0,.6);
  font-family: "Courier New", monospace;
}
.screen .screen-title { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px dashed #7a5f38; padding-bottom: 8px; margin-bottom: 10px; }
.screen .screen-title b { font-size: 16px; letter-spacing: 2px; }
.screen .screen-title span { font-size: 11px; color: #c9a86a; }
.screen-item { padding: 7px 0; border-bottom: 1px dashed rgba(255,210,122,.18); font-size: 13.5px; line-height: 1.6; }
.screen-item:last-child { border-bottom: none; }
.screen-item .ic { color: #ffcf6a; margin-right: 6px; }
.screen-item.urgent { color: #ff8a5c; }
.screen-empty { color: #8a7452; text-align: center; padding: 24px; font-size: 13px; }

.bulletin {
  background: #fbf3df; border: 8px solid #b08a52; border-radius: 6px; padding: 14px 16px;
  box-shadow: 0 6px 18px rgba(120,90,50,.2);
}
.bulletin h3 { margin: 0 0 10px; font-size: 14px; color: #7a5a2e; letter-spacing: 1px; }
.bulletin .paper {
  background: #fffdf5; border: 1px solid #e6d6b4; border-radius: 4px; padding: 12px 14px;
  box-shadow: 0 2px 4px rgba(120,90,50,.12); margin-bottom: 10px; position: relative;
}
.bulletin .paper::before { content: "●"; position: absolute; top: -8px; left: 10px; font-size: 13px; }
.bulletin .paper .pt { font-weight: 600; color: #6a4c22; font-size: 13px; margin-bottom: 3px; }
.bulletin .paper .pd { color: #6b5a40; font-size: 12.5px; line-height: 1.65; }
.bulletin .paper .pmeta { color: #a08c6a; font-size: 11px; margin-top: 4px; }

/* ---------- 悬浮音乐 ---------- */
#music-float {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 90;
  background: rgba(58,44,28,.94); color: #ffd27a; border: 1px solid #8a6a3a;
  border-radius: 10px; padding: 8px 14px; font-size: 12.5px; box-shadow: 0 6px 18px rgba(0,0,0,.3);
  display: none; align-items: center; gap: 10px; max-width: 92vw; pointer-events: none;
}
#music-float.show { display: flex; }
#music-float .mf-song { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
#music-float .mf-who { color: #c9a86a; font-size: 11px; white-space: nowrap; }
#music-float .mf-prog { font-variant-numeric: tabular-nums; color: #ffe6a8; }
@media (max-width: 760px) {
  #music-float { bottom: 74px; padding: 6px 10px; font-size: 11.5px; }
  #music-float .mf-song { max-width: 34vw; }
}

/* 作息分区块 */
.sch-section { border-top: 1px dashed var(--line); padding-top: 12px; margin-top: 12px; }
.sch-section:first-of-type { border-top: none; padding-top: 0; margin-top: 4px; }
.sch-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.sch-title b { font-size: 14px; color: var(--accent2); }

/* 学生动态 */
.feed-list { max-height: 320px; overflow-y: auto; padding-right: 4px; }
.feed-item { display: flex; align-items: baseline; gap: 8px; padding: 6px 2px; border-bottom: 1px dashed rgba(160,130,90,.28); font-size: 13px; line-height: 1.5; }
.feed-item:last-child { border-bottom: none; }
.feed-time { flex: 0 0 42px; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.feed-dot { flex: 0 0 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); transform: translateY(-1px); }
.feed-dot.ft-study { background: #b07a3a; }
.feed-dot.ft-life { background: #4f7d4a; }
.feed-dot.ft-health { background: #bf7a2a; }
.feed-dot.ft-mind { background: #7d5a9e; }
.feed-dot.ft-discipline { background: #b34a3a; }
.feed-dot.ft-shame { background: #c02a6a; }
.feed-text { flex: 1; color: var(--text); }
