:root {
  --bg: #f8f8f5;
  --ink: #1f2328;
  --muted: #6b7078;
  --line: #e2e2dc;
  --card: #ffffff;
  --accent: #3e63dd;
  --accent-soft: #eaeffd;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#app { display: grid; grid-template-columns: 1fr 380px; height: 100vh; }
#stage { position: relative; min-width: 0; min-height: 0; }
#view { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#view.hot { cursor: pointer; }
#view.grabbing { cursor: grabbing; }
#hint { position: absolute; right: 14px; top: 12px; max-width: 520px; text-align: right; font-size: 12px; color: var(--muted); pointer-events: none; }

#panel {
  overflow-y: auto; background: #fbfbf9; border-left: 1px solid var(--line);
  padding: 18px 16px 28px; display: flex; flex-direction: column; gap: 12px;
}
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
#share { white-space: nowrap; }
h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card[hidden] { display: none; }
#modeText { margin: 6px 0 10px; }
#modeTitle { color: var(--accent); }

#modes { display: flex; flex-wrap: wrap; gap: 6px; }
#modes button {
  font: inherit; font-weight: 600; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
#modes button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#modes kbd { font: 11px ui-monospace, monospace; margin-left: 6px; opacity: 0.55; }

/* матрицы */
.mat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.preset { font: inherit; max-width: 190px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.mat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; padding: 8px 12px;
  border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); border-radius: 10px;
}
.cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.num {
  width: 100%; font: 600 15px ui-monospace, "SF Mono", Menlo, Consolas, monospace; text-align: center;
  border: 1px solid transparent; border-radius: 6px; padding: 3px 2px; background: #f3f3ef; color: var(--ink);
}
.num:focus { outline: 2px solid var(--accent); background: #fff; }
.rng { width: 100%; margin: 0; accent-color: var(--accent); }

/* таймлайн */
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.opts { margin-top: 8px; font-size: 13px; color: var(--muted); }
.row.opts label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
#timeline {
  position: absolute; left: 16px; right: 16px; bottom: 14px; max-width: 780px; margin: 0 auto;
  background: rgba(255,255,255,0.95); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 14px; box-shadow: 0 4px 18px rgba(0,0,0,0.07);
}
#timeline #t { flex: 1; min-width: 120px; margin: 0; accent-color: var(--accent); }
#tval { min-width: 58px; text-align: right; font: 600 13px ui-monospace, monospace; color: var(--muted); }
button { font: inherit; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); }
button:hover { background: #f3f3ef; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 112px; }
button.primary:hover { background: #3454c4; }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); }
select { font: inherit; }

/* живые значения */
#live { border-top: 1px solid var(--line); padding-top: 10px; }
.big { font: 700 20px ui-monospace, monospace; margin-bottom: 4px; }
.note { margin-top: 8px; color: #3f444b; font-size: 13px; }
.muted { color: var(--muted); font-size: 12px; }
.kv { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.ev { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0; font-size: 13px; }
.sw { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
table.m { border-collapse: separate; border-spacing: 10px 2px; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); border-radius: 6px; font: 600 13px ui-monospace, monospace; }
table.m td { text-align: right; min-width: 38px; }
.two { display: flex; gap: 14px; flex-wrap: wrap; }

kbd { font-family: ui-monospace, monospace; }

@media (max-width: 880px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  #panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}
