/* 自犬 Studio · 界面样式
   配色与尺寸照抄 Scratch 3.0 官方规范（取自 scratch-gui/src/css 与 themes）。
   布局：左「分类+积木面板+工作区」/ 右「舞台」/ 底「代码」（可折叠）。 */

:root {
  /* ── 缩放（用户可调，弥补高分屏字小）── */
  --ui-scale: 1.4;

  /* ── Scratch 官方色板（来自 themes/gui/light.js）── */
  --sb-bg: #ffffff;
  --sb-workspace: #F9F9F9;
  --sb-flyout: #F9F9F9;
  --sb-toolbox: #FFFFFF;
  --sb-text: #575E75;            /* text-primary */
  --sb-text-dim: #8a90a6;
  --sb-grid: #dddddd;
  --sb-scrollbar: #CECDCE;
  --sb-border: rgba(0, 0, 0, .15);
  --sb-menubar: #855CD6;         /* looks-secondary，Scratch 顶栏紫 */
  --sb-menubar-hover: #714EB6;
  --sb-input: #ffffff;
  --sb-shadow: rgba(0, 0, 0, .15);
  --sb-selected: #E9EEF2;        /* toolboxSelected */
  --sb-hover: #4C97FF;

  /* ── Scratch 官方尺寸（来自 css/units.css）── */
  --sb-space: calc(0.5rem * var(--ui-scale));
  --sb-radius: calc(0.25rem * var(--ui-scale));
  --sb-menubar-h: calc(3rem * var(--ui-scale));
  --sb-panel-head-h: calc(2.75rem * var(--ui-scale));
  --sb-font: "Helvetica Neue", Helvetica, Arial, "Microsoft YaHei", sans-serif;

  /* ── 字号（比 Scratch 原版放大，适配高分屏）── */
  --fs-sm: calc(14px * var(--ui-scale));
  --fs-base: calc(15px * var(--ui-scale));
  --fs-lg: calc(17px * var(--ui-scale));
  --fs-code: calc(15px * var(--ui-scale));
}

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--sb-bg);
  color: var(--sb-text);
  font-family: var(--sb-font);
  font-size: var(--fs-base);
  overflow: hidden;
}

/* ── 顶栏（Scratch 紫）── */
.studio-head {
  flex: 0 0 auto;
  background: var(--sb-menubar);
  color: #fff;
}

.studio-head-inner {
  height: var(--sb-menubar-h);
  padding: 0 calc(1rem * var(--ui-scale));
  display: flex;
  align-items: center;
  gap: calc(0.75rem * var(--ui-scale));
  font-size: var(--fs-lg);
}

.studio-brand {
  font-weight: bold;
  color: #fff;
  text-decoration: none;
}
.studio-sep { opacity: .6; }

.studio-title {
  color: rgba(255,255,255,.85);
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  font-size: var(--fs-sm);
}
.studio-title:hover { border-bottom-color: rgba(255,255,255,.5); }

.studio-savehint {
  font-size: calc(12px * var(--ui-scale));
  color: rgba(255,255,255,.75);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  padding: 1px calc(0.5rem * var(--ui-scale));
}

.studio-head-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sb-space);
}

.studio-back {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: var(--fs-sm);
}
.studio-back:hover { color: #fff; }

/* ── 布局 ── */
.studio-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--sb-border);
  gap: 1px;
}

/* ── 工具栏 ── */
.studio-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sb-space);
  padding: calc(0.5rem * var(--ui-scale)) calc(1rem * var(--ui-scale));
  background: var(--sb-bg);
}

.studio-bar-left, .studio-bar-right {
  display: flex;
  align-items: center;
  gap: calc(0.4rem * var(--ui-scale));
}
.studio-bar-right { margin-left: auto; }

.sb-label { font-size: var(--fs-sm); color: var(--sb-text); }
.sb-hint { font-size: var(--fs-sm); color: var(--sb-text-dim); }

.sb-select {
  appearance: none !important;
  -webkit-appearance: none !important;
  background-color: var(--sb-input) !important;
  color: var(--sb-text) !important;
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  padding: 0 calc(1.6rem * var(--ui-scale)) 0 calc(0.6rem * var(--ui-scale));
  height: calc(2rem * var(--ui-scale));
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%23575E75' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right calc(0.5rem * var(--ui-scale)) center;
}
.sb-select:focus { outline: none; border-color: var(--sb-hover); }

/* Scratch 风格圆角按钮 */
.sb-btn {
  background: var(--sb-bg);
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: calc(1rem * var(--ui-scale));
  height: calc(2rem * var(--ui-scale));
  padding: 0 calc(0.85rem * var(--ui-scale));
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.sb-btn:hover { background: var(--sb-selected); }

.sb-btn-primary {
  background: var(--sb-hover);
  border-color: var(--sb-hover);
  color: #fff;
}
.sb-btn-primary:hover { background: #4280D7; border-color: #4280D7; }

/* 绿旗运行按钮 */
.sb-btn-run {
  background: #4CBF56;
  border-color: #4CBF56;
  color: #fff;
  font-weight: 500;
}
.sb-btn-run:hover { background: #43a94c; border-color: #43a94c; }

/* ── 主区 ── */
.studio-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  background: var(--sb-border);
  gap: 1px;
}

.studio-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--sb-bg);
  overflow: hidden;
}
.pane-blocks { flex: 0 0 auto; width: 62%; }
.pane-stage  { flex: 1 1 auto; }

.pane-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sb-space);
  padding: 0 calc(0.75rem * var(--ui-scale));
  height: var(--sb-panel-head-h);
  font-size: var(--fs-sm);
  color: var(--sb-text);
  border-bottom: 1px solid var(--sb-border);
  background: var(--sb-bg);
  user-select: none;
}

.pane-badge {
  font-size: var(--fs-sm);
  color: var(--sb-text-dim);
  border: 1px solid var(--sb-border);
  border-radius: 999px;
  padding: 0 calc(0.5rem * var(--ui-scale));
}

.pane-mini {
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-radius: calc(0.75rem * var(--ui-scale));
  color: var(--sb-text);
  font-size: calc(12px * var(--ui-scale));
  height: calc(1.5rem * var(--ui-scale));
  padding: 0 calc(0.5rem * var(--ui-scale));
  cursor: pointer;
  font-family: inherit;
}
.pane-mini:hover { background: var(--sb-selected); }

.pane-collapse {
  background: none;
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  color: var(--sb-text);
  font-size: calc(12px * var(--ui-scale));
  width: calc(1.4rem * var(--ui-scale));
  height: calc(1.3rem * var(--ui-scale));
  line-height: 1;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  flex: 0 0 auto;
}
.pane-collapse:hover { background: var(--sb-selected); }

.pane-collapsed > .pane-body { display: none; }
.pane-collapsed { flex: 0 0 auto !important; height: auto !important; }

.stage-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: calc(0.4rem * var(--ui-scale));
}

#blockly-div {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  position: relative;
}

/* ── 舞台 ── */
.stage-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--sb-workspace);
  padding: var(--sb-space);
  box-sizing: border-box;
}

.stage-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  background: #fff;
  display: block;
  box-shadow: 0 0 calc(0.5rem * var(--ui-scale)) var(--sb-shadow);
}
.stage-frame[hidden] { display: none; }

.stage-console {
  flex: 0 0 auto;
  max-height: 45%;
  overflow: auto;
  margin: var(--sb-space) 0 0;
  padding: calc(0.6rem * var(--ui-scale)) calc(0.75rem * var(--ui-scale));
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--fs-code);
  line-height: 1.7;
  color: #2b2f3a;
  background: #fff;
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  white-space: pre-wrap;
  word-break: break-all;
}
.stage-console:empty::before {
  content: "点「▶ 运行」看结果";
  color: var(--sb-text-dim);
}

/* ── 代码区 ── */
.pane-code {
  flex: 0 0 auto;
  height: 24vh;
  min-height: 80px;
}

.code-view {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: calc(0.75rem * var(--ui-scale)) calc(1rem * var(--ui-scale));
  overflow: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: var(--fs-code);
  line-height: 1.7;
  color: #2b2f3a;
  background: var(--sb-bg);
  white-space: pre;
  tab-size: 2;
}

/* ── 分隔条 ── */
.splitter {
  flex: 0 0 auto;
  background: var(--sb-border);
  position: relative;
  z-index: 5;
}
.splitter-v { width: 4px; cursor: col-resize; }
.splitter-h { height: 4px; cursor: row-resize; }
.splitter:hover, .splitter.dragging { background: var(--sb-hover); }

/* 滚动条（Scratch 灰） */
.code-view::-webkit-scrollbar, .stage-console::-webkit-scrollbar {
  width: calc(0.75rem * var(--ui-scale)); height: calc(0.75rem * var(--ui-scale));
}
.code-view::-webkit-scrollbar-thumb, .stage-console::-webkit-scrollbar-thumb {
  background: var(--sb-scrollbar);
  border-radius: 6px;
  border: 2px solid var(--sb-bg);
}

/* ── 提示条 ── */
.studio-toast {
  position: fixed;
  left: 50%;
  bottom: calc(2rem * var(--ui-scale));
  transform: translateX(-50%) translateY(6px);
  background: #fff;
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  padding: calc(0.6rem * var(--ui-scale)) calc(1rem * var(--ui-scale));
  font-size: var(--fs-sm);
  box-shadow: 0 2px 10px var(--sb-shadow);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  z-index: 999;
}
.studio-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 设置抽屉 ── */
.settings-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 1000;
}
.settings-mask.open { opacity: 1; pointer-events: auto; }

.settings-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(calc(28rem * var(--ui-scale)), 94vw);
  background: #fff;
  border-left: 1px solid var(--sb-border);
  transform: translateX(100%);
  transition: transform .22s ease;
  z-index: 1001;
  display: flex;
  flex-direction: column;
}
.settings-drawer.open { transform: translateX(0); }

.settings-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 0 calc(1rem * var(--ui-scale));
  height: var(--sb-menubar-h);
  background: var(--sb-menubar);
  color: #fff;
  font-size: var(--fs-lg);
}
.settings-head .close {
  margin-left: auto;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: calc(0.75rem * var(--ui-scale));
  color: #fff;
  font-size: var(--fs-sm);
  height: calc(1.8rem * var(--ui-scale));
  padding: 0 calc(0.6rem * var(--ui-scale));
  cursor: pointer;
  font-family: inherit;
}

.settings-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: var(--sb-space) calc(1rem * var(--ui-scale)) calc(1.5rem * var(--ui-scale));
}

.set-group { margin-top: calc(1.2rem * var(--ui-scale)); }
.set-group h4 {
  margin: 0 0 calc(0.6rem * var(--ui-scale));
  font-size: var(--fs-sm);
  font-weight: bold;
  color: var(--sb-text);
}

.set-row {
  display: flex;
  align-items: center;
  gap: calc(0.6rem * var(--ui-scale));
  margin-bottom: calc(0.65rem * var(--ui-scale));
  font-size: var(--fs-sm);
}
.set-row label { color: var(--sb-text); flex: 0 0 auto; }
.set-row .val {
  margin-left: auto;
  color: var(--sb-text-dim);
  font-size: var(--fs-sm);
  font-family: Consolas, monospace;
  min-width: calc(3rem * var(--ui-scale));
  text-align: right;
}

.set-input {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(2rem * var(--ui-scale));
  background: var(--sb-input);
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  padding: 0 calc(0.6rem * var(--ui-scale));
  font-size: var(--fs-sm);
  font-family: inherit;
}
.set-input:focus { outline: none; border-color: var(--sb-hover); }

.set-area {
  width: 100%;
  min-height: calc(7rem * var(--ui-scale));
  background: #fff;
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  padding: calc(0.5rem * var(--ui-scale));
  font-family: Consolas, monospace;
  font-size: calc(13px * var(--ui-scale));
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
}
.set-area:focus { outline: none; border-color: var(--sb-hover); }

.set-color {
  width: calc(2.6rem * var(--ui-scale));
  height: calc(2rem * var(--ui-scale));
  padding: 0;
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  background: #fff;
  cursor: pointer;
}

.set-btn {
  background: #fff;
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: calc(1rem * var(--ui-scale));
  height: calc(2rem * var(--ui-scale));
  padding: 0 calc(0.85rem * var(--ui-scale));
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
}
.set-btn:hover { background: var(--sb-selected); }
.set-btn-primary {
  background: var(--sb-hover);
  border-color: var(--sb-hover);
  color: #fff;
}

.set-note {
  font-size: calc(13px * var(--ui-scale));
  color: var(--sb-text-dim);
  line-height: 1.7;
  margin: calc(0.4rem * var(--ui-scale)) 0 0;
}

.set-presets {
  display: flex;
  flex-wrap: wrap;
  gap: calc(0.4rem * var(--ui-scale));
  margin-bottom: calc(0.6rem * var(--ui-scale));
}
.set-preset {
  background: #fff;
  border: 1px solid var(--sb-border);
  border-radius: calc(1rem * var(--ui-scale));
  color: var(--sb-text);
  font-size: calc(13px * var(--ui-scale));
  padding: 2px calc(0.6rem * var(--ui-scale));
  cursor: pointer;
  font-family: inherit;
}
.set-preset:hover { background: var(--sb-selected); }

input[type="checkbox"] {
  width: calc(1.1rem * var(--ui-scale));
  height: calc(1.1rem * var(--ui-scale));
  accent-color: var(--sb-hover);
  cursor: pointer;
}

/* ══════════════════════════════════════════
   Blockly 定制：照 Scratch 的工具箱与面板
   ══════════════════════════════════════════ */
.blocklyToolboxDiv {
  background: var(--sb-toolbox) !important;
  border-right: 1px solid var(--sb-border) !important;
  padding: calc(0.5rem * var(--ui-scale)) 0 !important;
  width: calc(11rem * var(--ui-scale)) !important;
}

/* Scratch 式分类：彩色圆点 + 文字 */
.blocklyToolboxCategory {
  height: auto !important;
  line-height: 1.4 !important;
  padding: calc(0.6rem * var(--ui-scale)) calc(0.75rem * var(--ui-scale)) !important;
  border-left: none !important;
  border-radius: calc(0.5rem * var(--ui-scale)) !important;
  margin: calc(0.15rem * var(--ui-scale)) calc(0.4rem * var(--ui-scale)) !important;
  position: relative;
  transition: background .14s ease;
}
.blocklyToolboxCategory::before {
  content: "";
  position: absolute;
  left: calc(0.6rem * var(--ui-scale));
  top: 50%;
  transform: translateY(-50%);
  width: calc(1.15rem * var(--ui-scale));
  height: calc(1.15rem * var(--ui-scale));
  border-radius: 50%;
  background: var(--cat-color, #8795a1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}

.blocklyToolboxCategory:hover { background: rgba(76,151,255,.12) !important; }
.blocklyToolboxCategory[aria-selected="true"] { background: var(--sb-selected) !important; }

.blocklyTreeRowContentContainer {
  display: flex !important;
  align-items: center !important;
  gap: calc(0.5rem * var(--ui-scale)) !important;
  padding: 0 0 0 calc(1.7rem * var(--ui-scale)) !important;
}

.blocklyToolboxCategoryIcon { display: none !important; }

.blocklyToolboxCategoryLabel, .blocklyTreeLabel {
  font-family: var(--sb-font) !important;
  font-size: var(--fs-sm) !important;
  color: var(--sb-text) !important;
  line-height: 1.4 !important;
  white-space: nowrap !important;
}

.blocklyFlyoutBackground {
  fill: var(--sb-flyout) !important;
  fill-opacity: 1 !important;
}
.blocklyFlyoutLabelText {
  fill: var(--sb-text) !important;
  font-size: var(--fs-sm) !important;
}
.blocklyText { font-family: var(--sb-font) !important; }
.blocklyHtmlInput {
  font-family: var(--sb-font) !important;
  background: #fff !important;
  color: var(--sb-text) !important;
}

/* ── 窄屏 ── */
@media (max-width: 900px) {
  body { overflow: auto; }
  .studio-main { flex-direction: column; }
  .pane-blocks { width: 100% !important; flex: 0 0 auto !important; height: 46vh; }
  .pane-stage  { flex: 0 0 auto !important; height: 34vh; }
  .splitter-v { display: none; }
  .pane-code { height: 24vh; }
}
