html[data-theme="night"] {
  --bg:#0b0d10; --panel:#161b22; --line:#2c3a48; --text:#e8eef4; --muted:#9aa8b5; --accent:#c9a227;
  --paper:#fff; --ink:#111; --input:#0f1419; --danger-bg:#3a1e1e; --danger-line:#7a3333;
  --tab:#243040; --tab-on:#3a5a40; --drop:#152028; --drop-hot:#1a3020; --rule:#2a3a48;
  --th:#e6e6e6; --td-even:#f3f3f3; --td-odd:#fff;
  --logo-dark:#0a1628; --logo-gold:#c9a227;
}
html[data-theme="paper"] {
  --bg:#f4efe4; --panel:#fffaf0; --line:#cbbfa8; --text:#1a1714; --muted:#5c5348; --accent:#8a5a12;
  --paper:#fff; --ink:#1a1714; --input:#fff; --danger-bg:#f8e0d8; --danger-line:#a33;
  --tab:#efe4d2; --tab-on:#d4b483; --drop:#efe8d8; --drop-hot:#e4d5b5; --rule:#d2c4aa;
  --th:#e8dfd0; --td-even:#f6f0e6; --td-odd:#fff;
  --logo-dark:#1a1714; --logo-gold:#8a5a12;
}
html[data-theme="high"] {
  --bg:#000; --panel:#111; --line:#fff; --text:#fff; --muted:#ddd; --accent:#ffe600;
  --paper:#fff; --ink:#000; --input:#000; --danger-bg:#300; --danger-line:#f00;
  --tab:#000; --tab-on:#330; --drop:#000; --drop-hot:#030; --rule:#666;
  --th:#000; --td-even:#eee; --td-odd:#fff;
  --logo-dark:#000000; --logo-gold:#ffe600;
}
html[data-theme="slate"] {
  --bg:#1c2833; --panel:#273746; --line:#5d6d7e; --text:#f4f6f7; --muted:#aab7b8; --accent:#5dade2;
  --paper:#f8fbff; --ink:#102030; --input:#1b2631; --danger-bg:#4a2323; --danger-line:#c0392b;
  --tab:#1b2631; --tab-on:#1a5276; --drop:#1b2631; --drop-hot:#145a32; --rule:#5d6d7e;
  --th:#d6eaf8; --td-even:#eaf2f8; --td-odd:#fff;
  --logo-dark:#102030; --logo-gold:#5dade2;
}
html[data-theme="sand"] {
  --bg:#3d3226; --panel:#4a3d2e; --line:#8a7358; --text:#f6ecd9; --muted:#cbb99a; --accent:#e0b15a;
  --paper:#fff8ea; --ink:#2a2118; --input:#2f261c; --danger-bg:#5a3020; --danger-line:#c0392b;
  --tab:#2f261c; --tab-on:#6b542e; --drop:#2f261c; --drop-hot:#3d4a20; --rule:#8a7358;
  --th:#ead9b8; --td-even:#f4ead6; --td-odd:#fff8ea;
  --logo-dark:#2a2118; --logo-gold:#e0b15a;
}
html, body {
  background: var(--bg, #1c2833);
  color: var(--text, #f4f6f7);
  margin: 0;
}
#ub-working{position:fixed;inset:0;display:none;align-items:center;justify-content:center;background:rgba(6,10,16,.86);z-index:9999}
#ub-working.on{display:flex}
#ub-working .ub-working-card{position:relative;text-align:center;padding:16px 18px 22px;border-radius:14px;background:#0b1220;border:1px solid #2c3a48}
#ub-working .ub-working-x{position:absolute;top:8px;right:8px;width:36px;height:36px;min-height:36px;padding:0;border:0;border-radius:8px;background:#243140;color:#fff;font-size:26px;line-height:32px;cursor:pointer}
#ub-working .ub-working-x[hidden]{display:none}
#ub-working img{width:min(560px,90vw);height:auto;display:block}
#ub-working p{margin:10px 0 0;font-size:22px;font-weight:700;color:#fff;letter-spacing:.03em}
a { color: var(--accent); }
input, select, textarea, button {
  font-size: 16px;
  min-height: 44px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}
button { cursor: pointer; }
.card, .editor-bar { background: var(--panel); border-color: var(--line); }
.sheet-editor { background: var(--paper); color: var(--ink); }
.theme-bar { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:8px 0 16px; }
.theme-bar select { width:auto; }
.tabs { overflow-x:auto; -webkit-overflow-scrolling:touch; }
@media (max-width: 720px) {
  .wrap { padding: 10px; }
  .layout, .grid, .row { display:block !important; }
  .tabs .tab { flex:1 0 auto; }
  h1.brand .brand-logo { height:36px; }
  table { display:block; overflow-x:auto; }
}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible, [contenteditable]:focus-visible {
  outline: 3px solid var(--accent, #c9a227);
  outline-offset: 2px;
}
.skip-link {
  position: absolute;
  left: 8px;
  top: -40px;
  background: var(--accent, #c9a227);
  color: #111;
  padding: 8px 12px;
  z-index: 20;
}
.skip-link:focus { top: 8px; }
img.theme-logo, h1.brand .brand-logo, .home img.brand, .ub-logo img {
  background: transparent !important;
  padding: 0;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.user-menu { position: fixed; top: 10px; right: 12px; z-index: 50; text-align: left; }
.top-tools {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100%;
  z-index: 80;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
  padding: 6px 8px;
  box-sizing: border-box;
  background: var(--bg, #0b0d10);
  border-bottom: 1px solid var(--line, #2c3a48);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.top-tools .bar-logo { height: 34px; width: auto; flex: 0 0 auto; display: block; background: transparent; }
.top-tools .user-menu { position: static; flex: 0 0 auto; }
.top-tools button, .top-tools .user-menu > summary { white-space: nowrap; font-weight: 700; min-height: 36px; padding: 6px 10px; font-size: 14px; }
body:has(.top-tools) { padding-top: var(--ub-bar, 52px); }
.loc-fold { grid-column: 1 / -1; }
.tpl-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 4px; }
.tpl-bar select, .tpl-bar input[type=text] { width: auto; min-width: 10em; flex: 1 1 140px; }
.tpl-bar button { min-height: 40px; }
body:has(.top-tools) .wrap { padding-top: 12px; }
html, body { overflow-x: clip; }
.user-menu > summary { cursor: pointer; list-style: none; background: var(--panel, #161b22); color: var(--text, #e8eef4); border: 1px solid var(--line, #2c3a48); border-radius: 8px; padding: 8px 14px; font-weight: 700; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > div { position: absolute; right: 0; margin-top: 6px; min-width: 180px; background: var(--panel, #161b22); color: var(--text, #e8eef4); border: 1px solid var(--line, #2c3a48); border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
.user-menu a { display: block; padding: 12px 14px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line, #2c3a48); }
.user-menu a:last-child { border-bottom: 0; }

.preview-fold { margin: 16px 0 8px; }
.preview-fold > summary { cursor: pointer; font-weight: 700; color: var(--text, #e8eef4); background: var(--panel, #161b22); border: 1px solid var(--line, #2c3a48); border-radius: 8px; padding: 12px 14px; }
.preview-fold[open] > summary { border-radius: 8px 8px 0 0; }
.preview-fold:not([open]) > :not(summary) { display: none !important; }
.preview-fold > .editor-wrap { margin-top: 0; }
