:root {
  --bg: #1b1d20;
  --panel: #25282c;
  --panel-2: #2e3238;
  --line: #3d424a;
  --text: #e6e6e6;
  --dim: #9aa0a8;
  --accent: #f0a33a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* so display rules like .row { display: flex } can't defeat the attribute */
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:active { background: #3a3f47; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 12px; }

#app { display: flex; height: 100%; }
#panel { width: 264px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 12px; overflow-y: auto; }
.toolbar { display: flex; gap: 8px; }
.toolbar button { flex: 1; }
h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
h3 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
.group-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 4px; }
.group-label:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, 44px); gap: 6px; }
.grid.modules { grid-template-columns: none; grid-template-rows: repeat(3, 44px); grid-auto-flow: column; grid-auto-columns: 44px; }   /* a column per kind, tier 1 at the top */
.tile { width: 44px; height: 44px; display: grid; place-items: center; background: var(--panel-2);
  border: 2px solid var(--line); border-radius: 6px; cursor: grab; user-select: none; -webkit-user-select: none;
  touch-action: pan-y; }
.tile:hover { border-color: var(--accent); }
.solve { display: flex; flex-direction: column; gap: 8px; margin-top: -4px; }   /* sits right under Save / Load / Clear */
button.primary { background: #4a3a20; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #5a4626; }
button:disabled { opacity: .5; cursor: progress; }
#footer { margin-top: auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; flex: none; }
#plant { font-size: 11px; line-height: 1.35; color: var(--dim); min-width: 0; min-height: 30px; white-space: nowrap; }
#plant b { color: var(--text); font-weight: 600; }
#helpWrap { position: relative; flex: none; }
#helpBtn { width: 26px; height: 26px; padding: 0; border-radius: 50%; line-height: 1; font-weight: 700; color: var(--dim); }
#helpBtn:hover { color: var(--text); border-color: var(--accent); }
#helpTip { position: fixed; left: 276px; bottom: 12px; width: min(380px, calc(100vw - 292px)); max-height: calc(100vh - 24px); overflow-y: auto;
  background: rgba(15, 16, 18, .97); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; z-index: 40; box-shadow: 0 4px 16px rgba(0, 0, 0, .5); }
#helpTip ul { margin: 0; padding-left: 16px; color: var(--dim); font-size: 12px; }
#helpTip li { margin: 3px 0; }

#stage { position: relative; flex: 1; min-width: 0; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center;
  color: var(--dim); pointer-events: none; padding: 0 16px; }
#zoomctl { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 6px; }
#zoomctl button { min-width: 36px; padding: 6px 10px; background: rgba(37, 40, 44, .92); }
#mode { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 270px); text-align: center;
  background: rgba(15, 16, 18, .93); border: 1px solid var(--line); border-radius: 999px; padding: 6px 16px; font-size: 12px;
  pointer-events: none; z-index: 5; }
#watch { position: absolute; top: 12px; right: 12px; width: 210px; display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100% - 64px); overflow-y: auto; pointer-events: none; z-index: 4; }
.wcard { pointer-events: auto; background: rgba(28, 30, 34, .94); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 6px 8px 7px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.wcard:hover { border-color: #4aa8e8; }
.whead { display: flex; align-items: center; gap: 7px; }
.wtitle { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wx { padding: 0 6px; line-height: 1.2; font-size: 17px; background: transparent; border: 0; color: var(--dim); }
.wx:hover { color: #fff; border: 0; }
.wsub { color: var(--dim); font-size: 11px; margin: 2px 0 0 29px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wval { margin-left: 29px; display: flex; align-items: baseline; gap: 8px; }
.wval b { font-size: 18px; }
.wdelta { font-size: 11px; color: var(--dim); }
.wline { display: flex; align-items: center; gap: 6px; margin: 3px 0 0 29px; font-size: 12px; }
@media (max-width: 720px) { #watch { width: 160px; } }
#tip { position: absolute; pointer-events: none; background: rgba(15, 16, 18, .95); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 9px; font-size: 12px; max-width: 280px; white-space: pre-line; z-index: 5; }
#error { position: absolute; left: 16px; right: 16px; top: 16px; background: #5a2323; border: 1px solid #a33;
  border-radius: 6px; padding: 10px 14px; }

.ico { display: inline-block; position: relative; flex: none; background-image: url(sprites.png); background-repeat: no-repeat; }
.ico[data-n]::after { content: attr(data-n); position: absolute; right: -3px; bottom: -4px; font-size: 10px; line-height: 1;
  color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000; font-weight: 600; }
#ghost { position: fixed; pointer-events: none; z-index: 20; opacity: .85; transform: translate(-50%, -50%); }

#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 30; padding: 16px; }
#modal[hidden] { display: none; }
.dlg { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: min(640px, 100%);
  max-height: min(80vh, 100%); display: flex; flex-direction: column; overflow: hidden; }
.dlg header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-weight: 600;
  border-bottom: 1px solid var(--line); }
.dlg header button { padding: 0 8px; font-size: 20px; line-height: 1.3; }
#fuelRow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px 0; }
#fuelRow[hidden], #rateRow[hidden], #opRow[hidden], #freeRow[hidden] { display: none; }
#freeRow { padding: 10px 14px 0; }
#freeRow label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
#opRow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px 0; }
#opRow .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
#opBtns { display: flex; gap: 6px; flex-wrap: wrap; }
#opBtns button.sel { border-color: var(--accent); background: #4a3a20; }
#rateRow { display: flex; align-items: center; gap: 10px; padding: 10px 14px 0; }
#rateRow .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
#rateInput { width: 110px; padding: 5px 8px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; }
#rateInput:focus { outline: none; border-color: var(--accent); }
#fuelRow .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
#fuelChips { display: flex; gap: 4px; flex-wrap: wrap; }
#fuelChips button { padding: 3px; line-height: 0; border-width: 2px; }
#fuelChips button.sel { border-color: var(--accent); background: #4a3a20; }
#fuelName { color: var(--dim); font-size: 12px; }
#search { margin: 10px 14px; padding: 8px 10px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; }
#search:focus { outline: none; border-color: var(--accent); }
#recipeList { overflow-y: auto; padding: 0 8px 10px; }
.row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; flex-wrap: wrap; }
.row:hover { background: var(--panel-2); }
.row.current { outline: 1px solid var(--accent); }
.row .nm { flex: 1 1 150px; min-width: 0; }
.row .flow { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.row .arrow { color: var(--dim); }
.row .time { color: var(--dim); font-size: 11px; margin-right: 2px; }
.empty { padding: 14px; color: var(--dim); text-align: center; }

/* Narrow screens: panel moves to the bottom so the canvas keeps most of the space */
@media (max-width: 720px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; height: 36%; border-right: 0; border-top: 1px solid var(--line);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  #helpTip { left: 12px; bottom: calc(36% + 8px); width: calc(100vw - 24px); }
  #zoomctl { bottom: 12px; }
}
