:root {
  --bg: #040b0f;
  --bg-accent: #07171f;
  --panel: rgba(8, 19, 25, 0.84);
  --ink: #b5ffd8;
  --muted: #66b89a;
  --line: rgba(76, 176, 144, 0.36);
  --button: #0ec676;
  --button-hover: #14f08f;
  --glow: rgba(20, 240, 143, 0.42);
  --editor-bg: #061118;
  --editor-ink: #8bfec4;
  --editor-gutter: #0a1a22;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Rajdhani", "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -20%, rgba(48, 182, 143, 0.28) 0, transparent 42%),
    radial-gradient(circle at 95% 5%, rgba(0, 199, 255, 0.22) 0, transparent 34%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-accent) 100%);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(130, 255, 190, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(130, 255, 190, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  opacity: 0.25;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.topbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 0 0 1px rgba(20, 240, 143, 0.06), 0 12px 32px rgba(0, 0, 0, 0.5), inset 0 0 26px rgba(20, 240, 143, 0.08);
  backdrop-filter: blur(3px);
}

.brand-mark {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 12px;
  background: radial-gradient(circle at 30% 25%, rgba(0, 252, 168, 0.25), transparent 58%), rgba(3, 14, 19, 0.75);
  border: 1px solid rgba(0, 252, 168, 0.35);
  box-shadow: 0 0 18px rgba(0, 252, 168, 0.22), inset 0 0 22px rgba(0, 217, 255, 0.16);
  display: grid;
  place-items: center;
}

.brand-mark svg {
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 0 8px rgba(0, 252, 168, 0.45));
}

.logo-frame {
  fill: rgba(2, 10, 14, 0.35);
  stroke: rgba(0, 252, 168, 0.55);
  stroke-width: 3;
}

.logo-scan {
  fill: none;
  stroke: rgba(0, 252, 168, 0.38);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.logo-wave {
  fill: none;
  stroke: url(#forgePulse);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logo-tag {
  fill: rgba(0, 252, 168, 0.9);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
}

.topbar-text {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(20, 240, 143, 0.5);
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 0 16px rgba(20, 240, 143, 0.08);
}

button {
  border: 1px solid rgba(20, 240, 143, 0.5);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

#btnRun {
  background: var(--button);
  color: #032313;
  box-shadow: 0 0 16px var(--glow);
}

#btnRun.btn-danger {
  background: rgba(125, 18, 31, 0.92);
  border-color: rgba(255, 97, 126, 0.62);
  color: #ffdbe3;
  box-shadow: 0 0 14px rgba(255, 74, 114, 0.32);
}

.icon-btn {
  width: 46px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.hotkey-hint {
  color: var(--muted);
  letter-spacing: 0.08em;
  font-size: 0.86rem;
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
  padding: 0 4px;
}

.btn-secondary {
  background: rgba(9, 27, 35, 0.85);
  color: #88e9bc;
}

.btn-secondary:hover {
  background: rgba(11, 40, 50, 0.95);
}

.btn-danger {
  background: rgba(125, 18, 31, 0.92);
  border-color: rgba(255, 97, 126, 0.62);
  color: #ffdbe3;
  box-shadow: 0 0 14px rgba(255, 74, 114, 0.32);
}

.btn-danger:hover {
  background: rgba(162, 24, 43, 0.96);
  box-shadow: 0 0 18px rgba(255, 74, 114, 0.48);
}

#btnRun:hover {
  background: var(--button-hover);
  box-shadow: 0 0 22px rgba(20, 240, 143, 0.56);
}

#btnRun.btn-danger:hover {
  background: rgba(162, 24, 43, 0.96);
  box-shadow: 0 0 18px rgba(255, 74, 114, 0.48);
}

button:hover {
  transform: translateY(-1px);
}

.preview-panel iframe {
  width: 100%;
  height: 420px;
  max-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #061118;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.editors {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4), inset 0 0 20px rgba(20, 240, 143, 0.07);
  backdrop-filter: blur(2px);
}

.panel h2 {
  margin: 4px 2px 10px;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.editor-shell {
  border: 1px solid rgba(20, 240, 143, 0.4);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(20, 240, 143, 0.1), inset 0 0 20px rgba(20, 240, 143, 0.08);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 10px;
  background: linear-gradient(180deg, #0e252f 0%, #08171d 100%);
  border-bottom: 1px solid rgba(20, 240, 143, 0.26);
}

.editor-label {
  margin-left: 8px;
  color: #7adbb5;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-name-input {
  margin-left: 8px;
  width: min(280px, 70%);
  border: 1px solid rgba(20, 240, 143, 0.3);
  border-radius: 6px;
  background: rgba(3, 17, 22, 0.85);
  color: #9dfacd;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
}

.editor-name-input:focus {
  outline: none;
  border-color: rgba(20, 240, 143, 0.7);
  box-shadow: 0 0 0 2px rgba(20, 240, 143, 0.2);
}

.editor-body {
  display: grid;
  grid-template-columns: 52px 1fr;
  min-height: 54vh;
  background: var(--editor-bg);
  align-items: start;
  position: relative;
}

#lineNumbers {
  margin: 0;
  padding: 12px 8px 12px 0;
  text-align: right;
  color: #4d8d77;
  background: var(--editor-gutter);
  border-right: 1px solid rgba(20, 240, 143, 0.24);
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

#inputCode {
  --code-font-size: 0.9rem;
  --code-line-height: 1.5;
  --code-line-step: calc(var(--code-font-size) * var(--code-line-height));
  width: 100%;
  min-height: 54vh;
  resize: none;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(20, 240, 143, 0.028) 0,
    rgba(20, 240, 143, 0.028) var(--code-line-step),
    rgba(0, 217, 255, 0.045) var(--code-line-step),
    rgba(0, 217, 255, 0.045) calc(var(--code-line-step) * 2)
  );
  background-origin: content-box;
  background-clip: content-box;
  color: var(--editor-ink);
  padding: 12px;
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
  font-size: var(--code-font-size);
  line-height: var(--code-line-height);
  caret-color: #d7ffe8;
  overflow: hidden;
}

#inputCode:focus {
  outline: none;
}

.editor-autocomplete {
  position: absolute;
  z-index: 30;
  min-width: 200px;
  max-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: rgba(4, 16, 22, 0.98);
  border: 1px solid rgba(20, 240, 143, 0.45);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.42), 0 0 16px rgba(20, 240, 143, 0.15);
  padding: 4px;
}

.editor-autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  color: #a5f8cf;
  text-align: left;
  padding: 7px 8px;
  border-radius: 6px;
  font-family: "JetBrains Mono", "IBM Plex Mono", Menlo, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: none;
}

.editor-autocomplete-text {
  display: block;
  min-width: 0;
  padding-right: 8px;
}

.editor-autocomplete-item:hover,
.editor-autocomplete-item.is-active {
  background: rgba(20, 240, 143, 0.18);
  color: #d9ffe9;
}

.editor-autocomplete-label {
  display: block;
  font-weight: 700;
}

.editor-autocomplete-detail {
  display: block;
  margin-top: 2px;
  color: rgba(149, 232, 195, 0.78);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

.editor-autocomplete-help {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(20, 240, 143, 0.42);
  border-radius: 999px;
  background: rgba(8, 30, 39, 0.94);
  color: #9cf8cf;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  text-transform: none;
}

.editor-autocomplete-help:hover {
  background: rgba(20, 240, 143, 0.2);
  color: #dcffe9;
}

.statusbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.statusbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0%, rgba(0, 252, 168, 0.08) 35%, rgba(0, 217, 255, 0.3) 50%, rgba(0, 252, 168, 0.1) 65%, transparent 100%);
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

.statusbar.statusbar-flash::before {
  animation: statusbarSweep 760ms ease-out 1;
}

#statusText {
  position: relative;
  z-index: 1;
}

@keyframes statusbarSweep {
  0% {
    transform: translateX(-120%);
    opacity: 0;
  }

  15% {
    opacity: 0.9;
  }

  100% {
    transform: translateX(120%);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 14px;
    gap: 10px;
  }

  .topbar {
    gap: 10px;
    padding: 12px;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
  }

  .brand-mark svg {
    width: 48px;
    height: 48px;
  }

  .topbar h1 {
    font-size: 1.55rem;
  }

  .topbar p {
    font-size: 0.9rem;
  }

  .toolbar {
    padding: 10px;
    gap: 6px;
  }

  .toolbar button,
  .toolbar .hotkey-hint {
    min-height: 40px;
  }

  .hotkey-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    border: 1px solid rgba(20, 240, 143, 0.26);
    border-radius: 8px;
  }

  .editor-name-input {
    width: min(320px, 95%);
  }

  .editors {
    grid-template-columns: 1fr;
  }

  .editor-body,
  #inputCode {
    min-height: 38vh;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .brand-mark svg {
    width: 40px;
    height: 40px;
  }

  .topbar h1 {
    font-size: 1.35rem;
  }

  .topbar p {
    margin-top: 4px;
    font-size: 0.82rem;
    line-height: 1.25;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 48px 1fr 1fr;
    align-items: stretch;
  }

  #btnRun {
    grid-row: span 2;
    min-height: 86px;
  }

  .hotkey-hint {
    min-height: 40px;
    font-size: 0.74rem;
  }

  #btnLoad,
  #btnSave,
  #btnHelp {
    width: 100%;
    min-height: 40px;
    font-size: 0.78rem;
    letter-spacing: 0.03em;
  }

  .panel {
    padding: 8px;
    border-radius: 14px;
  }

  .editor-body {
    grid-template-columns: 40px 1fr;
    min-height: 46vh;
  }

  #lineNumbers {
    padding-right: 6px;
    font-size: 0.78rem;
  }

  #inputCode {
    min-height: 46vh;
    padding: 10px;
    font-size: 0.84rem;
    line-height: 1.45;
  }

  .editor-autocomplete {
    left: 46px !important;
    right: 8px;
    min-width: 0;
    max-width: none;
  }

  .preview-panel iframe {
    height: 360px;
    max-height: 58vh;
  }
}
