/* 雪花球：冷色、安静的冬夜感。蓝灰标题条、浅蓝灰底、按钮从中蓝灰到深蓝灰、深棕球座。
   3D 画面铺满整个窗口，所有按钮悬浮在它上面。界面是居中的一列，列宽由壳算好写进 --col-w，--u = 列宽 / 100。
   按钮固定像素，不随屏幕放大。所有按钮平面、没有阴影。
   带文字的按钮底：亮度 ≥ 210 或 ≤ 125，强制深色下不会出现灰底深字。 */
:root {
  --outside: #dce5e8;
  --stage: #dce5e8;
  --stage-edge: #cad7db;
  --band: #6c7a82;
  --on-band: #dce5e8;
  --paper: #e9eff1;
  --paper-edge: #d2dde1;

  /* 共用部件（弹窗、提示条）跟着这套色 */
  --bg: #dce5e8;
  --surface: #e9eff1;
  --surface-2: #d2dde1;
  --field: #f1f5f6;
  --bar: #33424a;
  --ink: #2f3c43;
  --ink-2: #52626b;
  --ink-3: #8a9ba3;
  --line: #46535a;
  --accent: #6fa3a3;
  --danger: #8f3a3a;
  --on-dark: #eef3f5;
}

html,
body {
  background-color: var(--stage);
}

/* ---------- 层级：3D 画面 → 飘雪 → 触摸层 → 界面层 ---------- */
.sg-stage {
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 基础飘雪特效：在 3D 画面之上、界面之下，整列高度，不挡操作。 */
.sg-snowfx {
  position: fixed;
  z-index: 2;
  top: 0;
  height: 100%;
  pointer-events: none;
}

/* 缩放、平移、转球、拖立牌都落在这一层：整个窗口，不可见。 */
.sg-hit {
  position: fixed;
  z-index: 3;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 界面层：整个窗口，本身不接指针，只有按钮和面板接。整页抖动的滤镜挂在这一层。 */
.sg-root {
  position: fixed;
  z-index: 4;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sg-col {
  position: absolute;
  top: 0;
  height: 100%;
}

/* ---------- 标题条（铺满这一列的宽度，下沿向上拱）---------- */
.sg-band {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(var(--band-side) + 6px);
  pointer-events: none;
}

.sg-band-bg {
  position: absolute;
  left: calc(var(--u) * -3);
  top: calc(var(--u) * -3);
  width: calc(100% + var(--u) * 6);
  height: calc(100% + var(--u) * 3);
}

.sg-band-in {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

/* 标题：盒子和标题条正中的高一样高。字形在字框里偏下，上移 0.05em 后墨水落在正中；padding-left 抵消字间距，左右也居中；两头给中 / EN 留位。 */
.sg-title {
  position: absolute;
  left: 72px;
  right: 72px;
  top: 0;
  height: var(--band-center);
  margin: 0;
  padding-left: 0.08em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--u) * 5.6);
  font-weight: var(--title-weight);
  line-height: 1;
  letter-spacing: 0.08em;
  color: var(--on-band);
  white-space: nowrap;
  -webkit-transform: translateY(-0.05em);
  transform: translateY(-0.05em);
}

/* 中 / EN：固定在标题条右上角，一个整体的二选一分段钮，小而扁（高 22），和标题同一条水平中线；点击区每半 44 × 44 用伪元素向外扩，不占版面。 */
.sg-lang {
  position: absolute;
  z-index: 2;
  top: calc((var(--band-center) - 22px) / 2);
  right: 8px;
  box-sizing: border-box;
  display: flex;
  height: 22px;
  border-radius: 6px;
  background: #46535a;
  pointer-events: auto;
}

.sg-lang-btn {
  position: relative;
  min-width: 0;
  height: 100%;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 900;
  line-height: 22px;
  color: #cfdadf;
}

.sg-lang-btn:first-child {
  border-radius: 6px 0 0 6px;
}

.sg-lang-btn:last-child {
  border-radius: 0 6px 6px 0;
}

.sg-lang-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 44px;
  height: 44px;
  margin-top: -22px;
}

.sg-lang-btn:first-child::after {
  right: 0;
}

.sg-lang-btn:last-child::after {
  left: 0;
}

.sg-lang-btn[aria-pressed='true'] {
  background: #dce5e8;
  color: #2f3c43;
}

/* ---------- 悬浮件的摆放区：整列 ---------- */
.sg-ui {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sg-chip,
.sg-tool,
.sg-scenesw,
.sg-cell {
  pointer-events: auto;
}

.icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 基础钮：标题条下面居中一排，每钮 46 × 30（看得见的形状）、icon 16，任何屏幕都一样；点击区 52 × 44（伪元素）。 */
.sg-basics {
  position: absolute;
  left: 0;
  top: calc(var(--band-side) + 14px);
  width: 100%;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.sg-chip {
  position: relative;
  flex: none;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 30px;
  margin: 0 3px;
  padding: 0;
  border: 2px solid #5a676f;
  border-radius: 9px;
  background: #6c7a82;
  color: #eef3f5;
}

.sg-chip::after {
  content: '';
  position: absolute;
  left: -5px;
  right: -5px;
  top: -9px;
  bottom: -9px;
}

.sg-chip .icon {
  display: block;
  width: 16px;
  height: 16px;
}

.sg-chip[aria-pressed='true'] {
  border-color: #27333a;
  background: #33424a;
}

.sg-chip:disabled {
  border-color: #8b999f;
  background: #9aa8ae;
  color: #d3dde1;
  cursor: default;
}

/* ---------- 工具窗：靠左悬浮，竖排五个钮；顶上一条把手（可拖）和「收起」 ---------- */
.sg-win {
  position: fixed;
  z-index: 2;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 68px;
  padding: 4px;
  border: 2px solid #b4c4cc;
  border-radius: 12px;
  background: #e9eff1;
  pointer-events: auto;
}

.sg-win-head {
  display: flex;
  align-items: center;
  height: 26px;
}

.sg-win-grip {
  position: relative;
  flex: 1 1 auto;
  min-width: 10px;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.sg-win-grip::before {
  content: '';
  position: absolute;
  left: -6px;
  right: -2px;
  top: -8px;
  bottom: -8px;
}

.sg-win-grip span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 4px;
  margin-left: -7px;
  margin-top: -4px;
  border-top: 2px solid #8a9ba3;
  border-bottom: 2px solid #8a9ba3;
}

.sg-win-fold {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 4px;
  border-radius: 7px;
  background: #cddae0;
  color: #2f3c43;
}

.sg-win-fold::after {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  top: -10px;
  bottom: -10px;
}

.sg-win-fold .icon {
  display: block;
  width: 12px;
  height: 12px;
  margin-left: 2px;
}

.sg-win-fold[aria-expanded='false'] .icon {
  -webkit-transform: rotate(180deg);
  transform: rotate(180deg);
}

.sg-win-foldtext {
  font-size: 11px;
  font-weight: 700;
  line-height: 14px;
  white-space: nowrap;
}

.sg-win-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin-top: 4px;
}

.sg-win.is-folded .sg-win-body {
  display: none;
}

/* 工具钮：图案在上、名字在下，底色从中蓝灰到最深 */
.sg-tool {
  position: relative;
  box-sizing: border-box;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  height: 46px;
  margin: 2px 0;
  padding: 0 2px;
  border: 2px solid #5a676f;
  border-radius: 10px;
  background: #6c7a82;
  color: #eef3f5;
}

.sg-tool .icon {
  display: block;
  width: 20px;
  height: 20px;
  margin-bottom: 2px;
}

.sg-tool-name {
  font-size: 11px;
  font-weight: 700;
  line-height: 13px;
  white-space: nowrap;
}

.sg-tool-dark {
  border-color: #323c43;
  background: #404c54;
}

.sg-tool-darkest {
  border-color: #27333a;
  background: #33424a;
}

.sg-tool[aria-pressed='true'] {
  border-color: #232d33;
  background: #2f3c43;
  color: #eef3f5;
}

/* 场景钮：28 高的扁条，左右箭头夹着「场景」 */
.sg-scenesw {
  position: relative;
  box-sizing: border-box;
  height: 28px;
  border: 2px solid #5a676f;
  border-radius: 9px;
  background: #6c7a82;
  color: #eef3f5;
}

.sg-scenesw {
  display: flex;
  align-items: center;
}

.sg-scenesw-btn {
  position: relative;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 100%;
  padding: 0;
  color: #eef3f5;
}

.sg-scenesw-btn::after {
  content: '';
  position: absolute;
  left: -7px;
  right: -7px;
  top: -10px;
  bottom: -10px;
}

.sg-scenesw-btn .icon {
  display: block;
  width: 14px;
  height: 14px;
}

.sg-scenesw-name {
  font-size: 12px;
  font-weight: 700;
  line-height: 14px;
  white-space: nowrap;
}

.sg-scenesw-name {
  padding: 0 4px;
}

/* ---------- 列底：场景钮居中，下面是标签页 ---------- */
.sg-dock {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  pointer-events: none;
}

.sg-scenerow {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
  pointer-events: none;
}

.sg-scenerow .sg-scenesw {
  pointer-events: auto;
}

/* 场景名和署名：场景钮上方，只有文字（画在画布里） */
.sg-scene {
  position: absolute;
  left: 0;
  bottom: 100%;
  width: 100%;
  height: calc(var(--u) * 12);
  margin-bottom: 4px;
  pointer-events: none;
}

.sg-panel {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  border: 2px solid #b4c4cc;
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  background: #e9eff1;
  pointer-events: auto;
}

.ct-tabs {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  margin-bottom: 8px;
  border: 2px solid #b4c4cc;
  border-radius: 10px;
  background: #cddae0;
  overflow: hidden;
}

.ct-tab {
  flex: 1 1 0;
  min-width: 0;
  height: 32px;
  padding: 0 4px;
  font-size: 13px;
  font-weight: 700;
  line-height: 32px;
  text-align: center;
  white-space: nowrap;
  color: #2f3c43;
}

.ct-tab[aria-selected='true'] {
  background: #33424a;
  color: #eef3f5;
}

/* 三个标签页叠在同一格里，高度取最高的那一页，切页时面板不变高。 */
.ct-stack {
  display: grid;
  width: 100%;
}

.ct-stack > .ct-grid {
  grid-area: 1 / 1;
  min-width: 0;
}

.ct-grid {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 4px;
  overflow-x: auto;
  touch-action: pan-x;
}

.ct-grid[data-on='false'] {
  visibility: hidden;
  pointer-events: none;
}

/* 格子：全部是 44 × 44 的小正方形 */
.ct-item,
.sg-cell {
  position: relative;
  flex: none;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0 6px 0 0;
  padding: 0;
  border: 2px solid #43525b;
  border-radius: 8px;
  background: #4f606a;
  color: #eef3f5;
}

.ct-item:last-child {
  margin-right: 0;
}

.ct-item[aria-selected='true'] {
  border: 3px solid #232d33;
  background: #5e707b;
}

.ct-art {
  display: block;
  width: 34px;
  height: 34px;
}

.ct-thumb {
  display: block;
  width: 34px;
  height: 34px;
  pointer-events: none;
}

.ct-item > .icon {
  display: block;
  width: 22px;
  height: 22px;
}

.ct-swatch {
  background: #443a37;
}

.ct-swatch[aria-selected='true'] {
  background: inherit;
}

.color-button.ct-custom {
  width: 44px;
  height: 44px;
  border: 2px solid #43525b;
  border-radius: 8px;
}

.color-button.ct-custom.is-empty {
  background: #e9eff1;
  color: #2f3c43;
}

.color-button.ct-custom.is-open {
  box-shadow: none;
  border: 3px solid #232d33;
}

/* ---------- 选中框：叠在球上，随立牌走 ---------- */
.sg-sel {
  position: fixed;
  z-index: 3;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.sg-sel-box {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  box-sizing: border-box;
  border: 3px solid #eef3f5;
  border-radius: 8px;
}

.sg-sel-box::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  border: 1.5px dashed #232d33;
  border-radius: 5px;
}

.sg-handle {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid #eef3f5;
  border-radius: 50%;
  background: #33424a;
  color: #eef3f5;
  touch-action: none;
  pointer-events: auto;
}

.sg-handle::before {
  content: '';
  position: absolute;
  left: -8px;
  right: -8px;
  top: -8px;
  bottom: -8px;
  border-radius: 50%;
}

.sg-handle .icon {
  display: block;
  width: 16px;
  height: 16px;
}

/* ---------- 弹窗和提示条：同一套手剪纸片，没有阴影 ---------- */
.modal {
  border: calc(var(--u) * 0.6) solid var(--line);
  border-radius: calc(var(--u) * 1.4);
  background-color: var(--surface);
}

/* 标题行：右边不为 × 留位，标题在条里上下居中、左右居中 */
.modal-head {
  padding-right: var(--gap-3);
}

.modal-title {
  text-align: center;
}

/* 关闭 ×：面板右上角的小 ×，字形 18px、可见框 20 × 20、离角约 6px（含面板的边）、无底色无边框；点击区由模板的 ::before 扩到 44 × 44，不占版面 */
.modal-close {
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
}

.modal-close::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  margin-top: -22px;
}

/* 没有标题时第一行右边只多留 14 像素，不留整块宽度 */
.modal-untitled .modal-body > :first-child:not(.modal-stack),
.modal-untitled .modal-stack > :first-child {
  max-width: calc(100% - 14px);
}

.btn {
  border: calc(var(--u) * 0.6) solid var(--line);
  border-radius: calc(var(--u) * 1.6);
  background: var(--paper);
  color: var(--ink);
}

.btn-primary {
  background: var(--bar);
  border-color: #27333a;
  color: var(--on-dark);
}

.btn-danger {
  background: var(--danger);
  border-color: #5a2323;
  color: #f1eaea;
}

.toast {
  border-radius: calc(var(--u) * 1.4);
}

/* 整页抖动：界面层整个挂一层滤镜，里面的所有件一起抖；界面层外面的弹窗另外再挂同一个。 */
.is-boiling .sg-root,
.is-boiling .modal {
  filter: url(#boil);
}

/* WebKit：不给整个窗口大的界面层挂滤镜，只给有内容的几块各挂一次同一个滤镜（原因见 boil.js）。 */
.is-boil-split .sg-root {
  filter: none;
}

.is-boil-split .sg-band,
.is-boil-split .sg-basics,
.is-boil-split .sg-win,
.is-boil-split .sg-dock,
.is-boil-split .sg-sel-box,
.is-boil-split .sg-sel .sg-handle {
  filter: url(#boil);
}

/* 矮窗口：标签页收矮。 */
@media (max-height: 520px) {
  .ct-tab {
    height: 26px;
    line-height: 26px;
    font-size: 12px;
  }

  .ct-tabs {
    margin-bottom: 4px;
  }

  .sg-panel {
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }
}
