:root {
  --navy: #0D2B5C;
  --navy-soft: #14376E;
  --primary: #1E88E5;
  --primary-dark: #1565C0;
  --cyan: #29B6F6;
  --accent: #FF8A00;
  --bg: #F2F6FC;
  --panel: #ffffff;
  --border: #DCE7F5;
  --text: #1A2B4A;
  --text-light: #5A6B8C;
  --radius: 12px;
  --shadow: 0 6px 20px rgba(13, 43, 92, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
  height: 60px; display: flex; align-items: center; gap: 16px; padding: 0 18px;
  background: linear-gradient(100deg, #0B2447, var(--navy) 45%, #123C7A);
  color: #fff; position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand-text { font-size: 16px; font-weight: 800; letter-spacing: 0.02em; }
.brand-tag {
  font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 5px;
  background: rgba(41, 182, 246, 0.2); color: #7FD4FF; border: 1px solid rgba(41, 182, 246, 0.4);
}
.project-name {
  width: 200px; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.18); background: rgba(255,255,255,0.1);
  color: #fff; font-size: 13.5px; font-weight: 600; outline: none;
}
.project-name::placeholder { color: rgba(255,255,255,0.5); }
.project-name:focus { border-color: var(--cyan); background: rgba(255,255,255,0.16); }

.mode-switch {
  display: flex; padding: 3px; border-radius: 9px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.14);
  margin-left: auto;
}
.mode-btn {
  padding: 6px 20px; border: 0; border-radius: 7px; background: transparent;
  color: rgba(255,255,255,0.75); font-size: 13px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: all 0.2s;
}
.mode-btn:hover { color: #fff; }
.mode-btn.active { background: #fff; color: var(--navy); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.divider { width: 1px; height: 22px; background: rgba(255,255,255,0.16); margin: 0 2px; }

.btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08); color: #fff; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: all 0.2s; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.18); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-run { background: #17B26A; border-color: #17B26A; }
.btn-run:hover { background: #12945A; }
.btn-stop { background: #E5484D; border-color: #E5484D; }
.btn-stop:hover { background: #C93B40; }
.btn-user { background: rgba(41,182,246,0.18); border-color: rgba(41,182,246,0.5); color: #A9E2FF; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- 布局 ---------- */
.layout {
  display: grid; grid-template-columns: 1fr 440px; gap: 12px;
  height: calc(100vh - 60px); padding: 12px;
}
.editor { position: relative; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; }
.blockly-host { width: 100%; height: 100%; }

/* ---------- Python 编辑器 ---------- */
.python-pane { display: flex; flex-direction: column; height: 100%; }
.python-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: #F8FBFF;
}
.python-title { font-size: 14px; font-weight: 800; color: var(--navy); }
.python-hint { font-size: 12px; color: var(--text-light); flex: 1; }
.python-bar .btn { background: #fff; color: var(--text); border-color: var(--border); }
.python-bar .btn:hover { border-color: var(--primary); color: var(--primary); }
.py-editor {
  flex: 1; width: 100%; border: 0; resize: none; outline: none;
  padding: 18px 20px; font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 14px; line-height: 1.75; color: #10243F; background: #FBFDFF;
  tab-size: 4;
}

/* ---------- 右侧面板 ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 800; color: var(--navy);
}
.stage-tools { display: flex; gap: 6px; }
.mini-btn {
  padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text-light); font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }

.stage-wrap { padding: 12px; display: flex; justify-content: center; align-items: center; }
#stage {
  width: 100%; max-width: 416px; height: auto; aspect-ratio: 4 / 3;
  border-radius: 10px; background: #0E2247; display: block;
}

.code-panel { flex: 1; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel-tab {
  flex: 0 0 auto; padding: 10px 16px; border: 0; background: transparent;
  font-size: 13px; font-weight: 700; color: var(--text-light); cursor: pointer;
  font-family: inherit; border-bottom: 2px solid transparent;
}
.panel-tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 4px; vertical-align: middle; }
.panel-body { flex: 1; min-height: 0; overflow: auto; }
.code-view {
  margin: 0; padding: 14px 16px; font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.7; color: #24405F; white-space: pre-wrap; word-break: break-word;
}
.console {
  padding: 14px 16px; font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.7; color: #24405F;
}
.console .line { padding: 1px 0; border-bottom: 1px dashed rgba(220, 231, 245, 0.7); }
.console .line.err { color: #C93B40; }
.console .line.sys { color: #8A9AB8; }
.panel-foot {
  display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border);
  background: #F8FBFF;
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(8, 22, 45, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 380px; max-width: calc(100vw - 32px); background: #fff; border-radius: 16px;
  overflow: hidden; box-shadow: 0 24px 60px rgba(6, 20, 42, 0.35);
}
.modal-card.wide { width: 620px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; color: var(--navy); }
.modal-close {
  border: 0; background: transparent; font-size: 24px; line-height: 1;
  color: var(--text-light); cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--navy); }
.modal-body { padding: 20px 22px; max-height: 60vh; overflow: auto; }
.modal-foot { display: flex; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1; background: #F4F8FE; color: var(--text); border-color: var(--border); }
.modal-foot .btn-run { background: #17B26A; color: #fff; border-color: #17B26A; }
.modal-foot .btn:hover { border-color: var(--primary); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-light); margin-bottom: 6px; }
.field input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); font-size: 14px; font-family: inherit; outline: none;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,136,229,0.12); }
.form-error { font-size: 12.5px; color: #C93B40; margin-top: 4px; }

.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px; transition: all 0.2s;
}
.project-item:hover { border-color: var(--primary); background: #F7FBFF; }
.project-item .p-name { flex: 1; font-size: 14px; font-weight: 700; color: var(--navy); cursor: pointer; }
.project-item .p-time { font-size: 11.5px; color: var(--text-light); }
.project-item .p-open, .project-item .p-del {
  border: 0; background: transparent; font-size: 12.5px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.project-item .p-open { color: var(--primary); }
.project-item .p-del { color: #C93B40; }
.empty-tip { padding: 24px; text-align: center; color: var(--text-light); font-size: 13.5px; }

.sample-list { display: flex; flex-direction: column; gap: 8px; }
.sample-item {
  text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; cursor: pointer; font-family: inherit;
}
.sample-item:hover { border-color: var(--primary); background: #F7FBFF; }
.sample-item b { display: block; font-size: 14px; color: var(--navy); margin-bottom: 3px; }
.sample-item small { font-size: 12px; color: var(--text-light); }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 999px; background: rgba(13, 43, 92, 0.92);
  color: #fff; font-size: 13.5px; font-weight: 600; z-index: 200;
  box-shadow: 0 10px 30px rgba(6, 20, 42, 0.3);
}
.toast[hidden] { display: none; }

/* ---------- Blockly 微调 ---------- */
.blocklyToolbox {
  background: #F8FBFF !important;
  border-right: 1px solid var(--border) !important;
  padding: 10px 8px !important;
  min-width: 128px;
}
.blocklyToolboxCategoryContainer { margin: 0 0 4px 0 !important; }
.blocklyToolboxCategory {
  height: 42px !important;
  line-height: 42px !important;
  margin-bottom: 0 !important;
  padding: 0 14px !important;
  border-radius: 10px;
  transition: background-color .15s ease;
}
.blocklyToolboxCategoryLabel {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  letter-spacing: 1px;
  padding: 0 2px !important;
  color: var(--text);
}
.blocklyToolboxCategory:not(.blocklyToolboxSelected):hover {
  background-color: rgba(30, 136, 229, .10) !important;
}
.blocklyToolboxCategory:not(.blocklyToolboxSelected):hover .blocklyToolboxCategoryLabel {
  color: var(--primary-dark) !important;
}
.blocklyToolboxSelected .blocklyToolboxCategoryLabel { color: #fff !important; }
.blocklyFlyoutBackground { fill: #FBFDFF !important; }
.blocklyMainBackground { stroke: none !important; }
.blocklySvg { background: #FCFEFF; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 360px; }
  .project-name { width: 150px; }
}

/* ---------- 传感器模拟 ---------- */
.sensor-panel {
  border-top: 1px solid var(--border); padding: 10px 14px 12px;
  display: flex; flex-direction: column; gap: 6px; background: #F8FBFF;
}
.sensor-title { font-size: 11.5px; font-weight: 800; color: var(--text-light); letter-spacing: 0.04em; }
.sensor-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-light); }
.sensor-row span { width: 28px; flex: 0 0 auto; }
.sensor-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.sensor-row b { width: 46px; text-align: right; font-size: 12px; color: var(--navy); }

/* ---------- 通用补充 ---------- */
.btn-danger { background: rgba(229, 72, 77, 0.14); border-color: rgba(229, 72, 77, 0.5); color: #FFC9CA; }
.btn-danger:hover { background: rgba(229, 72, 77, 0.26); }
.modal-tip { font-size: 12.5px; color: var(--text-light); line-height: 1.7; }
.modal-tip a { color: var(--primary); font-weight: 700; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; font-family: inherit; outline: none; resize: vertical; line-height: 1.6;
}
.field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,136,229,0.12); }

/* ---------- 作业面板 ---------- */
.hw-section { margin-bottom: 20px; }
.hw-title { font-size: 13px; font-weight: 800; color: var(--navy); margin: 14px 0 8px; }
.class-list { display: flex; flex-wrap: wrap; gap: 8px; min-height: 22px; }
.class-chip {
  padding: 4px 10px; border-radius: 999px; background: #EAF4FF; color: var(--primary-dark);
  font-size: 12px; font-weight: 700;
}
.join-row { display: flex; gap: 8px; margin-top: 10px; }
.join-row input {
  flex: 1; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; font-family: inherit; outline: none;
}
.join-row input:focus { border-color: var(--primary); }
.join-row .btn { background: #F4F8FE; color: var(--text); border-color: var(--border); }
.homework-list { display: flex; flex-direction: column; gap: 10px; }
.homework-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #FCFDFF;
}
.hw-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hw-head b { font-size: 14px; color: var(--navy); }
.hw-status { font-size: 11.5px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #F0F3F8; color: var(--text-light); }
.hw-status.done { background: #E8F5E9; color: #1B7F3B; }
.hw-status.ok { background: #E3F2FD; color: #1565C0; }
.hw-meta { font-size: 11.5px; color: var(--text-light); margin-top: 5px; }
.hw-desc { font-size: 13px; color: var(--text); margin-top: 6px; line-height: 1.6; }
.hw-feedback { font-size: 12.5px; color: #1B7F3B; margin-top: 6px; }
.hw-actions { margin-top: 10px; display: flex; gap: 8px; }
.hw-actions .btn { background: #17B26A; color: #fff; border-color: #17B26A; }

/* ---------- 分享页 ---------- */
body.share-page { overflow: hidden; display: flex; flex-direction: column; height: 100vh; }
.share-title { display: flex; flex-direction: column; min-width: 0; flex: 1; margin-left: 8px; }
.share-title span { font-size: 14.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-title small { font-size: 11.5px; color: rgba(255,255,255,0.62); }
.share-layout {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 440px; gap: 12px; padding: 12px;
}
.share-canvas {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.share-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.panel.grow { flex: 1; }
.share-foot {
  height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; color: var(--text-light); border-top: 1px solid var(--border); background: #fff;
}
.share-foot a { color: var(--primary); font-weight: 700; }
.share-page .code-panel .panel-body { overflow: auto; }

/* ---------- 作品墙 ---------- */
body.gallery-page { overflow: auto; min-height: 100vh; background: var(--bg); }
.gallery-intro { flex: 1; font-size: 12.5px; color: rgba(255,255,255,0.68); }
.gallery-main { max-width: 1120px; margin: 0 auto; padding: 26px 20px 10px; }
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(226px, 1fr)); gap: 16px;
}
.work-card {
  display: block; text-decoration: none; background: #fff; border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); transition: transform 0.18s, box-shadow 0.18s;
}
.work-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(13, 43, 92, 0.16); }
.work-cover {
  position: relative; height: 132px; display: flex; align-items: center; justify-content: center;
}
.work-glyph { font-size: 34px; color: rgba(255,255,255,0.85); }
.work-mode {
  position: absolute; left: 10px; top: 10px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0,0,0,0.18); color: #fff; font-size: 11px; font-weight: 800;
}
.work-body { padding: 12px 14px 14px; }
.work-body b { display: block; font-size: 14.5px; color: var(--navy); margin-bottom: 4px; }
.work-body small { font-size: 11.5px; color: var(--text-light); }
.site-foot { text-align: center; font-size: 12px; color: var(--text-light); padding: 26px 0 34px; }

/* ---------- 教师端 ---------- */
body.teacher-page { overflow: auto; min-height: 100vh; }
.teacher-main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.teacher-card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 26px 28px; max-width: 460px; margin: 30px auto;
}
.teacher-card h2 { font-size: 18px; color: var(--navy); margin-bottom: 8px; }
.teacher-card .field { margin-top: 14px; }
.teacher-card .btn { width: 100%; margin-top: 18px; justify-content: center; }
.auth-tabs { display: flex; gap: 8px; margin: 18px 0 4px; }
.auth-tab {
  flex: 1; padding: 8px 0; border-radius: 8px; border: 1px solid var(--border); background: #F8FBFF;
  font-size: 13px; font-weight: 700; color: var(--text-light); cursor: pointer; font-family: inherit;
}
.auth-tab.active { background: #EAF4FF; border-color: var(--primary); color: var(--primary-dark); }
.teach-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.teach-head h2 { font-size: 20px; color: var(--navy); }
.inline-form { display: flex; gap: 8px; }
.inline-form input {
  height: 36px; width: 260px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; font-family: inherit; outline: none;
}
.inline-form input:focus { border-color: var(--primary); }
.inline-form .btn { background: #17B26A; border-color: #17B26A; }
.teach-list { display: flex; flex-direction: column; gap: 10px; }
.teach-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.teach-row .row-main { flex: 1; min-width: 0; }
.teach-row .row-main b { display: block; font-size: 14.5px; color: var(--navy); }
.teach-row .row-meta { font-size: 11.5px; color: var(--text-light); }
.code-chip {
  font-size: 11.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px;
  background: #EAF4FF; color: var(--primary-dark); white-space: nowrap;
}
.teach-row .btn { background: #F4F8FE; color: var(--text); border-color: var(--border); }
.teach-row .btn:hover { border-color: var(--primary); color: var(--primary); }
.teach-row .btn-danger { background: #FDECEC; border-color: #F5C2C3; color: #C93B40; }
.teach-title { font-size: 22px; color: var(--navy); margin: 14px 0 8px; }
.join-code-box {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px;
  background: #F8FBFF; border: 1px dashed var(--border); border-radius: 10px; font-size: 13px; color: var(--text-light);
}
.join-code-box b { font-size: 18px; letter-spacing: 0.14em; color: var(--primary-dark); }
.assign-form {
  display: flex; flex-direction: column; gap: 8px; padding: 14px; margin-bottom: 14px;
  background: #F8FBFF; border: 1px solid var(--border); border-radius: 12px;
}
.assign-form input[type="text"], .assign-form input:not([type]), .assign-form textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; font-family: inherit; outline: none; resize: vertical;
}
.assign-form textarea { line-height: 1.6; }
.assign-form input:focus, .assign-form textarea:focus { border-color: var(--primary); }
.assign-form .btn { align-self: flex-start; background: #17B26A; border-color: #17B26A; }
.assign-due { font-size: 12px; color: var(--text-light); display: flex; align-items: center; gap: 8px; }
.assign-due input { padding: 6px 8px; border-radius: 7px; border: 1px solid var(--border); font-family: inherit; }

/* ---------- 批改弹窗 ---------- */
.review-card { width: 1000px; max-width: calc(100vw - 32px); }
.review-body { display: grid; grid-template-columns: 1fr 340px; gap: 18px; padding: 18px 22px; max-height: 74vh; }
.review-left { min-width: 0; }
#reviewBlockly {
  width: 100%; height: 480px; border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; background: #FCFEFF;
}
.review-right { display: flex; flex-direction: column; min-height: 0; }
.code-view.small { max-height: 200px; overflow: auto; background: #F8FBFF; border: 1px solid var(--border); border-radius: 10px; }
.review-form { margin-top: 14px; }
.review-form .field { margin-bottom: 10px; }
.review-form .btn { background: #17B26A; border-color: #17B26A; }

@media (max-width: 1360px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 7px 10px; font-size: 12.5px; }
  .project-name { width: 150px; }
  .mode-btn { padding: 6px 14px; }
}

@media (max-width: 980px) {
  body.share-page { overflow: auto; height: auto; }
  .share-layout { grid-template-columns: 1fr; }
  .share-canvas { height: 460px; }
  .share-side { min-height: 520px; }
  .review-body { grid-template-columns: 1fr; max-height: 78vh; overflow: auto; }
  #reviewBlockly { height: 320px; }
  .teacher-main { padding: 16px 12px 40px; }
  .teach-row { flex-wrap: wrap; }
}

