/*
 * simulator.css — PyDevices Interactive Python Simulator Stylesheet
 *
 * Full-screen IDE workspace with resizable panels, Monaco Editor integration,
 * realistic device bezel, real-time REPL console, and dark/light themes.
 */

:root {
  --bg-app: #090d16;
  --bg-panel: #0f172a;
  --bg-panel-subtle: #1e293b;
  --bg-control: #1e293b;
  --bg-control-hover: #334155;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --accent: #f54e00;
  --accent-glow: rgba(245, 78, 0, 0.3);
  --accent-blue: #38bdf8;
  --accent-green: #34d399;
  --accent-red: #f87171;
  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Monaco, Consolas, monospace;
  --header-height: 54px;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-panel-subtle: #f8fafc;
  --bg-control: #e2e8f0;
  --bg-control-hover: #cbd5e1;
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  --accent: #ea580c;
  --accent-glow: rgba(234, 88, 12, 0.2);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Top Navigation & Action Toolbar
   ========================================================================== */

.sim-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 50;
  user-select: none;
}

.sim-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
}

.sim-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.sim-brand-title {
  white-space: nowrap;
}

.sim-brand-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, rgba(245, 78, 0, 0.2), rgba(56, 189, 248, 0.2));
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  white-space: nowrap;
  flex: none;
}

.sim-header-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.sim-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* Control elements & Buttons */

.sim-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.sim-select-wrap select {
  appearance: none;
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 30px 6px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.sim-select-wrap select:hover {
  border-color: var(--accent);
  background: var(--bg-control-hover);
}

.sim-select-wrap::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  pointer-events: none;
}

.sim-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

.sim-btn:hover {
  background: var(--bg-control-hover);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.sim-btn:active {
  transform: translateY(0);
}

.sim-btn-primary {
  background: linear-gradient(135deg, #f54e00, #ff6b26);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.sim-btn-primary:hover {
  background: linear-gradient(135deg, #ff6019, #ff7e42);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.sim-btn kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0.85;
}

.sim-icon-btn {
  padding: 6px 10px;
}

.sim-icon-btn svg {
  width: 16px;
  height: 16px;
}

.sim-install-hint {
  position: fixed;
  z-index: 1000;
  top: 58px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 13px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--bg-panel);
  color: var(--text-main);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  font-size: 0.82rem;
}

.sim-install-hint[hidden] { display: none; }
.sim-install-arrow { color: var(--accent); font-size: 1.4rem; line-height: 1; }
.sim-install-dismiss {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
}

@media (max-width: 720px) {
  .sim-install-hint { top: 72px; right: 8px; max-width: calc(100vw - 16px); }
}

/* ==========================================================================
   Workspace Main Layout & Split Panes
   ========================================================================== */

.sim-workspace {
  display: flex;
  width: 100%;
  height: calc(100% - var(--header-height));
  position: relative;
  overflow: hidden;
}

/* Left Pane: Code Editor */
.sim-editor-pane {
  flex: 1 1 50%;
  min-width: 280px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  position: relative;
}

.sim-pane-header {
  height: 36px;
  background: var(--bg-panel-subtle);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}

.sim-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
}

/* File tab strip above the editor */
.sim-tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 100%;
  min-width: 0;
  flex: 0 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.sim-tabs::-webkit-scrollbar {
  display: none;
}

.sim-file-tab {
  display: flex;
  align-items: center;
  flex: none;
  border-bottom: 2px solid transparent;
}

.sim-file-tab.is-active {
  border-bottom-color: var(--accent);
}

.sim-file-tab-name {
  background: none;
  border: none;
  padding: 0 4px 0 8px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.sim-file-tab.is-active .sim-file-tab-name,
.sim-file-tab-name:hover {
  color: var(--text-main);
}

.sim-file-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-right: 4px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-subtle);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.sim-file-tab-close:hover {
  background: var(--bg-control-hover);
  color: var(--accent-red);
}

/* main.py is the entry point: it is always present, so it has no close button
   and the tab keeps the same padding as the others. */
.sim-file-tab.is-entry .sim-file-tab-name {
  padding-right: 8px;
}

.sim-tab-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 22px;
  height: 22px;
  margin-right: auto;
  padding: 0;
  background: none;
  border: none;
  border-radius: 5px;
  color: var(--text-subtle);
  cursor: pointer;
}

.sim-tab-add:hover {
  background: var(--bg-control);
  color: var(--text-main);
}

/* The program name, at the right of the tab strip. Distinct from the file tabs
   next to it: it names the whole program, not one of its files. */
.sim-program {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  max-width: 40%;
  padding: 4px 9px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.sim-program:hover {
  background: var(--bg-control);
  border-color: var(--border-color);
  color: var(--text-main);
}

.sim-program svg {
  flex: none;
  opacity: 0.75;
}

.sim-program #program-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A drawn dot rather than a "•" glyph: a bullet sized to look right needs a
   collapsed line-height, which leaves the element with a zero-height box. */
.sim-program-dirty {
  display: inline-block;
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.sim-program-dirty[hidden] {
  display: none;
}

.sim-editor-container {
  flex: 1;
  width: 100%;
  height: calc(100% - 36px);
  position: relative;
}

/* Drag Splitter */
.sim-splitter-v {
  width: 6px;
  background: var(--border-subtle);
  cursor: col-resize;
  position: relative;
  flex: none;
  transition: background 0.15s ease;
  z-index: 40;
  /* Without this the browser claims the gesture for scrolling and the
     pointermove stream stops after the first event on touch devices. */
  touch-action: none;
}

.sim-splitter-v:hover, .sim-splitter-v.is-dragging {
  background: var(--accent);
}

/* 6px is comfortable for a mouse but far too thin for a fingertip; widen the
   hit target without moving the visible line. */
.sim-splitter-v::before {
  content: '';
  position: absolute;
  inset: 0 -7px;
}

/* Right Pane: Simulator & Console */
.sim-preview-pane {
  flex: 1 1 50%;
  min-width: 320px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
}

.sim-device-stage {
  flex: 1 1 60%;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  position: relative;
  background:
    radial-gradient(400px 300px at 50% 50%, rgba(56, 189, 248, 0.04), transparent 70%),
    var(--bg-app);
}

/* Realistic Device Bezel */
.sim-device-bezel {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(145deg, #2a313d, #141821);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 1px rgba(255, 255, 255, 0.15);
  position: relative;
  transition: all 0.25s ease;
}

.sim-device-bezel.is-round {
  border-radius: 50%;
  padding: 18px;
}

.sim-device-bezel.is-round #display_canvas {
  border-radius: 50%;
}

#display_canvas {
  display: block;
  background: #000000;
  border-radius: 12px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.9);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

#aux_canvas {
  display: none;
}

/* Horizontal Splitter between Device and Console */
.sim-splitter-h {
  height: 6px;
  width: 100%;
  background: var(--border-subtle);
  cursor: row-resize;
  position: relative;
  flex: none;
  transition: background 0.15s ease;
  z-index: 40;
  touch-action: none;
}

.sim-splitter-h:hover, .sim-splitter-h.is-dragging {
  background: var(--accent);
}

.sim-splitter-h::before {
  content: '';
  position: absolute;
  inset: -7px 0;
}

/* Console / Output Panel */
.sim-console-pane {
  flex: 1 1 40%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
}

/* xterm-backed REPL. The cursor and line editing belong to MicroPython itself,
   so there is no separate input element to style. */
.sim-terminal-body {
  flex: 1;
  min-height: 0;
  padding: 8px 4px 8px 12px;
  overflow: hidden;
  background: #080c14;
}

.sim-terminal-body .xterm {
  height: 100%;
}

.sim-terminal-body .xterm-viewport {
  overflow-y: auto;
  background: transparent !important;
}

.sim-terminal-body .xterm-viewport::-webkit-scrollbar {
  width: 10px;
}

.sim-terminal-body .xterm-viewport::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 5px;
}

[data-theme="light"] .sim-terminal-body {
  background: #ffffff;
}

/* Status indicator pill in status bar */
.sim-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  /* Sits beside the REPL label rather than being spread across the header by
     the pane header's space-between. */
  margin: 0 auto 0 14px;
}

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

.sim-status-dot.is-ready { background: var(--accent-green); }
.sim-status-dot.is-busy { background: var(--accent); animation: pulse 1s infinite alternate; }
.sim-status-dot.is-error { background: var(--accent-red); }

@keyframes pulse {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

/* Overflow ("more actions") menu */
.sim-menu-wrap {
  position: relative;
  display: flex;
}

.sim-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  padding: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  z-index: 60;
}

.sim-menu[hidden] {
  display: none;
}

.sim-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.sim-menu-item:hover:not(:disabled),
.sim-menu-item:focus-visible {
  background: var(--bg-control);
  outline: none;
}

.sim-menu-item:disabled {
  color: var(--text-subtle);
  cursor: default;
}

.sim-menu-item svg {
  flex: none;
}

.sim-menu-sep {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 5px 4px;
}

/* "Reset VM to apply" banner over the device stage */
.sim-stage-notice {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 7px 8px 7px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  font-size: 0.8rem;
  color: var(--text-main);
  z-index: 30;
}

.sim-stage-notice[hidden] {
  display: none;
}

.sim-stage-notice-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
}

.sim-stage-notice-dismiss:hover {
  color: var(--text-main);
}

/* Modal dialogs. The `* { margin: 0 }` reset above would otherwise defeat the
   `margin: auto` a modal <dialog> relies on to centre itself. */
.sim-dialog {
  margin: auto;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-panel);
  color: var(--text-main);
  padding: 20px 22px;
  min-width: 300px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.sim-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.sim-dialog-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.sim-dialog-fields {
  display: flex;
  gap: 12px;
}

.sim-dialog-fields label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sim-dialog-fields input {
  width: 110px;
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  outline: none;
}

.sim-dialog-fields input:focus {
  border-color: var(--accent);
}

.sim-dialog-hint {
  margin-top: 12px;
  font-size: 0.74rem;
  color: var(--text-subtle);
  max-width: 260px;
}

.sim-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Saved programs dialog */
.sim-dialog-wide {
  width: min(440px, calc(100vw - 32px));
}

.sim-save-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sim-save-name {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sim-save-name input {
  width: 100%;
  background: var(--bg-control);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  outline: none;
}

.sim-save-name input:focus {
  border-color: var(--accent);
}

.sim-save-list {
  list-style: none;
  margin: 14px 0 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.sim-save-list:empty {
  display: none;
}

.sim-save-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.sim-save-list li:last-child {
  border-bottom: none;
}

.sim-save-list li.is-current {
  background: var(--bg-panel-subtle);
}

.sim-save-entry {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.sim-save-entry:hover .sim-save-entry-name {
  color: var(--accent);
}

.sim-save-entry-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sim-save-entry-meta {
  font-size: 0.71rem;
  color: var(--text-subtle);
}

.sim-save-delete {
  flex: none;
  background: none;
  border: none;
  color: var(--text-subtle);
  font-size: 1.05rem;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.sim-save-delete:hover {
  color: var(--accent-red);
  background: var(--bg-control);
}

.sim-save-empty {
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--text-subtle);
}

.sim-save-empty[hidden] {
  display: none;
}

.sim-dialog-actions a.sim-btn {
  text-decoration: none;
}

/* Toast Message */
.sim-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  transform: translateY(60px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

.sim-toast.is-active {
  transform: translateY(0);
  opacity: 1;
}

/* Responsive Stacking for Mobile / Narrow screens */
@media (max-width: 880px) {
  .sim-header {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }

  .sim-workspace {
    flex-direction: column;
    height: calc(100% - 90px);
  }

  .sim-splitter-v {
    display: none;
  }

  .sim-editor-pane {
    flex: 1 1 50%;
    min-height: 250px;
  }

  .sim-preview-pane {
    flex: 1 1 50%;
    min-height: 250px;
  }

  .sim-header-center {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }
}
