:root {
  --bg: #0f1720;
  --bg2: #16212d;
  --bg3: #1e2c3b;
  --line: #2a3b4e;
  --fg: #e6edf3;
  --fg2: #9fb1c3;
  --accent: #3fb8af;
  --accent2: #f2b84b;
  --danger: #f06a6a;
  --ok: #5ccf7a;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
sub { font-size: .72em; line-height: 0; }
.hint { color: var(--fg2); font-size: 13px; }
.center { text-align: center; }
.spacer { flex: 1; }

button {
  font: inherit; color: var(--fg); background: var(--bg3); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; touch-action: manipulation;
}
button:hover { border-color: #3d5670; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #062421; border-color: var(--accent); font-weight: 600; }
button.accent { background: var(--accent2); color: #2a1d00; border-color: var(--accent2); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 3px 9px; font-size: 13px; }
button.danger { color: var(--danger); }
button.on { background: var(--accent); color: #062421; border-color: var(--accent); }

input, textarea {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 100;
  background: var(--bg3); border: 1px solid var(--line); padding: 8px 16px; border-radius: 20px;
  box-shadow: 0 6px 20px #0008; transition: opacity .4s; max-width: 90vw;
}
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }
.toast.out { opacity: 0; }

/* 登录 / 卡片 */
.center-card { margin: auto; padding: 28px; max-width: 360px; width: 100%; text-align: center; }
.login .logo { font-size: 56px; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg2); flex-shrink: 0;
}
.topbar .back { font-size: 18px; padding: 2px 8px; color: var(--fg); }
.game-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { font-size: 12px; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.badge.live { background: #1c4a46; color: #7fe3da; }
.badge.ok { background: #1f4a2b; color: var(--ok); }
.badge.gray { background: var(--bg3); color: var(--fg2); }

/* 大厅 */
.lobby { overflow: auto; padding: 14px; display: grid; gap: 16px; max-width: 1000px; width: 100%; margin: 0 auto; }
@media (min-width: 800px) { .lobby { grid-template-columns: 360px 1fr; align-items: start; } }
#create-form { display: flex; flex-direction: column; gap: 10px; }
#create-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--fg2); }
#create-form em { color: var(--danger); font-style: normal; }
.pwrow { display: flex; gap: 6px; }
/* 用普通文本框 + 圆点遮挡，避免手机弹出密码安全键盘 */
.masked { -webkit-text-security: disc; text-security: disc; }
.list-head { display: flex; align-items: center; gap: 6px; }
.list-head h2 { margin: 0; flex: 1; }
.game-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.game-item { display: block; position: relative; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--fg); }
.game-item:hover { border-color: var(--accent); }
.gi-title { font-weight: 600; }
.gi-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--fg2); margin-top: 4px; align-items: center; }
.gi-answer { font-size: 13px; color: var(--accent2); margin-top: 4px; }
.game-item [data-del] { position: absolute; right: 8px; top: 8px; }

/* 游戏布局：手机上下，桌面左右 */
.game { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.panel {
  flex-shrink: 0; max-height: 62dvh; overflow-y: auto; background: var(--bg2);
  border-top: 1px solid var(--line); padding: 0 12px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.panel-closed .composer, .panel-closed .obj-detail { display: none; }
@media (min-width: 900px) {
  .game { flex-direction: row; }
  .panel { width: 440px; max-height: none; border-top: 0; border-left: 1px solid var(--line); }
  .panel-closed .composer, .panel-closed .obj-detail { display: block; }
  #panel-toggle { display: none; }
}
.panel-bar { position: sticky; top: 0; z-index: 2; background: var(--bg2); display: flex; align-items: center; gap: 6px; padding: 8px 0 6px; }
.bench-title { font-weight: 600; }

/* 对象标签 */
.ochip {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; margin: 1px 2px;
  border-radius: 12px; font-size: 13px; line-height: 1.6; vertical-align: baseline;
  background: #233648; border: 1px solid #35506b; color: var(--fg); white-space: nowrap;
}
.ochip.st-gas { background: #2a2f4a; border-color: #4b5590; }
.ochip.st-solution { background: #1d3a3a; border-color: #2f6666; }
.ochip.st-solid { background: #3a3324; border-color: #6b5a35; }
.ochip.st-liquid { background: #1d3147; border-color: #2f5680; }
.ochip.st-mixture { background: #33283f; border-color: #5d4677; }
.ochip.sel { outline: 2px solid var(--accent2); outline-offset: 1px; }
.ochip.missing { opacity: .5; }
.bench { display: flex; flex-wrap: wrap; gap: 4px 0; max-height: 96px; overflow-y: auto; }
.obj-detail { font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 8px 0; }
.obj-detail .from { color: var(--fg2); margin-top: 2px; }
.hidden-truth { color: var(--accent2); font-size: 13px; margin-top: 2px; }

/* 记录 */
.turn { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.turn-head { font-size: 13px; color: var(--fg2); display: flex; gap: 6px; align-items: center; }
.turn-head b { color: var(--fg); }
.turn-head .time { margin-left: auto; font-size: 12px; }
.tno { font-family: ui-monospace, Menlo, monospace; color: var(--accent); }
.turn .act { margin: 4px 0; font-weight: 600; }
.phen { margin: 4px 0; padding-left: 20px; }
.turn.start .phen { padding-left: 0; }
.phen li { margin: 2px 0; }
.data { border-collapse: collapse; font-size: 13px; margin: 6px 0; }
.data th, .data td { border: 1px solid var(--line); padding: 3px 8px; text-align: left; vertical-align: top; }
.data th { color: var(--fg2); font-weight: normal; white-space: nowrap; }
.newobjs { font-size: 13px; color: var(--fg2); margin-top: 4px; }
.rejected { color: var(--danger); margin-top: 4px; }
.guess-line { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.formula { font-weight: 600; font-size: 16px; }
.ok { color: var(--ok); } .no { color: var(--danger); } .close { color: var(--accent2); }
.turn.pending { color: var(--fg2); display: flex; align-items: center; gap: 8px; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { border-radius: var(--radius); padding: 12px; text-align: center; background: #1f3a2a; border: 1px solid #2f6a45; }
.banner.revealed { background: var(--bg3); border-color: var(--line); }
.banner .answer { font-size: 24px; font-weight: 700; color: var(--accent2); margin: 4px 0; }

/* 操作面板 */
.composer { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lbl { font-size: 12px; color: var(--fg2); min-width: 2.6em; }
.lbl small { font-size: 11px; }
.ops { display: flex; flex-direction: column; gap: 4px; }
.opgroup { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.opgroup button { padding: 3px 9px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 3px 8px; font-size: 13px; background: var(--bg); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #062421; }
.rinput { display: flex; gap: 6px; flex: 1; min-width: 180px; }
.rinput input { font-family: ui-monospace, Menlo, monospace; font-size: 16px; }
.rpreview { min-height: 1.4em; font-size: 18px; padding-left: 3.2em; color: var(--accent2); }
.modal .rpreview { padding-left: 4px; }
.robj { display: inline-flex; align-items: center; gap: 6px; }
.action-preview { font-size: 13px; color: var(--fg2); background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.action-preview .warn { color: var(--accent2); }
.submit { padding: 10px; font-size: 16px; }
#target-chip.flash .ochip { animation: flash .6s; }
@keyframes flash { 50% { transform: scale(1.15); } }

/* 键盘 */
.kb { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px; user-select: none; -webkit-user-select: none; }
.kb-tabs { display: flex; gap: 4px; margin-bottom: 6px; overflow-x: auto; }
.kb-tabs button { padding: 3px 10px; font-size: 13px; white-space: nowrap; }
.kb button { touch-action: manipulation; }
.el { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 0; line-height: 1.1; min-height: 40px; }
.el b { font-size: 15px; }
.el small { font-size: 10px; color: var(--fg2); }
.kb-common { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.kb-table-wrap { overflow-x: auto; }
.kb-table { display: grid; grid-template-columns: repeat(18, 36px); grid-auto-rows: 40px; gap: 2px; width: max-content; }
.kb-table .el { min-height: 0; padding: 0; border-radius: 5px; }
.kb-table .el b { font-size: 13px; }
.kb-table .el small { font-size: 9px; }
.ptgap { font-size: 10px; color: var(--fg2); display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 5px; }
.ptspace { height: 8px; }
.cat-alkali { background: #4a2a2a; } .cat-alkaline { background: #4a3a26; }
.cat-transition { background: #3a3346; } .cat-post { background: #2c3a4a; }
.cat-metalloid { background: #2c4438; } .cat-nonmetal { background: #23452f; }
.cat-halogen { background: #2a4446; } .cat-noble { background: #3c2a46; }
.cat-lanthanide { background: #463a2c; } .cat-actinide { background: #46302c; }
.kb-digits { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 6px; }
.kb-digits button { padding: 7px 0; font-size: 16px; }
.kb-digits .kb-wide { font-size: 14px; }
.kb-reagents { display: flex; flex-direction: column; gap: 5px; max-height: 210px; overflow-y: auto; }
.kb-rgroup { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.kb-rgroup span { font-size: 12px; color: var(--fg2); width: 4.5em; }
.kb-rgroup button { padding: 3px 8px; font-size: 13px; }
.kb-objects { display: flex; flex-wrap: wrap; gap: 4px; }
.kb-objects .hint { width: 100%; margin: 0 0 4px; }

/* 弹窗 */
.modal-bg { position: fixed; inset: 0; background: #000a; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px 14px 0 0; padding: 16px;
  width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 14px; } }
.modal h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.tree, .tree ul { list-style: none; margin: 0; padding-left: 18px; }
.tree { padding-left: 0; }
.tree ul { border-left: 1px dashed var(--line); margin-left: 10px; }
.tnode { padding: 4px 0; }
.tfrom { font-size: 12px; color: var(--fg2); padding-left: 6px; }
