/* ============ 全局 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #0f1424;
    --bg2: #161d33;
    --panel: #1b2440;
    --panel2: #222e54;
    --line: #2c3a63;
    --txt: #e8ecf8;
    --txt-dim: #9aa6c8;
    --accent: #ffc857;
    --accent2: #4fd1c5;
    --green: #4caf50;
    --red: #ef5350;
    --blue: #42a5f5;
}
html, body { height: 100%; }
body {
    font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
    background: var(--bg);
    color: var(--txt);
    overflow: hidden;
    user-select: none;
}
button { font-family: inherit; cursor: pointer; }

/* ============ 顶栏 ============ */
.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 16px;
    background: linear-gradient(180deg, #1a2240, #131a30);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 18px rgba(0,0,0,.35);
    /* 顶栏是常驻控件，必须高于弹窗遮罩（.modal-mask 为 z-index:100）：
       否则随机事件弹窗的整屏遮罩会盖住顶栏，设置按钮与暂停/倍速按钮全部点不到。
       注意 position 必须显式声明——元素是 static 时 z-index 不生效。 */
    position: relative;
    z-index: 110;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.brand-logo { font-size: 26px; }
.brand-name {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    letter-spacing: 1px;
}
.resources { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
.res {
    display: flex; align-items: center; gap: 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    padding: 6px 12px; border-radius: 10px;
    font-weight: 600; font-size: 14px; min-width: 70px;
}
.res .ic { font-size: 15px; }
.res.debt { color: var(--red); }
.res.good { color: var(--green); }
.res.bad { color: var(--red); }

.timebox { display: flex; align-items: center; gap: 12px; }
.date { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.season { font-size: 16px; }
.speed { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.spd {
    border: none; background: transparent; color: var(--txt-dim);
    width: 34px; height: 30px; border-radius: 7px; font-size: 14px; transition: .15s;
}
.spd:hover { background: var(--panel2); color: var(--txt); }
.spd.active { background: var(--accent); color: #1a1300; }

/* ============ 三栏布局 ============ */
.layout {
    display: grid;
    grid-template-columns: 260px 1fr 280px;
    height: calc(100vh - 64px);
}
.panel { background: var(--bg2); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.infobox { border-right: none; border-left: 1px solid var(--line); }
.panel-title { font-size: 13px; color: var(--accent2); text-transform: uppercase; letter-spacing: 1px; margin: 14px 0 8px; font-weight: 700; }
.panel-title:first-child { margin-top: 0; }

.tax-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: var(--txt-dim); }
.seg { display: flex; background: var(--panel); border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.seg button { border: none; background: transparent; color: var(--txt-dim); padding: 5px 12px; font-size: 12px; }
.seg button.active { background: var(--accent2); color: #04130f; font-weight: 700; }

.cats { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.cat-btn { border: 1px solid var(--line); background: var(--panel); color: var(--txt-dim); padding: 4px 9px; border-radius: 14px; font-size: 11px; }
.cat-btn.active { background: var(--accent); color: #1a1300; border-color: transparent; font-weight: 700; }

.build-list { display: flex; flex-direction: column; gap: 6px; }
.build-card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; transition: .12s; }
.build-card:hover { border-color: var(--accent2); transform: translateY(-1px); }
.build-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: var(--panel2); }
.build-card.disabled { opacity: .45; filter: grayscale(.4); }
.bc-icon { font-size: 22px; width: 30px; text-align: center; }
.bc-body { flex: 1; min-width: 0; }
.bc-name { font-size: 13px; font-weight: 700; }
.bc-cost { font-size: 11px; color: var(--accent); font-weight: 700; }
.bc-desc { font-size: 10px; color: var(--txt-dim); margin-top: 1px; line-height: 1.25; }

.tools, .io-row { display: flex; gap: 6px; margin-top: 12px; }
.tool-btn, .io-btn { flex: 1; border: 1px solid var(--line); background: var(--panel); color: var(--txt); padding: 8px; border-radius: 9px; font-size: 12px; font-weight: 600; }
.tool-btn.active { background: var(--red); border-color: transparent; color: #fff; }
.io-btn.danger { color: var(--red); }
.io-btn:hover, .tool-btn:hover { background: var(--panel2); }

/* ============ 3D 城市画布 ============ */
.city-wrap { display: flex; flex-direction: column; background: #0b1020; position: relative; }
.city-toolbar { height: 38px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; font-size: 12px; color: var(--txt-dim); border-bottom: 1px solid var(--line); background: var(--bg2); }
#cursor-info { color: var(--accent2); font-weight: 700; }
#canvas3d { flex: 1; position: relative; overflow: hidden; }
#canvas3d canvas { display: block; }
.cam-hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); font-size: 11px; color: var(--txt-dim); background: rgba(10,16,32,.55); padding: 4px 12px; border-radius: 12px; pointer-events: none; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--txt-dim); font-size: 14px; }

/* ============ 信息栏 ============ */
.breakdown { font-size: 12px; color: var(--txt-dim); line-height: 1.7; }
.breakdown b { color: var(--txt); }
.breakdown .row { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding: 2px 0; }
.log { font-size: 12px; max-height: 200px; overflow-y: auto; }
.log .entry { padding: 5px 8px; border-bottom: 1px solid var(--line); border-radius: 6px; margin-bottom: 3px; background: var(--panel); }
.log .entry .t { color: var(--txt-dim); font-size: 10px; margin-right: 6px; }
.log .entry.good { border-left: 3px solid var(--green); }
.log .entry.bad { border-left: 3px solid var(--red); }
.log .entry.info { border-left: 3px solid var(--blue); }
.help { font-size: 11px; color: var(--txt-dim); line-height: 1.65; }
.help p { margin-bottom: 5px; }
.help b { color: var(--accent2); }

/* ============ Toast ============ */
.toast-stack { position: fixed; top: 76px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent2); padding: 10px 14px; border-radius: 10px; font-size: 13px; max-width: 280px; box-shadow: 0 8px 24px rgba(0,0,0,.45); animation: slidein .25s ease; }
.toast.bad { border-left-color: var(--red); }
.toast.good { border-left-color: var(--green); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============ 弹窗 ============ */
.modal-mask { position: fixed; inset: 0; background: rgba(5,8,18,.7); display: none; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(3px); }
.modal-mask.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; max-width: 440px; width: 90%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal h3 { color: var(--accent); font-size: 20px; margin-bottom: 12px; }
.modal p { color: var(--txt-dim); line-height: 1.6; margin-bottom: 18px; font-size: 14px; white-space: pre-line; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions button { border: none; padding: 10px 20px; border-radius: 10px; font-weight: 700; font-size: 14px; background: var(--accent); color: #1a1300; }
.modal-actions button.alt { background: var(--panel2); color: var(--txt); border: 1px solid var(--line); }

/* ============ 设置弹窗 ============ */
.icon-btn {
    border: 1px solid var(--line); background: var(--panel); color: var(--txt);
    width: 38px; height: 38px; border-radius: 10px; font-size: 17px; line-height: 1;
    display: flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { background: var(--panel2); border-color: var(--accent2); }

/* 设置弹窗始终位于事件弹窗之上，避免事件弹窗开着时打不开设置 */
#settings-mask { z-index: 120; }

.settings-modal { max-width: 620px; width: 92%; text-align: left; padding: 0; overflow: hidden; }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.settings-head h3 { margin: 0; font-size: 17px; }
.settings-close { border: none; background: transparent; color: var(--txt-dim); font-size: 15px; width: 30px; height: 30px; border-radius: 8px; }
.settings-close:hover { background: var(--panel2); color: var(--txt); }

.settings-body { display: grid; grid-template-columns: 156px 1fr; min-height: 250px; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-right: 1px solid var(--line); background: rgba(0,0,0,.16); }
.settings-tab { text-align: left; border: 1px solid transparent; background: transparent; color: var(--txt-dim); padding: 9px 11px; border-radius: 9px; font-size: 13px; font-weight: 600; transition: .12s; }
.settings-tab:hover { background: var(--panel2); color: var(--txt); }
.settings-tab.active { background: var(--panel2); color: var(--accent); border-color: var(--line); }

.settings-pages { padding: 16px 20px; overflow-y: auto; max-height: 62vh; }
.settings-page[hidden] { display: none; }
.settings-item { display: flex; align-items: center; gap: 14px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.settings-item:last-child { border-bottom: none; }
.si-body { flex: 1; min-width: 0; }
.si-name { font-size: 13px; font-weight: 700; }
.si-desc { font-size: 11px; color: var(--txt-dim); margin-top: 3px; line-height: 1.45; }
.si-empty { font-size: 12px; color: var(--txt-dim); }

/* 开关：沿用按钮风格，样式与 .spd/.cat-btn 一致 */
.switch { flex: none; width: 44px; height: 24px; padding: 0; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); position: relative; transition: .18s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--txt-dim); transition: .18s; }
.switch:hover { border-color: var(--accent2); }
.switch.on { background: var(--accent2); border-color: transparent; }
.switch.on::after { left: 22px; background: #04130f; }

/* ============ 开发者浮层（画布左上角，仅开发者选项开启时可见） ============ */
.dev-overlay {
    position: absolute; top: 10px; left: 10px; z-index: 5;
    display: flex; flex-direction: column; gap: 4px;
    background: rgba(10,16,32,.62); border: 1px solid var(--line);
    border-radius: 10px; padding: 8px 12px;
    font-size: 11px; color: var(--txt-dim);
    backdrop-filter: blur(6px); pointer-events: none;
}
.dev-overlay[hidden] { display: none; }
.dev-row { display: flex; align-items: baseline; gap: 8px; }
.dev-k { letter-spacing: .5px; }
.dev-v { color: var(--accent2); font-size: 14px; font-variant-numeric: tabular-nums; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2c3a63; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a4a78; }
