/* 哐哐照片墙：深炭灰的房间、墨绿黑板、深棕木框，标题牌灰粉，点缀红和米色。
   舞台是一块画布，铺满整页（窄屏是标题牌下面的整块），上面是一张无限大的桌子，黑板是桌上的一件东西。
   窄屏：四钮悬浮在舞台顶部、道具栏（选了一类就换成这一类的款式和颜色）悬浮在舞台底部；
   宽屏（电脑、平板横屏、手机横屏）：标题、四钮、道具都在悬浮的右侧栏里，舞台铺满整页。
   悬浮件都是实心底色，不占舞台的位置；舞台上被它们盖住的边由 js/app.js 量出来交给黑板。
   所有尺寸用 px 和变量，页面整体随窗口伸缩。 */
:root {
  color-scheme: only light;
  --page: #231f1d;
  --bar: #302a28;
  --bar-2: #3b3431;
  --line: #5a4d49;
  --ink: #efe3dc;
  --ink-2: #c4b3ab;
  --ink-3: #8e7f78;
  --plate: #7d6b68;
  --on-plate: #f6ede8;
  --cream: #e6d8d0;
  --red: #a3261b;
  --wood: #3a2b22;
  --tile: 56px;
  --rail: 104px;
  --pick-h: 104px;

  --bg: #231f1d;
  --surface: #302a28;
  --surface-2: #3f3836;
  --field: #3b3431;
  --accent: #e6d8d0;
  --on-dark: #f6ede8;
}

@media (max-width: 359px) {
  :root { --tile: 48px; }
}

@media (min-width: 600px) and (orientation: portrait) {
  :root { --tile: 72px; }
}

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

/* ---------- 壳：窄屏从上到下 ---------- */
.app {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--page);
}

/* 整页轻轻抖动：滤镜在 js/ui/boil.js 里生成，网址带 ?still=1 时不挂；有字的地方用位移小一半的那个 */
.wall-boil {
  filter: url(#wall-boil);
}

.wall-boil-soft {
  filter: url(#wall-boil-soft);
}

/* 标题牌：别着夹子，居中；左上角是「黑板」，右上角是小的中 / EN */
.titlebar {
  position: relative;
  z-index: 2;
  grid-column: 1;
  grid-row: 1;
  padding: 12px 56px 0;
  text-align: center;
}

.plate {
  position: relative;
  display: inline-block;
  padding: 4px 20px;
  border-radius: 9px;
  background: var(--plate);
}

.plate::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -7px;
  width: 18px;
  height: 11px;
  margin-left: -9px;
  border-radius: 3px;
  background: var(--cream);
}

.title {
  margin: 0;
  color: var(--on-plate);
  font-weight: 900;
  font-size: 20px;
  line-height: 26px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

html[lang="en"] .title {
  font-size: 18px;
  letter-spacing: 0;
}

.board-chip {
  position: absolute;
  top: 18px;
  left: 8px;
  height: 22px;
  padding: 0 8px;
  border: 2px solid var(--ink-2);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  white-space: nowrap;
}

.board-chip::before {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  top: -11px;
  bottom: -11px;
}

.board-chip.is-on {
  background: var(--ink-2);
  color: var(--page);
}

.lang-chip {
  position: absolute;
  top: 18px;
  right: 8px;
  display: flex;
  height: 22px;
  border: 2px solid var(--ink-2);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

.lang-chip::before {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  top: -11px;
  bottom: -11px;
}

.lang-zh,
.lang-en {
  display: block;
  padding: 0 6px;
}

html[lang^="zh"] .lang-zh,
html[lang="en"] .lang-en {
  background: var(--ink-2);
  color: var(--page);
}

/* ---------- 四钮：回退、重做、重新开始、导出，一排居中，每个 44 × 32、图标 18、无阴影；点按区用伪元素扩到 48 × 44 ---------- */
/* 窄屏：悬浮在舞台顶部。这一条本身不接指针，按钮之间的空隙按下去落在舞台上。 */
.ctrl {
  position: relative;
  z-index: var(--z-float);
  grid-column: 1;
  grid-row: 2;
  align-self: start;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px 8px;
  pointer-events: none;
}

.basic-group {
  display: flex;
  flex: none;
}

.basic-group .tool {
  position: relative;
  pointer-events: auto;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 32px;
  margin: 0 3px;
  border: 2px solid var(--ink-2);
  border-radius: 9px 8px 9px 8px;
  background: var(--bar-2);
  color: var(--ink);
}

.basic-group .tool::before {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: -6px;
  bottom: -6px;
}

.basic-group .tool .icon {
  display: block;
  width: 18px;
  height: 18px;
}

.basic-group .tool .icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 4.6;
}

.basic-group .tool[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* ---------- 舞台（画布）：铺满整页，四钮和道具栏悬浮在它上面 ---------- */
.stage {
  position: relative;
  z-index: 0;
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  min-height: 0;
  overflow: hidden;
}

/* 木框和板面都由画布画出来（wall/draw.js），这里只是放画布的容器 */
.board {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.wall-canvas {
  position: absolute;
  left: 0;
  top: 0;
  touch-action: none;
}

/* 黑板上盖着的手柄、输入框：不挡住黑板上的手势，只有自己的部分可点 */
.wall-overlay {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-rail);
  pointer-events: none;
}

.wall-handle {
  position: absolute;
  display: none;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  padding: 0;
  border: 2px solid var(--page);
  border-radius: 50%;
  background: var(--cream);
  color: var(--page);
  pointer-events: auto;
  touch-action: none;
}

.wall-handle::before {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  top: -8px;
  bottom: -8px;
}

.wall-handle .icon {
  display: block;
  width: 14px;
  height: 14px;
  margin: 6px;
}

.wall-handle .icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 6;
}

.wall-handle.is-turn .icon,
.wall-handle.is-color .icon {
  width: 18px;
  height: 18px;
  margin: 4px;
}

.wall-handle.is-turn .icon svg,
.wall-handle.is-color .icon svg {
  stroke-width: 4.6;
}

.wall-handle.is-color.is-open {
  background: var(--page);
  color: var(--cream);
}

/* 便签、相纸上写字的输入框：和画布上的字同样排版，整个按 16 像素排好再缩放、旋转到对应位置 */
.wall-edit {
  position: absolute;
  display: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  resize: none;
  overflow: hidden;
  outline: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.375;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: anywhere;
  pointer-events: auto;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
}

/* 量折行用的隐藏文本块，样式和输入框一致 */
.wall-text-probe {
  position: fixed;
  left: -9999px;
  top: 0;
  margin: 0;
  padding: 0;
  border: 0;
  visibility: hidden;
  pointer-events: none;
  font-weight: 700;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: anywhere;
}

/* 挂绳子、贴胶带时的悬浮小条 */
.wall-chip {
  position: fixed;
  z-index: var(--z-float);
  display: none;
  align-items: center;
  max-width: calc(100% - 16px);
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}

.wall-chip-text {
  padding: 8px 4px 8px 14px;
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
  cursor: move;
  touch-action: none;
}

.wall-chip-close {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 36px;
  color: var(--ink);
}

.wall-chip-close .icon {
  display: block;
  width: 14px;
  height: 14px;
}

.wall-chip-close .icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 5;
}

/* 从面板里拖出来的款式 */
.wall-ghost {
  position: fixed;
  z-index: var(--z-modal);
  left: 0;
  top: 0;
  opacity: 0.92;
  pointer-events: none;
  -webkit-transform: translate(-50%, -50%) scale(1.15);
  transform: translate(-50%, -50%) scale(1.15);
}

.wall-ghost.is-away {
  opacity: 0.4;
}

/* ---------- 道具栏：窄屏悬浮在舞台底部，一行，两组并排；选了一类后，同一块地方换成这一类的款式和颜色，高度不变 ---------- */
.tools {
  position: relative;
  z-index: 15;
  grid-column: 1;
  grid-row: 2;
  align-self: end;
  display: grid;
  padding: 8px 6px 8px;
  border-radius: 14px 14px 0 0;
  background: var(--bar);
}

.tools-main,
.tools-pick {
  grid-area: 1 / 1;
  min-width: 0;
  height: var(--pick-h);
}

.tools-main {
  display: flex;
  align-items: center;
}

.tools-pick {
  visibility: hidden;
}

.tools.is-picking .tools-main {
  visibility: hidden;
}

.tools.is-picking .tools-pick {
  visibility: visible;
}

.tool-group {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  align-items: flex-end;
}

.tool-item {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.tool-tile {
  position: relative;
  display: block;
  width: var(--tile);
  height: var(--tile);
  padding: 0;
  border-radius: 12px;
  background: transparent;
}

.tool-name {
  margin-top: 5px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  line-height: 15px;
  white-space: nowrap;
}

/* 选中：托起一点 + 实线亮边，名字变亮 */
.tool-item.is-on .tool-tile {
  outline: 3px solid var(--cream);
  -webkit-transform: translateY(-3px);
  transform: translateY(-3px);
}

.tool-item.is-on .tool-name {
  color: var(--cream);
}

/* ---------- 图案块：大小由清单或样式定，里面是 wall/art.js 画好的画布 ---------- */
.piece {
  position: relative;
  display: block;
  flex: none;
  width: 100%;
  height: 100%;
  border-radius: 9px;
  color: var(--ink);
}

.piece-art {
  display: block;
  width: 100%;
  height: 100%;
}

.piece .icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
}

.piece .icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 4.6;
}

/* ---------- 面板：窄屏换进底栏（款式一排左右滑，上面一排颜色），宽屏落在右侧栏空位里 ---------- */
.rail-slot {
  display: contents;
}

/* 宽屏右侧栏的实心底板；窄屏不显示 */
.rail-back {
  display: none;
}

.tray {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}

.tray-head {
  display: flex;
  flex: none;
  align-items: center;
}

.tray-title {
  flex: 1 1 auto;
  padding: 10px 14px 0;
  color: var(--cream);
  font-size: 15px;
  font-weight: 900;
  line-height: 22px;
}

.tray-close {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink-2);
  border-radius: 50%;
  color: var(--ink);
}

.tray-close::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: -6px;
  bottom: -6px;
}

.tray-close .icon {
  display: block;
  width: 14px;
  height: 14px;
}

.tray-close .icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 6;
}

.tray-colors {
  flex: none;
  min-width: 0;
}

.tray-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px 8px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tray-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-gap: 6px;
}

.tray-item {
  position: relative;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 44px;
  padding: 8px 2px 6px;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
}

.tray-body.is-scroll .tray-item {
  touch-action: pan-y;
}

.tray-item.is-on {
  background: var(--surface-2);
}

.tray-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 56px;
}

.kind-rope .tray-art { height: 40px; }
.kind-pin .tray-art { height: 64px; }
.kind-photo .tray-art { height: 68px; }

.tray-name {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  white-space: nowrap;
}

.tray-check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cream);
  visibility: hidden;
}

.tray-check::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid var(--wood);
  border-width: 0 2px 2px 0;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.tray-item.is-on .tray-check {
  visibility: visible;
}

/* 换色的一排：原色、基础色、自选色 */
.color-row {
  display: flex;
  align-items: center;
  padding: 4px 8px;
}

.color-row > * {
  flex: none;
  margin-right: 10px;
}

.color-swatch,
.color-row .color-button {
  position: relative;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--ink-3);
  border-radius: 50%;
}

.color-swatch::before,
.color-row .color-button::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: -8px;
  bottom: -8px;
}

.color-swatch.is-on,
.color-row .color-button.is-on {
  border-color: var(--cream);
  box-shadow: none;
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

.color-row .color-button.is-empty {
  border-style: solid;
  background: conic-gradient(#e0574d, #f6cf4a, #7fb58a, #5c86c8, #9a7cc4, #ee7f98, #e0574d);
}

.row-chip {
  position: relative;
  height: 28px;
  padding: 0 10px;
  border: 2px solid var(--ink-2);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 24px;
  white-space: nowrap;
}

.row-chip::before {
  content: "";
  position: absolute;
  left: -4px;
  right: -4px;
  top: -8px;
  bottom: -8px;
}

.row-chip.is-on {
  border-color: var(--cream);
  background: var(--cream);
  color: var(--page);
}

.color-pop .color-row {
  flex-wrap: wrap;
  width: 252px;
  max-width: 100%;
  padding: 10px 6px 2px 10px;
}

.color-pop .color-row > * {
  margin-bottom: 8px;
}

/* 窄屏：面板在底栏里。左边是 × 和这一类的名字，右边上面一排颜色、下面一排款式，都是左右滑 */
.tray.is-bar {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
}

/* 左边的 × 和名字：实心底、叠在滚动行之上，滚动行的内容无论如何都不会盖到它。 */
.tray.is-bar .tray-head {
  position: relative;
  z-index: 2;
  grid-column: 1;
  grid-row: 1 / 3;
  flex-direction: column-reverse;
  justify-content: center;
  background: var(--bar);
}

.tray.is-bar .tray-title {
  flex: none;
  padding: 6px 0 0;
  font-size: 12px;
  line-height: 15px;
  white-space: nowrap;
}

.tray.is-bar .tray-colors {
  position: relative;
  z-index: 1;
  grid-column: 2;
  grid-row: 1;
  -webkit-clip-path: inset(0);
  clip-path: inset(0);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.tray.is-bar .tray-colors::-webkit-scrollbar,
.tray.is-bar .tray-body::-webkit-scrollbar {
  display: none;
}

.tray.is-bar .tray-body {
  z-index: 1;
  grid-column: 2;
  grid-row: 2;
  padding: 0;
  -webkit-clip-path: inset(0);
  clip-path: inset(0);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.tray.is-bar .tray-grid {
  display: flex;
  height: 100%;
}

.tray.is-bar .tray-item {
  flex: none;
  min-width: 64px;
  height: 100%;
  margin-right: 4px;
  padding: 4px 6px 3px;
}

.tray.is-bar .tray-body.is-scroll .tray-item {
  touch-action: pan-x;
}

.tray.is-bar .tray-art,
.tray.is-bar .kind-rope .tray-art,
.tray.is-bar .kind-pin .tray-art,
.tray.is-bar .kind-photo .tray-art {
  flex: none;
  height: 46px;
}

.tray.is-bar .piece {
  -webkit-transform: scale(0.8);
  transform: scale(0.8);
}

.tray.is-bar .kind-rope .piece {
  -webkit-transform: none;
  transform: none;
}

.tray.is-bar .kind-pin .piece {
  -webkit-transform: scale(0.7);
  transform: scale(0.7);
}

.tray.is-bar .kind-photo .piece {
  -webkit-transform: scale(0.68);
  transform: scale(0.68);
}

.tray.is-bar .tray-name {
  margin-top: 2px;
}

/* ---------- 平板竖屏 ---------- */
@media (min-width: 600px) and (orientation: portrait) {
  .title { font-size: 26px; line-height: 34px; }
  html[lang="en"] .title { font-size: 24px; }
  .lang-chip,
  .board-chip { top: 22px; }
  .tool-name { font-size: 14px; }
}

/* ---------- 宽屏（电脑、平板横屏、手机横屏）：黑板占左边整块，右侧栏从上到下是标题、四钮、道具（两行） ---------- */
@media (min-width: 700px) and (orientation: landscape) {
  :root { --tile: 64px; --rail: 272px; }

  .app {
    grid-template-columns: minmax(0, 1fr) var(--rail);
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }

  .stage { grid-column: 1 / -1; grid-row: 1 / -1; }

  .rail-back {
    display: block;
    z-index: 1;
    grid-column: 2;
    grid-row: 1 / -1;
    border-left: 2px solid var(--line);
    border-radius: 14px 0 0 14px;
    background: var(--page);
  }

  .titlebar { grid-column: 2; grid-row: 1; padding-left: 64px; padding-right: 64px; }
  .plate { padding-left: 12px; padding-right: 12px; }
  .ctrl { grid-column: 2; grid-row: 2; align-self: auto; pointer-events: auto; }

  .tools {
    display: block;
    z-index: 2;
    grid-column: 2;
    grid-row: 3;
    align-self: start;
    margin: 0 8px 8px;
    padding: 6px;
    border-radius: 14px;
    overflow: hidden;
  }

  .tools-main {
    display: block;
    height: auto;
  }

  .tools-pick {
    display: none;
  }

  /* 右侧栏道具下面的空位：选中一类后内嵌面板落在这里 */
  .rail-slot {
    position: relative;
    z-index: 2;
    display: block;
    grid-column: 2;
    grid-row: 4;
    min-height: 0;
    margin: 0 8px 8px;
  }

  /* 内嵌面板：实心底色、占满空位、里面自己滚，不浮在黑板上、不弹窗 */
  .tray.is-inline {
    max-height: 100%;
    height: 100%;
  }

  .tray.is-inline .tray-close {
    display: none;
  }

  .tray.is-inline .color-row {
    flex-wrap: wrap;
    padding: 8px 8px 0;
  }

  .tray.is-inline .color-row > * {
    margin-bottom: 8px;
  }

  .tool-group {
    flex: none;
    align-items: stretch;
  }

  .tool-item {
    justify-content: center;
    margin: 3px;
    padding: 8px 0 6px;
    border-radius: 10px;
    background: var(--bar-2);
  }

  .tool-item.is-on .tool-tile {
    -webkit-transform: none;
    transform: none;
  }
}

@media (min-width: 1100px) and (orientation: landscape) {
  :root { --tile: 88px; --rail: 300px; }
  .title { font-size: 24px; line-height: 32px; }
  html[lang="en"] .title { font-size: 22px; }
  .lang-chip,
  .board-chip { top: 21px; }
  .tool-name { font-size: 14px; }
}

/* 矮屏横放（手机横屏）：标题和四钮压得更紧，道具小一点 */
@media (min-width: 700px) and (orientation: landscape) and (max-height: 520px) {
  :root { --tile: 48px; --rail: 264px; }

  .titlebar { padding-top: 10px; }
  .ctrl { padding-top: 6px; padding-bottom: 6px; }
  .lang-chip,
  .board-chip { top: 15px; }
  .title { font-size: 18px; line-height: 24px; }
  html[lang="en"] .title { font-size: 16px; }
  .tool-name { font-size: 11px; margin-top: 3px; }

  /* 矮屏放不下内嵌面板：右侧栏的道具钮换成这一类的款式和颜色，和竖屏的底栏一样 */
  .tools {
    display: grid;
  }

  .tools-main {
    height: auto;
  }

  .tools-pick {
    display: block;
    height: auto;
  }
}

@media (max-width: 359px) {
  .titlebar { padding-top: 10px; }
  .title { font-size: 18px; line-height: 24px; }
  html[lang="en"] .title { font-size: 16px; }
  .lang-chip,
  .board-chip { top: 15px; }
  .ctrl { padding-top: 8px; padding-bottom: 6px; }
}
