:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e3e6ec;
  --accent: #6b5bff;
  --san: #4f7cff;
  --hp: #ff5d5d;
  --mp: #46c08a;
  --gm: #eef0ff;
  --roll: #fff7e6;
  --crit: #ff8a3d;
  --fail: #c0392b;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); height: 100vh; display: flex; flex-direction: column;
}

/* ---------- 首页 ---------- */
.home { flex: 1; display: flex; align-items: center; justify-content: center; }
.home-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 30px; width: 380px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.08);
}
.home-card h1 { margin: 0 0 4px; font-size: 22px; }
.home-card .sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.home-card label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 5px; }
.home-card input {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font-size: 14px;
}
.home-card input:focus { outline: none; border-color: var(--accent); }
.home-card .primary {
  width: 100%; margin-top: 18px; background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 11px; font-size: 14px; cursor: pointer;
}
.home-card .primary:hover { filter: brightness(1.05); }
.divider { text-align: center; margin: 16px 0 4px; color: var(--muted); position: relative; }
.divider span { background: var(--panel); padding: 0 10px; position: relative; z-index: 1; }
.divider:before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--line); }
.row { display: flex; gap: 8px; }
.row input { text-transform: uppercase; letter-spacing: 2px; }
.row button { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 0 16px; cursor: pointer; }
.row button:hover { border-color: var(--accent); color: var(--accent); }
.home-card .hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 14px 0 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.room-info { display: flex; align-items: center; gap: 10px; }
.room-code { font-size: 14px; }
.room-code b { letter-spacing: 2px; color: var(--accent); }
button.ghost { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
.players { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.pchip { font-size: 12px; background: #eef0f3; border-radius: 999px; padding: 4px 10px; color: var(--muted); }
.pchip.me { background: #e7e3ff; color: var(--accent); font-weight: 600; }

/* ---------- 主布局 ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 320px 1fr; gap: 0; min-height: 0; }
.sheets { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 16px; overflow-y: auto; }
.stage { display: flex; flex-direction: column; min-height: 0; }

/* ---------- 角色卡 ---------- */
.sheet { background: #fafbfc; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.sheet.me { border-color: var(--accent); background: #f6f4ff; }
.sheet-h { font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.tag { font-size: 11px; background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 6px; }
.tag.host { background: #f0a020; }
.stat { display: grid; grid-template-columns: 38px 1fr 52px; align-items: center; gap: 8px; margin-bottom: 6px; }
.sl { font-size: 12px; color: var(--muted); }
.sv { font-size: 12px; text-align: right; color: var(--muted); }
.bar { height: 12px; background: #e9ebef; border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; transition: width .3s; }
.bar.san i { background: var(--san); }
.bar.hp i { background: var(--hp); }
.bar.mp i { background: var(--mp); }
.bar.mhp i { background: #7a3df0; }
.db { font-size: 12px; color: var(--muted); margin: 4px 0; }
.attrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 8px 0; }
.attrs span { background: #f0f1f4; border-radius: 6px; padding: 4px; text-align: center; font-size: 11px; color: var(--ink); }
.skills { display: flex; flex-wrap: wrap; gap: 5px; }
.sk { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px; font-size: 11px; }
.sk span { color: var(--muted); }
.sk b { margin-left: 4px; }
.insane { font-size: 12px; color: var(--fail); margin-top: 6px; font-weight: 600; }
.sheet.monster { border-color: #c9b3f5; background: #f7f1ff; }
.sheet.clues { border-color: #b9d8ff; background: #f2f8ff; }
.clues ul { margin: 6px 0 0; padding-left: 18px; font-size: 12px; line-height: 1.6; }
.sheet.ending { border-color: var(--accent); background: #f6f4ff; }
.endtext { font-size: 14px; line-height: 1.7; margin-top: 4px; }

/* ---------- 聊天 ---------- */
.chat { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg.gm { background: var(--gm); align-self: flex-start; border-top-left-radius: 2px; }
.msg.pl { background: var(--accent); color: #fff; align-self: flex-end; border-top-right-radius: 2px; }
.msg .who { font-size: 11px; opacity: .7; margin-bottom: 3px; }
.dice { background: var(--roll); border: 1px dashed #e0b15a; border-radius: 8px; padding: 7px 10px; font-size: 13px; color: #7a5a1a; }
.dice.crit b { color: var(--crit); }
.dice.ext b, .dice.hard b, .dice.ok b { color: #2c8a4a; }
.dice.fail b, .dice.fum b { color: var(--fail); }
.hintline { font-size: 12px; color: #2b6cb0; background: #f0f7ff; border-radius: 6px; padding: 5px 8px; margin-top: 6px; }

/* ---------- 操作区 ---------- */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.actions button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: 12px; cursor: pointer; transition: .15s;
}
.actions button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.actions button.sp { border-color: #ffd0d0; color: var(--fail); }
.actions button.sp:hover { background: #fff0f0; }
.say { display: flex; gap: 8px; }
.say input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.say input:focus { outline: none; border-color: var(--accent); }
.say button { background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 0 18px; cursor: pointer; }
.say button:hover { filter: brightness(1.05); }

/* ---------- 设置弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,22,30,.5); display: none; align-items: center; justify-content: center; z-index: 60; }
.modal-box { background: #fff; border-radius: 14px; padding: 22px 24px; width: 420px; max-width: 92vw; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0 0 6px; }
.modal-box .hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 0 0 12px; }
.modal-box label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.modal-box input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 13px; }
.modal-box input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions button { border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; }
.modal-actions .primary { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.modal-actions .ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.mode { margin-top: 14px; font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; display: inline-block; }
.mode.ai { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 600; }
