:root {
  --paper: #f3eee3;
  --panel: #fbf8f1;
  --panel-2: #efe8da;
  --ink: #2a2521;
  --ink-2: #6b6158;
  --line: #ddd2bf;
  --accent: #a8382a;
  --accent-2: #c9583f;
  --jade: #2f7a5f;
  --gold: #a7822f;
  --sky: #3c6ea8;
  --bad: #b23a3a;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 10px;
  --font: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --ui: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17171a; --panel: #1f1f23; --panel-2: #26262b; --ink: #ece6da; --ink-2: #a39a8d;
    --line: #34343b; --accent: #e0705c; --accent-2: #ef8a74; --jade: #5fbf98; --gold: #d6b25e; --sky: #7aa7e0;
    --bad: #ef6b6b; --warn: #e3a948; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.55 var(--ui); }
h1, h2, h3, .serif { font-family: var(--font); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 7px; padding: 4px 10px; transition: background .15s, border-color .15s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-2); }
button.small { padding: 1px 7px; font-size: 12px; }
button.on { background: var(--jade); color: #fff; border-color: var(--jade); }
select, input[type=text] { font: inherit; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.muted { color: var(--ink-2); }
.good { color: var(--jade); } .bad { color: var(--bad); } .warn { color: var(--warn); } .gold { color: var(--gold); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.tag.jade { color: var(--jade); border-color: var(--jade); }
.tag.red { color: var(--accent); border-color: var(--accent); }

/* layout */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); }
.topbar .title { font: 600 18px var(--font); color: var(--accent); }
.res { display: flex; gap: 14px; flex-wrap: wrap; }
.res b { font-variant-numeric: tabular-nums; }
.res small { font-size: 11px; }
.speed button { min-width: 34px; }
.layout { display: grid; grid-template-columns: 300px 1fr 300px; gap: 12px; padding: 12px 16px; max-width: 1500px; margin: 0 auto; }
@media (max-width: 1150px) { .layout { grid-template-columns: 280px 1fr; } .side-right { grid-column: 1 / -1; } }
@media (max-width: 760px) { .layout { grid-template-columns: 1fr; padding: 8px; } .topbar { padding: 8px; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.section-title { font: 600 13px var(--ui); color: var(--ink-2); margin: 10px 0 4px; letter-spacing: .05em; }

.bar { position: relative; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--jade), #58a585); border-radius: 6px; }
.bar.age > i { background: linear-gradient(90deg, var(--gold), var(--warn)); }
.bar.age.danger > i { background: linear-gradient(90deg, var(--warn), var(--bad)); }
.bar.prog > i { background: linear-gradient(90deg, var(--sky), #6b98cf); }
.barlabel { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-top: 2px; }

.realm { font: 600 22px var(--font); }
.bt-ready { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); } }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { border-radius: 8px 8px 0 0; border-bottom: none; }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.bcard { border: 1px solid var(--line); border-radius: 9px; padding: 10px; background: var(--panel); display: flex; flex-direction: column; gap: 4px; }
.bcard .lv { font: 600 13px var(--ui); color: var(--gold); }
.bcard .cost { font-size: 12px; }
.bcard .desc { font-size: 12px; color: var(--ink-2); min-height: 34px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; }
.tablewrap { overflow-x: auto; }

.log { max-height: 520px; overflow-y: auto; font-size: 13px; }
.log div { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.log .t { color: var(--ink-2); font-size: 11px; margin-right: 4px; }
.log .great { color: var(--accent); font-weight: 600; }
.log .goal { color: var(--gold); }
.log .event { color: var(--sky); }

.goal { border-left: 3px solid var(--gold); padding: 4px 8px; margin-bottom: 8px; background: var(--panel-2); border-radius: 0 6px 6px 0; }
.goal .gt { font-weight: 600; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 15, 10, .45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 10px; color: var(--accent); }
.modal .choices { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.modal .choices button { text-align: left; padding: 8px 12px; }
.waves { display: flex; gap: 3px; align-items: flex-end; height: 70px; margin: 8px 0; }
.waves div { flex: 1; background: var(--jade); border-radius: 3px 3px 0 0; position: relative; }
.waves div.dead { background: var(--bad); }
.waves div.heal { outline: 2px solid var(--gold); }

/* creation */
.create { max-width: 760px; margin: 30px auto; padding: 0 16px; }
.create h1 { text-align: center; color: var(--accent); font-size: 34px; margin: 10px 0 4px; letter-spacing: .1em; }
.create .sub { text-align: center; color: var(--ink-2); margin-bottom: 20px; }
.attr-row { display: grid; grid-template-columns: 60px 28px 34px 28px 1fr; gap: 6px; align-items: center; margin: 4px 0; }
.attr-row b { text-align: center; font-size: 16px; }
.origins { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.origin { border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; background: var(--panel); }
.origin.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.roots { display: flex; gap: 6px; }
.el { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; align-items: center; justify-content: center; color: #fff; font: 600 13px var(--font); }
.el.metal { background: #b0953d; } .el.wood { background: #3d8a4f; } .el.water { background: #3a6fae; } .el.fire { background: #c2452e; } .el.earth { background: #8a6a3d; }
.el.sm { width: 18px; height: 18px; font-size: 11px; }

#toast-root { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 6px 14px; border-radius: 8px; font-size: 13px; opacity: .95; animation: fade 2.6s forwards; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes fade { 0% { transform: translateY(8px); opacity: 0; } 10%, 80% { transform: none; opacity: .95; } 100% { opacity: 0; } }
