/* 星谷 · 像素小镇聊天
 * 硬边、直角、暖夜色；canvas 负责像素画面，UI 负责对话
 */
:root {
  --bg: #171310;
  --bg2: #1e1915;
  --card: #221c16;
  --ln: #3a2f25;
  --ln2: #4a3c2e;
  --tx: #efe3d1;
  --sub: #a08c74;
  --ac: #e6a866;
  --ac2: #c2803f;
  --ok: #7fb069;
  --warn: #d97757;
  --on-ac: #201810;
  --hud-h: 46px;
  --dock-h: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--tx);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

body { display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
#hud {
  height: calc(var(--hud-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, #201a15, #171310);
  border-bottom: 2px solid var(--ln);
  position: relative; z-index: 20;
}
.hud-l { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.brand { font-size: 15px; font-weight: 700; letter-spacing: 3px; color: var(--ac); }
.meta { font-size: 10.5px; color: var(--sub); letter-spacing: .6px; white-space: nowrap; }
.hud-r { display: flex; align-items: center; gap: 6px; }
.pill {
  font-size: 11px; color: var(--tx); background: #241d17; border: 2px solid var(--ln);
  padding: 4px 9px; letter-spacing: .4px; font-family: inherit; cursor: pointer;
}
.pill:active { background: #2d251d; }
.icn {
  width: 32px; height: 30px; display: grid; place-items: center;
  background: #241d17; border: 2px solid var(--ln); color: var(--sub); cursor: pointer;
}
.icn:active { color: var(--tx); }

/* ---------- 画布 ---------- */
#stage { flex: 1 1 auto; position: relative; overflow: hidden; background: #100d0a; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }

.hint {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 78px;
  font-size: 10.5px; color: #e8d9c2; background: rgba(24, 19, 15, .82);
  border: 2px solid #3b3026; padding: 5px 10px; letter-spacing: .4px;
  pointer-events: none; transition: opacity .35s; white-space: nowrap;
}
.hint.off { opacity: 0; }

.selcard {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  background: rgba(28, 22, 17, .95); border: 2px solid var(--ln2);
  padding: 9px 10px; display: flex; align-items: center; gap: 9px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .25);
}
.selcard .av { width: 26px; height: 26px; flex: 0 0 26px; border: 2px solid var(--ln2); }
.selcard .txt { flex: 1; min-width: 0; }
.selcard .n { font-size: 12.5px; font-weight: 650; letter-spacing: .3px; }
.selcard .s { font-size: 10.5px; color: var(--sub); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selcard button {
  font-family: inherit; font-size: 11px; color: var(--on-ac); background: var(--ac);
  border: 2px solid var(--ac2); padding: 6px 10px; cursor: pointer; letter-spacing: .4px;
}
.selcard .ghost { background: none; color: var(--sub); border-color: var(--ln2); }

/* ---------- 底部输入 ---------- */
#dock {
  flex: 0 0 auto;
  height: calc(var(--dock-h) + env(safe-area-inset-bottom));
  padding: 0 10px env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 8px;
  background: #1b1611; border-top: 2px solid var(--ln);
  position: relative; z-index: 20;
}
.mic {
  width: 38px; height: 38px; flex: 0 0 38px; background: #241d17;
  border: 2px solid var(--ln); display: grid; place-items: center; cursor: pointer;
}
#castDot { width: 16px; height: 16px; display: block; border-radius: 0; }
.field { flex: 1; min-width: 0; }
#msg, #cInput, .inp {
  width: 100%; height: 38px; background: #120f0c; border: 2px solid var(--ln);
  color: var(--tx); font-family: inherit; font-size: 13px; padding: 0 10px; outline: none;
}
#msg:focus, #cInput:focus, .inp:focus { border-color: var(--ac2); }
#msg::placeholder, #cInput::placeholder, .inp::placeholder { color: #6e6053; }
.go {
  width: 38px; height: 38px; flex: 0 0 38px; background: var(--ac); color: var(--on-ac);
  border: 2px solid var(--ac2); font-size: 17px; font-weight: 700; cursor: pointer;
  font-family: inherit;
}
.go:active { transform: translateY(1px); }
.go[disabled] { opacity: .45; }

/* ---------- 聊天页 ---------- */
.chat {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  background: var(--bg); transform: translateY(100%); transition: transform .24s cubic-bezier(.3,.9,.3,1);
  visibility: hidden;
}
.chat.on { transform: none; visibility: visible; }
.chat-h {
  flex: 0 0 auto; padding: env(safe-area-inset-top) 10px 0;
  height: calc(50px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, #221b15, #1a1511); border-bottom: 2px solid var(--ln);
}
.chat-h .back {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: none; border: none; color: var(--sub); cursor: pointer; font-size: 18px;
}
#chatMore { width: auto; min-width: 48px; padding: 0 8px; font-size: 11.5px; letter-spacing: .5px; white-space: nowrap; }
.chat-h .back:active { color: var(--tx); }
.chat-h .who { flex: 1; min-width: 0; text-align: center; }
.chat-h .nm { font-size: 13.5px; font-weight: 650; letter-spacing: .6px; }
.chat-h .st { font-size: 10px; color: var(--sub); margin-top: 1px; letter-spacing: .4px; }
.chat-body {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 9px;
}
.chat-dock {
  flex: 0 0 auto; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; background: #1b1611; border-top: 2px solid var(--ln);
}

.msg { max-width: 84%; font-size: 13.5px; line-height: 1.66; letter-spacing: .2px; }
.msg .b {
  padding: 8px 10px; border: 2px solid var(--ln2); background: #221c16;
  white-space: pre-wrap; word-break: break-word;
}
.msg.me { align-self: flex-end; }
.msg.me .b { background: #2a2118; border-color: #5b4732; color: #f6e9d6; }
.msg.sys { align-self: center; max-width: 92%; }
.msg.sys .b { background: none; border: none; color: var(--sub); font-size: 10.5px; padding: 2px 0; text-align: center; }
.msg .meta { font-size: 9.5px; color: #6e6053; margin-top: 4px; letter-spacing: .4px; }
.msg.me .meta { text-align: right; }
.typing { display: inline-flex; gap: 3px; align-items: center; height: 12px; }
.typing i { width: 4px; height: 4px; background: var(--ac); display: block; animation: bl 1s infinite; }
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes bl { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- 弹层 ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end;
  background: rgba(8, 6, 5, .62); opacity: 0; transition: opacity .2s;
}
.sheet-wrap.on { opacity: 1; }
.sheet-wrap.hidden { display: none; }
.sheet {
  width: 100%; max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: #1d1712; border-top: 2px solid var(--ln2);
  padding: 14px 12px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(14px); transition: transform .22s;
}
.sheet-wrap.on .sheet { transform: none; }

.sh { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.sh .t { font-size: 13px; font-weight: 700; letter-spacing: 1.2px; color: var(--ac); }
.sh .x { font-family: inherit; font-size: 11px; color: var(--sub); background: none; border: 2px solid var(--ln); padding: 4px 9px; cursor: pointer; }

.fld { margin-top: 10px; }
.fld > label { display: block; font-size: 10.5px; color: var(--sub); letter-spacing: .6px; margin-bottom: 5px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.btn {
  font-family: inherit; font-size: 12px; color: var(--tx); background: #2a2219;
  border: 2px solid var(--ln2); padding: 8px 12px; cursor: pointer; letter-spacing: .4px;
}
.btn:active { background: #332a1f; }
.btn.pri { background: var(--ac); border-color: var(--ac2); color: var(--on-ac); font-weight: 650; }
.btn.block { display: block; width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: inherit; font-size: 11px; color: var(--sub); background: #221b15;
  border: 2px solid var(--ln); padding: 6px 9px; cursor: pointer;
}
.chip.on { color: var(--on-ac); background: var(--ac); border-color: var(--ac2); }
.tiny { font-size: 10.5px; line-height: 1.7; color: var(--sub); }
.muted { color: var(--sub); }
.hr { height: 2px; background: var(--ln); margin: 14px 0 4px; }

/* 团队输出墙 */
.wall { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.col {
  flex: 0 0 154px; border: 2px solid var(--ln); background: #191410;
  display: flex; flex-direction: column; min-height: 120px; max-height: 220px;
}
.wallwrap { position: relative; }
.wallhint { font-size: 9.5px; color: #6e6053; margin-top: 4px; letter-spacing: .4px; }
.col .ch { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-bottom: 2px solid var(--ln); }
.col .ch .n { font-size: 11px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col .ch .s { font-size: 9px; color: var(--sub); letter-spacing: .4px; }
.col .cb { padding: 8px; font-size: 11px; line-height: 1.62; color: #dfd0bd; white-space: pre-wrap; word-break: break-word; flex: 1; overflow-y: auto; }
.col .cb:empty::before { content: '…'; color: #5c5044; }
.col.run { border-color: #6b5433; }
.col.ok { border-color: #47603a; }
.col.err { border-color: #6b3a2e; }
.brief { font-size: 10px; color: #8d7b66; border-bottom: 1px dashed var(--ln); padding-bottom: 5px; margin-bottom: 6px; }
.card2 { border: 2px solid var(--ln); background: #191410; padding: 10px; }
.dot { width: 6px; height: 6px; background: var(--sub); flex: 0 0 6px; }
.dot.run { background: var(--ac); animation: bl 1.2s infinite; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--warn); }

.toast {
  position: fixed; left: 50%; top: calc(var(--hud-h) + env(safe-area-inset-top) + 12px);
  transform: translateX(-50%) translateY(-6px);
  background: #efe3d1; color: #201810; font-size: 11.5px; padding: 7px 12px;
  border: 2px solid #b9a48a; opacity: 0; pointer-events: none; transition: .2s; z-index: 90; max-width: 82vw; text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%); }
.hint { z-index: 5; }
.hidden { display: none !important; }
