* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
    --ink: #1a1a1a;
    --muted: #666;
    --line: #e0e0e0;
    --bg: #f5f5f5;
    --ok: #1f8a4c;
    --danger: #c62828;
    --warn: #f9a825;
    --fs: 18px;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

#app {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: var(--vh, 100%);
    display: flex;
    flex-direction: column;
    background: #fff;
}

/* ---------- Buttons ---------- */
.btn {
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--ink);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 15px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}
.btn:active { background: var(--ink); color: #fff; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:active { background: #444; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.icon { min-width: 44px; padding: 0 8px; font-weight: 600; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #4c8dff; outline-offset: 2px; }

/* ---------- Kopfzeile ---------- */
.top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    border-bottom: 2px solid var(--line);
    background: #fafafa;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; margin-right: 4px; }
.brand strong { font-weight: 300; font-size: 20px; letter-spacing: 1px; }
.brand span { font-size: 11px; color: var(--muted); }
.spacer { flex: 1; }
.group { display: flex; flex-wrap: wrap; gap: 6px; }
.projbtn { max-width: 260px; }
.projname { overflow: hidden; text-overflow: ellipsis; max-width: 150px; font-weight: 600; }
.projbtn small { color: var(--muted); font-size: 12px; }

.protect { gap: 8px; }
.protect .dot { width: 12px; height: 12px; border-radius: 50%; background: #bbb; }
.protect.on { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.protect.on .dot { background: var(--ok); }
.protect.off { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; }
.protect.off .dot { background: #fff; }

.run { font-weight: 700; }

/* ---------- Hinweisleisten ---------- */
.banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    font-size: 14px;
    line-height: 1.4;
}
.banner > span, .banner > strong { flex: 1; }
.banner.danger { background: var(--danger); color: #fff; }
.banner.danger .btn { background: #fff; border-color: #fff; color: var(--danger); }
.banner.warn { background: #fff3cd; color: #5c4400; border-bottom: 1px solid #f0d98a; }
.banner.note { background: #eef4ff; color: #234; border-bottom: 1px solid #d3e0f7; font-size: 13px; }

/* ---------- Reiter + Bereiche ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); background: #fafafa; }
.tabs button {
    flex: 1;
    min-height: 46px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    font: inherit;
    font-size: 16px;
    cursor: pointer;
    touch-action: manipulation;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--ink); font-weight: 700; background: #fff; }

#panes { flex: 1; min-height: 0; display: flex; }
#codePane, #previewPane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#panes[data-tab="code"] #previewPane:not(.fullscreen) { display: none; }
#panes[data-tab="preview"] #codePane { display: none; }

@media (orientation: landscape) and (min-width: 820px) {
    .tabs { display: none; }
    #panes[data-tab] #codePane, #panes[data-tab] #previewPane:not(.fullscreen) { display: flex; }
    #codePane { border-right: 2px solid var(--line); }
}

/* ---------- Zeichenleiste ---------- */
.symbols {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: #f0f0f0;
    -webkit-overflow-scrolling: touch;
    flex: none;
}
.symbols .btn { min-width: 46px; padding: 0 6px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 20px; font-weight: 600; flex: none; }
.symbols .btn.wordy { font-family: inherit; font-size: 14px; padding: 0 10px; }
.symbols .sep { width: 1px; background: #ccc; margin: 4px 4px; flex: none; }

/* ---------- Editor ---------- */
#editor { flex: 1; min-height: 0; position: relative; background: #fff; }
#editor .cm-editor { height: 100%; font-size: var(--fs); background: #fff; }
#editor .cm-editor.cm-focused { outline: none; }
#editor .cm-scroller { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; overflow: auto; -webkit-overflow-scrolling: touch; }
#editor .cm-content { padding: 8px 0 40vh; }
#editor .cm-gutters { background: #fafafa; border-right: 1px solid var(--line); color: #999; }
#editor .cm-activeLine { background: #f4f6ff; }
#editor .cm-activeLineGutter { background: #eceff9; }
#editor .cm-cursor { border-left-width: 2px; }
#editor .cm-imgchip {
    display: inline-block;
    padding: 0 8px;
    margin: 0 2px;
    border: 1px solid #8fa3d6;
    border-radius: 6px;
    background: #eaf0ff;
    color: #234;
    font-size: .8em;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- Vorschau + Konsole ---------- */
.pvbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: #fafafa; flex: none; }
#frameHost { flex: 1; min-height: 0; position: relative; background: #fff; }
#frameHost iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
#frameHost .empty { padding: 28px; color: var(--muted); text-align: center; line-height: 1.6; }
#previewPane.fullscreen { position: fixed; inset: 0; z-index: 40; background: #fff; display: flex !important; }

.console { flex: none; border-top: 2px solid var(--line); background: #1e1e24; color: #e8e8f0; }
.conbar { display: flex; align-items: center; gap: 8px; padding: 4px 8px; background: #fafafa; border-bottom: 1px solid var(--line); }
.badge { display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 11px; background: var(--danger); color: #fff; font-size: 12px; text-align: center; }
#consoleLog { height: 160px; overflow: auto; padding: 6px 0; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; -webkit-overflow-scrolling: touch; }
.console.collapsed #consoleLog { display: none; }
#consoleLog .line { padding: 2px 12px; white-space: pre-wrap; overflow-wrap: anywhere; border-bottom: 1px solid #2c2c34; }
#consoleLog .line.error { background: #4a1f24; color: #ffb4b4; }
#consoleLog .line.warn { background: #43391a; color: #ffe08a; }
#consoleLog .line.info, #consoleLog .line.debug { color: #9fc7ff; }
#consoleLog .line.sys { color: #a8a8c0; font-style: italic; }

/* ---------- Fußzeile ---------- */
.site-footer {
    flex: none;
    padding: 6px 14px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #fafafa;
    font-size: 11px;
    color: #888;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 16px;
}
.site-footer a { color: #888; text-decoration: none; }
.site-footer a:hover { color: var(--ink); }
.site-footer .links { display: flex; gap: 16px; }

/* ---------- Dialoge ---------- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, .5);
    display: flex; align-items: center; justify-content: center;
    padding: 12px;
}
.sheet {
    width: 100%; max-width: 580px; max-height: 92%;
    display: flex; flex-direction: column;
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .35);
    overflow: hidden;
}
.sheet.danger { border: 3px solid var(--danger); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; font-weight: 600; }
.sheet.danger .sheet-head h2 { color: var(--danger); }
.sheet-body { padding: 16px 18px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.sheet-body p { line-height: 1.5; }
.hint { font-size: 13px; color: var(--muted); }
.warnlist { margin-left: 20px; line-height: 1.5; }
.warnlist li { margin-bottom: 8px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.actions.col { flex-direction: column; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row label { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
select, input[type="text"] { min-height: 44px; padding: 0 10px; border: 1px solid #aaa; border-radius: 8px; font: inherit; font-size: 16px; background: #fff; color: var(--ink); width: 100%; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; line-height: 1.4; cursor: pointer; }
.check input { width: 26px; height: 26px; flex: none; margin-top: 1px; }
.check small { color: var(--muted); }
code { background: #eee; padding: 3px 8px; border-radius: 4px; font-size: 14px; overflow-wrap: anywhere; }

.plist { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: stretch; gap: 6px; }
.plist .open { flex: 1; min-width: 0; justify-content: flex-start; text-align: left; flex-direction: column; align-items: flex-start; gap: 0; padding: 6px 12px; }
.plist .open b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.plist .open small { color: var(--muted); font-size: 12px; }
.plist li.current .open { border-width: 3px; }

.snipgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.snip { flex-direction: column; align-items: flex-start; gap: 2px; white-space: normal; text-align: left; padding: 12px; min-height: 84px; justify-content: flex-start; }
.snip .ic { font-size: 24px; }
.snip b { font-weight: 600; }
.snip small { color: var(--muted); font-size: 13px; }
.snip:active small { color: #ddd; }

.imgprev { border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.imgprev img { max-width: 100%; max-height: 180px; }

#toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    z-index: 200; max-width: 90%;
    background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px;
    font-size: 15px; line-height: 1.4; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

@media (max-width: 700px) {
    .brand span { display: none; }
    .btn { padding: 0 10px; }
}
