:root, html[data-theme="hud"] {
  --bg: #071018;
  --ink: #e8f6ff;
  --muted: #8eabc0;
  --panel: rgba(10, 22, 36, 0.78);
  --line: color-mix(in srgb, var(--accent) 78%, #fff 0%);
  --grid: rgba(120, 190, 220, 0.16);
  --accent: #e25c12;
  --card: rgba(255, 255, 255, 0.04);
  --danger: #ff5a4a;
  --ok: #7dffb3;
  --warn: #ffd166;
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #efe6d6;
  --ink: #1c2430;
  --muted: #5c6b7a;
  --panel: rgba(247, 243, 234, 0.92);
  --grid: rgba(28, 36, 48, 0.12);
  --card: rgba(255, 255, 255, 0.45);
  color-scheme: light;
}
html[data-theme="contrast"] {
  --bg: #000;
  --ink: #fff;
  --muted: #fff;
  --panel: #000;
  --grid: rgba(255, 255, 0, 0.28);
  --card: #000;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  font: 16px/1.45 var(--kp-font), Outfit, "Noto Sans", "Noto Sans Arabic", "Noto Sans Ethiopic", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  background-attachment: fixed;
  scroll-padding-bottom: 72px;
}
button, input, select { font: inherit; color: inherit; }
button { min-height: 48px; min-width: 48px; }
html.big-type { font-size: 20px; }
html.big-type .num { font-size: 2.5rem; }
html.is-projector { font-size: 22px; }
html.is-projector .num { font-size: 3.2rem; }
html.is-projector .top, html.is-projector .dock, html.is-projector .sheet { display: none !important; }
.proj-exit { display: none; }
html.is-projector .proj-exit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 80;
  min-width: 72px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  color: var(--ink);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 65%, transparent);
}
html.is-classic #app { display: none; }
html.is-classic .classic-frame { display: block; }
.classic-frame { display: none; position: fixed; inset: 0; width: 100%; height: 100%; border: 0; z-index: 5; background: #0e2744; }
html[data-kb-bar="1"]:not(.kb-framed) .top { top: 48px; padding-right: 16px; }
html.is-projector .kb-bar { display: none !important; }
html.is-projector body.kb-on { padding-top: 0; }
@media (max-width: 720px) {
  html[data-kb-bar="1"]:not(.kb-framed) .top { padding-right: 12px; }
}
.top {
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 15.5rem 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; overflow: hidden; flex: 1; }
.brand h1 { margin: 0; font-size: 1.35rem; font-weight: 750; letter-spacing: 0.01em; }
.ver, .who { color: var(--muted); font-size: 0.92rem; }
.who { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 720px) {
  .top { align-items: flex-start; padding: 8px 13.5rem 8px 12px; min-height: 72px; }
  .brand { flex-wrap: wrap; row-gap: 0; }
  .brand h1 { font-size: 1.15rem; flex: 1 0 100%; }
}
.board { position: relative; width: 100%; max-width: 100%; min-height: calc(100vh - 64px); direction: ltr; }
.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 0 22px color-mix(in srgb, var(--accent) 42%, transparent), inset 0 1px 0 rgba(255,255,255,.18);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  will-change: transform;
  animation: tile-in .45s ease both;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(155deg, rgba(255,255,255,.18), transparent 42%);
  z-index: 2;
}
.board .tile:nth-child(2) { animation-delay: .04s; }
.board .tile:nth-child(3) { animation-delay: .08s; }
.board .tile:nth-child(4) { animation-delay: .12s; }
.board .tile:nth-child(5) { animation-delay: .16s; }
.board .tile:nth-child(6) { animation-delay: .2s; }
@keyframes tile-in { from { opacity: 0; } to { opacity: 1; } }
.tile:hover {
  box-shadow: 0 0 0 1px var(--accent), 0 0 32px color-mix(in srgb, var(--accent) 62%, transparent), inset 0 1px 0 rgba(255,255,255,.22);
}
html[data-theme="contrast"] .tile { border-width: 3px; backdrop-filter: none; box-shadow: none; }
.tile.dragging { z-index: 5; }
.tile-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 8px 0 12px;
  cursor: grab;
  touch-action: none;
  background: var(--card);
}
.tile-bar h2 { margin: 0; flex: 1; min-width: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-bar button, .grip {
  min-width: 48px;
  min-height: 48px;
  border: 0;
  background: transparent;
  border-radius: 12px;
}
.tile-bar button[aria-pressed="true"] { color: var(--accent); }
.body { flex: 1; min-height: 0; overflow: auto; padding: 8px 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.grip {
  position: absolute;
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
  touch-action: none;
  background:
    linear-gradient(135deg, transparent 50%, var(--accent) 50%, var(--accent) 62%, transparent 62%, transparent 70%, var(--accent) 70%, var(--accent) 78%, transparent 78%);
}
.dock {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 30;
  display: flex;
  flex-wrap: nowrap;
  direction: ltr;
  gap: 6px;
  align-items: center;
  height: 52px;
  padding: 0 8px;
  max-width: none;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 28%, transparent);
}
.dock button {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plus { flex: 0 0 44px; width: 44px; height: 44px; min-width: 44px; border-radius: 50%; font-size: 1.6rem; line-height: 1; padding: 0; }
.dock button, .btn, .key, .tick, .segpiece, .lane button {
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--panel) 80%, #000 20%);
  border-radius: 14px;
  padding: 0 14px;
  min-height: 48px;
}
.dock > button { min-height: 44px; height: 44px; padding: 0 8px; }
.dock button[aria-pressed="true"], .seg button[aria-pressed="true"] { outline: 2px solid var(--accent); }
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); }
.panel {
  position: absolute;
  inset-inline-start: 12px;
  top: 12px;
  bottom: 12px;
  width: min(440px, calc(100vw - 24px));
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 12px 14px 24px;
}
.panel h2 { margin: 8px 0; }
.panel label, .field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 0.92rem; color: var(--muted); }
.panel input, .panel select, .body input, .body select {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  background: var(--card);
  padding: 0 12px;
  width: 100%;
}
input[type="range"] { padding: 0; accent-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.num {
  margin: 4px 0;
  font-size: 1.8rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-shadow: 0 0 16px color-mix(in srgb, var(--accent) 75%, transparent);
}
.note { color: var(--muted); font-size: 0.85rem; margin: 4px 0; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; flex: 1 1 auto; min-height: 0; align-content: stretch; grid-auto-rows: minmax(44px, 1fr); }
.key { padding: 0; min-height: 44px; height: 100%; }
.tape-scroll { overflow-x: auto; overflow-y: hidden; max-width: 100%; border-radius: 12px; background: #102033; }
html[data-theme="light"] .tape-scroll { background: #f7f3ea; }
.tape { display: flex; align-items: flex-end; height: 148px; }
.tick {
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  height: 52px;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  border: 0;
  border-left: 2px solid var(--accent);
  background: transparent;
  position: relative;
  align-self: flex-end;
}
.tick.half { height: 96px; border-left-width: 3px; }
.tick.inch { height: 140px; border-left-width: 4px; }
.tick span { position: absolute; top: 6px; left: 4px; font-size: 0.75rem; }
.tick.lit { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.stick { display: flex; min-height: 48px; height: auto; width: 100%; border-radius: 8px; overflow-x: auto; overflow-y: hidden; background: rgba(255,255,255,.06); margin: 4px 0 10px; }
.segpiece { border-radius: 0; min-width: 44px; min-height: 44px; flex: 0 0 auto; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.segpiece.cut { opacity: 0.45; text-decoration: line-through; }
.kerf { background: #e25c12; min-width: 3px; }
.waste { background: repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255,255,255,.15) 4px, rgba(255,255,255,.15) 6px); }
.scene { width: 140px; height: 140px; margin: 8px auto; perspective: 640px; }
.cube { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.2,.7,.2,1); }
.face {
  position: absolute; inset: 0;
  border: 2px solid var(--accent);
  border-radius: 14px;
  background: rgba(0,0,0,.45);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 14px;
  backface-visibility: hidden;
}
.pip { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); margin: auto; }
.rotor {
  width: min(100%, 220px);
  aspect-ratio: 1;
  border-radius: 50%;
  margin: 12px auto;
  border: 4px solid var(--accent);
  transition: transform 1.6s cubic-bezier(.15,.7,.1,1);
}
.pointer { width: 0; height: 0; margin: 0 auto; border-left: 10px solid transparent; border-right: 10px solid transparent; border-top: 16px solid var(--accent); }
.rollbed { height: 110px; position: relative; overflow: hidden; border-bottom: 3px solid var(--muted); }
.wheel {
  width: 84px; height: 84px; border-radius: 50%;
  border: 6px solid var(--accent);
  background:
    radial-gradient(circle at 50% 50%, transparent 8px, var(--ink) 9px, var(--ink) 12px, transparent 13px),
    repeating-conic-gradient(from 0deg, var(--accent) 0 12deg, transparent 12deg 30deg);
  position: absolute; top: 16px; left: 8px;
}
.ringwrap { display: grid; place-items: center; flex: 1 1 120px; min-height: 120px; color: var(--accent); }
.ringwrap svg { width: auto; height: 100%; max-width: 100%; max-height: 100%; filter: drop-shadow(0 0 8px var(--accent)); }
.fig, .mat, .pro, .gearbox { color: var(--accent); }
.gearbox { width: 100%; height: 180px; flex: 1 1 140px; min-height: 140px; }
.gearbox svg { width: 100%; height: 100%; }
.gearbox path { fill: color-mix(in srgb, var(--accent) 32%, transparent); }
.mat { background: rgba(255,255,255,.04); border-radius: 8px; }
.boom { color: var(--danger); }
html:not(.is-reduced) .shake { animation: buzz .35s linear 3; }
@keyframes buzz {
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
.meter { height: 36px; border-radius: 999px; overflow: hidden; display: flex; background: #102033; }
.meter i { display: block; height: 100%; }
.meter .c { width: 45%; background: #1f8a4c; }
.meter .l { width: 30%; background: #c9841a; }
.meter .h { width: 25%; background: #a32020; }
.needle { height: 18px; width: 18px; border-radius: 50%; background: #fff; margin-top: -27px; box-shadow: 0 0 12px var(--accent); }
.lanes { display: grid; gap: 8px; }
.lane { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.lane.win { outline: 3px solid var(--ok); border-radius: 12px; }
.pix { display: grid; grid-template-columns: repeat(16, 44px); gap: 4px; width: max-content; max-width: none; }
.pix button { width: 44px; height: 44px; min-width: 44px; min-height: 44px; aspect-ratio: auto; padding: 0; border-radius: 4px; background: #123; }
.pix button.on { background: var(--accent); }
.bitrow { display: flex; gap: 6px; }
.bitrow button { flex: 1; }
.swatch { height: 64px; border-radius: 12px; border: 1px solid var(--line); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 96px; }
.bars span { flex: 1; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 4px; }
.teamgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.seat { min-width: 48px; min-height: 48px; border-radius: 12px; display: grid; place-items: center; font-weight: 750; }
.pro { width: 100%; height: 180px; touch-action: none; flex: 1 1 140px; min-height: 140px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.presets button { width: 48px; padding: 0; border-radius: 50%; }
html[dir="rtl"] .top { text-align: start; }
html[dir="rtl"] .tile-bar,
html[dir="rtl"] .tile .body { direction: rtl; text-align: start; }
html[dir="rtl"] .tile .body .tape-scroll,
html[dir="rtl"] .tile .body .stick,
html[dir="rtl"] .tile .body .keys,
html[dir="rtl"] .tile .body .pix,
html[dir="rtl"] .tile .body .pro,
html[dir="rtl"] .tile .body .gearbox,
html[dir="rtl"] .tile .body .mat,
html[dir="rtl"] .tile .body .meter { direction: ltr; }
html[lang="ar"] body,
html[lang="fa-AF"] body,
html[lang="ti"] body,
html[data-kp-lang="ar"] body,
html[data-kp-lang="fa-AF"] body,
html[data-kp-lang="ti"] body { line-height: 1.5; }
html[dir="rtl"] .proj-exit { left: 12px; right: auto; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.tool-ico, .tile-ico { flex: 0 0 24px; width: 24px; height: 24px; display: inline-flex; color: var(--accent); }
.tool-ico svg, .tile-ico svg { width: 24px; height: 24px; display: block; }
.sheet .panel > .row { flex-wrap: nowrap; min-height: 44px; }
.sheet .panel > .row strong { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .panel > .row .note { display: none; }
.sheet .panel > .row > .btn { flex: 0 0 104px; width: 104px; min-width: 104px; max-width: 104px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-bar [data-gear] { flex: 0 0 48px; width: 48px; min-width: 48px; height: 48px; min-height: 48px; font-size: 1.35rem; line-height: 1; padding: 0; }
.tile[data-title="0"] .tile-bar h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tile[data-corners="square"] { border-radius: 0; }
.tile[data-quiet="1"], .tile[data-quiet="1"]:hover { box-shadow: none; }
.tile[data-digits="S"] .num { font-size: 1.2rem; }
.tile[data-digits="L"] .num { font-size: 2.6rem; }
.sheet.tool-settings .panel, .sheet.menu-sheet .panel { inset-inline-start: auto; inset-inline-end: auto; right: auto; left: 12px; }
.sheet { z-index: 70; }
#bits-menu { display: none !important; }
html.is-projector .tile[data-proj="0"] { display: none !important; }
.tile-bar { align-items: center; height: auto; }
.tile-bar h2 { white-space: normal; overflow: hidden; text-overflow: unset; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.2; max-height: 2.6em; }
.dock { height: auto; min-height: 52px; }
.dock button { padding: 0 6px; overflow: visible; text-overflow: unset; }
.plus { flex: 1 1 auto; width: auto; min-width: 44px; height: 44px; border-radius: 14px; font-size: 1rem; line-height: 1.2; padding: 0 10px; }
@media (max-width: 520px) {
  .dock { flex-wrap: wrap; padding: 4px; gap: 4px; }
  .dock > button, .plus { flex: 1 1 calc(50% - 4px); }
}
.prompt-edit .row { align-items: center; }
.prompt-edit input, .prompt-edit select { flex: 1 1 120px; min-width: 0; min-height: 44px; }
.presets input[type="color"] { width: 48px; min-width: 48px; height: 48px; padding: 0; }
.sheet .presets button:not([aria-label]) { width: auto; min-width: 48px; border-radius: 12px; padding: 0 10px; }
