:root {
  --bg: #f6f1e4;
  --card: #fffdf7;
  --ink: #2f3326;
  --muted: #7a7867;
  --line: #e4dcc6;
  --accent: #5c8f2e;
  --accent-ink: #3f6a1c;
  --accent-soft: #e6f0d6;
  --bad: #c62828;
  --good: #2e7d32;
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Sarabun, system-ui, sans-serif; font-size: 15px; }
h1, h2, h3, button, .clock { font-family: Mitr, Sarabun, sans-serif; }
h1 { margin: 0; font-size: 1.5rem; font-weight: 600; color: var(--accent-ink); }
h2 { margin: 0 0 10px; font-size: 1.05rem; font-weight: 500; }
.top { padding: 16px 20px 6px; max-width: 1500px; margin: 0 auto; }
.sub { margin: 2px 0 0; color: var(--muted); }
.src { margin: 4px 0 0; color: var(--muted); font-size: 0.8rem; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; padding: 10px 20px 30px; max-width: 1500px; margin: 0 auto; }
@media (max-width: 980px) { .layout { grid-template-columns: minmax(0, 1fr); padding: 10px 16px 30px; } .top { padding: 14px 16px 4px; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 14px; }
.side-col .card:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.hint { color: var(--muted); font-size: 0.82rem; margin: 6px 0; }
.muted { color: var(--muted); }

button { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px; padding: 8px 14px; font-size: 0.92rem; cursor: pointer; min-height: 38px; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: wait; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-ink); }
button.link { border: 0; background: none; color: var(--accent-ink); text-decoration: underline; padding: 6px 0; min-height: 0; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.stage-wrap { position: relative; background: #efe7d3; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#stage { display: block; width: 100%; touch-action: none; cursor: grab; }
.hud { position: absolute; background: rgba(255, 253, 247, 0.94); border-radius: 16px; padding: 8px 12px; box-shadow: 0 6px 20px rgba(40, 60, 20, 0.18); border: 2px solid rgba(92, 143, 46, 0.35); }
.hud-tl { top: 10px; left: 10px; }
.hud-tr { top: 10px; right: 10px; text-align: right; }
.hud-bl { bottom: 10px; left: 10px; width: min(300px, calc(100% - 90px)); }
.hud-bl:empty { display: none; }
.clock-row { display: flex; align-items: baseline; gap: 8px; }
.clock { font-size: 1.6rem; font-weight: 600; color: var(--accent-ink); }
.day { font-size: 0.8rem; color: var(--muted); }
.speed { display: flex; gap: 4px; margin-top: 4px; }
.speed button { min-height: 32px; min-width: 34px; padding: 0 8px; border-radius: 10px; font-weight: 600; background: linear-gradient(#fff, #eef5e4); }
.speed button.on { background: linear-gradient(#9ccc65, #5c8f2e); color: #fff; border-color: #4f7a2a; }
.speed .play { background: linear-gradient(#66bb6a, #2e7d32); color: #fff; border-color: #2e7d32; }
.money { font-family: Mitr, sans-serif; font-size: 1.5rem; font-weight: 600; color: var(--good); transition: transform 0.15s; }
.money.neg { color: var(--bad); }
.money.up { transform: scale(1.08); }
.money-sub { font-size: 0.75rem; color: var(--muted); }
.crumb { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; background: rgba(47, 59, 37, 0.82); color: #fff; border-radius: 999px; padding: 4px 6px 4px 14px; font-size: 0.82rem; max-width: 46%; }
.crumb button { min-height: 28px; padding: 0 12px; border-radius: 999px; background: #fff; }
.crumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; }
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { min-height: 34px; width: 38px; padding: 0; border-radius: 10px; font-size: 1rem; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12); }
.card-title { font-family: Mitr, sans-serif; font-weight: 600; font-size: 1rem; color: var(--accent-ink); }
.card-sub { font-size: 0.8rem; color: var(--muted); margin: 2px 0 6px; }
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 10px; font-size: 0.75rem; color: var(--muted); }
.card-grid b { display: block; font-size: 0.95rem; color: var(--ink); }
.enter { width: 100%; margin-top: 8px; }
.sim-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.portrait { position: relative; width: 46px; height: 46px; border-radius: 50%; border: 3px solid #43d047; flex: none; overflow: hidden; }
.portrait i { position: absolute; left: 50%; top: 6px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; }
.need { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 6px; font-size: 0.78rem; margin: 3px 0; }
.need i { display: block; height: 10px; border-radius: 6px; background: #e8e2d0; overflow: hidden; }
.need b { display: block; height: 100%; border-radius: 6px; transition: width 0.3s; }
.hud-bl .btns { margin-top: 4px; }
.hud-bl .btns button { min-height: 30px; padding: 0 10px; }
.hud-bl .hint { margin: 4px 0 0; font-size: 0.7rem; }
@media (max-width: 600px) {
  .hud { padding: 6px 8px; border-radius: 12px; }
  .clock { font-size: 1.2rem; }
  .speed button { min-width: 28px; min-height: 28px; padding: 0 5px; }
  .money { font-size: 1.05rem; }
  .money-sub, .day { display: none; }
  .crumb { top: auto; bottom: 10px; left: 10px; transform: none; max-width: calc(100% - 70px); }
  .crumb span { display: none; }
  .crumb:has(button[hidden]) { display: none; }
  .zoom { top: 156px; bottom: auto; }
  .zoom button { min-height: 30px; width: 32px; }
  .hud-tl { right: 10px; }
  .speed { flex-wrap: wrap; }
  .hud-tr { top: 104px; right: 10px; padding: 4px 10px; }
  .hud-bl { position: static; width: auto; margin: 0; border-radius: 0; border: 0; box-shadow: none; border-top: 1px solid var(--line); }
}
.end-card { position: absolute; inset: 12% 18%; z-index: 3; background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); overflow: auto; }
.end-card h3 { margin: 0 0 6px; }
@media (max-width: 700px) { .end-card { inset: 4%; } }


.plan { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.pcol { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1 0 40px; }
.pbar { position: relative; width: 100%; height: 130px; padding: 0; border-radius: 8px; background: #f3eedf; overflow: hidden; }
.pbar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(#8bbd5a, #5c8f2e); }
.pbar.over .fill { background: linear-gradient(#ef9a9a, #c62828); }
.pbar .dem { position: absolute; left: 0; right: 0; border-top: 2px dashed #333; }
.pbar .n { position: absolute; top: 6px; left: 0; right: 0; font-weight: 600; text-align: center; }
.ph { font-size: 0.8rem; color: var(--muted); }
.pminus { min-height: 26px; padding: 0 10px; font-size: 0.9rem; }
.plan-sum { font-size: 0.85rem; margin: 6px 0 0; }

label { display: block; font-size: 0.86rem; color: var(--muted); }
select, input[type=number] { font: inherit; color: var(--ink); width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: #fff; min-height: 38px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
label.inline input { width: 70px; margin: 0; }
.slider { margin: 10px 0; }
.sl-head { display: flex; justify-content: space-between; gap: 8px; color: var(--ink); }
.sl-head b { color: var(--accent-ink); white-space: nowrap; }
input[type=range] { width: 100%; accent-color: var(--accent); }
details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; color: var(--accent-ink); }
.chan { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.chan > b, .chan > span { grid-column: 1 / -1; }
.chan > span { font-size: 0.8rem; }

.pnl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.pnl th, .pnl td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.pnl th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.pnl .r { text-align: right; }
.pnl tr.total td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
.pnl tr.hl td { background: var(--accent-soft); font-weight: 600; }
.pnl.small { font-size: 0.84rem; margin-top: 6px; }
.pnl-title { margin: 0 0 6px; font-weight: 600; font-size: 0.88rem; }
.kpis { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 0.84rem; color: var(--muted); }
.kpis b { color: var(--ink); }
.kpis i { font-style: normal; }
.best { margin: 8px 0; }
.best b { color: var(--accent-ink); }
.chart { width: 100%; display: block; margin-top: 8px; }
.chart[hidden], .end-card[hidden] { display: none; }
.mini-plan { display: flex; gap: 4px; align-items: flex-end; margin: 8px 0; }
.mini-plan span { display: flex; flex-direction: column; align-items: center; flex: 1; font-size: 0.75rem; }
.mini-plan i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.mini-plan small { color: var(--muted); }
.shifts { margin: 6px 0 10px; padding-left: 18px; font-size: 0.88rem; }
#btn-month { margin-top: 10px; }

.slider.off { opacity: 0.4; }
.pill { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; background: var(--accent-soft); color: var(--accent-ink); }
.pill.warn { background: #fff3cd; color: #8a6d00; }
.pill.ok { background: var(--accent-soft); color: var(--accent-ink); }
.tbl-scroll { overflow-x: auto; }
.pnl.bt td, .pnl.bt th { white-space: nowrap; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; letter-spacing: 1px; background: #f3eedf; padding: 1px 4px; border-radius: 4px; }
#btn-instant, #btn-month { margin-top: 10px; }
#all-live { margin-bottom: 4px; }

/* ---------------- โหมดเกม: แถบเครื่องมือ + แผง */
.toolbar { position: absolute; right: 60px; bottom: 10px; display: flex; gap: 6px; background: rgba(47, 59, 37, 0.88); padding: 6px; border-radius: 18px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); }
.toolbar button { display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 0; width: 58px; padding: 5px 2px; border-radius: 13px; border: 0; background: rgba(255, 255, 255, 0.1); color: #fff; }
.toolbar button span { font-size: 1.35rem; line-height: 1.1; transition: transform 0.15s; }
.toolbar button small { font-size: 0.66rem; font-family: Mitr, sans-serif; white-space: nowrap; }
.toolbar button:hover span { transform: scale(1.18) translateY(-2px); }
.toolbar button.on { background: linear-gradient(#9ccc65, #5c8f2e); box-shadow: inset 0 0 0 2px #dcedc8; }
.tool-panel { position: absolute; right: 60px; bottom: 82px; width: min(380px, calc(100% - 80px)); max-height: calc(100% - 190px); display: flex; flex-direction: column; background: var(--card); border-radius: 18px; box-shadow: 0 12px 36px rgba(30, 40, 10, 0.3); border: 2px solid rgba(92, 143, 46, 0.4); z-index: 2; animation: pop 0.18s ease-out; }
.tool-panel[hidden] { display: none; }
@keyframes pop { from { transform: translateY(10px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.tp-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 6px; font-family: Mitr, sans-serif; color: var(--accent-ink); }
.tp-head .x { min-height: 28px; width: 30px; padding: 0; border-radius: 50%; }
.tp-body { padding: 0 14px 8px; overflow-y: auto; }
.tp-foot { border-top: 1px dashed var(--line); padding: 8px 14px 10px; background: #f8f4e8; border-radius: 0 0 16px 16px; }
.proj { font-size: 0.86rem; }
.proj b { font-family: Mitr, sans-serif; font-size: 1.05rem; }
.missions { display: flex; flex-direction: column; gap: 1px; font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.missions .ok { color: var(--accent-ink); }
.stars-big { font-size: 1.2rem; letter-spacing: 2px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { display: flex; flex-direction: column; align-items: center; min-height: 44px; padding: 5px 11px; border-radius: 12px; font-family: Mitr, sans-serif; font-size: 0.86rem; background: #fff; }
.chip small { font-family: Sarabun, sans-serif; font-size: 0.7rem; color: var(--muted); }
.chip.on { background: linear-gradient(#9ccc65, #5c8f2e); color: #fff; border-color: #4f7a2a; transform: translateY(-1px); box-shadow: 0 3px 8px rgba(80, 130, 40, 0.35); }
.chip.on small { color: #eaf5dc; }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.sub-h { margin: 10px 0 0; font-weight: 600; font-size: 0.86rem; }
.big-line { font-size: 0.95rem; margin: 4px 0; }
.big-line b { font-family: Mitr, sans-serif; font-size: 1.3rem; color: var(--accent-ink); }
.stepper { display: grid; grid-template-columns: 1fr 38px minmax(70px, auto) 38px; align-items: center; gap: 6px; margin: 8px 0; }
.stepper span { font-size: 0.86rem; }
.stepper span small { display: block; font-size: 0.72rem; color: var(--muted); }
.stepper button { min-height: 36px; padding: 0; border-radius: 50%; font-size: 1.1rem; font-weight: 700; background: linear-gradient(#fff, #eef5e4); }
.stepper b { text-align: center; font-family: Mitr, sans-serif; font-size: 1.05rem; }
.hours { display: flex; gap: 2px; align-items: flex-end; height: 62px; margin: 4px 0 0; }
.hours span { flex: 1; position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.hours i { display: block; width: 100%; background: #c5e1a5; border-radius: 4px 4px 0 0; min-height: 2px; }
.hours i.over { background: #ef9a9a; }
.hours b { position: absolute; top: 0; font-size: 0.72rem; }
.hours small { font-size: 0.62rem; color: var(--muted); }
.staff-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.staff, .app-card, .preset { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 12px; background: #fff; flex-wrap: wrap; }
.ava { width: 32px; height: 32px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-family: Mitr, sans-serif; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 2px #43d047; }
.who { flex: 1; min-width: 110px; display: flex; flex-direction: column; }
.who small { color: var(--muted); font-size: 0.74rem; }
.ctl { display: flex; gap: 3px; }
.ctl button, .preset button { min-height: 30px; min-width: 30px; padding: 0 6px; border-radius: 9px; }
.fire { color: var(--bad); }
.app-card.off { opacity: 0.55; }
.app-card .stepper { width: 100%; margin: 2px 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.toggle { min-height: 30px; border-radius: 999px; padding: 0 12px; font-size: 0.78rem; }
.toggle.on { background: #e8f5e9; border-color: #66bb6a; color: #2e7d32; }
.advisor { display: flex; gap: 8px; align-items: flex-start; background: #fffbe6; border: 1px solid #f3e3a3; border-radius: 12px; padding: 8px 10px; margin-top: 8px; font-size: 0.84rem; }
.ava-adv { font-size: 1.6rem; line-height: 1; }
button.small { min-height: 30px; padding: 0 12px; margin-top: 4px; }
.row-in { display: flex; gap: 6px; margin: 6px 0; }
.row-in input { flex: 1; font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; min-height: 38px; }
.preset-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.toast { position: absolute; left: 50%; top: 56px; transform: translate(-50%, -10px); background: rgba(47, 59, 37, 0.92); color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 0.88rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; white-space: nowrap; z-index: 4; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .pos { color: #b9f6a6; } .toast .neg { color: #ffab91; }
.stars { font-size: 0.78rem; margin-top: 2px; }
.stars-end { font-size: 1.6rem; margin: 4px 0; }
.stars-end small { font-size: 0.85rem; color: var(--muted); }
details.expert > summary { list-style: none; cursor: pointer; }
details.expert > summary::-webkit-details-marker { display: none; }
details.expert > summary h2 { display: inline; }
details.expert > summary::after { content: ' ▾'; color: var(--muted); }
details.expert[open] > summary::after { content: ' ▴'; }
@media (max-width: 600px) {
  .toolbar { position: static; border-radius: 0; overflow-x: auto; justify-content: flex-start; }
  .toolbar button { flex: none; }
  .tool-panel { position: static; width: auto; max-height: none; border-radius: 0; border-left: 0; border-right: 0; animation: none; }
  .tp-foot { border-radius: 0; }
  .toast { top: 110px; white-space: normal; width: 90%; text-align: center; border-radius: 14px; }
}
.est-list { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.est { display: grid; grid-template-columns: 46px 1fr 30px 44px 30px; align-items: center; gap: 6px; font-size: 0.82rem; }
.est .h { color: var(--muted); }
.est i { display: block; height: 10px; background: #eee6d3; border-radius: 6px; overflow: hidden; }
.est i b { display: block; height: 100%; background: linear-gradient(90deg, #a5c882, #5c8f2e); border-radius: 6px; }
.est button { min-height: 28px; padding: 0; border-radius: 50%; font-weight: 700; }
.est .v { text-align: center; font-family: Mitr, sans-serif; }
.est:has(> .v:nth-child(3)) { grid-template-columns: 46px 1fr 44px; }
.end-card.wide { inset: 4% 6%; }
.end-card tr.clickable { cursor: pointer; }
.end-card tr.clickable:hover td { background: var(--accent-soft); }
.go { font-size: 0.75rem; color: var(--accent-ink); text-decoration: underline; }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.kpi-row div { background: #f8f4e8; border-radius: 12px; padding: 8px 10px; }
.kpi-row span { display: block; font-size: 0.75rem; color: var(--muted); }
.kpi-row b { display: block; font-family: Mitr, sans-serif; font-size: 1.15rem; }
.kpi-row small { font-size: 0.72rem; color: var(--muted); }
.split { display: flex; height: 18px; border-radius: 9px; overflow: hidden; background: #eee6d3; margin: 6px 0 4px; }
.split i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.75rem; color: var(--muted); }
.legend i, .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
.team-line { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.hud-bl .enter + .enter { margin-top: 6px; }
@media (max-width: 700px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.src-link { display: inline-block; margin: 4px 0; padding: 7px 12px; border-radius: 10px; background: #fff3e0; border: 1px solid #ffcc80; color: #8a4b00; font-weight: 600; text-decoration: none; font-size: 0.86rem; }
.src-link:hover { background: #ffe0b2; }
.new-data { position: absolute; left: 50%; top: 56px; transform: translateX(-50%); z-index: 5; background: #fff3e0; border: 2px solid #ffb74d; border-radius: 999px; font-weight: 600; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2); }
