:root {
  --header-grad-start: #4a3d8f;
  --header-grad-mid: #6d5eb5;
  --header-grad-end: #8070c8;
  --tile-grad-start: #2e2468;
  --tile-grad-mid: #362879;
  --tile-grad-end: #4a3d8f;
  --tile-hover-start: #3a2e80;
  --tile-hover-mid: #4a3a9a;
  --tile-hover-end: #5a4da8;

  --bg: #f0eee6;
  --bg-glow: #f8f2db;
  --panel: #fbfaf4;
  --panel-head-top: #ffffff;
  --panel-head-bottom: #f8f3e9;
  --ink: #17202a;
  --muted: #44515f;
  --line: #c9c3b5;

  --control-bg: #ffffff;
  --control-border: #c9c3b5;
  --control-hover: #f4efe2;
  --button-top: #5f6773;
  --button-bottom: #454d59;
  --button-border: #9099a8;
  --button-hover-top: #6d7683;
  --button-hover-bottom: #515a68;
  --button-shadow: rgba(20, 24, 34, 0.42);

  --start: #00b7ff;
  --accent: #b3442a;
  --ok: #00d66b;
  --warn: #ff2a2a;

  --cell: #fffdf8;
  --cell-border: #d8d1c3;
  --tape-ink: #17202a;
  --tape-cell-hover-border: #6f5319;
  --tape-paper-top: #fff6df;
  --tape-paper-bottom: #f3e8cb;
  --tape-paper-fibre: rgba(145, 120, 74, 0.11);
  --tape-paper-shadow: rgba(85, 64, 35, 0.09);
  --read-bg: #fff2b3;
  --head: #ff3b3b;
  --tape-cell-size: 46px;
  --tape-head-stroke: 4px;
  --tape-hover-stroke: 4px;

  --table-head: #f7f2e7;
  --table-row-border: #e3ddd0;
  --active-row: #ffea00;

  --diagram-bg: #fffefb;
  --node-fill: #ffffff;
  --node-stroke: #47525f;
  --node-current-fill: #fff2b3;
  --node-current-stroke: #a17700;
  --edge: #74808d;
  --label: #22313f;
  --edge-label-badge-bg: #fff0b8;
  --edge-label-badge-border: #ffd400;
  --edge-label-read: #00a6ff;
  --edge-label-write: #ff4d4d;
  --edge-label-move: #00e676;
}

[hidden] {
  display: none !important;
}

body[data-theme="dark"] {
  --bg: #000000;
  --bg-glow: #000000;
  --panel: #2e2468;
  --panel-head-top: #3a2e80;
  --panel-head-bottom: #2e2468;
  --ink: #e8edf2;
  --muted: #c9c3ee;
  --line: #5a4da8;

  --control-bg: #24303a;
  --control-border: #3c4b57;
  --control-hover: #2b3944;
  --button-top: #3a3f47;
  --button-bottom: #22262c;
  --button-border: #98a5b9;
  --button-hover-top: #444a53;
  --button-hover-bottom: #2a2f36;
  --button-shadow: rgba(0, 0, 0, 0.48);

  --start: #19b5ff;
  --accent: #ff8f6b;
  --ok: #39ff7a;
  --warn: #ff3b3b;

  --cell: #24303a;
  --cell-border: #42505c;
  --tape-ink: #1e252c;
  --tape-cell-hover-border: #5c430f;
  --tape-paper-top: #e5d9be;
  --tape-paper-bottom: #d6c7a8;
  --tape-paper-fibre: rgba(102, 84, 54, 0.12);
  --tape-paper-shadow: rgba(0, 0, 0, 0.3);
  --read-bg: #5e4d1a;
  --head: #ff3b3b;

  --table-head: #28343e;
  --table-row-border: #33414d;
  --active-row: #ffd400;

  --diagram-bg: #1a2129;
  --node-fill: #2a3640;
  --node-stroke: #8ea0b0;
  --node-current-fill: #5e4d1a;
  --node-current-stroke: #ffd86b;
  --edge: #8ea0b0;
  --label: #d7e1ea;
  --edge-label-badge-bg: #3e2f00;
  --edge-label-badge-border: #ffd400;
  --edge-label-read: #19b5ff;
  --edge-label-write: #ff5252;
  --edge-label-move: #00ff85;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #000000;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: pan-x pan-y;
  scrollbar-width: thin;
  scrollbar-color: #6d63b0 #000000;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
  background: #000000;
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #7f74c6, #5d529f);
  border: 2px solid #000000;
  border-radius: 999px;
}

html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #9388db, #6f63b6);
}

html::-webkit-scrollbar-corner,
body::-webkit-scrollbar-corner {
  background: #000000;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  caret-color: #ffffff;
}

[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  caret-color: #ffffff;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100svh;
  padding: 10px;
  gap: 10px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 66px;
  background: linear-gradient(
    135deg,
    var(--header-grad-start) 0%,
    var(--header-grad-mid) 50%,
    var(--header-grad-end) 100%
  );
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 6px 18px rgba(25, 14, 66, 0.5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 58px;
  width: auto;
  display: block;
  transform-origin: 50% 50%;
  transition: transform 180ms ease-out;
}

.brand h1 {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1;
  color: #ffffff;
}

.brand-tagline {
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.1;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Hamburger button */
.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 30px;
  height: 22px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
  position: relative;
  z-index: 31;
  transition: opacity 160ms ease;
}

.hamburger-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.hamburger-btn span {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform 200ms ease, opacity 200ms ease;
}

.hamburger-btn.is-open {
  opacity: 0;
  pointer-events: none;
}

/* Slide-in menu */
.app-menu {
  position: fixed;
  top: 0;
  right: -260px;
  bottom: 0;
  width: 260px;
  background: linear-gradient(
    180deg,
    var(--tile-grad-start) 0%,
    var(--tile-grad-mid) 100%
  );
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  transition: right 260ms cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0ms 260ms;
  visibility: hidden;
}

.app-menu.is-open {
  right: 0;
  transition: right 260ms cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0ms 0ms;
  visibility: visible;
}

.app-shell {
  position: relative;
}

.menu-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  height: 66px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.menu-title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-transform: uppercase;
  position: relative;
  top: 1px;
}

.menu-close-btn {
  margin-left: auto;
}

.menu-concertina-trigger,
.menu-item-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  text-align: left;
}

.menu-concertina-trigger:hover,
.menu-item-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: transparent;
}

.concertina-arrow {
  font-size: 0.8rem;
  transition: transform 180ms ease;
}

.menu-concertina-list {
  list-style: none;
  margin: 2px 0 6px;
  padding: 0;
}

.menu-concertina-list[hidden] {
  display: none;
}

.menu-preset-btn {
  display: block;
  width: 100%;
  padding: 8px 24px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}

.menu-preset-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: transparent;
}

button,
select,
input {
  font: inherit;
  color: var(--ink);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
}

button {
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: #f7f7ff;
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  border: 1px solid var(--button-border);
  box-shadow: 0 4px 10px var(--button-shadow);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  background-clip: padding-box;
  -webkit-background-clip: padding-box;
}

select,
input {
  border-radius: 6px;
  padding: 4px 6px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c9c3ee' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
}

button:hover:not(:disabled):not(.hamburger-btn):not(.tape-cell):not(.rule-del-btn):not(.btn-clear-states):not(.menu-concertina-trigger):not(.menu-item-btn):not(.menu-preset-btn):not(.tape-symbol-choice) {
  border-color: #bcc7db;
  background: linear-gradient(180deg, var(--button-hover-top), var(--button-hover-bottom));
  box-shadow: 0 6px 14px var(--button-shadow);
  transform: translateY(-1px);
}

button:focus-visible:not(.hamburger-btn):not(.tape-cell):not(.rule-del-btn):not(.btn-clear-states):not(.menu-concertina-trigger):not(.menu-item-btn):not(.menu-preset-btn):not(.tape-symbol-choice) {
  outline: 2px solid #d7e0f2;
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.layout {
  display: grid;
  grid-template-rows: 46% 1fr auto;
  gap: 10px;
  min-height: 0;
  flex: 1;
}

.card {
  background: linear-gradient(
    135deg,
    var(--tile-grad-start) 0%,
    var(--tile-grad-mid) 50%,
    var(--tile-grad-end) 100%
  );
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
  transition: box-shadow 140ms ease, background 140ms ease;
}

.card:hover {
  background: linear-gradient(
    135deg,
    var(--tile-hover-start) 0%,
    var(--tile-hover-mid) 50%,
    var(--tile-hover-end) 100%
  );
  box-shadow: 0 14px 28px rgba(10, 6, 30, 0.55);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
}

.rules-panel .panel-head,
.diagram-panel .panel-head {
  min-height: 51px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.transport-controls {
  gap: 7px;
}

.transport-controls .symbol-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

.symbol-btn {
  min-width: 42px;
  height: 40px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.symbol-btn svg {
  width: 28px;
  height: 28px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.symbol-btn svg.solid-icon {
  fill: currentColor;
  stroke: none;
}

.symbol-btn svg .solid-icon-shape {
  fill: currentColor;
  stroke: none;
}

.symbol-btn svg path,
.symbol-btn svg rect {
  vector-effect: non-scaling-stroke;
}

.symbol-btn svg.solid-icon path,
.symbol-btn svg.solid-icon rect {
  vector-effect: none;
}

#cellSizeValue {
  min-width: 44px;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-actions.compact label {
  font-size: 0.85rem;
  color: var(--muted);
}

.panel-actions.compact input {
  width: 66px;
  margin-left: 4px;
}

.tape-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.tape-panel.card,
.tape-panel.card:hover,
.rules-panel.card,
.rules-panel.card:hover,
.diagram-panel.card,
.diagram-panel.card:hover {
  background: #000000;
}

.tape-panel.card,
.tape-panel.card:hover,
.rules-panel.card,
.rules-panel.card:hover,
.diagram-panel.card,
.diagram-panel.card:hover {
  transform: none;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
}

.tape-panel.card,
.rules-panel.card,
.diagram-panel.card {
  transition: none;
}

.tape-panel.card {
  overflow: visible;
}

/* .tape-panel.card uses overflow: visible (so the tape controls popover can
   escape the card), which means the card's border-radius no longer clips the
   header background. Round the header's own corners to match so it doesn't
   poke out past the card's rounded top corners. */
.tape-panel.card > .panel-head {
  border-top-left-radius: 9px;
  border-top-right-radius: 9px;
}

.tape-viewport {
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
  padding: 10px;
  min-height: 0;
  touch-action: none;
  cursor: grab;
}

.tape-viewport.dragging {
  cursor: grabbing;
}

.tape-grid {
  width: 100%;
  display: grid;
  gap: 0;
}

.tape-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--tape-cell-size);
  gap: 4px;
  width: max-content;
  padding: 3px 4px;
  border-radius: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      var(--tape-paper-fibre) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, var(--tape-paper-top), var(--tape-paper-bottom));
  box-shadow: none;
}

.tape-grid .tape-row:first-child {
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
}

.tape-grid .tape-row:last-child {
  border-bottom-left-radius: 7px;
  border-bottom-right-radius: 7px;
}

.tape-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: var(--tape-cell-size);
  height: var(--tape-cell-size);
  font-weight: 700;
  font-size: clamp(1rem, calc(var(--tape-cell-size) * 0.52), 10rem);
  line-height: 1;
  border: 1px solid var(--cell-border);
  background: transparent;
  color: var(--tape-ink);
  border-radius: 6px;
  box-shadow: inset 0 0 0 0 transparent;
  transition: border-color 90ms linear, box-shadow 90ms linear;
  user-select: none;
  cursor: pointer;
}

.cell-symbol-stack {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.cell-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 60ms linear;
}

@media (hover: hover) and (pointer: fine) {
  button.tape-cell:hover:not(:disabled) {
    border-color: var(--tape-cell-hover-border);
    background: transparent;
    outline: var(--tape-hover-stroke) solid var(--tape-cell-hover-border);
    outline-offset: calc(-1 * var(--tape-hover-stroke));
    box-shadow: inset 0 0 0 var(--tape-hover-stroke) var(--tape-cell-hover-border);
  }
}

@media (hover: none), (pointer: coarse) {
  .tape-cell {
    -webkit-tap-highlight-color: transparent;
  }

  button.tape-cell:focus,
  button.tape-cell:focus-visible,
  button.tape-cell:active,
  button.tape-cell:focus-visible:not(:disabled):not(.hamburger-btn) {
    outline: none;
    box-shadow: inset 0 0 0 0 transparent;
    background: transparent;
    border-color: var(--cell-border);
  }
}

body.touch-input .tape-cell {
  -webkit-tap-highlight-color: transparent;
}

body.touch-input button.tape-cell:focus,
body.touch-input button.tape-cell:focus-visible,
body.touch-input button.tape-cell:active,
body.touch-input button.tape-cell:focus-visible:not(:disabled):not(.hamburger-btn) {
  outline: none !important;
  box-shadow: inset 0 0 0 0 transparent !important;
  background: transparent !important;
  border-color: var(--cell-border) !important;
}

.tape-cell.head {
  outline: 3px solid var(--head);
  outline-offset: -3px;
}

.tape-head-indicator {
  position: absolute;
  border: var(--tape-head-stroke) solid var(--head);
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 0 0 2px rgba(8, 18, 28, 0.35),
    0 0 16px rgba(13, 79, 134, 0.35);
  transition: border-color 80ms linear, box-shadow 80ms linear;
  pointer-events: none;
  z-index: 2;
  box-sizing: border-box;
}

.tape-head-target {
  position: absolute;
  color: var(--head);
  border: 2px dashed currentColor;
  border-radius: 6px;
  background: transparent;
  box-shadow: inset 0 0 0 1px currentColor;
  opacity: 0.6;
  pointer-events: none;
  z-index: 1;
  box-sizing: border-box;
}

.tape-cell.active-read {
  background: var(--read-bg);
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 0.92rem;
  flex-wrap: wrap;
  color: var(--muted);
}

.status-main {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

#statusState,
#statusStep {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--control-bg);
}

#statusMessage {
  display: inline-flex;
  align-items: center;
  color: #ffe28a;
}

.status-tools {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: auto;
}

.status-tools #btnAddRow,
.status-tools #btnRemoveRow,
.workspace-controls-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

.status-tools #btnAddRow svg,
.status-tools #btnRemoveRow svg,
.workspace-controls-btn svg {
  width: 21px;
  height: 21px;
}

.status-tools label,
.workspace-control-group .status-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.workspace-controls-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  z-index: 20;
}

.workspace-controls-popover.open-below {
  top: calc(100% + 10px);
  bottom: auto;
}

.workspace-controls-card {
  width: min(320px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--panel) 92%, #ffffff 8%) 0%,
    color-mix(in srgb, var(--panel) 97%, #000000 3%) 100%
  );
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.42);
}

.workspace-controls-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.workspace-controls-head h3 {
  margin: 0;
  font-size: 0.98rem;
  color: var(--ink);
}

.workspace-controls-close {
  position: static;
}

.workspace-controls-grid {
  display: grid;
  gap: 12px;
}

.workspace-control-group {
  display: grid;
  gap: 8px;
}

.workspace-control-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace-control-inline-spread {
  justify-content: space-between;
}

.workspace-controls-popover input[type="range"] {
  width: 100%;
  accent-color: var(--edge-label-badge-border);
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  height: 18px;
}

.workspace-controls-popover input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #000000;
  border: 1px solid var(--line);
}

.workspace-controls-popover input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--edge-label-badge-border);
  border: 1px solid #000000;
}

.workspace-controls-popover input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: #000000;
  border: 1px solid var(--line);
}

.workspace-controls-popover input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--edge-label-badge-border);
  border: 1px solid #000000;
}

.workspace-controls-popover input[type="range"]:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

#executionSpeedLabel {
  display: inline-block;
  width: 32px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--muted);
}

.status-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-height: 0;
}

.workspace-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  color: #ffea00;
  background: linear-gradient(
    135deg,
    var(--header-grad-start) 0%,
    var(--header-grad-mid) 50%,
    var(--header-grad-end) 100%
  );
  box-shadow: 0 6px 18px rgba(25, 14, 66, 0.5);
  font-size: 0.92rem;
}

.workspace-footer-copy {
  min-width: 0;
}

.workspace-footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.workspace-footer a:hover,
.workspace-footer a:focus-visible {
  color: #ffffff;
}

.modal a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.help-symbol-chip {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.08em 0.42em;
  border: 1px solid var(--cell-border);
  border-radius: 5px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      var(--tape-paper-fibre) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, var(--tape-paper-top), var(--tape-paper-bottom));
  color: var(--tape-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), inset 0 -1px 0 var(--tape-paper-shadow);
  font-family: "Roboto Mono", "Fira Code", monospace;
  font-size: 0.94em;
  font-weight: 700;
  line-height: 1.2;
  vertical-align: baseline;
}

.help-symbol-chip-blank {
  color: transparent;
  text-shadow: none;
}

.help-action-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55em;
  height: 1.35em;
  padding: 0 0.36em;
  border-radius: 7px;
  border: 1px solid var(--button-border);
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  color: #f7f7ff;
  box-shadow: 0 3px 8px var(--button-shadow);
  font-family: "Roboto Mono", "Fira Code", monospace;
  font-size: 0.9em;
  font-weight: 700;
  line-height: 1;
  vertical-align: baseline;
}

.help-action-chip-add {
  border-color: #1f7a3a;
  background: linear-gradient(180deg, #39b764, #1e7f3f);
  color: #ffffff;
}

.help-action-chip-row {
  border-color: var(--button-border);
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  color: #f7f7ff;
}

.help-action-chip-icon {
  min-width: 1.9em;
  height: 1.45em;
  padding: 0 0.2em;
}

.help-action-chip-icon svg {
  width: 1.05em;
  height: 1.05em;
  display: block;
}

.modal a:hover,
.modal a:focus-visible {
  opacity: 0.8;
}

.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 16px;
  box-sizing: border-box;
  z-index: 9999;
  color: var(--ink);
}

.modal-backdrop.is-open {
  display: flex;
}

.modal {
  width: min(420px, calc(100vw - 24px));
  margin: 0 auto;
  position: relative;
  z-index: 1;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000000;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #6d63b0 #1a1430;
}

.modal::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.modal::-webkit-scrollbar-track {
  background: linear-gradient(180deg, #221a44, #140f28);
}

.modal::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #7f74c6, #5d529f);
  border: 2px solid #1a1430;
  border-radius: 999px;
}

.modal::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #9388db, #6f63b6);
}

.modal::-webkit-scrollbar-corner {
  background: #1a1430;
}

.modal h3 {
  margin: 0 0 10px;
  padding-right: 42px;
}

.modal > h3 {
  margin: -14px -14px 10px;
  padding: 10px 46px 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.modal-close-x {
  position: absolute;
  top: 8px;
  right: 10px;
}

.modal label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.modal input[type="text"] {
  width: 100%;
  margin-bottom: 10px;
  font-size: 16px; /* Prevent iOS Safari auto-zoom on focus */
}

.modal-feedback {
  margin: -2px 0 10px;
  color: #ffd166;
  font-size: 0.9rem;
  line-height: 1.3;
}

.modal-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-check input[type="radio"] {
  width: 16px;
  height: 16px;
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  margin: 0;
  border: 2px solid var(--edge-label-badge-border);
  border-radius: 50%;
  background: #000000;
}

.modal-check input[type="radio"]::before {
  content: "";
  width: 8px;
  height: 8px;
  transform: scale(0);
  transition: transform 120ms ease-in-out;
  border-radius: 50%;
  background: #1b1b1b;
}

.modal-check input[type="radio"]:checked {
  background: #ffea00;
  border-color: #ffea00;
}

.modal-check input[type="radio"]:checked::before {
  transform: scale(1);
}

.modal-check input[type="radio"]:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.tape-symbol-picker {
  position: fixed;
  z-index: 10000;
  min-width: 240px;
  max-width: min(380px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.96);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
  color: var(--ink);
}

.tape-symbol-picker[hidden] {
  display: none;
}

.tape-symbol-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(46px, 1fr));
  gap: 8px;
  max-height: min(320px, calc(100dvh - 96px));
  overflow: auto;
  padding: 2px;
  box-sizing: border-box;
}

.tape-symbol-choice {
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 10px;
  background: #244562;
  border-color: #3b6b93;
  font-size: 1.15rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.tape-symbol-choice.is-empty-slot {
  opacity: 0.35;
}

@media (hover: hover) and (pointer: fine) {
  .tape-symbol-choice:hover:not(:disabled) {
    border-color: #5f97c4;
    background: #2f5678;
    box-shadow: 0 6px 14px var(--button-shadow);
    transform: translateY(-1px);
  }
}

.tape-symbol-choice:focus-visible {
  box-shadow: inset 0 0 0 2px #d7e0f2;
}

body.touch-input .tape-symbol-choice:focus,
body.touch-input .tape-symbol-choice:focus-visible,
body.touch-input .tape-symbol-choice:active {
  outline: none !important;
  box-shadow: none !important;
  background: #244562 !important;
  border-color: #3b6b93 !important;
}

.move-picker {
  min-width: 0;
  width: max-content;
  outline: none;
}

.move-picker-preview {
  min-height: 1.6em;
  margin-bottom: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #3b6b93;
  font-size: 1.2rem;
  letter-spacing: 0.1em;
  text-align: center;
  word-break: break-all;
}

.move-picker-preview.is-empty {
  opacity: 0.5;
  font-size: 1rem;
  letter-spacing: 0;
}

.move-picker-grid,
.move-picker-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.move-picker-actions {
  margin-top: 8px;
}

#movePicker .move-choice,
#movePicker .move-picker-action,
#readPicker .move-picker-action {
  min-width: 46px;
  height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  background: #244562;
  border-color: #3b6b93;
  box-shadow: none;
  font-size: 1.15rem;
  line-height: 1;
}

#movePicker .move-choice[data-move="S"] {
  font-size: 1rem;
}

#movePicker .move-picker-action,
#readPicker .move-picker-action {
  flex: 1;
  font-size: 1rem;
}

#movePicker .move-picker-set,
#readPicker .move-picker-set {
  background: #1f6a3c;
  border-color: #38a165;
}

@media (hover: hover) and (pointer: fine) {
  #movePicker .move-choice:hover:not(:disabled),
  #movePicker .move-picker-action:hover:not(:disabled),
  #readPicker .move-picker-action:hover:not(:disabled) {
    border-color: #5f97c4;
    background: #2f5678;
    box-shadow: 0 6px 14px var(--button-shadow);
    transform: translateY(-1px);
  }

  #movePicker .move-picker-set:hover:not(:disabled),
  #readPicker .move-picker-set:hover:not(:disabled) {
    background: #27824b;
    border-color: #4cc07f;
  }
}

#movePicker .move-choice:focus-visible,
#movePicker .move-picker-action:focus-visible,
#readPicker .move-picker-action:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px #d7e0f2;
}

.read-picker {
  min-width: 200px;
}

.read-picker-hint {
  margin-bottom: 8px;
  font-size: 0.85rem;
  opacity: 0.75;
  text-align: center;
}

.write-picker {
  min-width: 200px;
}

.write-picker-same {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  height: 44px;
  font-size: 0.9rem;
  padding: 0 8px;
}

.tape-symbol-choice.is-selected {
  background: #1f6a3c;
  border-color: #38a165;
}

@media (hover: hover) and (pointer: fine) {
  .tape-symbol-choice.is-selected:hover:not(:disabled) {
    background: #27824b;
    border-color: #4cc07f;
  }
}

body.touch-input .tape-symbol-choice.is-selected:focus,
body.touch-input .tape-symbol-choice.is-selected:focus-visible,
body.touch-input .tape-symbol-choice.is-selected:active {
  background: #1f6a3c !important;
  border-color: #38a165 !important;
}

body.touch-input #movePicker .move-choice:focus,
body.touch-input #movePicker .move-choice:active {
  outline: none !important;
  box-shadow: none !important;
  background: #244562 !important;
  border-color: #3b6b93 !important;
}

.alphabet-modal {
  width: fit-content;
  max-width: calc(100vw - 24px);
}

.about-modal .about-modal-content {
  line-height: 1.45;
}

.about-modal .about-menu-note {
  margin: 6px 0 10px;
}

.about-modal .about-menu-note-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  margin: 0 0.12em;
  vertical-align: -0.22em;
  color: currentColor;
}

.about-modal .about-menu-note-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  fill: none;
}

.about-modal .about-show-on-start {
  margin: 8px 0;
}

.about-modal .about-show-on-start input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  border: 2px solid #ffd400;
  background: #000000;
  border-radius: 3px;
}

.about-modal .about-show-on-start input[type="checkbox"]::before {
  content: "";
  width: 4px;
  height: 8px;
  border: solid #1b1b1b;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transform-origin: center;
  transition: transform 120ms ease-in-out;
}

.about-modal .about-show-on-start input[type="checkbox"]:checked {
  background: #ffd400;
  border-color: #ffd400;
}

.about-modal .about-show-on-start input[type="checkbox"]:checked::before {
  transform: rotate(45deg) scale(1);
}

.about-modal .about-show-on-start input[type="checkbox"]:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

.about-modal .about-modal-image {
  float: left;
  width: 110px;
  height: auto;
  margin: 2px 12px 8px 0;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.about-modal .about-modal-content::after {
  content: "";
  display: block;
  clear: both;
}

@media (max-width: 420px) {
  .about-modal .about-modal-image {
    width: 92px;
    margin-right: 10px;
  }
}

.alphabet-modal-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.35;
  text-align: center;
}

.alphabet-modal-grid {
  display: grid;
  grid-template-columns: repeat(4, 52px);
  justify-content: center;
  gap: 6px;
}

.alphabet-core-slot,
.alphabet-user-slot {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  aspect-ratio: 1;
  padding: 4px;
  box-sizing: border-box;
}

.alphabet-core-fixed {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  font-weight: 700;
  font-size: 1.3rem;
}

.alphabet-user-slot {
  position: relative;
  display: grid;
  place-items: center;
  background: #244562;
  border-color: #3b6b93;
}

.alphabet-user-slot input[type="text"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: 1.3rem;
  color: inherit;
  box-sizing: border-box;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  line-height: 1;
}

.alphabet-user-slot input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.alphabet-user-slot input[type="text"]:focus-visible {
  outline: none;
  box-shadow: none;
}

.alphabet-modal-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

#alphabetModalFeedback {
  text-align: center;
}

.workspace-found-actions {
  justify-content: center;
}

.danger-btn {
  border-color: var(--warn);
  color: #ffffff;
  background: linear-gradient(180deg, #ff5a5a, #c92222);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  margin-right: auto;
}

.danger-btn:hover:not(:disabled) {
  border-color: #ff9c9c;
  background: linear-gradient(180deg, #ff6c6c, #d62c2c);
}

.danger-btn-inline {
  border-color: var(--warn);
  color: #ffffff;
  background: linear-gradient(180deg, #ff5a5a, #c92222);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.danger-btn-inline:hover:not(:disabled) {
  border-color: #ff9c9c;
  background: linear-gradient(180deg, #ff6c6c, #d62c2c);
}

.confirm-message {
  margin: 6px 0 2px;
  line-height: 1.4;
  color: var(--ink);
}

.help-modal {
  width: min(620px, calc(100vw - 24px));
  display: grid;
  gap: 10px;
}

.tasks-modal {
  width: min(760px, calc(100vw - 24px));
  display: grid;
  gap: 12px;
}

.tasks-modal-status {
  margin: 0;
  color: var(--muted);
}

.tasks-modal-list {
  display: grid;
  gap: 12px;
}

.tasks-modal-actions {
  align-items: center;
  margin-top: -4px;
  margin-bottom: 2px;
}

.tasks-modal-position {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.92rem;
}

.tasks-modal-shortcut {
  margin: -4px 0 0;
  justify-self: end;
  color: var(--muted);
  font-size: 0.82rem;
}

.task-card {
  display: grid;
  gap: 10px;
  padding: 2px 0 0;
}

.task-card-title {
  margin: 0;
  color: #ffe28a;
  font-size: 1.08rem;
}

.task-card-description,
.task-card-outcome,
.task-card-tape-label {
  margin: 0;
}

.task-card-description,
.task-card-outcome {
  line-height: 1.45;
}

.task-card-outcome {
  font-weight: 800;
  letter-spacing: 0.05em;
}

.task-card-outcome.accept {
  color: var(--ok);
}

.task-card-outcome.reject {
  color: var(--warn);
}

.task-card-outcome.halt {
  color: #f59e0b;
}

.task-card-tape-block {
  display: grid;
  gap: 6px;
}

.task-card-tape-label {
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-tape-preview {
  display: grid;
  justify-content: start;
  gap: 4px;
  --task-head-stroke: clamp(1px, calc(var(--tape-head-stroke) * 0.52), 3px);
}

.task-tape-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 24px;
  gap: 3px;
  width: max-content;
  padding: 3px 4px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      var(--tape-paper-fibre) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, var(--tape-paper-top), var(--tape-paper-bottom));
  border-radius: 6px;
}

.task-tape-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--cell-border);
  border-radius: 5px;
  color: var(--tape-ink);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1;
  position: relative;
}

.task-tape-cell.is-head {
  outline: var(--task-head-stroke) solid var(--head);
  outline-offset: calc(-1 * var(--task-head-stroke));
}

.task-tape-cell.is-head::before {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--task-head-stroke) solid var(--head);
  border-radius: 5px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 0 0 1px rgba(8, 18, 28, 0.35),
    0 0 10px rgba(13, 79, 134, 0.35);
  transition: border-color 80ms linear, box-shadow 80ms linear;
  pointer-events: none;
  box-sizing: border-box;
}

@media (max-width: 520px) {
  .tasks-modal {
    width: min(100%, calc(100vw - 24px));
  }

  .task-tape-row {
    grid-auto-columns: 22px;
  }

  .task-tape-cell {
    width: 22px;
    height: 22px;
    font-size: 0.84rem;
  }
}

.help-modal p {
  margin: 0;
  padding: 10px 12px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background:
    radial-gradient(120% 170% at 10% 12%, rgba(255, 255, 255, 0.04) 0%, transparent 58%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.1));
  line-height: 1.45;
}

.help-modal p strong {
  display: block;
  margin: 0 0 4px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--line);
  color: #ffe28a;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.help-modal p strong + br {
  display: none;
}

.help-modal .help-symbol-chip {
  margin-top: -1px;
}

.state-node-group {
  cursor: pointer;
}

.state-node-group .state-node,
.state-node-group .label,
.state-node-group .state-node.terminal-inner {
  transition: transform 110ms ease, filter 110ms ease, stroke-width 110ms ease;
}

.state-node-group:hover .state-node,
.state-node-group:focus-visible .state-node {
  filter: drop-shadow(0 0 7px rgba(255, 255, 255, 0.22));
  stroke-width: 3;
}

.state-node-group:hover .state-node.accept,
.state-node-group:focus-visible .state-node.accept {
  filter: drop-shadow(0 0 10px rgba(57, 255, 122, 0.5));
}

.state-node-group:hover .state-node.reject,
.state-node-group:focus-visible .state-node.reject {
  filter: drop-shadow(0 0 10px rgba(255, 59, 59, 0.5));
}

.state-node-group:hover .state-node.halt,
.state-node-group:focus-visible .state-node.halt {
  filter: drop-shadow(0 0 10px rgba(245, 158, 11, 0.55));
}

.state-node-group:hover .state-node,
.state-node-group:hover .state-node.terminal-inner,
.state-node-group:hover .label,
.state-node-group:focus-visible .state-node,
.state-node-group:focus-visible .state-node.terminal-inner,
.state-node-group:focus-visible .label {
  transform: translateY(-1px);
}

@keyframes halted-state-breath {
  0%,
  100% {
    transform: scale(1);
    stroke-width: 5;
  }
  50% {
    transform: scale(1.06);
    stroke-width: 5.8;
  }
}

.state-node-group.halted-node .state-node.current,
.state-node-group.halted-node .state-node.terminal-inner {
  transform-origin: center;
  transform-box: fill-box;
  animation: halted-state-breath 1300ms ease-in-out infinite;
}

.state-node-group.halted-node .state-node.accept {
  filter: drop-shadow(0 0 12px rgba(57, 255, 122, 0.55));
}

.state-node-group.halted-node .state-node.reject {
  filter: drop-shadow(0 0 12px rgba(255, 59, 59, 0.55));
}

.state-node-group.halted-node .state-node.halt {
  filter: drop-shadow(0 0 12px rgba(245, 158, 11, 0.6));
}

.state-pill {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 8px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--ink);
  background: #000000;
}

#stateStartBadge {
  border-color: var(--start);
}

#stateAcceptBadge {
  border-color: var(--ok);
}

#stateRejectBadge {
  border-color: var(--warn);
}

#stateHaltBadge {
  border-color: #f59e0b;
}

.rules-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.rules-table-wrap {
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #8a7d5f #efe7d3;
}

.rules-table-wrap::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.rules-table-wrap::-webkit-scrollbar-track {
  background: linear-gradient(180deg, #f5efde, #e9dfc7);
}

.rules-table-wrap::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #a69672, #7f7050);
  border: 2px solid #efe7d3;
  border-radius: 999px;
}

.rules-table-wrap::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #b9a983, #8d7c59);
}

.rules-table-wrap::-webkit-scrollbar-corner {
  background: #e9dfc7;
}

body[data-theme="dark"] .rules-table-wrap {
  scrollbar-color: #6d63b0 #231a56;
}

body[data-theme="dark"] .rules-table-wrap::-webkit-scrollbar-track {
  background: linear-gradient(180deg, #2d2367, #241a55);
}

body[data-theme="dark"] .rules-table-wrap::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #7f74c6, #5d529f);
  border-color: #241a55;
}

body[data-theme="dark"] .rules-table-wrap::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #9388db, #6f63b6);
}

body[data-theme="dark"] .rules-table-wrap::-webkit-scrollbar-corner {
  background: #241a55;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--table-row-border);
  padding: 6px;
  text-align: left;
}

#rulesTable th:last-child,
#rulesTable td:last-child {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--table-head);
  z-index: 1;
}

td input,
td select {
  width: 100%;
}

#rulesTable td .move-btn,
#rulesTable td .read-btn,
#rulesTable td .write-btn {
  width: 100%;
  min-height: 34px;
  padding: 5px 24px 6px 6px;
  border-radius: 6px;
  text-align: left;
  font-family: "Segoe UI", "Segoe UI Symbol", "Noto Sans", "Trebuchet MS", sans-serif;
  line-height: 1.3;
  color: var(--ink);
  background-color: var(--control-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c9c3ee' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  border: 1px solid var(--control-border);
  box-shadow: none;
  transform: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#rulesTable td .move-btn:hover:not(:disabled),
#rulesTable td .read-btn:hover:not(:disabled),
#rulesTable td .write-btn:hover:not(:disabled) {
  background-color: var(--control-bg);
  border-color: var(--control-border);
  box-shadow: none;
  transform: none;
}

#rulesTable td .move-btn:focus-visible,
#rulesTable td .read-btn:focus-visible,
#rulesTable td .write-btn:focus-visible,
#rulesTable td .move-btn.picker-anchor-open,
#rulesTable td .read-btn.picker-anchor-open,
#rulesTable td .write-btn.picker-anchor-open,
#rulesTable td select:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 0;
}

#rulesTable tr.has-overlap td:nth-child(1) select,
#rulesTable tr.has-overlap td .read-btn,
#rulesTable tr.has-overlap td .read-btn:hover:not(:disabled) {
  border-color: #ff5a5a;
  box-shadow: inset 0 0 0 1px #ff5a5a;
}

#rulesTable td select {
  font-family: "Segoe UI", "Segoe UI Symbol", "Noto Sans", "Trebuchet MS", sans-serif;
  min-height: 34px;
  line-height: 1.3;
  padding-top: 5px;
  padding-bottom: 6px;
}

@supports (-webkit-touch-callout: none) {
  #rulesTable td select {
    min-height: 36px;
    line-height: 1.35;
    padding-top: 6px;
    padding-bottom: 8px;
  }
}

.rule-del-btn {
  min-width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8f1c1c;
  background: #cf2a2a;
  color: #ffffff;
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 0.9;
}

.rule-del-btn:hover:not(:disabled) {
  background: #e13c3c;
  border-color: #a52323;
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.rule-del-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.rule-del-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
}

#rulesTable tbody .rule-del-btn {
  font-size: 0;
  line-height: 1;
}

.btn-clear-states {
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-color: #8f1c1c;
  background: linear-gradient(180deg, #f15454, #b32020);
  color: #ffffff;
}

#btnClearStates,
#btnAddState,
#btnSortRules,
#btnAddRule,
#btnExpandDiagram {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

#btnExpandDiagram {
  display: inline-grid;
  place-items: center;
}

#btnAddState {
  display: inline-grid;
  place-items: center;
}

#btnAddRule {
  display: inline-grid;
  place-items: center;
}

#btnSortRules {
  display: inline-grid;
  place-items: center;
}

#btnAddState,
#btnAddRule,
#btnRun {
  border-color: #1f7a3a;
  background: linear-gradient(180deg, #39b764, #1e7f3f);
  color: #ffffff;
}

#btnAddState:hover:not(:disabled),
#btnAddRule:hover:not(:disabled),
#btnRun:hover:not(:disabled) {
  border-color: #269548;
  background: linear-gradient(180deg, #45c671, #239349);
  box-shadow: 0 6px 14px rgba(37, 140, 72, 0.45);
}

#btnAddState:focus-visible,
#btnAddRule:focus-visible,
#btnRun:focus-visible {
  outline: 2px solid #d8ffd8;
  outline-offset: 2px;
}

#btnClearStatesExpanded,
#btnAddStateExpanded {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
}

.btn-clear-states svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btnAddState svg,
#btnSortRules svg,
#btnAddRule svg,
#btnAddStateExpanded svg,
#btnExpandDiagram svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#btnExpandDiagram svg {
  display: block;
  position: relative;
  left: 0.5px;
  top: -0.5px;
}


.btn-clear-states:hover:not(:disabled) {
  border-color: #a52323;
  background: linear-gradient(180deg, #ff6666, #c32727);
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.btn-clear-states:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

tr.active-rule {
  background: linear-gradient(180deg, var(--tape-paper-top), var(--tape-paper-bottom));
}

tr.active-rule td {
  background:
    radial-gradient(130% 170% at 12% 18%, var(--tape-paper-fibre) 0%, transparent 64%),
    radial-gradient(140% 185% at 86% 80%, var(--tape-paper-fibre) 0%, transparent 70%),
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      var(--tape-paper-fibre) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, var(--tape-paper-top), var(--tape-paper-bottom));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), inset 0 -1px 0 var(--tape-paper-shadow);
}

tr.executing-rule {
  background: linear-gradient(180deg, #39b764, #1e7f3f);
}

tr.executing-rule td {
  background:
    radial-gradient(130% 170% at 12% 18%, rgba(255, 255, 255, 0.12) 0%, transparent 64%),
    radial-gradient(140% 185% at 86% 80%, rgba(18, 94, 48, 0.2) 0%, transparent 70%),
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      rgba(255, 255, 255, 0.07) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, #39b764, #1e7f3f);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), inset 0 -1px 0 rgba(11, 68, 33, 0.45);
}

.diagram-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

#diagram {
  width: 100%;
  height: 100%;
  background: #000000;
}

.diagram-modal {
  width: calc(100vw - 24px);
  height: calc(100dvh - 24px);
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.diagram-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -14px -14px 0;
  padding: 10px 46px 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  position: relative;
}

.diagram-modal-actions {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.diagram-modal-head h3 {
  margin: 0;
  padding-right: 42px;
}

@media (max-width: 700px) {
  .diagram-modal-title-suffix {
    display: none;
  }
}

.diagram-modal-body {
  min-height: 0;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  background: #000000;
}

#diagramExpanded {
  width: 100%;
  height: 100%;
  display: block;
  background: #000000;
}

.state-node {
  fill: var(--node-fill);
  stroke: var(--node-stroke);
  stroke-width: 2;
}

.state-node.start {
  stroke: var(--start);
  stroke-width: 3;
}

.state-node.accept {
  stroke: var(--ok);
  stroke-width: 3;
}

.state-node.terminal-inner {
  fill: none;
  stroke-width: 2;
}

.state-node.terminal-inner {
  stroke: currentColor;
}

.state-node.terminal-inner {
  color: var(--node-stroke);
}

.state-node.accept,
.state-node.terminal-inner.accept {
  color: var(--ok);
  stroke: var(--ok);
}

.state-node.reject {
  stroke: var(--warn);
  stroke-width: 3;
}

.state-node.terminal-inner.reject {
  color: var(--warn);
  stroke: var(--warn);
}

.state-node.halt {
  stroke: #f59e0b;
  stroke-width: 3;
}

.state-node.terminal-inner.halt {
  color: #f59e0b;
  stroke: #f59e0b;
}

.state-node.current {
  stroke-width: 5;
}

.edge {
  stroke: var(--edge);
  stroke-width: 1.5;
  fill: none;
}

.label {
  font-size: var(--diagram-label-size, 12px);
  fill: var(--label);
}

.label.current-state-label {
  font-size: calc(var(--diagram-label-size, 12px) * 1.22);
  font-weight: 800;
}

.label .state-subscript {
  font-size: 0.7em;
  baseline-shift: -0.34em;
}

.edge-label-bg {
  fill: #000000;
  stroke: var(--edge-label-badge-border);
  stroke-width: 1;
}

.edge-label-bg.active-transition-badge {
  stroke: #ffea00;
  stroke-width: 2.4;
}

.edge-label {
  font-weight: 700;
}

.edge-label-read {
  fill: var(--edge-label-read);
}

.edge-label-write {
  fill: var(--edge-label-write);
}

.edge-label-move {
  fill: var(--edge-label-move);
}

@media (max-width: 960px) {
  .layout {
    grid-template-rows: 44% 1fr auto;
  }

  .bottom-row {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

@media (max-width: 1200px) and (min-width: 769px) {
  .status-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .status-main {
    gap: 8px;
    flex-wrap: nowrap;
  }
}

@media (max-width: 768px), (max-height: 500px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1024px) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    padding: 6px;
    gap: 6px;
  }

  .layout {
    grid-template-rows: auto auto auto;
    flex: none;
    gap: 6px;
  }

  .top-bar {
    height: auto;
    padding: 6px 8px;
  }

  .brand-logo {
    height: 56px;
  }

  .brand h1 {
    font-size: 1.18rem;
  }

  .brand-tagline {
    font-size: 0.98rem;
  }

  button {
    padding: 4px 7px;
    font-size: 0.82rem;
  }

  .symbol-btn {
    min-width: 34px;
    height: 32px;
    font-size: 0.85rem;
  }

  .symbol-btn svg {
    width: 20px;
    height: 20px;
  }

  .panel-head {
    padding: 5px 8px;
  }

  .rules-panel .panel-head,
  .diagram-panel .panel-head {
    min-height: 45px;
  }

  .panel-head h2 {
    font-size: 0.88rem;
  }

  .status-row {
    font-size: 0.78rem;
    padding: 5px 8px;
    gap: 8px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
  }

  .status-main {
    gap: 8px;
    flex-wrap: nowrap;
  }

  #statusMessage {
    display: none;
  }

  .status-tools {
    margin-left: auto;
  }

  .tape-panel {
    min-height: 0;
    height: auto;
  }

  .tape-viewport {
    height: calc((var(--tape-cell-size, 46px) + 6px) * var(--tape-rows, 1) + 20px);
    min-height: unset;
  }

  .bottom-row {
    grid-template-rows: auto auto;
    grid-template-columns: 1fr;
  }

  .rules-panel {
    min-height: 0;
    height: auto;
  }

  .rules-panel .rules-table-wrap {
    overflow: visible;
  }

  .rules-panel th {
    position: static;
  }

  .diagram-panel {
    min-height: 260px;
    height: 260px;
  }

  #btnFooterHelp {
    display: none;
  }
}
