: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: #5d529e;
  --button-bottom: #43377f;
  --button-border: #8478c6;
  --button-hover-top: #6a60ae;
  --button-hover-bottom: #4e4291;
  --button-shadow: rgba(32, 24, 72, 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;

  --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;
}

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: #5e52a6;
  --button-bottom: #3f347d;
  --button-border: #8b80d2;
  --button-hover-top: #7165bc;
  --button-hover-bottom: #4f4395;
  --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;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

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

.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;
}

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

.brand-tagline {
  color: var(--muted);
  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;
}

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

.hamburger-btn.is-open span:nth-child(1) {
  transform: translateY(9.5px) rotate(45deg);
}

.hamburger-btn.is-open span:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.is-open span:nth-child(3) {
  transform: translateY(-9.5px) rotate(-45deg);
}

/* 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;
  padding: 8px 12px;
  height: 66px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.menu-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-transform: uppercase;
}

.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;
}

button:hover:not(:disabled):not(.hamburger-btn) {
  border-color: #b8adff;
  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) {
  outline: 2px solid #c9c0ff;
  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));
}

.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;
}

.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-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), 3.4rem);
  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;
}

button.tape-cell:hover:not(:disabled) {
  border-color: var(--tape-cell-hover-border);
  background: transparent;
  outline: 2px solid var(--tape-cell-hover-border);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px var(--tape-cell-hover-border);
}

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

.tape-head-indicator {
  position: absolute;
  border: 4px 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;
}

.status-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

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

.status-tools input[type="range"] {
  width: min(220px, 38vw);
}

.status-tools-sep {
  display: inline-block;
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 4px;
}

.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 {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--ink);
  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 a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.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 {
  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: linear-gradient(
    135deg,
    var(--tile-grad-start) 0%,
    var(--tile-grad-mid) 50%,
    var(--tile-grad-end) 100%
  );
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55);
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.modal h3 {
  margin: 0 0 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-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-check input[type="checkbox"] {
  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: 3px;
  background: #000000;
}

.modal-check input[type="checkbox"]::before {
  content: "";
  width: 9px;
  height: 9px;
  transform: scale(0);
  transition: transform 120ms ease-in-out;
  clip-path: polygon(14% 44%, 0 59%, 41% 100%, 100% 16%, 84% 0, 37% 62%);
  background: #000000;
}

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

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

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

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

.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);
}

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

.state-node-group .state-node,
.state-node-group .label,
.state-node-group .state-node.accept-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,
.state-node-group:hover .state-node.accept-inner,
.state-node-group:hover .label,
.state-node-group:focus-visible .state-node,
.state-node-group:focus-visible .state-node.accept-inner,
.state-node-group:focus-visible .label {
  transform: translateY(-1px);
}

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

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

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

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

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

.rules-table-wrap {
  overflow: auto;
}

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

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

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

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

tr.active-rule {
  background: var(--active-row);
}

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

#diagram {
  width: 100%;
  height: 100%;
  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.accept-inner {
  fill: none;
  stroke: var(--ok);
  stroke-width: 2;
}

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

.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;
}

.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: 768px), (max-height: 500px) {
  .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: 36px;
  }

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

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

  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;
  }

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

  .status-row {
    font-size: 0.78rem;
    padding: 5px 8px;
    gap: 8px;
  }

  .tape-panel {
    min-height: 220px;
    height: 220px;
  }

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

  .rules-panel {
    min-height: 240px;
    height: 240px;
  }

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