:root {
  --bg: #08111f;
  --bg-soft: #0d1830;
  --border: rgba(90, 214, 255, 0.24);
  --text: #f4f8ff;
  --muted: #91a4c7;
  --cyan: #5ad6ff;
  --purple: #bb86fc;
  --green: #32d68f;
  --red: #ff6b81;
  --warning: #ffd166;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --visible-cells: 15;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(90, 214, 255, 0.14), transparent 30%),
    radial-gradient(circle at 85% 15%, rgba(187, 134, 252, 0.12), transparent 24%),
    linear-gradient(145deg, #050a14 0%, #0b1730 48%, #08111f 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  mask-image: radial-gradient(circle at center, black 45%, transparent 88%);
}
.app-shell { width: min(1440px, calc(100% - 32px)); margin: 24px auto; display: grid; gap: 20px; }
.hero, .panel {
  background: linear-gradient(180deg, rgba(15, 30, 57, 0.88), rgba(8, 17, 31, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.hero { padding: 24px; display: grid; gap: 18px; }
.hero-top, .panel-header, .transition-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.01em; }
.subtitle, .microcopy, .status-pill span:last-child, .meta small, .footer-note { color: var(--muted); }
.hero p, .panel p { margin: 0; line-height: 1.55; }
.accent { color: var(--cyan); }
.controls-grid, .main-grid, .editor-grid, .editor-form, .machine-meta, .tape-panel, .tape-stack { display: grid; gap: 20px; }
.controls-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end; }
.main-grid { grid-template-columns: 1.45fr 0.95fr; }
.panel { padding: 20px; overflow: hidden; }
.panel-title-group { display: grid; gap: 4px; }
.status-badges, .button-row, .meta, .summary-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.status-pill, .meta-chip {
  display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06); font-size: 0.9rem;
}
.status-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--cyan); box-shadow: 0 0 14px currentColor; }
.status-running .status-dot { color: var(--cyan); background: var(--cyan); }
.status-accepted .status-dot { color: var(--green); background: var(--green); }
.status-rejected .status-dot { color: var(--red); background: var(--red); }
.status-paused .status-dot { color: var(--warning); background: var(--warning); }
label { display: grid; gap: 8px; font-size: 0.95rem; color: var(--muted); }
input, select, button { font: inherit; }
input, select {
  width: 100%; min-height: 46px; border: 1px solid rgba(90, 214, 255, 0.16); background: rgba(7, 16, 32, 0.92);
  color: var(--text); border-radius: 14px; padding: 12px 14px; outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
input:focus, select:focus { border-color: rgba(90, 214, 255, 0.7); box-shadow: 0 0 0 4px rgba(90, 214, 255, 0.12); transform: translateY(-1px); }
button {
  border: 0; border-radius: 14px; padding: 12px 16px; cursor: pointer; color: var(--text);
  background: linear-gradient(135deg, rgba(90, 214, 255, 0.22), rgba(187, 134, 252, 0.18));
  border: 1px solid rgba(90, 214, 255, 0.24); transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  box-shadow: 0 10px 24px rgba(5, 10, 20, 0.28);
}
button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 26px rgba(0, 0, 0, 0.28); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: rgba(255, 255, 255, 0.04); border-color: rgba(255, 255, 255, 0.08); }
button.danger { background: rgba(255, 107, 129, 0.12); border-color: rgba(255, 107, 129, 0.34); }
.speed-wrap { display: grid; gap: 8px; }
.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { padding: 0; min-height: auto; background: transparent; border: 0; box-shadow: none; }
.tape-stage {
  position: relative; overflow: hidden; border-radius: 20px; border: 1px solid rgba(90, 214, 255, 0.16);
  background: linear-gradient(180deg, rgba(10, 19, 38, 0.98), rgba(5, 10, 20, 0.96)), radial-gradient(circle at top, rgba(90, 214, 255, 0.12), transparent 35%);
  padding: 64px 18px 24px; min-height: 210px;
}
.tape-stage-label { position: absolute; left: 18px; top: 14px; color: var(--muted); letter-spacing: 0.06em; font-size: 0.88rem; text-transform: uppercase; }
.head-indicator {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 6px; color: var(--cyan); z-index: 3;
}
.head-indicator .arrow { width: 0; height: 0; border-left: 12px solid transparent; border-right: 12px solid transparent; border-top: 18px solid var(--cyan); filter: drop-shadow(0 0 10px rgba(90, 214, 255, 0.55)); }
.head-indicator strong { font-size: 0.8rem; letter-spacing: 0.16em; }
.tape-track-wrap { overflow: hidden; }
.tape-track { display: grid; grid-template-columns: repeat(var(--visible-cells), minmax(56px, 1fr)); gap: 10px; will-change: transform; }
.tape-cell {
  position: relative; min-height: 108px; border-radius: 18px; border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(16, 30, 59, 0.95), rgba(7, 15, 30, 1)); display: grid; justify-items: center; align-content: center; gap: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); transition: transform 0.24s ease, border-color 0.24s ease, box-shadow 0.24s ease;
}
.tape-cell .index { position: absolute; bottom: 10px; font-family: "JetBrains Mono", monospace; font-size: 0.72rem; color: rgba(145, 164, 199, 0.72); }
.tape-cell .symbol { font-family: "JetBrains Mono", monospace; font-size: clamp(1.4rem, 2vw, 2rem); font-weight: 600; letter-spacing: 0.06em; }
.tape-cell.active { border-color: rgba(90, 214, 255, 0.85); box-shadow: 0 0 0 1px rgba(90, 214, 255, 0.5), 0 0 22px rgba(90, 214, 255, 0.22), inset 0 0 28px rgba(90, 214, 255, 0.12); transform: translateY(-5px) scale(1.02); }
.tape-cell.blank .symbol { color: rgba(145, 164, 199, 0.7); }
.state-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.state-card { border-radius: 16px; padding: 14px; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.03); min-height: 88px; display: grid; gap: 8px; transition: border-color 0.22s ease, transform 0.22s ease, box-shadow 0.22s ease; }
.state-card.active { border-color: rgba(90,214,255,0.7); transform: translateY(-2px); box-shadow: 0 12px 26px rgba(90,214,255,0.12); }
.state-card.accept { border-color: rgba(50,214,143,0.28); background: rgba(50,214,143,0.08); }
.state-card.reject { border-color: rgba(255,107,129,0.32); background: rgba(255,107,129,0.08); }
.state-card small { color: var(--muted); }
.mono, .log-list, .transition-table, .graph-caption { font-family: "JetBrains Mono", monospace; }
.log-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; max-height: 430px; overflow: auto; padding-right: 6px; }
.log-list li { border-radius: 14px; padding: 12px 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.05); line-height: 1.45; font-size: 0.9rem; }
.log-list li.accepted { border-color: rgba(50,214,143,0.32); background: rgba(50,214,143,0.08); }
.log-list li.rejected { border-color: rgba(255,107,129,0.32); background: rgba(255,107,129,0.08); }
.log-list li.warning { border-color: rgba(255,209,102,0.38); background: rgba(255,209,102,0.09); }
.log-list li.branch { border-color: rgba(90,214,255,0.22); }
.graph-stage { min-height: 470px; border-radius: 18px; border: 1px solid rgba(255,255,255,0.06); background: radial-gradient(circle at top, rgba(90,214,255,0.08), transparent 40%), rgba(255,255,255,0.02); overflow: hidden; }
#graphSvg { width: 100%; height: 470px; display: block; }
.field-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.transition-table-wrap { overflow: auto; border: 1px solid rgba(255,255,255,0.08); border-radius: 16px; background: rgba(255,255,255,0.02); }
.transition-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.transition-table th, .transition-table td { padding: 12px; border-bottom: 1px solid rgba(255,255,255,0.06); text-align: left; vertical-align: middle; }
.transition-table th { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; background: rgba(255,255,255,0.02); }
.transition-table td input, .transition-table td select { min-height: 40px; padding: 10px 12px; border-radius: 12px; }
.hidden { display: none !important; }
@media (max-width: 1180px) {
  .controls-grid, .main-grid { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-shell { width: min(100% - 18px, 100%); margin: 10px auto 22px; }
  .hero, .panel { padding: 16px; border-radius: 18px; }
  .button-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .tape-stage { padding-inline: 10px; }
  .tape-track { gap: 8px; }
  .tape-cell { min-height: 96px; }
  .graph-stage { min-height: 360px; }
  #graphSvg { height: 360px; }
}
