/* 青园模拟器：门户页的模型卡片 + 在线工作台的类桌面布局。
   颜色沿用 website/css/theme.css 里的变量。 */

/* Alpine 初始化完成前先藏住带 x-cloak 的元素，避免闪一下未求值的内容 */
[x-cloak] {
  display: none !important;
}

/* 输出面板用 hidden 属性切换。面板自己带 position/display 的规则，
   这里显式压过去，保证隐藏生效。 */
.studio [hidden] {
  display: none !important;
}

/* ------------------------------------------------------------ 门户页 */

.entry-badge {
  display: inline-block;
  align-self: flex-start;
  padding: .2rem .7rem;
  margin-bottom: .6rem;
  border-radius: 999px;
  background: var(--pale);
  color: var(--moss);
  font-size: .78rem;
  letter-spacing: .06em;
}

.entry-badge-api {
  background: #fdf3e0;
  color: #8a6417;
}

.plant-card {
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.plant-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 150px;
  background: linear-gradient(160deg, var(--pale), var(--cream));
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.plant-cover img,
.plant-cover svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.plant-cover-empty {
  font-size: 2.4rem;
  opacity: .45;
}

.plant-name {
  font-weight: 600;
  color: var(--forest);
  word-break: break-all;
}

.plant-labels {
  margin: .3rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
}

.plant-labels .tag {
  font-size: .72rem;
}

.plant-meta {
  font-size: .8rem;
  color: var(--muted);
}

/* ------------------------------------------------------------ 工作台外框 */

/* 工作台占满视口剩余高度，内部自己滚动，整页不滚动 —— 更接近单机软件的观感。
   --studio-top 是导航栏的实际高度，由 studio.js 量出来写在 :root 上；
   导航栏在窄屏会折行变高，写死数值会露出一条页面级滚动条。 */
.studio {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--studio-top, 82px));
  min-height: 520px;
  background: var(--cream);
  border-top: 1px solid var(--line);
}

/* 站点主区域默认留了 4rem 下边距，工作台页面要去掉，否则整页会多出一段可滚动区 */
.site-main:has(> .studio) {
  padding-bottom: 0;
}

.studio-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.studio-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* 宽度由 Alpine 的 splitPct 写成内联样式，这里只是拖动前的兜底 */
.studio-pane-input {
  width: 50%;
}

.studio-pane-output {
  flex: 1;
}

/* 左右分栏的拖动条 */
.studio-splitter {
  flex: 0 0 7px;
  cursor: col-resize;
  background: var(--line);
  position: relative;
  transition: background .15s;
}

.studio-splitter:hover {
  background: var(--sprout);
}

/* 中间三个小点，提示这里可以拖 */
.studio-splitter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 26px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px);
  background-size: 3px 6px;
  opacity: .55;
}

/* 拖动时别让页面选中文字，光标也保持一致 */
body.qy-dragging {
  cursor: col-resize;
  user-select: none;
}

/* tab 与 INPUT/OUTPUT 标签共用一条底线：都贴着 head 的下边缘，文字才对得齐 */
.studio-pane-head {
  display: flex;
  align-items: flex-end;
  gap: .6rem;
  padding: .35rem .6rem 0;
  background: var(--sand);
  border-bottom: 1px solid var(--line);
}

.studio-pane-title {
  font-size: .74rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  /* 与 .studio-tab 的下内边距一致，两者文字底线才在同一水平线上 */
  padding-bottom: .38rem;
  white-space: nowrap;
}

/* 增删文件的小按钮，固定在 tab 条右侧，不随 tab 滚动 */
.studio-pane-actions {
  display: flex;
  gap: .2rem;
  padding-bottom: .3rem;
  flex: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--moss);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover:not(:disabled) {
  background: var(--pale);
  border-color: var(--sprout);
}

.icon-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ------------------------------------------------------------ 工具栏 */

.studio-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .45rem .75rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.studio-toolbar .sep {
  width: 1px;
  align-self: stretch;
  margin: 0 .35rem;
  background: var(--line);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .28rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--forest);
  font-size: .88rem;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
}

.tool-btn:hover:not(:disabled) {
  background: var(--pale);
  border-color: var(--sprout);
}

.tool-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.tool-btn-primary {
  background: var(--leaf);
  border-color: var(--leaf);
  color: #fff;
  font-weight: 600;
}

.tool-btn-primary:hover:not(:disabled) {
  background: var(--moss);
  border-color: var(--moss);
  color: #fff;
}

/* 删除这类不可撤销的操作：平时只是字色偏红，悬停才整块变红，避免误点 */
.tool-btn-danger {
  color: #b02a37;
}

.tool-btn-danger:hover:not(:disabled) {
  background: #fdf1f2;
  border-color: #e4a4aa;
  color: #8f2129;
}

.tool-field {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
}

.tool-field input[type="number"] {
  width: 5rem;
  padding: .22rem .4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .85rem;
}

/* 当前植物名 / 版本 / 未保存标记 */
.studio-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
  min-width: 0;
}

.studio-status .plant {
  font-weight: 600;
  color: var(--forest);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 16rem;
}

.dirty-dot {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: var(--sun);
  font-weight: 600;
}

.dirty-dot::before {
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--sun);
}

/* ------------------------------------------------------------ 文件 / 输出 tab */

.studio-tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  min-width: 0;
  scrollbar-width: thin;
}

/* 每个 tab 都是一块独立的"标签片"：有自己的边框和底色。
   文件多的时候若只靠间距区分，一排 tab 会糊成一片。 */
.studio-tab {
  padding: .35rem .75rem .38rem;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 7px 7px 0 0;
  background: #efe9db;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.35;
  white-space: nowrap;
  cursor: pointer;
  flex: none;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.studio-tab:hover {
  color: var(--forest);
  background: #f8f5ee;
}

/* 选中的 tab 与下方面板连成一体：白底 + 顶部一条绿色指示条，
   再往下压 1px 盖住 head 的底边框 */
.studio-tab.active {
  background: #fff;
  color: var(--forest);
  font-weight: 600;
  box-shadow: inset 0 3px 0 var(--leaf);
  margin-bottom: -1px;
  padding-bottom: calc(.38rem + 1px);
}

.studio-tab .tab-dirty {
  color: var(--sun);
  font-weight: 700;
}

.studio-panel {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #fff;
  overflow: auto;
}

/* 隐藏而不销毁：ECharts / Three.js 的实例要保留下来 */
.studio-panel[hidden] {
  display: none;
}

/* ------------------------------------------------------------ 编辑器与预览 */

.qy-editor {
  position: absolute;
  inset: 0;
  font-size: 13px;
}

.qy-image-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .8rem;
  padding: 1.2rem;
}

.qy-image-preview img {
  max-width: 100%;
  max-height: 60vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    repeating-conic-gradient(#f6f6f6 0 25%, #fff 0 50%) 50% / 18px 18px;
}

.qy-hint {
  padding: 2rem;
  color: var(--muted);
  text-align: center;
  font-size: .9rem;
}

/* ------------------------------------------------------------ 输出 */

.qy-svg-view {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 1rem;
  text-align: center;
}

.qy-svg-view svg {
  max-width: 100%;
  height: auto;
  transform-origin: top center;
}

.qy-chart {
  height: 320px;
  width: 100%;
}

.qy-series-picker {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  padding: .5rem .8rem;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
}

.qy-series-picker label {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .8rem;
  color: var(--ink);
  padding: .12rem .5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}

.qy-table-wrap {
  overflow: auto;
  max-height: 40vh;
  border-top: 1px solid var(--line);
}

.qy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.qy-table th,
.qy-table td {
  padding: .25rem .55rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.qy-table th {
  position: sticky;
  top: 0;
  background: var(--pale);
  color: var(--forest);
  z-index: 1;
}

.qy-table td:first-child,
.qy-table th:first-child {
  text-align: left;
}

.qy-viewer {
  position: absolute;
  inset: 0;
}

.qy-viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.qy-viewer-tools {
  position: absolute;
  right: .6rem;
  top: .6rem;
  display: flex;
  gap: .3rem;
  z-index: 2;
}

.qy-log {
  margin: 0;
  padding: .8rem 1rem;
  font-size: .8rem;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.qy-log .err {
  color: #a4331f;
}

.qy-log .ok {
  color: var(--moss);
}

.qy-log time {
  color: var(--muted);
  margin-right: .5rem;
}

/* 运行中的遮罩 */
.qy-busy {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  background: rgba(255, 255, 255, .75);
  color: var(--moss);
  font-size: .9rem;
  z-index: 5;
}

/* ------------------------------------------------------------ 对话框内的列表 */

.model-row {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .5rem .2rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.model-row:hover {
  background: var(--pale);
}

.model-row .thumb {
  width: 46px;
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
  overflow: hidden;
}

.model-row .thumb img,
.model-row .thumb svg {
  max-width: 100%;
  max-height: 100%;
}

.version-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .2rem;
  border-bottom: 1px solid var(--line);
  font-size: .88rem;
}

.version-row .num {
  font-weight: 600;
  color: var(--forest);
  min-width: 3rem;
}

@media (max-width: 991.98px) {
  .studio {
    height: auto;
  }

  .studio-body {
    flex-direction: column;
  }

  /* 竖排时拖动条没有意义，宽度也交回给布局（覆盖内联的 splitPct） */
  .studio-splitter {
    display: none;
  }

  .studio-pane-input {
    width: 100% !important;
    border-bottom: 1px solid var(--line);
  }

  .studio-pane {
    height: 70vh;
  }
}
