/* 1 ไร่ รอดวิกฤต — farm workbench (looks and works like the fkSolar editor) */
main.wrap-wide { max-width: 1560px; }
.f1r-hero { max-width: 900px; margin: 0 0 16px; }
.f1r-kicker { margin: 0 0 4px; color: var(--acc-text); font-weight: 600; font-size: .9rem; }
.f1r-hero h1 { margin: 0 0 6px; font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.2; }
.f1r-lead { margin: 0; color: var(--sub); }

.f1r { --ws-bg: #0d0d10; --board: #15201a; --board-line: rgba(255, 255, 255, .055); --road: #2a2a2e; min-width: 0; }
:root[data-theme="light"] .f1r { --ws-bg: #f1f1f3; --board: #e8efdf; --board-line: rgba(0, 0, 0, .07); --road: #d7d4cc; }
.f1r *, .f1r *::before, .f1r *::after { min-width: 0; }

/* toolbar */
.ws-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; background: var(--surface); }
.ws-q { display: flex; flex-direction: column; gap: 4px; }
.ws-ql { font-size: .76rem; color: var(--sub); font-weight: 600; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 999px; background: var(--raised); }
.stepper button { width: 38px; height: 38px; border: 0; background: none; color: var(--text); font: 700 1.15rem/1 var(--font); cursor: pointer; border-radius: 999px; }
.stepper button:hover { color: var(--acc-text); }
.stepper b { min-width: 26px; text-align: center; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 999px; background: var(--raised); padding: 3px; }
.seg button { border: 0; background: none; color: var(--sub); font: 600 .88rem/1 var(--font); padding: 9px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--acc); color: var(--acc-ink); }
#f1r-land { min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--raised); color: var(--text); font: 500 .92rem var(--font); max-width: 100%; }
.ws-go { min-height: 40px; }
.ws-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; }
.ws-presets .ws-ql { margin-right: 2px; }
.chip-b { border: 1px solid var(--line-2); background: var(--raised); color: var(--text); border-radius: 999px; padding: 6px 12px; font: 500 .85rem/1.2 var(--font); cursor: pointer; white-space: nowrap; }
.chip-b:hover { border-color: var(--acc-line); }
.chip-b.on { border-color: var(--acc); background: var(--acc-soft); color: var(--acc-text); }

/* three columns */
.ws-main { display: grid; grid-template-columns: 236px minmax(0, 1fr) 330px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--r) var(--r); background: var(--ws-bg); overflow: hidden; }
.ws-pal, .ws-side { background: var(--surface); display: flex; flex-direction: column; max-height: 860px; }
.ws-pal { border-right: 1px solid var(--line); padding: 12px; gap: 8px; }
.ws-side { border-left: 1px solid var(--line); }
.ws-h { font-weight: 700; font-size: .95rem; }
.ws-h small { font-weight: 400; color: var(--sub); font-size: .75rem; margin-left: 4px; }
.ws-search { width: 100%; min-height: 36px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--raised); color: var(--text); font: 400 .88rem var(--font); }
.ws-cats { display: flex; flex-wrap: wrap; gap: 5px; }
.ws-cats .chip-b { padding: 4px 9px; font-size: .76rem; }
.ws-list { display: grid; gap: 5px; overflow: auto; padding-right: 2px; }
.pal-i { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 6px 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); color: var(--text); cursor: pointer; font: inherit; }
.pal-i:hover { border-color: var(--acc-line); }
.pal-ico { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 1rem; }
.pal-t { flex: 1; }
.pal-i b { display: block; font-size: .82rem; font-weight: 600; line-height: 1.3; }
.pal-i small { color: var(--sub); font-size: .72rem; }
.pal-i i { font-style: normal; color: var(--acc-text); font-weight: 700; font-size: 1.15rem; }

/* board */
.ws-center { display: flex; flex-direction: column; }
.ws-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.ws-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .76rem; color: var(--sub); }
.ws-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.ws-zoom { display: flex; gap: 4px; }
.ib { min-width: 34px; height: 32px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--raised); color: var(--text); font: 600 .85rem/1 var(--font); cursor: pointer; }
.ib:hover { border-color: var(--acc-line); }
.ib.on { border-color: var(--acc); color: var(--acc-text); }
.ws-stage { position: relative; overflow: auto; height: clamp(420px, calc(100vh - 290px), 760px); padding: 8px; display: flex; }
#f1r-svg { display: block; margin: auto; flex: none; user-select: none; -webkit-user-select: none; touch-action: pan-x pan-y pinch-zoom; font-family: var(--font); }
#f1r-svg .ground { fill: var(--board); }
#f1r-svg .gridl { stroke: var(--board-line); }
#f1r-svg .fence { fill: none; stroke: #6b5a3c; stroke-dasharray: 1.2 .6; }
#f1r-svg .gate { fill: var(--acc); }
#f1r-svg .dim { fill: var(--sub); }
#f1r-svg .n { cursor: grab; touch-action: none; }
#f1r-svg .n .nb { fill-opacity: .2; stroke: rgba(255, 255, 255, .22); }
:root[data-theme="light"] #f1r-svg .n .nb { fill-opacity: .28; stroke: rgba(0, 0, 0, .25); }
#f1r-svg .n:hover .nb { fill-opacity: .3; stroke: rgba(255, 255, 255, .45); }
#f1r-svg .n.sel .nb { stroke: var(--acc); fill-opacity: .32; }
#f1r-svg .n-road .nb { fill: var(--road); fill-opacity: 1; stroke: none; }
#f1r-svg .n-solar .nb, #f1r-svg .n-pump .nb { fill-opacity: .55; }
#f1r-svg .np { pointer-events: none; }
#f1r-svg .ns { opacity: .95; }
#f1r-svg .nt { fill: var(--text); font-weight: 650; pointer-events: none; }
#f1r-svg .nv { fill: var(--acc-text); font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none; }
#f1r-svg .nl { fill: var(--sub); pointer-events: none; }
#f1r-svg .nl.road { fill: var(--sub); letter-spacing: .05em; }
#f1r-svg .ni { pointer-events: none; }
#f1r-svg .nd { fill: #ff6b6b; stroke: var(--surface); }
#f1r-svg .handle { fill: var(--acc); stroke: #111; cursor: nwse-resize; }
#f1r-svg .wires { pointer-events: none; }
#f1r-svg .wb { fill: none; stroke: rgba(0, 0, 0, .55); stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="light"] #f1r-svg .wb { stroke: rgba(255, 255, 255, .8); }
#f1r-svg .wf { fill: none; stroke-linecap: round; stroke-linejoin: round; animation: f1r-flow 1.1s linear infinite; }
#f1r-svg .w.bad .wf { stroke: #ff6b6b; }
#f1r-svg .w.bad .port { fill: #ff6b6b; }
#f1r-svg .port { stroke: rgba(0, 0, 0, .5); stroke-width: .05; }
@keyframes f1r-flow { to { stroke-dashoffset: calc(var(--dash, 1) * -1); } }
@media (prefers-reduced-motion: reduce) { #f1r-svg .wf { animation: none; } }

/* status strip */
.ws-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.tile { background: var(--surface); padding: 9px 12px; display: flex; flex-direction: column; gap: 1px; }
.tile span { font-size: .72rem; color: var(--sub); }
.tile b { font-size: 1.15rem; font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile small { font-size: .72rem; color: var(--sub); line-height: 1.35; }
.tile.ok b { color: var(--ok); }
.tile.low b { color: var(--danger); }
.tile.warn b { color: #f5b942; }
.ws-hint { margin: 0; padding: 7px 12px; font-size: .74rem; color: var(--sub); background: var(--surface); border-top: 1px solid var(--line); }

/* right side */
.ws-tabs { display: flex; border-bottom: 1px solid var(--line); }
.ws-tabs button { flex: 1; padding: 11px 6px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--sub); font: 600 .9rem var(--font); cursor: pointer; }
.ws-tabs button.on { color: var(--text); border-bottom-color: var(--acc); }
.ws-tabs em { font-style: normal; display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 99px; background: #f5b942; color: #111; font-size: .72rem; line-height: 18px; }
.ws-pane { padding: 12px 14px 16px; overflow: auto; }
.ws-pane[hidden] { display: none; }
.ws-pane h3 { margin: 16px 0 6px; font-size: .92rem; }
.big { display: flex; align-items: baseline; gap: 8px; }
.big span { color: var(--sub); }
.big strong { font-size: 2.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
.big.ok strong, .okc { color: var(--ok); }
.big.low strong, .lowc { color: var(--danger); }
.big-sub { margin: 4px 0 8px; font-size: .86rem; color: var(--sub); }
.hint-fix, .plan-note { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; background: var(--raised); font-size: .84rem; line-height: 1.55; }
.plan-note { background: var(--acc-soft); border: 1px solid var(--acc-line); }
.link-b { border: 0; background: none; padding: 0; color: var(--acc-text); font: 600 .84rem var(--font); text-decoration: underline; cursor: pointer; }
.mts { display: grid; gap: 8px; }
.mt-top { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; }
.mt-top small { color: var(--sub); font-size: .72rem; }
.mt-top b { font-weight: 600; white-space: nowrap; }
.mt.low .mt-top b { color: var(--danger); }
.mt.ok .mt-top b { color: var(--ok); }
.mt.high .mt-top b { color: #f5b942; }
.mt-bar { position: relative; height: 7px; border-radius: 99px; background: var(--raised); margin-top: 3px; overflow: hidden; }
.mt-bar i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--ok); }
.mt.low .mt-bar i { background: var(--danger); }
.mt.high .mt-bar i { background: #f5b942; }
.mt-bar em { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .45; }
.mt-note { margin: 6px 0 0; font-size: .74rem; color: var(--sub); line-height: 1.5; }
.kv { display: flex; justify-content: space-between; gap: 10px; margin: 2px 0; font-size: .86rem; }
.kv span { color: var(--sub); }
.f1r .warn { margin: 6px 0 0; padding: 7px 10px; border-radius: 8px; background: var(--danger-soft); font-size: .84rem; line-height: 1.5; }
.loads, .outs, .firsts, .checks, .legend { list-style: none; margin: 6px 0 0; padding: 0; font-size: .84rem; }
.loads li.y { color: var(--ok); }
.loads li.n { color: var(--sub); text-decoration: line-through; opacity: .75; }
.outs li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.outs li span { color: var(--sub); }
.firsts b { display: inline-block; min-width: 80px; color: var(--acc-text); font-weight: 600; }
.checks li { position: relative; padding: 7px 10px 7px 28px; margin-bottom: 6px; border-radius: 8px; background: rgba(245, 185, 66, .12); line-height: 1.5; }
.checks li::before { content: "!"; position: absolute; left: 9px; top: 7px; width: 13px; height: 13px; border-radius: 50%; background: #f5b942; color: #111; font: 700 .7rem/13px var(--font); text-align: center; }
.ok-all { margin: 0; padding: 10px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend i { width: 22px; height: 4px; border-radius: 2px; }
.legend small { color: var(--sub); margin-left: auto; }

.ins-head { display: flex; gap: 10px; align-items: center; }
.ins-ico { flex: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.4rem; }
.ins-head b { display: block; }
.ins-val { margin: 8px 0 0; font-weight: 700; color: var(--acc-text); font-size: .92rem; }
.ins-note { color: var(--sub); line-height: 1.55; margin: 8px 0; }
.ins-dim { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ins-dim label, .ins-row { display: flex; flex-direction: column; gap: 3px; font-size: .78rem; color: var(--sub); margin-top: 6px; }
.ins-dim input, .ins-row select { width: 100%; min-height: 36px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--raised); color: var(--text); font: 500 .92rem var(--font); }
.ins-sub { margin: 10px 0 4px; font-weight: 600; font-size: .86rem; }
.fish { display: grid; gap: 2px; }
.fish-i { display: flex; gap: 8px; align-items: flex-start; padding: 5px 6px; border-radius: 8px; cursor: pointer; }
.fish-i:hover { background: var(--raised); }
.fish-i input { margin-top: 5px; accent-color: var(--acc); flex: none; }
.fish-i b { font-size: .84rem; }
.fish-i em { font-style: normal; color: var(--acc-text); font-size: .74rem; }
.fish-i small { display: block; color: var(--sub); font-size: .74rem; line-height: 1.4; }
.ins-act { display: flex; gap: 8px; margin-top: 12px; }
.ins-act .danger { color: var(--danger); }

.f1r-article { max-width: 880px; margin-top: 40px; }
.f1r-article .tbl { overflow-x: auto; }
.f1r-more { margin-top: 24px; }

@media (max-width: 1240px) {
  .ws-main { grid-template-columns: minmax(0, 1fr) 320px; }
  .ws-pal { grid-column: 1 / -1; order: 3; max-height: none; border-right: 0; border-top: 1px solid var(--line); }
  .ws-list { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); overflow: visible; }
  .ws-center { order: 1; }
  .ws-side { order: 2; }
  .ws-presets { margin-left: 0; }
}
@media (max-width: 900px) {
  .ws-main { grid-template-columns: minmax(0, 1fr); }
  .ws-center { order: 1; }
  .ws-pal { order: 2; }
  .ws-side { order: 3; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .ws-stage { height: auto; padding: 6px; }
  .ws-list { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 4px; scroll-snap-type: x proximity; }
  .pal-i { flex: 0 0 160px; scroll-snap-align: start; }
  .ws-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ws-strip .tile:first-child { grid-column: 1 / -1; }
  .ws-go { width: 100%; }
  .ws-bar { gap: 10px 12px; padding: 12px; }
  .ws-legend { font-size: .7rem; gap: 2px 8px; }
}

/* full screen: the workbench alone fills the screen (Fullscreen API, or a fixed layer on phones without it) */
.f1r.is-full { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; background: var(--bg); padding: 0; overflow: hidden; }
.f1r.is-full:fullscreen { background: var(--bg); }
.f1r.is-full .ws-bar { border-radius: 0; border-width: 0 0 1px; padding: 8px 12px; gap: 8px 12px; }
.f1r.is-full .ws-main { flex: 1; min-height: 0; border: 0; border-radius: 0; grid-template-rows: minmax(0, 1fr); }
.f1r.is-full .ws-pal, .f1r.is-full .ws-side { max-height: none; min-height: 0; overflow: auto; }
.f1r.is-full .ws-center { min-height: 0; }
.f1r.is-full .ws-stage { flex: 1; height: auto; min-height: 0; }
.f1r.is-full .ws-hint { display: none; }
.ib-fs { color: var(--acc-text); }
html.f1r-lock, html.f1r-lock body { overflow: hidden; }
@media (max-width: 1240px) {
  .f1r.is-full .ws-main { grid-template-rows: minmax(0, 1fr) auto; }
  .f1r.is-full .ws-pal { max-height: 30vh; }
}
@media (max-width: 900px) {
  .f1r.is-full { overflow-y: auto; }
  .f1r.is-full .ws-main { flex: none; grid-template-rows: none; }
  .f1r.is-full .ws-bar { display: none; }          /* phone: the board gets the screen; settings are one tap away */
  .f1r.is-full .ws-tools { position: sticky; top: 0; z-index: 2; background: var(--bg); }
  .f1r.is-full .ws-stage { height: auto; flex: none; }
  .f1r.is-full .ws-pal { max-height: none; }
}

/* the full-screen button sits in the top-right corner of the settings bar; inside full screen the exit button is in the board tools */
.ws-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; margin-left: auto; }
.ws-right .ws-presets { margin-left: 0; justify-content: flex-end; }
.ws-fs { height: 34px; border-color: var(--acc-line); background: var(--acc-soft); }
.ws-zoom .ib-fs { display: none; }
.f1r.is-full .ws-zoom .ib-fs { display: inline-block; }
.f1r.is-full .ws-bar .ws-fs { display: none; }
@media (max-width: 1240px) { .ws-right { margin-left: 0; width: 100%; } }

/* guide text */
.f1r-facts { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.f1r-facts li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.f1r-facts b { color: var(--acc-text); font-size: .95rem; }
.f1r-facts span { font-size: .85rem; color: var(--sub); line-height: 1.4; }
.f1r-article h2 { scroll-margin-top: 140px; }
.f1r-toc { padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 8px; }
.f1r-toc b { display: block; margin-bottom: 4px; }
.f1r-toc ol { margin: 0; padding-left: 20px; columns: 2; column-gap: 28px; font-size: .92rem; }
.f1r-toc li { break-inside: avoid; padding: 2px 0; }
.f1r-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.f1r-steps section { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.f1r-steps h3 { margin: 0 0 4px; font-size: .98rem; color: var(--acc-text); }
.f1r-steps p { margin: 0 0 6px; font-size: .88rem; color: var(--sub); }
.f1r-steps ul { margin: 0; padding-left: 18px; font-size: .9rem; }
.f1r-note { margin-top: 24px; padding: 12px 14px; border-radius: var(--r-sm); background: var(--raised); color: var(--sub); font-size: .9rem; }
@media (max-width: 760px) {
  .f1r-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f1r-steps { grid-template-columns: minmax(0, 1fr); }
  .f1r-toc ol { columns: 1; }
}
