/* ── 场景：一块能摆东西的地 ─────────────────────────────────────── */

.stage-host {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* 比地深一档，院子才看得出边界；否则整屏一色，不知道哪儿是自己的地 */
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(52,104,107,.16), transparent 72%),
    #cdc7ae;
}

.scene {
  position: absolute;
  inset: 0;
}

/* 地本身按场景坐标铺开，再整体缩放——物件坐标因此和屏幕大小无关。
   缩放和居中都由 render.js 一次算清，所以原点固定在左上角。 */
.scene-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: var(--paper) center / cover no-repeat;
  box-shadow: 0 3px 34px rgba(43,58,56,.24);
  outline: 1px solid rgba(43,58,56,.18);
}

.scene-item {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}
.scene-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
}

/* 骰子：一方牙白的小方块，点子是朱砂的 */
.dice {
  width: 100%;
  height: 100%;
  background: linear-gradient(160deg, #fffdf6, #efe8d2);
  border: 1px solid rgba(43,58,56,.2);
  border-radius: 14%;
  box-shadow: inset 0 -3px 6px rgba(43,58,56,.09), 0 2px 5px rgba(43,58,56,.18);
  padding: 12%;
}
.dice-face {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  place-items: center;
}
.dice-face .pip {
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: transparent;
}
.dice-face .pip.on {
  background: var(--zhu);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.18);
}

/* 院里的桌案：图上挂一方小牌 */
.table-piece { position: relative; width: 100%; height: 100%; }
.table-flag {
  position: absolute;
  right: -6px;
  top: -8px;
  /* 抵消物件自身的缩放，牌子永远是这么大 */
  transform: scale(var(--inv-x, 1), var(--inv-y, 1));
  transform-origin: top right;
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1;
  padding: 3px 5px;
  color: var(--paper);
  background: var(--zhu);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(43,58,56,.28);
}
.scene-item[data-kind="table"] { cursor: pointer; }

/* 计数器：一枚青玉筹码 */
.counter {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 30px;
  color: var(--paper);
  background: radial-gradient(120% 120% at 30% 25%, #4d8285, #2b5457);
  border-radius: 50%;
  border: 2px solid rgba(245,240,220,.5);
  box-shadow: 0 2px 6px rgba(43,58,56,.24);
}

.scene.editable .scene-item { cursor: grab; }
.scene.editable .scene-item.picked {
  outline: 2px solid var(--zhu);
  outline-offset: 3px;
}

.who .muted { padding-left: 8px; }

/* ── 工具条：选中一件东西才出现，贴着底边 ───────────────────────── */
.scene-tools {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-full);
  box-shadow: var(--shadow-md);
}
.scene-tools[hidden] { display: none; }

.tool {
  font: 500 var(--text-sm)/1 var(--font-ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-full);
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--t-quick), color var(--t-quick),
              background var(--t-quick), transform var(--t-tap);
}
.tool:hover { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.tool:active { transform: scale(.96); }
.tool.danger:hover { border-color: var(--coral); color: var(--coral-text); background: #fdeee9; }
.tool.snap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--mo-soft);
}
.tool.snap input { accent-color: var(--qing); }

/* ── 物件抽屉：贴左边一条，装着我传过的东西 ─────────────────────── */
.library {
  position: fixed;
  left: 0;
  /* 让开左上角那方竖着的「拾雲園」匾 */
  top: 148px;
  bottom: 88px;
  width: 196px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid var(--glass-line);
  border-left: none;
  border-radius: 0 var(--r-lg) var(--r-lg) 0;
  box-shadow: var(--shadow-md);
  font-family: var(--font-ui);
  transition: transform var(--t-slide) var(--ease-out);
}
.library.folded { transform: translateX(-100%); }

/* 收起来之后留一个小舌头在边上，点它再拉出来 */
.library-fold {
  position: absolute;
  left: 100%;
  top: 14px;
  width: 20px;
  height: 34px;
  font: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--ink-2);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-line);
  border-left: none;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  cursor: pointer;
}
.library-fold:hover { color: var(--teal); }
.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.library-head b {
  font: 600 var(--text-md)/1 var(--font-ui);
}
.library-head .tool { padding: 5px 12px; font-size: var(--text-sm); }
.library-quota { font-size: var(--text-xs); color: var(--ink-2); }
.library-err {
  font-size: 12px;
  color: #7a3427;
  background: #f7e8e3;
  border-left: 2px solid var(--zhu);
  padding: 6px 8px;
  line-height: 1.5;
}
.library-err[hidden] { display: none; }

.library-body { flex: 1; min-height: 0; overflow-y: auto; }
.library-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}
.library-item {
  aspect-ratio: 1;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color var(--t-quick), transform var(--t-quick), box-shadow var(--t-quick);
}
.library-item:hover { border-color: var(--teal); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.library-item:active { transform: scale(.97); }
.library-item img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* 页签：我的 / 公共 */
.library-tabs { display: flex; gap: 5px; }
.library-tab {
  flex: 1;
  font: inherit;
  font: 500 var(--text-sm)/1 var(--font-ui);
  padding: 6px 0;
  cursor: pointer;
  color: var(--ink-2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
}
.library-tab:hover { color: var(--teal); }
.library-tab.on {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--teal);
}

.library-search {
  font: var(--text-sm)/1 var(--font-ui);
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
.library-search:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(47,127,134,.15);
}

/* 每格右上角挂两个小标记：⋯（编辑）和 享（已分享） */
.library-cell { position: relative; }
.library-cell .library-item { width: 100%; }
.library-more {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 18px;
  padding: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  color: var(--ink-2);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .16s, color .16s;
}
.library-cell:hover .library-more { opacity: 1; }
.library-more:hover { color: var(--teal); }
.library-badge {
  position: absolute;
  left: 3px;
  bottom: 3px;
  font-family: var(--font-ui);
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  color: var(--paper);
  background: var(--teal);
  border-radius: 5px;
  opacity: .95;
}
.library-owner {
  position: absolute;
  left: 3px;
  bottom: 3px;
  right: 3px;
  font-size: 10px;
  color: var(--ink-2);
  background: rgba(255,255,255,.9);
  padding: 2px 4px;
  border-radius: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 单件的编辑面板 */
.library-edit { display: flex; flex-direction: column; gap: 8px; }
.library-preview {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background: #fffdf6;
  border: 1px solid rgba(43,58,56,.14);
  border-radius: 3px;
  padding: 6px;
}
.library-name {
  font: inherit;
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid rgba(43,58,56,.18);
  border-radius: 3px;
  background: #fffdf6;
  color: var(--mo);
  width: 100%;
}
.library-edit-row { display: flex; gap: 6px; }
.library-edit-row .tool { flex: 1; padding: 5px 0; font-size: 12px; }
.library-hint { font-size: 11px; line-height: 1.5; }

/* ── 留言板：贴右下角，来过的人留一句 ───────────────────────────── */
.notes {
  position: fixed;
  right: 0;
  bottom: 22px;
  z-index: 6;
  width: 252px;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid var(--glass-line);
  border-right: none;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  box-shadow: var(--shadow-md);
  font-family: var(--font-ui);
  transition: transform var(--t-slide) var(--ease-out);
}
.notes.folded { transform: translateX(calc(100% - 74px)); }

.notes-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.notes-head b {
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: .1em;
  font-weight: 500;
}
.notes-fold {
  font: inherit;
  font-size: 12px;
  border: none;
  background: none;
  color: var(--qing);
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}
.notes-fold:hover { color: var(--zhu); }

.notes-list {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}
.notes-empty { font-size: 12px; color: var(--mo-soft); line-height: 1.7; }

.note { display: flex; gap: 7px; align-items: flex-start; }
.note-body { flex: 1; min-width: 0; }
.note-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--mo-soft);
}
.note-head b { color: var(--qing); font-weight: 600; }
.note-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--mo);
  word-break: break-word;
  margin-top: 2px;
}

.notes-say { display: flex; gap: 7px; }
.notes-say input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid rgba(43,58,56,.18);
  border-radius: 999px;
  background: #fffdf6;
  color: var(--mo);
  min-width: 0;
}
.notes-say .go { border-radius: 999px; padding: 7px 16px; font-size: 13px; }

/* ── 桌面 ────────────────────────────────────────────────────────── */
/* 桌子比院子暗一档：像铺了张毡子，东西压在上面看得清 */
body.on-table .stage-host {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(52,104,107,.22), transparent 72%),
    #b9b39c;
}
body.on-table .scene-stage {
  background: #f0e9d2;
  box-shadow: 0 4px 40px rgba(43,58,56,.3);
}

/* 被人拿在手上的东西：自己拿的是青的，别人拿的是朱砂的，还挂着名字 */
.scene-item.held { outline: 2px solid var(--qing); outline-offset: 3px; }
.scene-item.held-other { outline-color: var(--zhu); cursor: not-allowed; }
.scene-item.held-other::after {
  content: attr(data-holder);
  position: absolute;
  left: 50%;
  top: -20px;
  transform: translateX(-50%);
  font-family: var(--sans);
  font-size: 11px;
  white-space: nowrap;
  color: var(--paper);
  background: var(--zhu);
  padding: 1px 7px;
  border-radius: 999px;
  opacity: .92;
}

.table-panel {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  font-family: var(--font-ui);
}
.table-here {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
  font-size: 12px;
  color: var(--mo-soft);
}
.table-tools { display: flex; gap: 7px; }
.table-panel .notice { margin: 0; font-size: 12px; padding: 5px 10px; }
.library-empty {
  grid-column: 1 / -1; /* 空状态是一段话，别挤在一列格子里 */
  font-size: 12px;
  color: var(--mo-soft);
  line-height: 1.7;
  padding: 8px 2px;
}

/* ══════════════════════════════════════════════════════════════════
   手机（≤720px）
   朋友多半在手机上开。桌面版那套"左边一根抽屉柱 + 右边一块留言板"在
   390px 上会把地整个盖住，中间只剩一条窄带 —— 等于没有院子。
   所以竖屏重排：抽屉沉到底部（拇指区），留言板缩成边上一个签，
   工具条上移，都别跟地抢位置。
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  /* 抽屉 → 底部抽屉，整行头部就是把手 */
  .library {
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 46vh;
    border: 1px solid var(--glass-line);
    border-bottom: none;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: 0 -6px 24px rgba(34,51,58,.14);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .library.folded { transform: translateY(calc(100% - 52px)); }
  .library-head { cursor: pointer; }         /* 整条头部可点开合 */
  .library-fold { display: none; }           /* 侧边小舌头在手机上没意义 */
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }

  /* 留言板 → 收起时就是边上一个签，不许还占着半屏 */
  .notes {
    bottom: calc(76px + env(safe-area-inset-bottom));
    max-height: 42vh;
    width: min(82vw, 300px);
  }
  .notes.folded {
    transform: translateX(calc(100% - 92px));
    max-height: 46px;
    overflow: hidden;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  /* 工具条上移，别压在底部抽屉上 */
  .scene-tools {
    bottom: auto;
    top: calc(76px + env(safe-area-inset-top));
    max-width: calc(100vw - 20px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .scene-tools::-webkit-scrollbar { display: none; }

  /* 桌案的坞同理 */
  .table-panel {
    left: 8px; right: 8px;
    transform: none;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  .table-tools { flex-wrap: wrap; justify-content: center; }
}

/* ── 草木 ────────────────────────────────────────────────────────── */
.plant-wrap { width: 100%; height: 100%; }
.plant { width: 100%; height: 100%; overflow: visible; }
/* 开花那阵子给一点点光，让人一眼看出"它正当季" */
.plant-wrap.blooming { filter: drop-shadow(0 0 10px rgba(224,168,60,.5)); }
.scene-item[data-kind="plant"] { cursor: pointer; }

/* 种子袋 */
.seedbag {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-top: 4px;
}
.seed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-full);
  background: var(--surface);
  font: 500 var(--text-sm)/1 var(--font-ui);
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--t-quick), transform var(--t-tap), background var(--t-quick);
}
.seed:hover { border-color: var(--leaf); background: #eef5ea; }
.seed:active { transform: scale(.96); }
.seed::before {
  content: '';
  width: 9px; height: 9px;
  border-radius: 50% 50% 50% 2px;
  background: var(--leaf);
}
.seed small { color: var(--ink-2); font-size: var(--text-xs); }
.seedbag-empty { font-size: var(--text-sm); color: var(--ink-2); line-height: 1.6; }

/* 园中现成物 */
.prop-wrap { width: 100%; height: 100%; }
.prop { width: 100%; height: 100%; overflow: visible; }
.library-group {
  font: 600 var(--text-xs)/1 var(--font-ui);
  color: var(--ink-2);
  letter-spacing: .08em;
  padding: 10px 2px 6px;
}
.library-item.prop-item { padding: 6px; }
.library-item.prop-item svg { width: 100%; height: 100%; }

/* ── 院里的酒坛 ───────────────────────────────────────────────────── */

.jar-wrap { position: relative; width: 100%; height: 100%; }
.jar-svg { width: 100%; height: 100%; display: block; }

/* 到日子的坛，坛口那点金光慢慢一呼一吸 */
.jar-ping { animation: jar-breathe 2.8s ease-in-out infinite; transform-origin: 96px 40px; }
@keyframes jar-breathe {
  0%, 100% { opacity: .35; transform: scale(.82); }
  50%      { opacity: .9;  transform: scale(1.15); }
}

.jar-label {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%) scale(var(--inv-x, 1), var(--inv-y, 1));
  transform-origin: bottom center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: rgba(34,51,58,.82);
  color: #f1e7cf;
  font: 500 11px/1.4 var(--font-ui);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-quick);
}
.scene-item[data-kind='jar']:hover .jar-label,
.jar-wrap.ready .jar-label { opacity: 1; }
