/* 初中物理 · 电学实验室 —— 样式 */

:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #dde5ee;
  --text: #22323f;
  --dim: #6d8092;
  --accent: #2f8fd8;
  --accent-soft: #e8f2fb;
  --ok: #2fa06a;
  --warn: #e0952b;
  --danger: #d9453a;
  --shadow: 0 1px 2px rgba(28, 50, 70, .06), 0 8px 24px rgba(28, 50, 70, .07);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand .logo {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 21px;
  border-radius: 12px;
  background: linear-gradient(140deg, #ffd977, #ffb347);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
}

.brand h1 { margin: 0; font-size: 17px; letter-spacing: .3px; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--dim); }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 7px 13px;
  font-size: 13.5px;
  font-family: inherit;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: #f6f9fc; border-color: #c8d6e4; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdf1f0; border-color: #f0c6c2; }

.chk {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--dim); cursor: pointer; user-select: none;
  padding: 6px 8px; border-radius: 9px;
}
.chk:hover { background: #f6f9fc; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; }

.dropdown { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 210px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px; display: none; z-index: 40;
}
.menu.open { display: block; }
.menu button {
  display: block; width: 100%; text-align: left;
  border: 0; background: transparent; font: inherit; font-size: 13.5px;
  padding: 9px 11px; border-radius: 8px; cursor: pointer; color: var(--text);
}
.menu button:hover { background: var(--accent-soft); color: #1c6cae; }

/* ---------- 主区 ---------- */

main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 218px minmax(0, 1fr) 288px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  overflow-y: auto;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 1.4px;
  color: var(--dim);
  text-transform: uppercase;
}
.panel h2:not(:first-child) { margin-top: 20px; }

.sub { margin: -4px 0 10px; font-size: 11.5px; color: #93a5b6; }

/* 元件卡片 */
.cards { display: flex; flex-direction: column; gap: 8px; }

.card {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  cursor: grab;
  font: inherit;
  text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .06s;
  touch-action: none;
}
.card:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card:active { cursor: grabbing; transform: scale(.985); }
.card canvas { width: 78px; height: 40px; flex: 0 0 auto; }
.card .card-name { font-size: 13.5px; font-weight: 600; }
.card .card-sub { font-size: 11px; color: var(--dim); display: block; font-weight: 400; }

/* 工具 */
.tools { display: flex; flex-direction: column; gap: 6px; }
.tool {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 9px 11px; font: inherit; font-size: 13.5px; cursor: pointer; text-align: left;
  color: var(--text);
}
.tool:hover { background: #f6f9fc; }
.tool.active { background: var(--accent-soft); border-color: var(--accent); color: #1c6cae; font-weight: 600; }

.tips { margin-top: 18px; font-size: 12px; color: var(--dim); }
.tips p { margin: 0 0 9px; line-height: 1.65; }
.tips .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #8fa3b6; margin: 0 3px; vertical-align: middle;
  box-shadow: 0 0 0 1.5px #fff inset;
}
.tips .warnTip {
  background: #fff7f6; border: 1px solid #f2cfcb; border-radius: 9px;
  padding: 8px 10px; color: #a5342a;
}

.tips .k {
  background: var(--accent-soft); color: #1c6cae; border-radius: 5px;
  padding: 0 5px; font-size: 11.5px; font-weight: 600;
}

kbd {
  background: #f1f5f9; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 0 5px; font-size: 11px; font-family: ui-monospace, monospace;
}

/* ---------- 画布 ---------- */

.stage {
  position: relative;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 0;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: default; }
.stage.tool-wire #canvas { cursor: crosshair; }
.stage.tool-erase #canvas { cursor: cell; }

.stage-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-size: 12.5px; color: #93a5b6; background: rgba(255,255,255,.9);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px;
  pointer-events: none; white-space: nowrap; transition: opacity .3s;
}

.zoombar {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px;
  box-shadow: 0 2px 8px rgba(28,50,70,.07);
  font-size: 12px; color: var(--dim);
}
.zoombar button {
  border: 0; background: transparent; cursor: pointer; font: inherit; font-size: 14px;
  width: 26px; height: 26px; border-radius: 7px; color: var(--text);
}
.zoombar button:hover { background: var(--accent-soft); }
.zoombar #btn-fit { width: auto; padding: 0 8px; font-size: 12px; }
.zoombar span { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }

.banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%) translateY(-8px);
  padding: 8px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  max-width: 88%; text-align: center;
}
.banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.banner.ok { background: #e8f8ef; color: #1d7a4d; border: 1px solid #b6e6cd; }
.banner.warn { background: #fff6e5; color: #a06a12; border: 1px solid #f2ddb0; }
.banner.danger { background: #fdeceb; color: #b32b20; border: 1px solid #f4c4c0; }

/* ---------- 右侧面板 ---------- */

.status { display: flex; flex-direction: column; gap: 8px; }

.card-status {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px;
  padding: 9px 11px; font-size: 13px; background: #fbfdff;
}
.card-status b { display: block; font-size: 13.5px; margin-bottom: 2px; }
.card-status p { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.6; }
.card-status.ok { border-left-color: var(--ok); }
.card-status.warn { border-left-color: var(--warn); }
.card-status.danger { border-left-color: var(--danger); background: #fff8f7; }
.card-status.info { border-left-color: var(--accent); }

.props .empty { font-size: 12.5px; color: #93a5b6; }

.prop-title {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.prop-title .tag {
  font-size: 14px; font-weight: 700;
}
.prop-title .tag small { font-weight: 500; color: var(--dim); font-size: 11.5px; margin-left: 6px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.row label { font-size: 12.5px; color: var(--dim); }
.row input[type="number"], .row input[type="text"], .row select {
  width: 108px; padding: 6px 9px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
  text-align: right;
}
.row input[type="text"] { text-align: left; }
.row input:focus, .row select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.row input[type="range"] {
  width: 116px; accent-color: var(--accent); height: 20px; padding: 0;
}

.hintbox {
  font-size: 11.5px; line-height: 1.65; border-radius: 9px;
  padding: 8px 10px; margin: 2px 0 6px;
}
.hintbox.ok { background: #eef8f2; color: #1d7a4d; border: 1px solid #bfe6d1; }
.hintbox.warn { background: #fff6e5; color: #a06a12; border: 1px solid #f2ddb0; }

.btn-row { display: flex; gap: 6px; margin-top: 10px; }
.btn-row button {
  flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 8px 6px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--text);
}
.btn-row button:hover { background: #f6f9fc; }
.btn-row button.primary { background: var(--accent-soft); border-color: var(--accent); color: #1c6cae; font-weight: 600; }
.btn-row button.del { color: var(--danger); }
.btn-row button.del:hover { background: #fdf1f0; }

.readings { display: flex; flex-direction: column; gap: 6px; }
.reading {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
  background: #fbfdff;
}
.reading .who { color: var(--dim); font-size: 12.5px; }
.reading .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.reading .val small { font-weight: 500; color: var(--dim); font-size: 11px; margin-left: 2px; }
.reading.over { border-color: #f0c6c2; background: #fdf1f0; }
.reading.over .val { color: var(--danger); }

.muted { font-size: 12.5px; color: #93a5b6; }

/* ---------- 实验探究 ---------- */

.mini {
  font: inherit; font-size: 11px; font-weight: 500; color: var(--dim);
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  padding: 1px 8px; margin-left: 6px; cursor: pointer;
}
.mini:hover { background: var(--accent-soft); color: #1c6cae; border-color: var(--accent); }

.lab select {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 9px; margin-bottom: 8px;
  background: #fff; color: var(--text);
}
.lab .lab-help {
  margin: 0 0 9px; font-size: 11.5px; line-height: 1.7; color: var(--dim);
  background: #f7fafd; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
}
.lab-actions { display: flex; gap: 6px; margin-bottom: 7px; }
.lab-actions button {
  flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 8px 4px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--text);
}
.lab-actions button:hover { background: #f6f9fc; }
.lab-actions button.primary { background: var(--accent-soft); border-color: var(--accent); color: #1c6cae; font-weight: 600; }

.lab-tablewrap {
  max-height: 138px; overflow: auto; border: 1px solid var(--line);
  border-radius: 9px; margin-bottom: 8px;
}
.lab table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.lab th, .lab td {
  padding: 5px 7px; text-align: right; border-bottom: 1px solid #eef2f7;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.lab th { position: sticky; top: 0; background: #f7fafd; color: var(--dim); font-weight: 600; }
.lab td:first-child, .lab th:first-child { text-align: center; color: #93a5b6; }
.lab tbody tr:last-child td { border-bottom: 0; }
#lab-graph { width: 100%; height: 168px; display: block; border: 1px solid var(--line); border-radius: 9px; background: #fff; }

/* ---------- 拖拽幽灵 ---------- */

.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 100;
  display: none; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--accent); border-radius: 12px;
  box-shadow: 0 10px 26px rgba(28,50,70,.18);
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.drag-ghost canvas { width: 70px; height: 38px; }
.drag-ghost span { font-size: 12.5px; font-weight: 600; }

/* ---------- 窄屏 ---------- */

@media (max-width: 1080px) {
  main { grid-template-columns: 190px minmax(0,1fr); grid-template-rows: minmax(0,1fr) auto; }
  .inspector { grid-column: 1 / -1; max-height: 42vh; }
}
@media (max-width: 720px) {
  main { grid-template-columns: minmax(0,1fr); grid-template-rows: auto minmax(240px,1fr) auto; }
  .palette, .inspector { max-height: 34vh; }
  .brand p { display: none; }
}
