@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ═══════════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #000000;
  --bg-elevated: #181818;
  --panel-bg: #060606;
  --panel-bg-hover: #1a1a1a;
  --border: #1a1a1a;
  --border-subtle: #1a1a1a;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;

  --accent: #666666;
  --accent-hover: #999999;
  --accent-glow: rgba(101, 136, 26, 0.25);
  --stop: #ff006e;
  --danger: #ff006e;
  --danger-hover: #c21129;

  --editor-caret: #B5179E;
  --editor-bg: #0a0a0a;
  --editor-text: #e8e8e8;

  --console-bg: #000000;
  --console-log: #d4d4d4;
  --console-err: #ff5555;
  --console-sys: #888888;
  --console-help: #fbbf24;

  --gradient-1: #b026ff;
  --btn-secondary-bg: #2a2a2a;
  --btn-secondary-border: #3a3a3a;
  --btn-secondary-hover: #383838;
}

body.light-mode {
  --bg: #f5f5f5;
  --bg-elevated: #ffffff;
  --panel-bg: #ffffff;
  --panel-bg-hover: #f0f0f0;
  --border: #d0d0d0;
  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-muted: #888888;
  --btn-secondary-bg: #e8e8e8;
  --btn-secondary-border: #ccc;
  --btn-secondary-hover: #ddd;
  --editor-bg: #ffffff;
  --editor-text: #1a1a1a;
  --console-bg: #f5f5f5;
  --console-log: #1a1a1a;
  --console-err: #cc0000;
  --console-sys: #555555;
  --console-help: #b45309;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ─── Header ─── */
header {
  padding: 16px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  height: 60px;
  width: auto;
  border-radius: 8px;
}

.logo-text {
  font-size: 20px;
  font-weight: 300;
  letter-spacing: -0.5px;
  color: #ffffff;
}

.logo-aria {
  color: #E93368;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Buttons ─── */
button {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--stop);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

button:hover {
  background: var(--panel-bg-hover);
  border-color: #333;
}

button.primary {
  background: #02FF01;
  border-color: #02FF01;
  color: #000;
  font-weight: 600;
}

button.primary:hover {
  background: #0fb820;
  border-color: #0fb820;
  box-shadow: 0 4px 12px rgba(19, 209, 28, 0.3);
}

button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger);
  color: #fff;
}

button.ghost {
  background: var(--btn-secondary-bg);
  border-color: var(--btn-secondary-border);
}

button.ghost:hover {
  background: var(--btn-secondary-hover);
  border-color: #4a4a4a;
}

/* ─── Dropdown ─── */
.dropdown {
  position: relative;
}

.dropdown-trigger {
  min-width: 140px;
  justify-content: space-between;
}

.dropdown-trigger::after {
  content: '▾';
  font-size: 10px;
  opacity: 0.6;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 220px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  max-height: 400px;
  overflow-y: auto;
}

.dropdown-menu.show {
  display: block;
  animation: dropdownIn 0.15s ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-category {
  padding: 8px 12px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-category::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.dropdown-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.1s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.dropdown-item:hover {
  background: var(--panel-bg-hover);
  color: var(--text-primary);
}

.dropdown-item .icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.dropdown-item.cat-variables .icon   { background: rgba(59, 130, 246, 0.2);  color: #B5179E; }
.dropdown-item.cat-conditionals .icon { background: rgba(168, 85, 247, 0.2); color: #a855f7; }
.dropdown-item.cat-loops .icon       { background: rgba(34, 197, 94, 0.2);   color: #22c55e; }
.dropdown-item.cat-procedures .icon  { background: rgba(236, 72, 153, 0.2);  color: #ec4899; }
.dropdown-item.cat-lists .icon       { background: rgba(245, 158, 11, 0.2);  color: #f59e0b; }
.dropdown-item.cat-strings .icon     { background: rgba(6, 182, 212, 0.2);   color: #06b6d4; }
.dropdown-item.cat-programs .icon    { background: rgba(6, 182, 212, 0.2);   color: #06b6d4; }

/* ─── Main layout ─── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  min-height: 0;
  position: relative;
}

.resizer {
  position: absolute;
  width: 12px;
  height: 100%;
  background: transparent;
  cursor: col-resize;
  top: 0;
  left: calc(50% - 6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.resizer::after {
  content: '';
  width: 4px;
  height: 48px;
  background: var(--border);
  border-radius: 2px;
  transition: all 0.2s ease;
}

.resizer:hover::after {
  background: var(--accent);
  height: 64px;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ─── Panel ─── */
.panel {
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}

.panel-header .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ─── Toolbar ─── */
.toolbar {
  padding: 12px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 8px;
}

/* ─── Editor ─── */
.editor-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--editor-bg);
}

.line-numbers {
  padding: 16px 12px;
  background: var(--editor-bg);
  color: var(--text-muted);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  text-align: right;
  user-select: none;
  border-right: 1px solid var(--border);
  min-width: 48px;
  overflow: hidden;
  white-space: pre;
}

textarea {
  flex: 1;
  padding: 16px;
  background: var(--editor-bg);
  color: var(--editor-text);
  border: none;
  outline: none;
  resize: none;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  caret-color: var(--editor-caret);
  overflow: auto;
}

textarea::placeholder {
  color: var(--text-muted);
}

/* ─── Console ─── */
.console {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--console-bg);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  line-height: 1.7;
}

.console .line { padding: 2px 0; border-radius: 4px; }
.console .log  { color: var(--console-log); }
.console .err  { color: var(--console-err); }
.console .sys  { color: var(--console-sys); }
.console .help {
  color: var(--console-help);
  background: rgba(251, 191, 36, 0.1);
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 8px;
  border-left: 3px solid var(--console-help);
}
.console .help-title { font-weight: 600; margin-bottom: 4px; }
.console .help-code {
  background: rgba(0,0,0,0.3);
  padding: 8px 12px;
  border-radius: 6px;
  margin-top: 8px;
  font-size: 12px;
  white-space: pre;
}

/* ─── Prompt ─── */
.prompt-wrap {
  display: none;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.prompt-wrap.show { display: flex; }

.prompt-wrap input {
  flex: 1;
  padding: 10px 14px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.prompt-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Status bar ─── */
.status {
  padding: 8px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.running {
  background: var(--accent);
  animation: pulse 1s infinite;
}

.status-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Footer ─── */
footer {
  padding: 12px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

footer a { color: var(--accent); text-decoration: none; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 2000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Keyboard hint ─── */
.kbd-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

kbd {
  padding: 2px 6px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
}

/* ─── Help Modal ─── */
.help-modal, .blocks-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  backdrop-filter: blur(4px);
}

.help-modal.show, .blocks-modal.show { display: flex; }

.help-content {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.help-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.help-header h3 { font-size: 18px; font-weight: 600; }

.help-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.7;
}

.help-section { margin-bottom: 24px; }

.help-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.help-section pre {
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

/* ─── Blocks Modal ─── */
.blocks-content {
  background: #ffffff;
  border: 1px solid #ccc;
  border-radius: 8px;
  width: 95%;
  max-width: 900px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.3);
}

.blocks-header {
  padding: 12px 20px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.blocks-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}

.blocks-header .close-btn {
  background: #e9ecef;
  border: 1px solid #ccc;
  color: #333;
  padding: 6px 12px;
  font-size: 12px;
}

.blocks-header .close-btn:hover { background: #ddd; }

.blocks-body {
  padding: 20px;
  overflow-y: auto;
  background: #ffffff;
  min-height: 200px;
}

/* ─── APCSP Block Styles (Authentic Exam Format) ─── */
#APblocks, .block-container {
  font-family: monospace;
  font-size: 14px;
  color: #000;
}

.block-statement { display: block; margin: 1px 0; }

.bl, .block-expr {
  border: solid 1px black;
  border-radius: 5px;
  font-family: monospace;
  padding: 2px 5px;
  background-color: white;
  display: inline-block;
  margin-top: 1px;
}

.val, .block-val {
  border: solid 1px black;
  border-radius: 0px;
  margin: 1px;
  padding: 2px 3px;
  display: inline-block;
  background-color: white;
}

.cond, .block-cond {
  border: solid 1px black;
  border-radius: 30px;
  padding: 1px 10px;
  display: inline-block;
  background-color: white;
}

.dark, .block-control {
  background-color: #dddddd;
  border: solid 1px black;
  border-radius: 5px;
  padding: 5px;
  padding-top: 5px;
  margin: 1px 0;
  display: block;
}

.block-control-header { display: inline; }
.block-control-body {
  display: block;
  margin-left: 16px;
  margin-top: 1px;
}

.block-procedure {
  background-color: #dddddd;
  border: solid 1px black;
  border-radius: 5px;
  padding: 5px;
  margin: 1px 0;
  display: block;
}

.block-procedure-header { display: inline; }
.block-procedure-body {
  display: block;
  margin-left: 16px;
  margin-top: 1px;
}

.block-keyword  { font-weight: normal; font-family: monospace; }
.block-arrow    { font-family: monospace; }

.block-list {
  border: solid 1px black;
  border-radius: 0px;
  padding: 2px 3px;
  display: inline-block;
  background-color: white;
}

.block-else {
  margin-top: 1px;
  font-family: monospace;
  display: block;
}

.blocks-error {
  background: #fff3f3;
  border: 1px solid #ffcdd2;
  border-radius: 5px;
  padding: 12px;
  color: #c62828;
  font-size: 14px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .resizer {
    width: 100%;
    height: 12px;
    top: calc(50% - 6px);
    left: 0;
    cursor: row-resize;
  }

  .resizer::after {
    width: 48px;
    height: 4px;
  }

  .toolbar { flex-wrap: wrap; }
  .kbd-hint { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   SYNTAX HIGHLIGHTING
   Overlay technique: highlight-layer sits behind a transparent
   textarea. Must match textarea font/size/padding exactly.
   ═══════════════════════════════════════════════════════════════ */

.editor-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--editor-bg);
}

#highlight-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  margin: 0;
  border: none;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 4;
  -moz-tab-size: 4;
  pointer-events: none;
  overflow: hidden;
  color: var(--editor-text);
  z-index: 0;
}

/* Hide scrollbar on highlight layer — textarea handles scrolling */
#highlight-layer::-webkit-scrollbar { display: none; }
#highlight-layer { scrollbar-width: none; }

/* Transparent textarea — in normal flex flow so scroll works correctly */
.editor-area textarea {
  flex: 1;
  position: relative;
  z-index: 1;
  background: transparent !important;
  color: transparent !important;
  caret-color: var(--editor-caret) !important;
  tab-size: 4;
  -moz-tab-size: 4;
  overflow: auto;
  resize: none;
  min-height: 0;
}

/* Prevent bold/italic tokens from shifting line heights */
#highlight-layer span {
  line-height: inherit;
  display: inline;
}

/* ── Token colors — dark mode ── */
.hl-keyword { color: #3fa9eb; }   /* IF ELSE REPEAT FOR EACH IN UNTIL TIMES */
.hl-proc    { color: #bd93f9; }   /* PROCEDURE RETURN */
.hl-io      { color: #2ade58; }   /* DISPLAY INPUT */
.hl-builtin { color: #cd56d1; }   /* APPEND INSERT REMOVE LENGTH CONTAINS SUBSTRING RANDOM */
.hl-string  { color: #ede611; }   /* "strings" */
.hl-number  { color: #fca03d; }   /* 42  3.14 */
.hl-arrow   { color: #ff006e; }   /* ←  ≤  ≥  ≠ */
.hl-comment { color: #788096; }   /* # comments */
.hl-boolop  { color: #969593; }   /* AND OR NOT MOD */
.hl-literal { color: #bd93f9; }   /* true false */

/* ── Token colors — light mode ── */
body.light-mode .hl-keyword { color: #9600c8; }
body.light-mode .hl-proc    { color: #7c3aed; }
body.light-mode .hl-io      { color: #166534; }
body.light-mode .hl-builtin { color: #0369a1; }
body.light-mode .hl-string  { color: #92400e; }
body.light-mode .hl-number  { color: #c2410c; }
body.light-mode .hl-arrow   { color: #be123c; }
body.light-mode .hl-comment { color: #6b7280; }
body.light-mode .hl-boolop  { color: #c2410c; }
body.light-mode .hl-literal { color: #7c3aed; }
