/* 山姆蛋程式農場（/games/automation-lab/）：網站導覽列下方是滿版遊戲，頁內工具列、相關作品和頁尾隱藏。 */
body.se-site[data-se-page="automation-lab"] { --se-header-height: 56px; display: block; margin: 0; padding: 0; min-height: 0; height: 100dvh; overflow: hidden; background: #0f1a22; overscroll-behavior: none; }
body.se-site[data-se-page="automation-lab"] > .lab-site-header { position: relative; z-index: 80; height: var(--se-header-height); min-height: var(--se-header-height); margin: 0; }
body.se-site[data-se-page="automation-lab"] .lab-site-header-inner { height: calc(var(--se-header-height) - 1.5px); min-height: calc(var(--se-header-height) - 1.5px); width: 100% !important; max-width: none !important; padding: 0 20px; }
body.se-site[data-se-page="automation-lab"] .samegg-brand-logo { flex: 0 0 32px; width: 32px; height: 32px; }
body.se-site[data-se-page="automation-lab"] .samegg-brand-name { font-size: 16px; }
body.se-site[data-se-page="automation-lab"] .samegg-brand-subtitle { display: none; }
body.se-site[data-se-page="automation-lab"] > :is(.lab-item-toolbar, .lab-related, .lab-site-footer) { display: none !important; }
body.se-site[data-se-page="automation-lab"] main.cf { width: 100%; max-width: none; height: calc(100dvh - var(--se-header-height)); margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; isolation: isolate; }
body.se-site[data-se-page="automation-lab"] main.cf :is(h1, h2, h3, p) { margin: 0; color: inherit; letter-spacing: 0; text-wrap: initial; }
body.se-site[data-se-page="automation-lab"] main.cf h1 { font-size: 17px; line-height: 1.3; font-weight: 900; }
body.se-site[data-se-page="automation-lab"] main.cf .cf-drawer-head h2 { font-size: 20px; line-height: 1.3; }
body.se-site[data-se-page="automation-lab"] main.cf .cf-tut h2 { margin-top: 2px; font-size: 19px; line-height: 1.3; color: #1d2a33; }
body.se-site[data-se-page="automation-lab"] main.cf :is(button, input, textarea) { box-shadow: none; letter-spacing: 0; }
/* 網站在 main 裡的按鈕與輸入框有全域樣式，這裡用較高的權重還原遊戲自己的樣子 */
body.se-site.se-site[data-se-page="automation-lab"] main.cf :is(button, textarea, input) { font-family: inherit; }
body.se-site.se-site[data-se-page="automation-lab"] main.cf button { min-width: 0; min-height: var(--btn-h, 0); }
body.se-site.se-site[data-se-page="automation-lab"] main.cf .ed textarea.ed-input { border: 0; border-radius: 0; background: transparent; color: transparent; font: inherit; line-height: var(--lh); padding: 10px 16px 40px 12px; box-shadow: none; outline: none; }
body.se-site.se-site[data-se-page="automation-lab"] main.cf .cf-menu textarea#m-import-text { border: 1px solid var(--cf-line); border-radius: 10px; background: #0f1a22; color: var(--cf-ink); font-family: var(--cf-mono); font-size: 12px; }
@media (max-width: 900px) {
  body.se-site[data-se-page="automation-lab"] { height: auto; overflow: visible; }
  body.se-site[data-se-page="automation-lab"] main.cf { height: auto; isolation: auto; }
  body.se-site[data-se-page="automation-lab"] main.cf.tut-on { padding-bottom: calc(var(--tut-h, 200px) + 24px); }
  body.se-site[data-se-page="automation-lab"] main.cf .cf-tut h2 { font-size: 17px; }
}

/* 遊戲工作區固定深色，場景本身是白天的天空。 */
.cf-page { margin: 0; background: #0f1a22; }
.cf {
  --cf-deep: #0f1a22; --cf-panel: #15222c; --cf-panel-2: #1b2b37; --cf-line: #2a3d4a;
  --cf-ink: #e7f0f4; --cf-muted: #9fb4c1; --cf-faint: #6f8796;
  --cf-green: #7ee2b8; --cf-green-ink: #08291d; --cf-amber: #ffcf7a; --cf-red: #ff8f7e; --cf-blue: #7fd3ff; --cf-pink: #ff9fc3;
  --cf-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, "Noto Sans Mono CJK TC", monospace;
  --cf-sans: "SamEggTC", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  position: relative;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh; min-height: 560px;
  background: var(--cf-deep); color: var(--cf-ink); font-family: var(--cf-sans); font-size: 14px; line-height: 1.5;
  overflow: hidden;
}
.cf *, .cf *::before, .cf *::after { box-sizing: border-box; }
.cf [hidden] { display: none !important; }
:where(.cf) button { font: inherit; color: inherit; cursor: pointer; }
.cf button:focus-visible, .cf textarea:focus-visible { outline: 2px solid var(--cf-green); outline-offset: 2px; }

/* ---------- 頂部列 ---------- */
.cf-bar { display: flex; align-items: center; gap: 16px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--cf-line); background: var(--cf-panel); }
.cf-title { display: flex; flex-direction: column; min-width: 0; }
.cf-title h1 { margin: 0; font-size: 17px; font-weight: 900; letter-spacing: .02em; white-space: nowrap; }
.cf-sub { font-size: 12px; color: var(--cf-muted); white-space: nowrap; }
.cf-inv { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.cf-chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 8px; border-radius: 999px; background: var(--cf-panel-2); border: 1px solid var(--cf-line); font-weight: 700; font-size: 13px; }
.cf-chip i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); }
.cf-chip b { font-family: var(--cf-mono); font-variant-numeric: tabular-nums; min-width: 2ch; }
.cf-chip.bump { animation: bump .45s cubic-bezier(.2, 1.6, .4, 1); }
.cf-fly { position: fixed; z-index: 140; width: 14px; height: 14px; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, .85), 0 4px 10px rgba(0, 0, 0, .25); will-change: transform; }
@keyframes bump { 30% { transform: scale(1.12); border-color: var(--cf-green); } }
.cf-tools { display: flex; gap: 8px; align-items: center; }
.cf-btn { --btn-h: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px; border-radius: 10px; border: 1px solid var(--cf-line); background: var(--cf-panel-2); font-weight: 700; font-size: 14px; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.cf-btn:hover:not(:disabled) { border-color: #3e5868; background: #213443; }
.cf-btn:active:not(:disabled) { transform: translateY(1px); }
.cf-btn:disabled { opacity: .45; cursor: not-allowed; }
.cf-icon { width: 38px; padding: 0; }
.cf-btn-go { background: var(--cf-green); color: var(--cf-green-ink); border-color: var(--cf-green); }
.cf-btn-go:hover:not(:disabled) { background: #9cf0cb; border-color: #9cf0cb; }
.cf-btn-sm { min-height: 30px; padding: 3px 12px; font-size: 13px; }
.cf-btn-danger { color: var(--cf-red); border-color: #5a3330; }
.cf-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--cf-amber); color: #3a2600; font-size: 12px; font-weight: 900; display: inline-grid; place-items: center; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(255, 207, 122, .2); } }
#btn-sound .mute { display: none; }
#btn-sound.muted .mute { display: inline; }
#btn-sound.muted .wave { display: none; }

/* ---------- 舞台 ---------- */
.cf-stage { display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 32vw, 460px); min-height: 0; }
.cf-world { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: linear-gradient(#6fbfe3, #bfe7f0 50%, #f5e8cc); touch-action: none; }
.farm-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; cursor: grab; }
.farm-canvas:active { cursor: grabbing; }
.cf-fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 15px; white-space: nowrap; color: #fff; text-shadow: 0 2px 6px rgba(15, 40, 60, .5); animation: pop 1.25s ease-out forwards; }
.pop-waste { color: #ffe1d8; font-size: 13px; }
.pop-big { font-size: 20px; color: #fff3a8; text-shadow: 0 2px 8px rgba(80, 50, 0, .55), 0 0 18px rgba(255, 210, 63, .6); animation-duration: 1.7s; }
.pop-warn { font-size: 13px; color: #3a2600; background: var(--cf-amber); padding: 2px 10px; border-radius: 8px; text-shadow: none; box-shadow: 0 4px 12px rgba(0, 0, 0, .2); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 14% { opacity: 1; transform: translate(-50%, -60%) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -240%) scale(1); } }
.cf-fallback { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 32px; text-align: center; color: #12303f; font-weight: 700; }

.cf-audio-hint { --btn-h: 34px; position: absolute; z-index: 3; left: 50%; top: 14px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 7px; padding: 6px 16px; border: 0; border-radius: 999px; background: rgba(255, 207, 122, .95); color: #3a2600; font-weight: 800; font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, .25); animation: pulse 1.6s ease-in-out infinite; }
.cf-catchup { position: absolute; z-index: 4; left: 50%; top: 56px; transform: translateX(-50%); width: min(420px, calc(100% - 28px)); display: grid; gap: 8px; padding: 10px 14px 12px; border-radius: 12px; background: rgba(15, 26, 34, .9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 10px 26px rgba(0, 0, 0, .35); font-size: 13px; font-weight: 700; }
.cf-catchup-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cf-catchup-track { height: 6px; border-radius: 9px; background: #26394a; overflow: hidden; }
.cf-catchup-track i { display: block; height: 100%; width: 0; background: var(--cf-green); border-radius: inherit; transition: width .2s; }
.cf-status { position: absolute; left: 14px; top: 14px; display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 10px; border-radius: 999px; background: rgba(15, 26, 34, .78); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-weight: 700; font-size: 13px; pointer-events: none; }
.cf-status i { width: 9px; height: 9px; border-radius: 50%; background: var(--cf-faint); }
.cf-status[data-state="running"] i, .cf-status[data-state="stepping"] i { background: var(--cf-green); box-shadow: 0 0 0 4px rgba(126, 226, 184, .25); animation: pulse-g 1.2s infinite; }
.cf-status[data-state="paused"] i { background: var(--cf-amber); }
.cf-status[data-state="error"] i { background: var(--cf-red); }
.cf-status[data-state="done"] i { background: var(--cf-blue); }
@keyframes pulse-g { 50% { box-shadow: 0 0 0 7px rgba(126, 226, 184, 0); } }

.cf-goal { position: absolute; left: 14px; bottom: 14px; width: min(330px, calc(100% - 92px)); border-radius: 14px; background: rgba(15, 26, 34, .86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 12px 30px -12px rgba(5, 20, 30, .6); overflow: hidden; }
.cf-goal-toggle { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 12px 16px 6px; border: 0; background: none; text-align: left; }
.cf-goal-toggle .eyebrow { font-size: 11px; letter-spacing: .1em; color: var(--cf-green); font-weight: 700; }
.cf-goal-toggle strong { font-size: 16px; line-height: 1.35; }
.cf-goal-body { display: grid; gap: 8px; padding: 0 16px 14px; }
.cf-goal-body p { margin: 0; color: var(--cf-muted); font-size: 13px; }
.cf-goal.min .cf-goal-body { display: none; }
.cf-goal.min .cf-goal-toggle { padding-bottom: 12px; }
.cf-prog { display: grid; grid-template-columns: 4em 1fr auto; align-items: center; gap: 8px; font-size: 12px; }
.cf-prog .bar { height: 7px; border-radius: 99px; background: #26394a; overflow: hidden; }
.cf-prog .bar i { display: block; height: 100%; background: var(--c); border-radius: inherit; transition: width .3s; }
.cf-prog b { font-family: var(--cf-mono); font-variant-numeric: tabular-nums; font-size: 12px; }

.cf-cam { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.cf-cam button { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 10px; background: rgba(15, 26, 34, .72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 20px; font-weight: 700; }
.cf-cam button:hover { background: rgba(15, 26, 34, .9); }

/* ---------- 程式面板 ---------- */
.cf-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto minmax(90px, 22%); min-height: 0; border-left: 1px solid var(--cf-line); background: var(--cf-panel); }
.cf-panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--cf-line); font-size: 12px; }
.cf-panel-head { padding: 6px 8px 0; gap: 6px; align-items: flex-end; border-bottom: 0; }
.cf-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.cf-tabs::-webkit-scrollbar { display: none; }
.cf-tab { --btn-h: 32px; display: inline-flex; align-items: center; gap: 6px; flex: none; max-width: 160px; padding: 6px 12px; border: 1px solid transparent; border-bottom: 0; border-radius: 9px 9px 0 0; background: transparent; color: var(--cf-faint); font-family: var(--cf-mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-tab:hover { color: var(--cf-muted); background: rgba(255, 255, 255, .03); }
.cf-tab[aria-selected="true"] { color: var(--cf-ink); background: #111d26; border-color: var(--cf-line); }
.cf-tab i { width: 7px; height: 7px; border-radius: 50%; background: var(--cf-amber); flex: none; opacity: .55; }
.cf-tab[aria-selected="true"] i { opacity: 1; }
.cf-tab i.run { background: var(--cf-green); opacity: 1; box-shadow: 0 0 0 3px rgba(126, 226, 184, .25); }
.cf-tab-btn { --btn-h: 30px; flex: none; width: 30px; height: 30px; margin-bottom: 3px; border: 1px solid var(--cf-line); border-radius: 8px; background: var(--cf-panel-2); color: var(--cf-muted); font-size: 16px; font-weight: 700; line-height: 1; }
.cf-tab-btn:hover:not(:disabled) { color: var(--cf-ink); }
.cf-tab-btn:disabled { opacity: .4; cursor: not-allowed; }
.cf-tab-pop { position: absolute; z-index: 15; right: 10px; top: 46px; width: min(320px, calc(100% - 20px)); display: grid; gap: 8px; padding: 12px 14px 14px; border-radius: 12px; background: #203241; border: 1px solid #36506a; box-shadow: 0 16px 36px rgba(0, 0, 0, .45); }
.cf-tab-row { display: flex; gap: 8px; align-items: center; }
.cf-tab-row input { flex: 1; min-width: 0; height: 32px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--cf-line); background: #0f1a22; color: var(--cf-ink); font-family: var(--cf-mono); font-size: 13px; }
.cf-tab-msg { margin: 0; font-size: 12px; color: var(--cf-amber); min-height: 0; }
.cf-tab-msg:empty { display: none; }
.cf-tab-note { margin: 0; font-size: 12px; color: var(--cf-faint); }
.cf-tab-note code { font-family: var(--cf-mono); color: var(--cf-blue); }
.cf-subhead { display: flex; justify-content: space-between; gap: 10px; padding: 5px 14px; border-top: 1px solid var(--cf-line); border-bottom: 1px solid var(--cf-line); background: #111d26; font-size: 12px; color: var(--cf-green); min-height: 26px; }
.cf-panel { position: relative; }
.cf-cam button[aria-pressed="true"] { background: var(--cf-green); color: var(--cf-green-ink); }
.cf-file { display: inline-flex; align-items: center; gap: 8px; font-family: var(--cf-mono); color: var(--cf-muted); }
.cf-file i { width: 8px; height: 8px; border-radius: 50%; background: var(--cf-amber); }
.cf-runinfo { color: var(--cf-faint); text-align: right; font-variant-numeric: tabular-nums; }

.cf-editor { position: relative; min-height: 0; background: #111d26; }
.ed { --lh: 22px; position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); height: 100%; overflow: hidden; font-family: var(--cf-mono); font-size: 14px; line-height: var(--lh); }
.ed-gutter { padding: 10px 10px 40px 12px; color: var(--cf-faint); text-align: right; user-select: none; min-width: 3.2em; font-variant-numeric: tabular-nums; background: #0f1a22; will-change: transform; }
.ed-gutter span { display: block; }
.ed-gutter span.on { color: var(--cf-green); font-weight: 700; }
.ed-gutter span.err { color: var(--cf-red); font-weight: 700; }
.ed-body { position: relative; overflow: hidden; }
.ed-hl, .ed-input { margin: 0; padding: 10px 16px 40px 12px; font: inherit; line-height: var(--lh); white-space: pre; tab-size: 4; letter-spacing: 0; }
.ed-hl { position: absolute; left: 0; top: 0; min-width: 100%; pointer-events: none; color: #d8e6ef; will-change: transform; }
.ed-hl .ln { display: block; position: relative; min-height: var(--lh); margin: 0 -16px 0 -12px; padding: 0 16px 0 12px; }
.ed-hl .ln.on { background: linear-gradient(90deg, rgba(126, 226, 184, .22), rgba(126, 226, 184, .04)); box-shadow: inset 3px 0 0 var(--cf-green); }
.ed-hl .ln.err { background: rgba(255, 143, 126, .14); box-shadow: inset 3px 0 0 var(--cf-red); text-decoration: underline wavy rgba(255, 143, 126, .8); text-underline-offset: 4px; }
.ed-input { position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: none; background: transparent; color: transparent; caret-color: #fff; overflow: auto; }
.ed-input::selection { background: rgba(127, 211, 255, .3); color: transparent; }
.t-kw { color: var(--cf-pink); font-weight: 600; }
.t-fn { color: var(--cf-blue); }
.t-call { color: #b8e0ff; }
.t-const { color: var(--cf-amber); }
.t-num { color: #b9f58c; }
.t-str { color: #c3f2a0; }
.t-com { color: var(--cf-faint); font-style: italic; }
.t-op { color: #8fa5b3; }
.ed-ac { position: absolute; z-index: 5; margin: 0; padding: 4px; list-style: none; min-width: 180px; border-radius: 10px; background: #203241; border: 1px solid #36506a; box-shadow: 0 10px 24px rgba(0, 0, 0, .4); font-size: 13px; }
.ed-ac li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.ed-ac li.sel { background: rgba(126, 226, 184, .2); }
.ed-ac small { color: var(--cf-faint); font-family: var(--cf-sans); }

.cf-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--cf-line); }
.cf-run { --btn-h: 40px; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 20px; border-radius: 10px; border: 0; background: var(--cf-green); color: var(--cf-green-ink); font-weight: 900; font-size: 15px; box-shadow: 0 6px 18px -6px rgba(126, 226, 184, .6); transition: transform .1s, background .15s; }
.cf-run:hover { background: #9cf0cb; }
.cf-run:active { transform: translateY(1px); }
.cf-run .i-pause { display: none; }
.cf-run[data-mode="pause"] { background: var(--cf-amber); color: #3a2600; box-shadow: 0 6px 18px -6px rgba(255, 207, 122, .6); }
.cf-run[data-mode="pause"] .i-pause { display: inline; }
.cf-run[data-mode="pause"] .i-play { display: none; }
.cf-speed { display: inline-flex; margin-left: auto; border: 1px solid var(--cf-line); border-radius: 10px; overflow: hidden; }
.cf-speed button { border: 0; background: var(--cf-panel-2); padding: 7px 10px; font-weight: 700; font-size: 13px; font-family: var(--cf-mono); }
.cf-speed button + button { border-left: 1px solid var(--cf-line); }
.cf-speed button[aria-pressed="true"] { background: var(--cf-ink); color: var(--cf-deep); }

.cf-console { overflow: auto; padding: 8px 16px 12px; border-top: 1px solid var(--cf-line); background: #0f1a22; font-family: var(--cf-mono); font-size: 13px; }
.cf-console .ln { padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.cf-console .sys { color: var(--cf-faint); font-family: var(--cf-sans); }
.cf-console .err { color: var(--cf-red); font-family: var(--cf-sans); font-weight: 700; }

/* ---------- 抽屜 ---------- */
.cf-scrim { position: absolute; inset: 0; z-index: 20; background: rgba(5, 12, 18, .45); }
.cf-drawer { position: absolute; z-index: 21; top: 0; right: 0; bottom: 0; width: min(460px, 100%); display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--cf-panel); border-left: 1px solid var(--cf-line); box-shadow: -20px 0 40px rgba(0, 0, 0, .35); animation: slide .22s ease-out; }
.cf-drawer-sm { width: min(380px, 100%); }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.cf-drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--cf-line); }
.cf-drawer-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.cf-drawer-head p { margin: 2px 0 0; color: var(--cf-muted); font-size: 13px; }
.cf-close { width: 36px; height: 36px; flex: none; border: 1px solid var(--cf-line); border-radius: 10px; background: var(--cf-panel-2); font-size: 20px; line-height: 1; }
.cf-up-list, .cf-help, .cf-menu { overflow: auto; padding: 14px 20px 28px; display: grid; gap: 10px; align-content: start; }
.cf-up { display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--cf-line); background: var(--cf-panel-2); }
.cf-up-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cf-up h3 { margin: 0; font-size: 16px; }
.cf-up p { margin: 0; color: var(--cf-muted); font-size: 13px; }
.cf-up .needs { color: var(--cf-faint); }
.cf-up .state { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: #26394a; color: var(--cf-muted); white-space: nowrap; }
.cf-up[data-state="ready"] { border-color: rgba(126, 226, 184, .55); box-shadow: inset 3px 0 0 var(--cf-green); }
.cf-up[data-state="ready"] .state { background: rgba(126, 226, 184, .18); color: var(--cf-green); }
.cf-up[data-state="owned"] { opacity: .6; }
.cf-up[data-state="owned"] .state { color: var(--cf-blue); }
.cf-up[data-state="locked"] h3 { color: var(--cf-muted); }
.cf-up .costs { display: flex; flex-wrap: wrap; gap: 6px; }
.cf-up .cf-btn { justify-self: start; margin-top: 4px; }
.cost { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 6px; border-radius: 999px; background: #26394a; color: var(--cf-red); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cost.ok { color: var(--cf-ink); }
.cost i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.cf-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cf-help-wrap { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
body.se-site.se-site[data-se-page="automation-lab"] main.cf .cf-help-wrap input#help-search { margin: 12px 20px 0; height: 38px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--cf-line); background: #0f1a22; color: var(--cf-ink); font-size: 14px; font-family: inherit; }
.cf-help-sec { display: grid; gap: 8px; }
details.cf-help-sec { padding: 10px 14px; border-radius: 12px; background: var(--cf-panel-2); border: 1px solid var(--cf-line); }
details.cf-help-sec.locked { opacity: .78; }
details.cf-help-sec.flash { animation: helpFlash 1.6s ease-out; }
@keyframes helpFlash { 0%, 40% { border-color: var(--cf-amber); box-shadow: 0 0 0 4px rgba(255, 207, 122, .2); } }
details.cf-help-sec summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; cursor: pointer; list-style: none; }
details.cf-help-sec summary::-webkit-details-marker { display: none; }
details.cf-help-sec summary::before { content: "▸"; color: var(--cf-faint); transition: transform .15s; }
details.cf-help-sec[open] summary::before { transform: rotate(90deg); }
.cf-help-name { font-weight: 800; font-size: 15px; }
.cf-help-lock { font-size: 11px; font-weight: 700; color: var(--cf-faint); padding: 1px 8px; border: 1px solid var(--cf-line); border-radius: 999px; }
.cf-help-codes { display: flex; flex-wrap: wrap; gap: 4px; flex-basis: 100%; }
details[open] .cf-help-codes { display: none; }
.cf-help-codes code { font-family: var(--cf-mono); font-size: 11.5px; color: var(--cf-blue); padding: 1px 6px; border-radius: 5px; background: #0f1a22; }
details.cf-help-sec dl { display: grid; gap: 8px; margin: 4px 0 0; }
details.cf-help-sec dl div { display: grid; gap: 2px; }
details.cf-help-sec dt code { font-family: var(--cf-mono); font-size: 13px; color: var(--cf-blue); font-weight: 600; }
details.cf-help-sec dd { margin: 0; font-size: 13px; color: var(--cf-muted); }
.cf-help-ex { display: grid; gap: 6px; justify-items: start; }
.cf-help-ex pre { width: 100%; margin: 0; padding: 8px 10px; border-radius: 8px; background: #0f1a22; font-family: var(--cf-mono); font-size: 12.5px; line-height: 1.55; overflow-x: auto; color: #d8e6ef; }
.cf-help-note { font-size: 12px; color: var(--cf-faint); }
.cf-help-tip { margin: 0; font-size: 12.5px; color: var(--cf-amber); }
.cf-help-tip::before { content: "提醒　"; font-weight: 800; }
.cf-help-empty { margin: 0; color: var(--cf-faint); font-size: 13px; }

.cf-help-sec h3 { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-size: 15px; }
.cf-help-sec h3 span { font-size: 11px; font-weight: 700; color: var(--cf-faint); padding: 1px 8px; border: 1px solid var(--cf-line); border-radius: 999px; }
.cf-help-item { display: grid; gap: 6px; padding: 12px 14px; border-radius: 12px; background: var(--cf-panel-2); border: 1px solid var(--cf-line); }
.cf-help-item.locked { opacity: .5; }
.cf-help-item code { font-family: var(--cf-mono); color: var(--cf-blue); font-weight: 600; }
.cf-help-item p { margin: 0; color: var(--cf-muted); font-size: 13px; }
.cf-help-item pre, .cf-toast pre { margin: 0; padding: 8px 10px; border-radius: 8px; background: #0f1a22; font-family: var(--cf-mono); font-size: 13px; overflow-x: auto; }
.cf-help-item .cf-btn { justify-self: start; }
.cf-menu .cf-btn { justify-content: flex-start; }
.cf-field { margin-top: 8px; font-size: 13px; color: var(--cf-muted); }
.cf-menu textarea { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--cf-line); background: #0f1a22; color: var(--cf-ink); font-family: var(--cf-mono); font-size: 12px; resize: vertical; }
.cf-sound { display: grid; gap: 10px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--cf-line); }
body.se-site[data-se-page="automation-lab"] main.cf .cf-sound h3 { font-size: 15px; font-weight: 800; }
.cf-sound-row { display: flex; align-items: center; gap: 12px; }
.cf-switch { display: inline-flex; align-items: center; gap: 8px; min-width: 7em; font-weight: 700; font-size: 14px; cursor: pointer; }
.cf-switch-wide { min-width: 0; font-weight: 600; font-size: 13px; }
.cf-switch input { width: 18px; height: 18px; accent-color: var(--cf-green); }
.cf-sound-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--cf-green); }
.cf-sound-row input[type="range"]:disabled { opacity: .35; }
.cf-sound-note { margin: 0; font-size: 12px; color: var(--cf-faint); }
.cf-danger { display: grid; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--cf-line); }
.cf-confirm { display: grid; gap: 8px; padding: 12px; border-radius: 10px; background: rgba(255, 143, 126, .08); border: 1px solid #5a3330; }
.cf-confirm p { margin: 0; font-size: 13px; }

.cf-toast { position: absolute; z-index: 30; left: 50%; top: 70px; width: min(420px, calc(100% - 32px)); transform: translate(-50%, -12px); opacity: 0; display: grid; gap: 8px; padding: 14px 16px; border-radius: 14px; background: #203241; border: 1px solid rgba(126, 226, 184, .45); box-shadow: 0 18px 40px -10px rgba(0, 0, 0, .55); transition: opacity .25s, transform .25s; }
.cf-toast.show { opacity: 1; transform: translate(-50%, 0); }
.cf-toast strong { font-size: 16px; color: var(--cf-green); }
.cf-toast p { margin: 0; color: var(--cf-muted); font-size: 13px; }
.cf-toast .row { display: flex; gap: 8px; }


/* ---------- 技能樹 ---------- */
.cf-drawer-tree { width: min(900px, 100%); }
.cf-tree { display: grid; grid-template-rows: auto minmax(180px, 1fr) auto; min-height: 0; }
.st-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 10px 20px; border-bottom: 1px solid var(--cf-line); font-size: 12px; color: var(--cf-muted); }
.st-legend span { display: inline-flex; align-items: center; gap: 5px; }
.st-legend svg, .st-ico svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.st-legend [data-b="code"], .st-node[data-b="code"] { --b: #ff9fc3; }
.st-legend [data-b="sense"], .st-node[data-b="sense"] { --b: #c9a7ff; }
.st-legend [data-b="farm"], .st-node[data-b="farm"] { --b: #9be37a; }
.st-legend [data-b="speed"], .st-node[data-b="speed"] { --b: #7fd3ff; }
.st-legend [data-b="water"], .st-node[data-b="water"] { --b: #5cb3dd; }
.st-legend [data-b="yield"], .st-node[data-b="yield"] { --b: #ffd23f; }
.st-legend [data-b="explore"], .st-node[data-b="explore"] { --b: #ff9a5c; }
.st-legend [data-b="legend"], .st-node[data-b="legend"] { --b: #ffd23f; }
.st-node[data-b="legend"] { border-width: 2px; border-color: #b98b1c; background: linear-gradient(160deg, #2b2410, #172631 70%); }
.st-node[data-b="legend"] .st-name { color: #ffe08a; }
.st-node[data-b="legend"][data-state="ready"] { animation: legendGlow 1.6s ease-in-out infinite; }
.st-node[data-b="legend"][data-state="owned"] { background: linear-gradient(160deg, #ffd23f, #f2a93b); border-color: #ffe9a3; }
.st-node[data-b="legend"][data-state="owned"] .st-name, .st-node[data-b="legend"][data-state="owned"] .st-cost { color: #3a2600; }
@keyframes legendGlow { 50% { box-shadow: 0 0 0 8px rgba(255, 210, 63, .2), 0 0 30px rgba(255, 210, 63, .5); } }
.st-legend svg { color: var(--b); }
.st-scroll { overflow: auto; min-height: 0; background: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .06) 1px, transparent 0) 0 0 / 22px 22px, #111d26; }
.st-canvas { position: relative; margin: 0 auto; }
.st-edges { position: absolute; inset: 0; overflow: visible; }
.st-edges path { fill: none; stroke-width: 3; stroke-linecap: round; }
.st-edges .own { stroke: var(--cf-green); opacity: .75; }
.st-edges .ready { stroke: var(--cf-amber); stroke-dasharray: 2 7; animation: flow 1s linear infinite; }
.st-edges .open { stroke: #5b7385; stroke-dasharray: 2 7; }
.st-edges .lock { stroke: #2c3f4c; }
@keyframes flow { to { stroke-dashoffset: -18; } }
.st-node { position: absolute; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-content: center; column-gap: 7px; row-gap: 3px; padding: 7px 9px; border-radius: 12px; border: 1.5px solid #2c3f4c; background: #172631; text-align: left; transition: transform .12s, border-color .15s, box-shadow .15s; }
.st-node:hover { transform: translateY(-2px); }
.st-ico { grid-row: 1 / 3; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: rgba(255, 255, 255, .05); color: var(--b); align-self: center; }
.st-name { font-weight: 800; font-size: 13px; line-height: 1.25; white-space: nowrap; }
.st-cost { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; font-size: 11px; color: var(--cf-red); font-variant-numeric: tabular-nums; font-family: var(--cf-mono); }
.st-cost i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-left: 2px; }
.st-node[data-state="locked"] { opacity: .5; }
.st-node[data-state="locked"] .st-ico { color: var(--cf-faint); }
.st-node[data-state="short"] .st-cost { color: var(--cf-muted); }
.st-node[data-state="ready"] { border-color: var(--cf-amber); box-shadow: 0 0 0 4px rgba(255, 207, 122, .14), 0 8px 20px -10px rgba(255, 207, 122, .6); }
.st-node[data-state="ready"] .st-cost { color: var(--cf-amber); }
.st-node[data-state="owned"] { border-color: rgba(126, 226, 184, .6); background: #16302b; }
.st-node[data-state="owned"] .st-ico { background: var(--cf-green); color: var(--cf-green-ink); }
.st-node[data-state="owned"] .st-cost { color: var(--cf-green); font-family: var(--cf-sans); }
.st-node[aria-pressed="true"] { outline: 2px solid var(--cf-ink); outline-offset: 3px; }
.st-detail { display: grid; align-content: start; gap: 8px; max-height: min(46vh, 440px); overflow: auto; padding: 14px 20px 18px; border-top: 1px solid var(--cf-line); background: var(--cf-panel-2); }
.st-detail:empty { display: none; }
.st-d-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.st-detail h3 { margin: 0; font-size: 17px; }
.st-effects { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; margin: 0; }
.st-effects div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 8px; background: #26394a; font-size: 13px; }
.st-effects dt { color: var(--cf-muted); }
.st-effects dd { margin: 0; font-weight: 800; color: var(--cf-amber); font-variant-numeric: tabular-nums; }
.st-teach { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.st-teach-label { font-size: 12px; font-weight: 800; color: var(--cf-green); margin-right: 2px; }
.st-teach code { padding: 2px 8px; border-radius: 6px; background: #0f1a22; border: 1px solid var(--cf-line); font-family: var(--cf-mono); font-size: 12px; color: var(--cf-blue); white-space: nowrap; }
body.se-site.se-site[data-se-page="automation-lab"] main.cf .st-help-link { --btn-h: 26px; margin-left: auto; padding: 2px 4px; border: 0; background: none; color: var(--cf-green); font-size: 13px; font-weight: 700; cursor: pointer; }
.st-help-link:hover { text-decoration: underline; }
.st-detail p { margin: 0; color: var(--cf-muted); font-size: 13px; }
.st-detail .cf-btn { justify-self: start; }
.st-needs { color: var(--cf-faint) !important; }
.st-costs { display: flex; flex-wrap: wrap; gap: 6px; }
.st-pill { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: #26394a; color: var(--cf-muted); white-space: nowrap; }
.st-pill[data-state="ready"] { background: rgba(255, 207, 122, .18); color: var(--cf-amber); }
.st-pill[data-state="owned"] { background: rgba(126, 226, 184, .16); color: var(--cf-green); }

/* ---------- 結局 ---------- */
.cf-crown { display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: #ffd23f; color: #3a2600; font-size: 11px; font-weight: 900; vertical-align: 2px; }
.cf-ending { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 50% 30%, rgba(255, 210, 63, .22), rgba(5, 12, 18, .72) 60%); animation: endIn .5s ease-out; }
@keyframes endIn { from { opacity: 0; } }
.cf-ending-card { position: relative; display: grid; justify-items: center; gap: 10px; width: min(520px, 100%); max-height: 100%; overflow: auto; padding: 28px 28px 24px; border-radius: 20px; background: #fffaf0; color: #1d2a33; text-align: center; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .7), 0 0 0 2px #ffd23f; animation: endCard .7s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes endCard { from { transform: translateY(24px) scale(.9); opacity: 0; } }
.cf-ending-crown { animation: crownBob 2.4s ease-in-out infinite; }
@keyframes crownBob { 50% { transform: translateY(-5px) rotate(-4deg); } }
.cf-ending-eyebrow { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: .12em; color: #b7791f; }
body.se-site[data-se-page="automation-lab"] main.cf .cf-ending h2 { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 900; color: #1d2a33; }
.cf-ending-lede { margin: 0; max-width: 40ch; color: #3c4b55; font-size: 14px; }
.cf-ending-lede code { padding: 1px 6px; border-radius: 6px; background: #efe6d3; color: #8a3d6b; font-family: var(--cf-mono); font-size: 13px; }
.cf-ending-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; width: 100%; margin: 6px 0 4px; }
.cf-ending-stats div { display: flex; justify-content: space-between; gap: 8px; padding: 7px 12px; border-radius: 10px; background: #f3ead6; font-size: 13px; }
.cf-ending-stats dt { color: #6b7a84; }
.cf-ending-stats dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }
.cf-ending-actions { display: flex; gap: 8px; margin-top: 4px; }
@media (max-width: 900px) { .cf-ending { position: fixed; } .cf-ending-stats { grid-template-columns: 1fr; } }

/* ---------- 新手教學 ---------- */
.cf-tut { position: absolute; z-index: 40; left: 16px; bottom: 16px; width: min(360px, calc(100% - 32px)); display: grid; gap: 8px; padding: 14px 18px 16px; border-radius: 16px; background: #fffaf0; color: #1d2a33; box-shadow: 0 24px 50px -16px rgba(0, 0, 0, .6), 0 0 0 1.5px rgba(255, 207, 122, .9); }
.cf-tut.tut-in { animation: tutIn .3s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes tutIn { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.tut-top { display: flex; justify-content: space-between; align-items: center; }
.tut-count { font-size: 12px; font-weight: 800; letter-spacing: .06em; color: #b7791f; }
.tut-skip { border: 0; background: none; padding: 4px 0; font-size: 12px; color: #6b7a84; text-decoration: underline; text-underline-offset: 3px; }
.tut-dots { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.tut-dots li { flex: 1; height: 4px; border-radius: 9px; background: #eadfc9; }
.tut-dots li.done { background: #7ac9a2; }
.tut-dots li.on { background: #e8a33a; }
.cf-tut h2 { margin: 2px 0 0; font-size: 19px; font-weight: 900; line-height: 1.3; }
.tut-body { display: grid; gap: 6px; font-size: 14px; color: #3c4b55; }
.tut-body p { margin: 0; }
.tut-body b { color: #1d2a33; }
.tut-body code, .tut-hint code { padding: 1px 6px; border-radius: 6px; background: #efe6d3; font-family: var(--cf-mono); font-size: 13px; color: #8a3d6b; }
.tut-body pre { margin: 2px 0; padding: 8px 12px; border-radius: 10px; background: #15222c; color: #d8e6ef; font-family: var(--cf-mono); font-size: 13px; line-height: 1.6; overflow-x: auto; }
.tut-hint { margin: 0; font-size: 12px; color: #6b7a84; }
.tut-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tut-actions:empty { display: none; }
.cf-tut .cf-btn:not(.cf-btn-go) { background: #fff; border-color: #d9cdb4; color: #1d2a33; }
.tut-focus { outline: 3px solid var(--cf-amber) !important; outline-offset: 4px; animation: tutRing 1.3s ease-in-out infinite; }
.tut-focus-in { outline-offset: -3px; }
@keyframes tutRing { 50% { outline-color: rgba(255, 207, 122, .35); } }

/* ---------- 手機與窄螢幕 ---------- */
@media (max-width: 900px) {
  .cf { height: auto; min-height: 100dvh; overflow: visible; grid-template-rows: auto auto; }
  .cf-bar { flex-wrap: wrap; gap: 8px 12px; padding-block: 8px; }
  .cf-title { flex: 1; }
  .cf-sub { display: none; }
  .cf-inv { order: 3; flex-basis: 100%; }
  .cf-chip { padding: 3px 10px 3px 6px; font-size: 12px; }
  .cf-btn { --btn-h: 40px; min-height: 40px; padding: 4px 11px; font-size: 13px; }
  .cf-icon { width: 40px; }
  .cf-stage { grid-template-columns: minmax(0, 1fr); }
  .cf-world { height: 52svh; min-height: 300px; }
  .cf-panel { border-left: 0; border-top: 1px solid var(--cf-line); grid-template-rows: auto auto minmax(260px, 46svh) auto minmax(80px, auto); }
  .cf-console { max-height: 160px; }
  .cf-goal { left: 10px; bottom: 10px; width: calc(100% - 72px); }
  .cf-goal-toggle { padding: 9px 12px 4px; }
  .cf-goal-toggle strong { font-size: 14px; }
  .cf-goal-body { padding: 0 12px 10px; gap: 6px; }
  .cf-cam { right: 10px; bottom: 10px; gap: 5px; }
  .cf-cam button { width: 34px; height: 34px; }
  .cf-status { left: 10px; top: 10px; }
  .cf-drawer, .cf-scrim { position: fixed; }
  /* 手機上網站導覽列固定在最上面：遊戲的抽屜、提示和結局要蓋在它上面，關閉鈕才按得到 */
  .cf-scrim { z-index: 100; }
  .cf-drawer { z-index: 101; padding-top: env(safe-area-inset-top, 0px); }
  .cf-tut { z-index: 110; }
  .cf-toast { z-index: 120; }
  .cf-ending { z-index: 130; }
  .cf-toast { position: fixed; top: 12px; }
  .ed { font-size: 13px; --lh: 21px; }
  .cf-controls { padding: 8px 12px; }
  .cf-speed { margin-left: 0; }
  .cf.tut-on { padding-bottom: calc(var(--tut-h, 200px) + 24px); }
  .cf-tut { position: fixed; left: 8px; right: 8px; top: auto; bottom: max(8px, env(safe-area-inset-bottom, 0px)); width: auto; max-height: 40svh; overflow: auto; padding: 12px 14px 14px; }
  .cf-tut h2 { font-size: 17px; }
  .cf-drawer:not([hidden]) ~ .cf-tut { top: max(8px, env(safe-area-inset-top, 0px)); bottom: auto; max-height: none; padding: 10px 14px; gap: 2px; }
  .cf-drawer:not([hidden]) ~ .cf-tut :is(.tut-body, .tut-dots, .tut-hint, .tut-actions) { display: none; }
  .cf.tut-on .cf-drawer { padding-top: 84px; }
  .cf-drawer-tree .st-detail { padding-bottom: max(18px, env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 420px) {
  .cf-lg { display: none; }
  body.se-site[data-se-page="automation-lab"] main.cf h1 { font-size: 16px; white-space: nowrap; }
  .cf-controls { display: grid; grid-template-columns: 1.4fr 1fr 1fr; }
  .cf-speed { grid-column: 1 / -1; justify-self: stretch; }
  .cf-speed button { flex: 1; }
  .cf-run { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .pop, .cf-chip.bump, .cf-badge, .cf-drawer, .cf-tut, .tut-focus, .st-edges .ready, .cf-ending, .cf-ending-card, .cf-ending-crown { animation-duration: .01s; }
  .cf-toast { transition: none; }
}
