/* dsforge 界面层。所有色值来自 theme.css 的 token。 */

html, body { height: 100%; }
body { overflow: hidden; }

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand__mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--violet-soft); color: var(--violet);
  border: 1px solid color-mix(in srgb, var(--violet) 30%, transparent);
}
.brand__mark .icon { width: 18px; height: 18px; }
.brand__name { font-weight: 680; font-size: var(--text-base); }
.brand__sub { font-size: var(--text-xs); color: var(--text-faint); }
.spacer { flex: 1; }

/* 顶栏的语言 / 主题选择器。
   用原生 <select> 而不是轮询按钮：轮询要点满一圈才能回到起点，
   语言加到四档（跟随系统 / 中 / 英 / 日）之后这个代价就很明显了。
   原生控件还白送键盘操作、屏幕阅读器语义和移动端的系统选择面板。

   做法是「壳负责外观，select 只负责交互」：select 自身完全透明，
   边框、底色、图标与焦点环都画在 .pick 上。 */
.pick { position: relative; display: inline-flex; align-items: center; }

/* 图标浮在 select 上方，且不吃点击。
   反过来做——壳负责内边距、select 只占中间那点宽度——药丸看着是一个控件，
   实际只有中间可点，点在图标或边距上没反应。这里让 select 铺满整个药丸，
   两个图标用绝对定位盖上去，于是「看起来能点的地方」都真的能点。 */
.pick__icon, .pick__caret {
  position: absolute;
  display: grid; place-items: center;
  pointer-events: none;
}
.pick__icon { left: var(--space-3); color: var(--text-muted); }
.pick__icon .icon { width: 15px; height: 15px; }
.pick__caret { right: var(--space-2); color: var(--text-faint); }
.pick__caret .icon { width: 13px; height: 13px; transform: rotate(90deg); }

.pick__select {
  appearance: none; -webkit-appearance: none;
  margin: 0;
  padding: var(--space-1) calc(var(--space-2) + 16px) var(--space-1) calc(var(--space-3) + 21px);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  outline: none;                /* 焦点环用下面的 :focus-visible 画，避免双层描边 */
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs); font-weight: 550;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.pick__select:hover { background: var(--surface-2); color: var(--text); }
.pick__select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--surface-2);
  color: var(--text);
}
.pick:hover .pick__icon, .pick:hover .pick__caret { color: var(--text); }
/* 展开后的列表默认由系统绘制，不继承 .pick 的颜色：不显式给底色的话，
   深色模式下有的平台会出现白底黑字。 */
.pick__select option { background: var(--surface); color: var(--text); }

/* 可定制 select（Chrome 135+）。原生弹出层在 Windows 上是一个 OS 级窗口，
   CSS 基本管不着，行高、圆角、配色都跟不上这个界面。base-select 把它变成
   真正的 DOM，于是可以用本项目自己的令牌画完。
   不支持的浏览器整段忽略，退回原生弹出层——功能一样，只是长得像系统的。
   这是渐进增强，不是兜底。 */
@supports (appearance: base-select) {
  .pick__select,
  .pick__select::picker(select) { appearance: base-select; }

  /* base-select 会给 select 自带一个箭头；箭头我们已经画在 .pick__caret 上了。
     这里只关箭头——内边距和边框归上面那条基础规则管，
     在这儿重置掉的话 select 会塌回 UA 的 24px 最小宽度。 */
  .pick__select::picker-icon { display: none; }

  .pick__select::picker(select) {
    box-sizing: border-box;
    min-width: 148px;
    margin-top: var(--space-1);
    padding: var(--space-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    /* 弹出层从 top layer 打开，进出场都要显式声明，否则关闭时是瞬间消失 */
    opacity: 0;
    translate: 0 -4px;
    transition:
      opacity var(--dur-fast) var(--ease),
      translate var(--dur-fast) var(--ease),
      overlay var(--dur-fast) allow-discrete,
      display var(--dur-fast) allow-discrete;
  }
  .pick__select:open::picker(select) { opacity: 1; translate: 0 0; }
  @starting-style {
    .pick__select:open::picker(select) { opacity: 0; translate: 0 -4px; }
  }

  .pick__select option {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: var(--text-sm);
    line-height: 1.4;
    cursor: pointer;
    /* 原生列表把选项挤成一行像素高，这里按面板里其他控件的节奏来 */
    min-height: 30px;
  }
  .pick__select option:hover,
  .pick__select option:focus {
    background: var(--surface-2);
    outline: none;
  }
  .pick__select option:checked { color: var(--accent-text); font-weight: 600; }
  /* 默认的选中标记是个跟随系统字体的 ✓，和界面里其他勾不是一套。
     留出固定宽度让文字对齐，选中时才显形。 */
  .pick__select option::checkmark {
    content: "";
    order: -1;
    width: 6px; height: 6px;
    flex: none;
    border-radius: 999px;
    background: var(--accent);
    opacity: 0;
  }
  .pick__select option:checked::checkmark { opacity: 1; }
}

/* ---------------- 主体两栏 ---------------- */
.main {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  min-height: 0;
}
.topbar, .main, .panel, .output { min-width: 0; }

.panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--space-5);
  background: var(--surface);
  display: flex; flex-direction: column; gap: var(--space-6);
}

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label {
  font-size: var(--text-xs); font-weight: 650; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-faint);
  display: flex; align-items: center; gap: var(--space-2);
}
.field__hint { font-size: var(--text-xs); color: var(--text-faint); line-height: 1.6; }

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-sm);
}
.textarea { min-height: 76px; resize: vertical; font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6; }
.select { cursor: pointer; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }

/* 风格卡片 */
.styles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.style-card {
  position: relative;
  text-align: left; cursor: pointer;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  display: grid; gap: var(--space-2);
}
.style-card:hover { border-color: var(--border-strong); }
.style-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.style-card__name { font-size: var(--text-sm); font-weight: 620; line-height: 1.25; }
.style-card__en { font-size: 10px; color: var(--text-faint); letter-spacing: .02em; }
.style-card--cross { opacity: .64; }
.style-card--cross:hover, .style-card--cross[aria-pressed="true"] { opacity: 1; }
.style-card__fit {
  width: fit-content;
  padding: 2px var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1.3;
}
.swatches { display: flex; gap: 3px; }
.swatch { width: 100%; height: 14px; border-radius: 3px; border: 1px solid rgba(128,128,128,.25); }

/* 分段控件 */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  overflow: hidden; background: var(--surface-2);
}
.segmented button {
  padding: var(--space-2) var(--space-1); border: 0; background: none; cursor: pointer;
  font-size: var(--text-xs); font-weight: 560; color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* 复选芯片 */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  background: var(--surface-2); color: var(--text-muted);
  font-size: var(--text-xs); cursor: pointer; font-weight: 550;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent-text);
}
.chip .icon { width: 12px; height: 12px; }

.config-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.panel__actions {
  position: sticky; bottom: calc(var(--space-5) * -1);
  margin: auto calc(var(--space-5) * -1) calc(var(--space-5) * -1);
  padding: var(--space-4) var(--space-5);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex; gap: var(--space-2);
}
.panel__actions .btn { flex: 1; }

/* ---------------- 输出区 ---------------- */
.output { display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.outbar {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}
.filetab {
  padding: var(--space-2) var(--space-3); border: 0; background: none; cursor: pointer;
  font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550;
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.filetab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.filetab .icon { width: 13px; height: 13px; }

.outbody { overflow: auto; min-height: 0; background: var(--bg); position: relative; }

.previewwrap { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.filebody { min-height: 100%; }
.previewbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  font-size: var(--text-xs); color: var(--text-muted);
}
.previewwrap iframe { width: 100%; height: 100%; border: 0; background: var(--surface); }

.codehead {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
}
.codehead__name { font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600; }
.codehead__desc { font-size: var(--text-xs); color: var(--text-faint); }

pre.filecode {
  margin: 0; padding: var(--space-5);
  font-size: var(--text-xs); line-height: 1.7;
  color: var(--text-muted); white-space: pre-wrap; word-break: break-word;
  tab-size: 2;
}
pre.filecode strong { color: var(--text); font-weight: 640; }

.placeholder {
  height: 100%; display: grid; place-items: center; padding: var(--space-10);
  text-align: center; color: var(--text-faint);
}
.placeholder__inner { max-width: 46ch; display: grid; gap: var(--space-3); justify-items: center; }
.placeholder .icon { width: 30px; height: 30px; color: var(--border-strong); }
.placeholder h2 { font-size: var(--text-lg); color: var(--text); }
.placeholder p { font-size: var(--text-sm); line-height: 1.7; }

.toast {
  position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%) translateY(16px);
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-full);
  background: var(--text); color: var(--bg); font-size: var(--text-sm); font-weight: 550;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base) var(--ease), transform var(--dur-base) var(--ease);
  z-index: 60;
}
.toast[data-show="1"] { opacity: 1; transform: translateX(-50%) translateY(0); }

.statline {
  font-size: var(--text-xs); color: var(--text-faint);
  display: flex; gap: var(--space-3); flex-wrap: wrap;
}

@media (max-width: 1080px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; min-height: 100dvh; }
  .main { grid-template-columns: 1fr; }
  .panel {
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .output { height: min(760px, 80dvh); min-height: 560px; }
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
  .brand { min-width: 0; flex: 1; }
  .brand > span:last-child { min-width: 0; }
  .brand__sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar > .spacer { display: none; }
  .statline {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-2);
  }
  .panel { padding: var(--space-4); }
  .panel__actions {
    bottom: calc(var(--space-4) * -1);
    margin: auto calc(var(--space-4) * -1) calc(var(--space-4) * -1);
    padding-inline: var(--space-4);
  }
  .previewbar, .codehead { flex-wrap: wrap; }
  .codehead__desc { order: 3; width: 100%; }
  .output { height: 78dvh; min-height: 520px; }
}

@media (max-width: 480px) {
  .brand__sub { display: none; }
  .statline { grid-template-columns: 1fr 1fr; }
  .styles { grid-template-columns: 1fr; }
  .panel__actions { flex-direction: column; }
  .output { height: 82dvh; min-height: 480px; }
  .previewbar .spacer { display: none; }
}
