:root {
  --bg: #0a0d14;
  --panel: #10151f;
  --panel-2: #0d1117;
  --border: #1e2836;
  --text: #d7e0ec;
  --dim: #6b7a90;
  --cyan: #4dd0e1;
  --orange: #ffab5e;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --accent: #ff5a7e;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
  --sans: 'Space Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(77,208,225,0.07), transparent 60%),
    radial-gradient(700px 500px at 0% 110%, rgba(255,90,126,0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
}

.app-root {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
  animation: fadeDown .5s ease both;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-berry { font-size: 34px; filter: drop-shadow(0 0 12px rgba(255,90,126,0.5)); }
.brand-title {
  margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--cyan), #fff 60%, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { margin: 2px 0 0; font-size: 12px; color: var(--dim); font-family: var(--mono); }

.status-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 999px; font-size: 13px;
  font-family: var(--mono);
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-dot.pulsing { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50% { box-shadow: 0 0 0 6px transparent; opacity: 0.55; }
}

/* Control bar */
.control-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 12px;
  animation: fadeDown .5s ease .05s both;
}
.btn {
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; color: var(--text);
  background: #161d2b; transition: all .15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-run { background: linear-gradient(180deg,#2ee06a,#16a34a); color: #04180b; border-color: #22c55e; }
.btn-run:hover:not(:disabled) { box-shadow: 0 4px 16px rgba(34,197,94,0.4); }
.btn-stop { background: linear-gradient(180deg,#ff6b6b,#dc2626); color: #1a0303; border-color: #ef4444; }
.btn-reset { background: #1a2233; }
.btn-share { background: #1a2233; border-color: #2b3956; color: var(--cyan); }
.ctrl-spacer { flex: 1; }
.cycles-label, .debug-toggle {
  display: flex; align-items: center; gap: 7px; font-size: 12px;
  font-family: var(--mono); color: var(--dim);
}
.cycles-input {
  width: 110px; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--cyan); font-family: var(--mono); font-size: 12px;
  padding: 6px 8px; border-radius: 6px;
}
.debug-toggle input, .cycles-label input[type=checkbox] { accent-color: var(--accent); }

/* Main grid */
.main-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  flex: 1; min-height: 0;
}
@media (max-width: 900px) { .main-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; display: flex; flex-direction: column;
  min-height: 420px;
  animation: fadeUp .5s ease .1s both;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; color: var(--dim);
  background: #0c1119;
}
.example-select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--cyan); font-family: var(--mono); font-size: 12px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
}

/* Editor */
.editor-wrap { display: flex; flex: 1; min-height: 260px; overflow: hidden; }
.line-nums {
  margin: 0; padding: 12px 10px 12px 14px; text-align: right;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: #3c4a5e; background: #0b0f16; user-select: none;
  overflow: hidden; white-space: pre; min-width: 46px;
}
.code-area {
  flex: 1; margin: 0; padding: 12px 14px; border: none; resize: none;
  background: var(--panel-2); color: #cfe3ea;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  outline: none; white-space: pre; overflow: auto; tab-size: 2;
}
.code-area::selection { background: rgba(77,208,225,0.3); }

/* Argument bar */
.arg-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-top: 1px solid var(--border);
  background: #0b0f16;
}
.arg-prompt { color: var(--green); font-family: var(--mono); font-size: 13px; font-weight: 700; white-space: nowrap; }
.arg-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--orange); font-family: var(--mono); font-size: 13px;
}
.arg-input::placeholder { color: #46566c; }

/* Output */
.output-panel { }
.tab-row {
  display: flex; align-items: center; border-bottom: 1px solid var(--border);
  background: #0c1119; padding-right: 12px;
}
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font-family: var(--mono); font-size: 12px;
  padding: 11px 15px; cursor: pointer; transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab-active { color: var(--cyan); border-bottom-color: var(--cyan); }
.cps-meter {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  color: var(--green); min-width: 70px; text-align: right;
}

.terminal {
  flex: 1; background: #04070c; padding: 14px; overflow: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  position: relative;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px);
}
.term-out { margin: 0; white-space: pre-wrap; word-break: break-word; color: #b6ffcf; }
.term-hint { color: #3c4a5e; }
.term-status {
  margin-top: 14px; padding-top: 10px; border-top: 1px dashed #1e2836;
  font-size: 12px;
}
.status-halted { color: var(--amber); }
.status-error { color: var(--red); }
.status-running { color: var(--green); }

.listing {
  flex: 1; background: var(--panel-2); padding: 12px 14px; overflow: auto;
}
.listing pre {
  margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  color: #9db4c8; white-space: pre;
}

/* VM state */
.vm-view { flex: 1; padding: 20px; background: var(--panel-2); overflow: auto; }
.vm-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
@media (max-width: 520px) { .vm-grid { grid-template-columns: repeat(2,1fr); } }
.reg-card {
  background: #0b1019; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; text-align: center;
}
.reg-name { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; }
.reg-val { font-family: var(--mono); font-size: 20px; color: var(--cyan); margin-top: 4px; word-break: break-all; }
.cycle-big {
  margin-top: 18px; background: #0b1019; border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; display: flex; align-items: baseline;
  justify-content: space-between;
}
.cycle-label { font-family: var(--mono); color: var(--dim); font-size: 13px; }
.cycle-num { font-family: var(--mono); font-size: 26px; font-weight: 800; color: var(--green); }
.vm-hint { margin-top: 16px; color: var(--dim); font-size: 12px; font-family: var(--mono); }

/* Footer */
.app-footer {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 4px 4px; font-family: var(--mono); font-size: 11px;
  color: var(--dim);
}
.app-footer a { color: var(--accent); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }
.foot-sep { opacity: 0.5; }

@keyframes fadeDown { from { opacity: 0; transform: translateY(-8px);} to { opacity: 1; transform: none;} }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px);} to { opacity: 1; transform: none;} }