/* ══════════════════════════════════════════════════════════════
   LOGIFUNGE — stylesheet
   v4: split out of index.html for maintainability + QOL polish
   (transitions, focus states, scrollbars, small-screen layout)
   ══════════════════════════════════════════════════════════════ */

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

/* ── LAYOUT: nothing scrolls except the editor ── */
html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  background: #111;
  color: #ccc;
}

/* ── SCROLLBARS (themed to match the dark UI instead of default chrome) ── */
* { scrollbar-width: thin; scrollbar-color: #333 #111; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: #111; }
*::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: #444; }

/* ── FOCUS STATES (keyboard accessibility) ── */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 1px solid #fa0;
  outline-offset: 1px;
}

/* ── TOP BAR ── */
#top-bar {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

#top-bar button, #top-bar input, #top-bar select {
  font-family: inherit;
  font-size: 12px;
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 2px 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
#top-bar button:hover { border-color: #aaa; color: #fff; }
#btn-run { border-color: #fa0; color: #fa0; }
#btn-run:hover { background: #fa0; color: #000; }
#btn-run.running { border-color: #f44; color: #f44; }

.sep { width: 1px; height: 20px; background: #333; margin: 0 2px; flex-shrink: 0; }
#spacer { flex: 1; }

#status { font-size: 11px; color: #666; white-space: nowrap; transition: color 0.15s ease; }
#status.ok  { color: #0f8; }
#status.err { color: #f44; }

#speed-wrap, #dir-wrap, #max-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #666;
  flex-shrink: 0;
}
#speed-wrap select, #max-wrap input { min-width: 84px; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}
#dir-indicator {
  color: #fa0;
  border: 1px solid #333;
  padding: 2px 6px;
  font-size: 11px;
}

/* mode toggle */
#mode-wrap { display: flex; border: 1px solid #333; flex-shrink: 0; }
#mode-wrap button {
  border: none;
  border-right: 1px solid #333;
  padding: 2px 8px;
  color: #555;
  font-size: 11px;
}
#mode-wrap button:last-child { border-right: none; }
#mode-wrap button.active { background: #222; color: #fa0; }

/* dim inputs */
#dim-wrap { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #555; flex-shrink: 0; }
#dim-wrap input { width: 40px; text-align: center; padding: 2px 4px; }
#dim-wrap.hidden { display: none; }

/* ── MAIN BODY ── */
#body {
  display: flex;
  height: calc(100vh - 36px);
}

/* ── EDITOR SIDE ── */
#editor-pane {
  width: 50%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #333;
}

#editor-pane-header {
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  border-bottom: 1px solid #333;
  font-size: 10px;
  color: #555;
  flex-shrink: 0;
  letter-spacing: 1px;
}

/* Ace editor fills the rest */
#ace-editor {
  flex: 1;
  overflow: hidden; /* ace handles its own scroll */
}

#stack-bar {
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  border-top: 1px solid #333;
  font-size: 10px;
  color: #555;
  overflow: hidden;
  flex-shrink: 0;
}
#stack-bar span.val {
  border: 1px solid #333;
  padding: 0 4px;
  color: #0f8;
  font-size: 10px;
}
#stack-bar span.val.packed {
  border: 2px solid #6ee7f9;
  background: rgba(110, 231, 249, 0.16);
  color: #6ee7f9;
  font-weight: 700;
  padding: 0 5px;
  border-radius: 3px;
}

/* ── OUTPUT SIDE ── */
#display-pane {
  width: 50%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#display-pane-header {
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid #333;
  font-size: 10px;
  color: #555;
  flex-shrink: 0;
  letter-spacing: 1px;
}

/* text output: no scroll on the pane itself */
#text-output {
  flex: 1;
  min-height: 0;
  padding: 12px;
  font-family: inherit;
  font-size: 13px;
  color: #0f8;
  display: none;
  overflow: hidden; /* no scroll */
  white-space: pre-wrap;
  word-break: break-all;
}
#text-output.visible { display: block; }

/* pixel output */
#pixel-output {
  flex: 1;
  min-height: 0;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#pixel-output.visible { display: flex; }

#canvas-wrap { position: relative; }
#pixel-canvas { image-rendering: pixelated; display: block; }
#grid-overlay { position: absolute; top: 0; left: 0; pointer-events: none; opacity: 0.15; }

/* ── HELP MODAL ── */
#help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#help-modal.open { display: flex; }

#help-box {
  background: #111;
  border: 1px solid #444;
  width: min(920px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 18px 22px;
  font-size: 12px;
}

#help-box h2 {
  font-size: 13px;
  color: #fa0;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#help-close { cursor: pointer; color: #555; font-size: 11px; transition: color 0.15s ease; }
#help-close:hover { color: #ccc; }

.help-section { margin-bottom: 16px; }
.help-section h3 { font-size: 10px; color: #555; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 8px; border-bottom: 1px solid #222; padding-bottom: 4px; }

.ref-table {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 4px 14px;
  align-items: start;
}
.ref-key {
  color: #fa0;
  font-family: inherit;
  white-space: nowrap;
}
.ref-desc {
  color: #888;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}

.help-hint { font-size: 10px; color: #444; margin-top: 12px; }

.ace_active-cell {
  background: rgba(250, 160, 0, 0.18) !important;
  box-shadow: inset 0 0 0 1px rgba(250, 160, 0, 0.45);
}

/* ── EXAMPLES inside help ── */
.example-card {
  border: 1px solid #2a2a2a;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.example-card:hover { border-color: #555; }
.example-card:focus-visible { outline: 1px solid #fa0; outline-offset: 1px; }
.example-name { color: #fa0; font-size: 11px; margin-bottom: 2px; }
.example-desc { color: #555; font-size: 10px; margin-bottom: 4px; }
.example-code { font-family: inherit; font-size: 11px; color: #0f8; background: #0a0a0a; padding: 4px 6px; white-space: pre; overflow-x: auto; }

/* ── RESPONSIVE: stack panes vertically on narrow / mobile viewports ── */
@media (max-width: 720px) {
  html, body { overflow-y: auto; height: auto; min-height: 100vh; }

  #top-bar { flex-wrap: wrap; height: auto; padding: 6px 8px; overflow-x: visible; }
  .sep { display: none; }

  #body { flex-direction: column; height: auto; }
  #editor-pane, #display-pane { width: 100%; }
  #editor-pane { border-right: none; border-bottom: 1px solid #333; }
  #ace-editor { height: 45vh; }
  #pixel-output, #text-output { min-height: 40vh; }

  #help-box { padding: 14px; }
  .ref-table { grid-template-columns: auto 1fr; }
}
