/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #080b14;
  --bg2: #0d1120;
  --bg3: #111827;
  --surface: rgba(255,255,255,0.04);
  --surface2: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #e8eaf0;
  --text2: #9ca3af;
  --text3: #6b7280;
  --purple: #a78bfa;
  --purple2: #7c3aed;
  --blue: #60a5fa;
  --blue2: #3b82f6;
  --pink: #f472b6;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --orange: #fb923c;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --glow-purple: 0 0 24px rgba(167,139,250,0.3);
  --glow-blue: 0 0 24px rgba(96,165,250,0.3);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* === BG ORBS === */
.bg-orbs {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
}
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.12;
}
.orb-1 { width: 600px; height: 600px; background: #7c3aed; top: -200px; left: -100px; animation: float1 12s ease-in-out infinite; }
.orb-2 { width: 500px; height: 500px; background: #2563eb; bottom: -150px; right: -100px; animation: float2 15s ease-in-out infinite; }
.orb-3 { width: 400px; height: 400px; background: #db2777; top: 40%; left: 50%; transform: translate(-50%,-50%); animation: float3 10s ease-in-out infinite; }

@keyframes float1 { 0%,100%{transform:translate(0,0)} 50%{transform:translate(30px,40px)} }
@keyframes float2 { 0%,100%{transform:translate(0,0)} 50%{transform:translate(-40px,-30px)} }
@keyframes float3 { 0%,100%{transform:translate(-50%,-50%)} 50%{transform:translate(-50%,-45%)} }

/* === HEADER === */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(8,11,20,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.header-inner {
  max-width: 1600px; margin: 0 auto;
  display: flex; align-items: center; gap: 32px;
  height: 64px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.15rem; font-weight: 700;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.tabs {
  display: flex; gap: 4px; flex: 1;
}
.tab {
  background: none; border: none; cursor: pointer;
  color: var(--text2); padding: 8px 16px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  transition: all 0.2s; white-space: nowrap;
}
.tab:hover { background: var(--surface2); color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, rgba(167,139,250,0.15), rgba(96,165,250,0.15));
  color: var(--purple);
  box-shadow: inset 0 0 0 1px rgba(167,139,250,0.25);
}

/* === MAIN === */
.main {
  position: relative; z-index: 1;
  max-width: 1600px; margin: 0 auto;
  padding: 24px;
}

/* === PANELS === */
.panel { display: none; }
.panel.active { display: block; }

.panel-header {
  margin-bottom: 24px;
}
.panel-header h1 {
  font-size: 2rem; font-weight: 800;
  background: linear-gradient(135deg, var(--purple), var(--blue), var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2; margin-bottom: 6px;
}
.panel-header p {
  color: var(--text2); font-size: 0.95rem;
}

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
}
.card-title {
  font-size: 0.9rem; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 14px;
}

/* === LAYOUTS === */
.builder-layout,
.convert-layout,
.minimize-layout,
.sim-layout {
  display: grid; gap: 20px;
}
.builder-layout { grid-template-columns: 340px 1fr; }
.convert-layout,
.minimize-layout { grid-template-columns: 360px 1fr; }
.sim-layout { grid-template-columns: 360px 1fr; }

.controls-col,
.steps-col,
.sim-controls-col { display: flex; flex-direction: column; gap: 16px; }

.canvas-col { display: flex; flex-direction: column; gap: 16px; }

/* === CANVAS CARD === */
.canvas-card {
  padding: 0; overflow: hidden;
}
.canvas-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.canvas-label {
  font-size: 0.85rem; font-weight: 600; color: var(--text2);
}
.canvas-actions { display: flex; gap: 8px; }
.canvas-wrap {
  background: rgba(0,0,0,0.2);
  position: relative;
}
.canvas-hint {
  padding: 8px 16px;
  font-size: 0.75rem; color: var(--text3);
  border-top: 1px solid var(--border);
}

/* === FORM ELEMENTS === */
.field-group {
  margin-bottom: 12px;
}
.field-group label {
  display: block; font-size: 0.8rem; color: var(--text2);
  margin-bottom: 6px; font-weight: 500;
}
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.15);
}
select { cursor: pointer; }
textarea { resize: vertical; font-family: 'JetBrains Mono', monospace; }

/* === BUTTONS === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-sm);
  font-family: inherit; font-weight: 600; cursor: pointer;
  transition: all 0.2s; font-size: 0.875rem;
  padding: 9px 18px; white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--purple2), var(--blue2));
  color: #fff;
  box-shadow: 0 2px 12px rgba(124,58,237,0.4);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(124,58,237,0.6);
}
.btn-outline {
  background: transparent;
  color: var(--purple); border: 1px solid rgba(167,139,250,0.4);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(167,139,250,0.1);
}
.btn-ghost {
  background: transparent; color: var(--text2); border: 1px solid var(--border2);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.algo-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* === STATE LIST === */
.state-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 200px; overflow-y: auto; }
.state-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--surface2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.state-item .state-name { flex: 1; font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
.state-item .state-badges { display: flex; gap: 4px; align-items: center; }
.state-toggle {
  font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; cursor: pointer;
  border: 1px solid; transition: all 0.15s; background: none; font-family: inherit;
}
.toggle-start { color: var(--green); border-color: var(--green); }
.toggle-start.active { background: var(--green); color: var(--bg); }
.toggle-accept { color: var(--yellow); border-color: var(--yellow); }
.toggle-accept.active { background: var(--yellow); color: var(--bg); }
.state-delete { color: var(--red); background: none; border: none; cursor: pointer; font-size: 1rem; padding: 2px; line-height: 1; }

/* === PRESET GRID === */
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset-btn {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); cursor: pointer;
  font-family: inherit; font-size: 0.8rem; padding: 8px; text-align: center;
  transition: all 0.2s; font-weight: 500;
}
.preset-btn:hover {
  border-color: var(--purple);
  background: rgba(167,139,250,0.1);
  color: var(--purple);
}

/* === TABLES === */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
  font-family: 'JetBrains Mono', monospace;
}
th {
  background: rgba(167,139,250,0.1); color: var(--purple);
  padding: 8px 12px; text-align: center;
  border: 1px solid var(--border2); font-weight: 600;
}
td {
  padding: 7px 12px; text-align: center;
  border: 1px solid var(--border); color: var(--text2);
}
tr:hover td { background: var(--surface2); }
td.start-col { color: var(--green); font-weight: 700; }
td.accept-col { color: var(--yellow); }
td.dead-col { color: var(--text3); }
td.marked { background: rgba(248,113,113,0.15); color: var(--red); }
td.highlight { background: rgba(167,139,250,0.2); color: var(--purple); font-weight: 700; }

/* === STEPS LIST === */
.steps-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 400px; overflow-y: auto;
  padding: 4px;
}
.step-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border2);
  background: var(--surface2);
  font-size: 0.82rem; color: var(--text2);
  line-height: 1.6; animation: slideIn 0.3s ease;
}
.step-item.step-new { border-color: var(--purple); background: rgba(167,139,250,0.08); }
.step-item.step-done { border-color: var(--green); }
.step-item.step-note { border-color: var(--blue); background: rgba(96,165,250,0.08); }
.step-item .step-title { font-weight: 600; color: var(--text); }
.step-item code { background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 4px; font-size: 0.8rem; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* === BADGE === */
.badge {
  font-size: 0.75rem; padding: 2px 10px; border-radius: 20px;
  background: rgba(167,139,250,0.15);
  color: var(--purple); border: 1px solid rgba(167,139,250,0.3);
  font-weight: 600; font-family: 'JetBrains Mono', monospace;
}

/* === SIMULATION === */
.sim-status {
  min-height: 80px; display: flex; flex-direction: column;
  gap: 8px; align-items: flex-start;
}
.sim-status-idle { color: var(--text3); font-size: 0.85rem; }
.sim-current-states {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.state-chip {
  font-family: 'JetBrains Mono', monospace;
  padding: 4px 10px; border-radius: 20px; font-size: 0.82rem;
  font-weight: 600; animation: popIn 0.3s ease;
}
.state-chip.active { background: rgba(167,139,250,0.2); color: var(--purple); border: 1px solid var(--purple); }
.state-chip.accept { background: rgba(52,211,153,0.2); color: var(--green); border: 1px solid var(--green); }
.state-chip.reject { background: rgba(248,113,113,0.2); color: var(--red); border: 1px solid var(--red); }
.state-chip.dead { background: rgba(107,114,128,0.2); color: var(--text3); border: 1px solid var(--text3); }

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.sim-history {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem; max-height: 200px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.history-row {
  display: flex; gap: 8px; align-items: center;
  padding: 4px 0; border-bottom: 1px solid var(--border);
  color: var(--text2);
}
.history-step { color: var(--text3); width: 24px; flex-shrink: 0; }
.history-symbol { color: var(--blue); }
.history-states { color: var(--purple); }
.history-arrow { color: var(--text3); }

/* === TAPE === */
.tape-display {
  display: flex; align-items: center; gap: 0;
  padding: 12px; overflow-x: auto; min-height: 60px;
  justify-content: center;
}
.tape-cell {
  width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: 1.1rem; font-weight: 700;
  border: 2px solid var(--border2);
  background: var(--surface2); color: var(--text);
  transition: all 0.3s;
}
.tape-cell:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.tape-cell:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.tape-cell.head { background: rgba(167,139,250,0.25); border-color: var(--purple); color: var(--purple); transform: scale(1.1); z-index: 1; }
.tape-cell.consumed { background: rgba(52,211,153,0.1); color: var(--green); border-color: rgba(52,211,153,0.4); }
.tape-cell.upcoming { opacity: 0.5; }

.sim-speed { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sim-speed label { font-size: 0.8rem; color: var(--text2); white-space: nowrap; }
.sim-speed input[type="range"] { flex: 1; accent-color: var(--purple); }
.sim-speed span { font-size: 0.8rem; color: var(--purple); font-family: 'JetBrains Mono'; width: 36px; }

/* === BATCH RESULTS === */
.batch-results { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.batch-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border-radius: var(--radius-sm); background: var(--surface2);
  font-family: 'JetBrains Mono', monospace; font-size: 0.82rem;
}
.batch-row .batch-str { flex: 1; color: var(--text); }
.batch-accept { color: var(--green); font-weight: 700; }
.batch-reject { color: var(--red); font-weight: 700; }

/* === RESULT BADGE === */
.result-badge {
  font-size: 0.8rem; font-weight: 700; padding: 4px 14px; border-radius: 20px;
}
.result-badge.accept { background: rgba(52,211,153,0.2); color: var(--green); border: 1px solid var(--green); }
.result-badge.reject { background: rgba(248,113,113,0.2); color: var(--red); border: 1px solid var(--red); }

/* === EQUIV LIST === */
.equiv-list { display: flex; flex-direction: column; gap: 8px; }
.equiv-class {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px;
  background: var(--surface2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.equiv-class-label {
  font-family: 'JetBrains Mono'; font-size: 0.85rem; font-weight: 700;
  color: var(--purple); white-space: nowrap;
}
.equiv-class-states {
  font-family: 'JetBrains Mono'; font-size: 0.8rem; color: var(--text2);
  line-height: 1.6;
}

/* === THEORY GRID === */
.theory-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}
.theory-card {
  transition: transform 0.2s, box-shadow 0.2s;
}
.theory-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.theory-icon {
  font-size: 2rem; margin-bottom: 12px;
}
.theory-card h3 {
  font-size: 1rem; font-weight: 700; margin-bottom: 10px;
  color: var(--text);
}
.theory-card p, .theory-card li {
  font-size: 0.875rem; color: var(--text2); line-height: 1.7;
}
.theory-card ul, .theory-card ol {
  padding-left: 18px; margin: 8px 0;
}
.theory-note {
  margin-top: 12px; padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(96,165,250,0.1); border-left: 3px solid var(--blue);
  font-size: 0.8rem; color: var(--blue); font-style: italic;
}
.code-block {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-family: 'JetBrains Mono'; font-size: 0.8rem; color: var(--purple);
  margin: 10px 0; line-height: 1.8;
}
.code-inline {
  font-family: 'JetBrains Mono'; font-size: 0.8rem; color: var(--purple);
  background: rgba(167,139,250,0.1); padding: 1px 6px; border-radius: 4px;
}

/* === SVG STYLES === */
.state-circle {
  fill: rgba(30,35,55,0.95); stroke: var(--border2); stroke-width: 2;
  cursor: pointer; transition: all 0.3s;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}
.state-circle.start-state { stroke: var(--green); }
.state-circle.accept-state { stroke: var(--yellow); }
.state-circle.start-accept { stroke: url(#grad-start-accept); }
.state-circle.highlighted { stroke: var(--purple); fill: rgba(167,139,250,0.15); filter: drop-shadow(0 0 12px rgba(167,139,250,0.6)); }
.state-circle.active-sim { stroke: var(--purple); fill: rgba(167,139,250,0.2); filter: drop-shadow(0 0 16px rgba(167,139,250,0.8)); animation: pulse-state 0.8s ease infinite; }
.state-circle.accept-sim { stroke: var(--green); fill: rgba(52,211,153,0.2); filter: drop-shadow(0 0 16px rgba(52,211,153,0.8)); }
.state-circle.dead-sim { stroke: var(--red); fill: rgba(248,113,113,0.1); }
.state-circle.dfa-dead { stroke: var(--text3); fill: rgba(50,50,60,0.5); }

@keyframes pulse-state {
  0%,100% { filter: drop-shadow(0 0 10px rgba(167,139,250,0.6)); }
  50%      { filter: drop-shadow(0 0 20px rgba(167,139,250,1)); }
}

.state-label { fill: var(--text); font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }

.accept-ring { fill: none; stroke: var(--yellow); stroke-width: 1.5; pointer-events: none; }
.start-arrow { stroke: var(--green); stroke-width: 2; fill: none; marker-end: url(#arrowhead-start); }
.start-arrow-note { fill: none; }

.trans-path { fill: none; stroke-width: 2; marker-end: url(#arrowhead); }
.trans-path.epsilon { stroke-dasharray: 5,3; }
.trans-path.highlighted { stroke-width: 3; filter: drop-shadow(0 0 6px currentColor); }
.trans-label-bg { fill: var(--bg3); rx: 4; }
.trans-label { font-family: 'JetBrains Mono'; font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }

/* === RADIO GROUP === */
.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-label {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: 0.85rem; color: var(--text2);
}
.radio-label input { accent-color: var(--purple); }
.radio-label span { transition: color 0.2s; }
.radio-label:has(input:checked) span { color: var(--purple); font-weight: 600; }

/* === TOAST === */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 30px;
  background: rgba(30,35,55,0.95); border: 1px solid var(--border2);
  color: var(--text); font-size: 0.875rem; font-weight: 500;
  backdrop-filter: blur(20px); box-shadow: var(--shadow);
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
  z-index: 9999;
}
.toast.show { opacity: 1; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.info { border-color: var(--purple); color: var(--purple); }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* === RESPONSIVE === */
@media (max-width: 1100px) {
  .builder-layout,
  .convert-layout,
  .minimize-layout,
  .sim-layout {
    grid-template-columns: 1fr;
  }
  .tabs { overflow-x: auto; }
}

@media (max-width: 600px) {
  .main { padding: 12px; }
  .panel-header h1 { font-size: 1.5rem; }
  .preset-grid { grid-template-columns: 1fr; }
  .theory-grid { grid-template-columns: 1fr; }
}
