/* HTML Editor Online — page + IDE styles. Colours meet WCAG AA contrast on their backgrounds. */
:root {
  --page-bg: #f1f5f9; --page-ink: #0f172a; --page-ink2: #334155; --page-muted: #475569; --page-line: #e2e8f0; --link: #0058b0;
  --ide-bg: #0b1220; --ide-panel: #111a2e; --ide-panel2: #16213a; --ide-line: #24324f; --ide-ink: #e5ecf6; --ide-muted: #a3b3cc;
  --accent: #38bdf8; --primary: #2563eb; --primary-ink: #ffffff; --ok: #34d399; --warn: #fbbf24; --err: #f87171;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --rail: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); background: var(--page-bg); color: var(--page-ink); line-height: 1.5; }
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
[hidden] { display: none !important; }

/* ---------- site header ---------- */
.site-hdr { background: var(--ide-bg); border-bottom: 1px solid var(--ide-line); }
.site-hdr-in { max-width: 1680px; margin: auto; padding: 0 16px; height: 48px; display: flex; align-items: center; gap: 18px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-text span { color: var(--accent); }
.brand .brand-logo { width: 26px; height: 26px; border-radius: 7px; display: inline-grid; place-items: center; font-size: 12px; color: #fff; background: linear-gradient(135deg, #0ea5e9, #8b5cf6); }
.site-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.site-nav > a, .nav-more-btn { white-space: nowrap; color: #cbd5e1; text-decoration: none; font-size: 14px; font-weight: 600; padding: 6px 10px; border-radius: 6px; background: none; border: 0; cursor: pointer; font-family: inherit; }
.site-nav > a:hover, .nav-more-btn:hover { background: var(--ide-panel2); color: #fff; }
.site-nav > a[aria-current="page"] { color: #fff; background: var(--ide-panel2); }
.nav-more { position: relative; }
.nav-more-menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--page-line); border-radius: 10px; box-shadow: 0 12px 30px rgba(15,23,42,.18); padding: 6px; min-width: 230px; z-index: 60; }
.nav-more-menu a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--page-ink); text-decoration: none; font-size: 14px; }
.nav-more-menu a:hover, .nav-more-menu a:focus { background: #eff6ff; }

/* ---------- intro + page grid ---------- */
main { max-width: 1680px; margin: auto; padding: 0 16px; }
.intro { padding: 12px 0 10px; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.intro h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.intro p { margin: 0; color: var(--page-muted); font-size: 14px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--rail); gap: 18px; align-items: start; }

/* ---------- ad rail (blank, reserved; no ad code) ---------- */
.ad-rail { position: sticky; top: 12px; }
.ad-slot { width: var(--rail); height: 600px; border: 1px dashed #cbd5e1; border-radius: 10px; background: #fff; display: flex; align-items: flex-start; justify-content: center; }
.ad-slot { position: relative; overflow: hidden; }
.ad-label { position: absolute; top: 6px; left: 0; right: 0; text-align: center; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #64748b; pointer-events: none; }
/* Second slot: below the whole workspace, above the explanatory content. Height is reserved (no layout shift). */
.ad-below { margin-top: 18px; }
.ad-slot.ad-wide { width: 100%; height: 250px; }
@media (max-width: 1279px) { :root { --rail: 250px; } }
@media (max-width: 1099px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* No side rail below 1100px: the below-workspace slot is the only ad. */
  .ad-rail { display: none; }
  .ad-below { display: flex; justify-content: center; }
  .ad-slot.ad-wide { width: 100%; max-width: 728px; height: 250px; }
}
@media (max-width: 768px) { .ad-slot.ad-wide { max-width: 336px; height: 280px; } }

/* ---------- application ---------- */
.app { position: relative; background: var(--ide-bg); color: var(--ide-ink); border: 1px solid var(--ide-line); border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column; height: clamp(540px, calc(100vh - 118px), 980px); }
.menubar { display: flex; gap: 2px; padding: 4px 6px; background: var(--ide-panel); border-bottom: 1px solid var(--ide-line); overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.menubar::-webkit-scrollbar { display: none; }
.menu { position: relative; }
.menu > button { background: none; border: 0; color: var(--ide-ink); font: 600 13px var(--sans); padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.menu > button:hover, .menu > button[aria-expanded="true"] { background: var(--ide-panel2); }
.menu-list { position: fixed; min-width: 240px; max-height: 70vh; overflow: auto; background: #0f1a30; border: 1px solid var(--ide-line); border-radius: 10px; padding: 5px; box-shadow: 0 16px 40px rgba(0,0,0,.45); z-index: 80; }
.menu-list button { display: flex; width: 100%; justify-content: space-between; gap: 18px; background: none; border: 0; color: var(--ide-ink); font: 13px var(--sans); text-align: left; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover, .menu-list button:focus { background: #1d2b4a; outline: none; }
.menu-list button kbd { font: 11px var(--mono); color: var(--ide-muted); }
.menu-list hr { border: 0; border-top: 1px solid var(--ide-line); margin: 4px 2px; }
.menu-list .menu-check::before { content: "✓ "; color: var(--ok); }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--ide-line); background: var(--ide-panel); flex-wrap: wrap; flex-shrink: 0; }
.tb-spacer { flex: 1; }
.seg { display: inline-flex; background: var(--ide-bg); border: 1px solid var(--ide-line); border-radius: 8px; padding: 2px; }
.seg-btn { background: none; border: 0; color: var(--ide-muted); font: 600 12px var(--sans); padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--ide-panel2); color: #fff; box-shadow: inset 0 0 0 1px #33456b; }
.btn { background: var(--ide-panel2); color: var(--ide-ink); border: 1px solid var(--ide-line); font: 600 12px var(--sans); padding: 6px 11px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3b5282; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #1d4ed8; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.kbd { font: 10px var(--mono); margin-left: 4px; }
.icon-btn { background: none; border: 1px solid transparent; color: var(--ide-ink); font-size: 15px; width: 32px; height: 30px; border-radius: 7px; cursor: pointer; }
.icon-btn:hover { border-color: var(--ide-line); background: var(--ide-panel2); }

.workspace { flex: 1; min-height: 0; display: flex; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.code-pane { flex: 0 0 55%; }
.preview-pane { flex: 1 1 45%; background: var(--ide-panel); }
.workspace.layout-code .preview-pane, .workspace.layout-code .splitter { display: none; }
.workspace.layout-code .code-pane { flex: 1 1 auto !important; }
.workspace.layout-preview .code-pane, .workspace.layout-preview .splitter { display: none; }
.splitter { flex: 0 0 6px; background: var(--ide-line); cursor: col-resize; touch-action: none; }
.splitter:hover, .splitter.dragging { background: var(--accent); }

.filetabs { display: flex; align-items: stretch; background: var(--ide-panel); border-bottom: 1px solid var(--ide-line); min-height: 34px; overflow-x: auto; scrollbar-width: none; }
.filetab { background: none; border: 0; border-right: 1px solid var(--ide-line); color: var(--ide-muted); font: 12px var(--mono); padding: 0 14px; cursor: pointer; white-space: nowrap; }
.filetab[aria-selected="true"] { background: var(--ide-bg); color: #fff; box-shadow: inset 0 2px 0 var(--accent); }
.filetab-note { margin-left: auto; align-self: center; padding: 0 10px; font-size: 11px; color: var(--ide-muted); white-space: nowrap; }
.code-wrap { position: relative; flex: 1; min-height: 0; }
.code { position: absolute; inset: 0; font-size: 14px; }
.code-placeholder { position: absolute; inset: 0; margin: 0; padding: 4px 8px 0 52px; font: 14px/18px var(--mono); color: var(--ide-muted); background: var(--ide-bg); white-space: pre-wrap; overflow: hidden; }

.visual-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--ide-panel); }
.vtoolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--ide-line); }
.vtoolbar button, .vtoolbar select { background: var(--ide-panel2); color: var(--ide-ink); border: 1px solid var(--ide-line); border-radius: 6px; font: 12px var(--sans); padding: 4px 8px; min-width: 30px; cursor: pointer; }
.vnote { margin: 0; padding: 6px 10px; font-size: 12px; color: #fde68a; background: #3a2e0c; border-bottom: 1px solid #5c4812; }
.visual-wrap iframe { flex: 1; width: 100%; border: 0; background: #fff; }

.preview-bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-bottom: 1px solid var(--ide-line); min-height: 34px; flex-wrap: wrap; }
.preview-bar select, .custom-vp input { background: var(--ide-bg); color: var(--ide-ink); border: 1px solid var(--ide-line); border-radius: 6px; font: 12px var(--sans); padding: 4px 6px; }
.custom-vp input { width: 70px; }
.dims { font: 11px var(--mono); color: var(--ide-muted); white-space: nowrap; }
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; background: #fff; }
.stage.device { background: repeating-linear-gradient(45deg, #0e172b, #0e172b 10px, #111d35 10px, #111d35 20px); display: flex; justify-content: center; align-items: flex-start; padding: 12px; }
.shell { width: 100%; height: 100%; background: #fff; }
.stage.device .shell { flex-shrink: 0; transform-origin: top center; border-radius: 10px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.shell iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.stage:fullscreen { padding: 0; }

.panel { flex-shrink: 0; border-top: 1px solid var(--ide-line); background: var(--ide-panel); display: flex; flex-direction: column; height: 165px; }
.panel.collapsed { height: 36px; }
.panel.collapsed .panel-body { display: none; }
.panel-tabs { display: flex; align-items: center; gap: 2px; padding: 0 4px; min-height: 36px; border-bottom: 1px solid var(--ide-line); overflow-x: auto; scrollbar-width: none; }
.ptabs { display: flex; gap: 2px; }
.ptab { background: none; border: 0; color: var(--ide-muted); font: 600 12px var(--sans); padding: 8px 10px; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; }
.ptab[aria-selected="true"] { color: #fff; border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: #7f1d1d; color: #fff; font-size: 10px; margin-left: 4px; }
.badge.warn { background: #78350f; }
.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 10px; font-size: 13px; }
.pview ul { list-style: none; margin: 0; padding: 0; }
.row { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid #1a2744; font-size: 12.5px; align-items: flex-start; }
.row .tag { font: 700 10px var(--mono); padding: 1px 6px; border-radius: 4px; flex-shrink: 0; margin-top: 2px; }
.row .msg { font-family: var(--mono); white-space: pre-wrap; word-break: break-word; flex: 1; }
.tag.log, .tag.info { background: #1e3a5f; color: #bfdbfe; }
.tag.warn { background: #4a3710; color: #fde68a; }
.tag.error, .tag.err { background: #4c1d1d; color: #fecaca; }
.tag.ok { background: #14432f; color: #bbf7d0; }
.empty { color: var(--ide-muted); font-style: italic; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--ide-muted); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-word; }
.seo-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.serp { background: #fff; color: #202124; border-radius: 8px; padding: 12px; font-family: arial, sans-serif; }
.serp .u { font-size: 12px; color: #4d5156; }
.serp .t { font-size: 18px; color: #1a0dab; margin: 2px 0; }
.serp .d { font-size: 13px; color: #4d5156; }
.card { background: #fff; color: #0f172a; border-radius: 8px; overflow: hidden; margin-top: 10px; }
.card .img { height: 120px; background: #e2e8f0; display: grid; place-items: center; color: #475569; font-size: 12px; }
.card .img img { width: 100%; height: 100%; object-fit: cover; }
.card .b { padding: 8px 10px; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--ide-panel2); border: 1px solid var(--ide-line); border-radius: 8px; padding: 8px; }
.stat b { display: block; font: 700 18px var(--mono); color: #fff; }
.stat span { font-size: 11px; color: var(--ide-muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 92px; border: 1px solid var(--ide-line); border-radius: 8px; overflow: hidden; background: var(--ide-panel2); color: var(--ide-ink); font: 11px var(--mono); cursor: pointer; padding: 0; }
.swatch i { display: block; height: 30px; }
.swatch span { display: block; padding: 3px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid #1a2744; font-size: 12.5px; }
.hist-row .btn { padding: 3px 8px; }

.statusbar { display: flex; gap: 14px; align-items: center; padding: 0 10px; height: 24px; background: #0a2a4a; color: #dbeafe; font: 11px var(--mono); flex-shrink: 0; white-space: nowrap; overflow: hidden; }
.drop { position: absolute; inset: 0; background: rgba(37,99,235,.18); border: 3px dashed var(--accent); display: none; align-items: center; justify-content: center; font-weight: 700; color: #fff; z-index: 50; }
.app.dragging .drop { display: flex; }
.app:fullscreen { height: 100vh; border-radius: 0; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--page-line); border-radius: 12px; padding: 0; max-width: min(720px, calc(100vw - 32px)); width: 100%; box-shadow: 0 24px 60px rgba(15,23,42,.35); color: var(--page-ink); }
dialog::backdrop { background: rgba(15,23,42,.55); }
.dlg-form { padding: 18px; }
.dlg-form h2 { margin: 0 0 10px; font-size: 18px; }
.dlg-form p, .dlg-form li { font-size: 14px; color: var(--page-ink2); }
.dlg-form textarea, .dlg-form input[type=text], .dlg-form input[type=url] { width: 100%; font: 13px var(--mono); border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px; }
.dlg-form textarea { height: 260px; resize: vertical; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.dlg-actions button { font: 600 14px var(--sans); padding: 8px 14px; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; cursor: pointer; color: var(--page-ink); }
.dlg-actions button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.dlg-actions button.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.tpl-grid button { text-align: left; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; padding: 10px; cursor: pointer; font: 14px var(--sans); color: var(--page-ink); }
.tpl-grid button b { display: block; margin-bottom: 2px; }
.tpl-grid button span { font-size: 12px; color: var(--page-muted); }
.shortcuts { width: 100%; border-collapse: collapse; font-size: 14px; }
.shortcuts td { padding: 6px 8px; border-bottom: 1px solid var(--page-line); }
.shortcuts td:last-child { font-family: var(--mono); white-space: nowrap; }

/* ---------- content below the tool ---------- */
.content { max-width: 920px; padding: 30px 0 10px; }
.content h2 { font-size: 22px; margin: 26px 0 8px; }
.content h3 { font-size: 16px; margin: 16px 0 4px; }
.content p, .content li { color: var(--page-ink2); font-size: 16px; }
.content code { font-family: var(--mono); font-size: .88em; background: #e2e8f0; padding: 1px 5px; border-radius: 4px; }
.table-wrap { overflow-x: auto; }
.content table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--page-line); border-radius: 10px; font-size: 14px; }
.content th, .content td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--page-line); vertical-align: top; }
.content th { background: #0f172a; color: #fff; }
.site-ftr { text-align: center; padding: 26px 16px 40px; font-size: 14px; color: var(--page-muted); border-top: 1px solid var(--page-line); margin-top: 30px; }
.noscript { padding: 16px; background: #fff7ed; color: #9a3412; }

/* ---------- mobile ---------- */
@media (max-width: 768px) {
  .site-hdr-in { gap: 10px; }
  .site-nav > a:not([aria-current]) { display: none; }
  .site-nav > a, .nav-more-btn { font-size: 13px; padding: 6px 8px; }
  .brand { font-size: 15px; }
  .filetab-note { display: none; }
  .preview-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .preview-bar > * { flex-shrink: 0; }
  .preview-bar select { max-width: 130px; }
  .intro h1 { font-size: 19px; }
  .intro p { font-size: 13px; }
  .app { height: auto; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex-shrink: 0; }
  .workspace { flex-direction: column; }
  .code-pane { flex: none !important; width: auto !important; height: 330px; }
  .preview-pane { flex: none; height: 380px; }
  .workspace.layout-code .code-pane { height: 520px; }
  .workspace.layout-preview .preview-pane { height: 560px; }
  .splitter { display: none; }
  .panel { height: 220px; }
  .panel.collapsed { height: 36px; }
  .seo-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .statusbar #stPos, .statusbar #stFile { display: none; }
}

/* ---------- v1.1: small-screen menu, scroll hints, plain-text fallback ---------- */
.menu-all { display: none; }
.menu-head { font: 700 10px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ide-muted); padding: 8px 10px 3px; }
.more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
.code-fallback { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; border: 0; resize: none; padding: 6px 10px; background: var(--ide-bg); color: var(--ide-ink);
  font: 14px/1.5 var(--mono); tab-size: 2; white-space: pre-wrap; outline: none; }
.code-fallback:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
@media (max-width: 640px) {
  .menu:not(.menu-all) { display: none; }
  .menu-all { display: block; }
  .toolbar #btnRun { order: -2; }
  .toolbar .seg:has([data-layout]) { order: -1; }
  .toolbar .tb-spacer { display: none; }
}
