:root {
  --bg: #0f1116;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa0aa;
  --accent: #3b82f6;
  --accent2: #2563eb;
  --ok: #34d399;
  --danger: #ef4444;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
header h1 { font-size: 19px; margin: 0; }
header .meta { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; padding: 12px 22px 0; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-bottom: none; padding: 9px 16px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line); }
.panel { display: none; padding: 22px; }
.panel.active { display: block; }
.wrap { max-width: 920px; margin: 0 auto; }

.note { display: none; background: #3a2a12; border: 1px solid #6b4e1f; color: #f4d699;
        padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
button:hover { border-color: #3a4150; }
button.primary { background: var(--accent); border-color: var(--accent2); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent2); }
button.danger { background: transparent; border-color: var(--danger); color: #fca5a5; }
.status { font-size: 13px; padding: 4px 10px; border-radius: 20px; }
.status.ok { background: rgba(52,211,153,.12); color: var(--ok); }
.status.off { background: rgba(154,160,170,.12); color: var(--muted); }

/* layout */
.editor-layout { display: grid; grid-template-columns: 320px 1fr; gap: 22px; align-items: start; }
@media (max-width: 760px) { .editor-layout { grid-template-columns: 1fr; } }

.layers { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ltab { font-size: 13px; padding: 6px 12px; }
.ltab.active { background: var(--accent); border-color: var(--accent2); color: #fff; }
.ltab.add { color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cell {
  aspect-ratio: 1 / 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 4px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; padding: 6px; text-align: center;
}
.cell:hover { border-color: #3a4150; }
.cell.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cellnum { font-size: 11px; color: var(--muted); }
.celltap { font-size: 15px; font-weight: 600; }
.cellhold { font-size: 11px; color: var(--muted); }

/* editor panel */
#editor { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
#editor h3 { margin: 0 0 10px; font-size: 15px; }
#editor .sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 6px; }
.action-editor { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.field { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.flabel { width: 84px; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.field select, .field input[type=text], .field input[type=number] {
  flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px;
}
.field textarea {
  flex: 1; min-height: 150px; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; padding: 8px; resize: vertical;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5;
}
.machelp { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.5; }
.tplrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.tpllabel { color: var(--muted); font-size: 12px; margin-right: 2px; }
.tplbtn { font-size: 12px; padding: 5px 9px; background: var(--panel); }
.tplbtn:hover { border-color: var(--accent); }
.mods { display: flex; flex-wrap: wrap; gap: 10px; }
.modlab { font-size: 13px; color: var(--text); }
.holdwrap { margin: 12px 0; font-size: 13px; color: var(--muted); }
hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* settings row */
.settings { display: flex; flex-wrap: wrap; gap: 16px; margin: 18px 0; padding: 14px; background: var(--panel);
            border: 1px solid var(--line); border-radius: var(--radius); }
.settings label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.settings input { width: 160px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 8px; }

/* log */
#log { background: #0b0d12; border: 1px solid var(--line); border-radius: 8px; padding: 10px; height: 140px;
       overflow: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: #9fb3c8; white-space: pre-wrap; margin-top: 12px; }

/* flash + help */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.card p, .card li { color: #c7ccd6; font-size: 14px; }
code { background: #0b0d12; border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
esp-web-install-button { display: inline-block; margin-top: 6px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
         background: var(--panel2); border: 1px solid var(--line); padding: 11px 18px; border-radius: 10px;
         opacity: 0; pointer-events: none; transition: .25s; font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: #fca5a5; }
