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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1e1e1e;
  color: #d4d4d4;
}

#app {
  display: flex;
  /* Use dvh for iOS Safari dynamic address bar, fallback to vh */
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  /* iOS Safari safe area for notch/address bar */
  padding-top: env(safe-area-inset-top);
}

#editor-panel {
  width: 40%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #3c3c3c;
}

#explicit-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 120px;
}

#repl-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 120px;
}

#repl-terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1a1a2e;
  font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

#repl-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.repl-entry {
  margin-bottom: 4px;
}

.repl-entry .repl-input-echo {
  color: #d4d4d4;
}

.repl-entry .repl-prompt {
  color: #6a9955;
}

.repl-entry .repl-result {
  color: #9cdcfe;
  margin-left: 20px;
}

.repl-entry .repl-nil {
  color: #6a6a6a;
  margin-left: 20px;
}

.repl-entry .repl-error {
  color: #f48771;
  margin-left: 20px;
}

.repl-entry .repl-print-output {
  color: #d4d4d4;
  margin-left: 20px;
  white-space: pre-wrap;
  font-style: italic;
}

#repl-input-line {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: #252530;
  border-top: 1px solid #3c3c3c;
}

#repl-input-line .repl-prompt {
  color: #6a9955;
  margin-right: 8px;
  font-weight: bold;
}

#repl-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #d4d4d4;
  font-family: inherit;
  font-size: inherit;
}

#repl-input::placeholder {
  color: #6a6a6a;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: #808080;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-hint {
  font-size: 11px;
  color: #6a6a6a;
}

.section-actions {
  display: flex;
  gap: 4px;
}

.action-btn {
  padding: 2px 8px;
  border: 1px solid #3c3c3c;
  background: transparent;
  color: #808080;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s ease;
}

.action-btn:hover {
  background: #3c3c3c;
  color: #d4d4d4;
}

.run-btn {
  color: #4ec9b0;
  font-size: 10px;
  padding: 2px 6px;
}

.run-btn:hover {
  background: #2d4a3e;
  color: #4ec9b0;
}

.section-divider {
  height: 4px;
  background: #3c3c3c;
  cursor: ns-resize;
}

#editor-explicit {
  flex: 1;
  background: #1e1e1e;
  overflow: hidden;
}

/* CodeMirror container fills parent */
#editor-explicit .cm-editor {
  height: 100%;
}

#editor-explicit .cm-scroller {
  overflow: auto;
}

#error-panel {
  min-height: 40px;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px 16px;
  background: #2d2020;
  color: #f48771;
  font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  display: none;
}

#error-panel.visible {
  display: block;
}

#viewport-panel {
  flex: 1;
  min-width: 0;  /* Allow flex shrink below content size */
  position: relative;
  background: #252526;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#viewport-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 12px;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
  gap: 8px;
  position: relative; /* keep above canvas */
  z-index: 2;
}

.export-btn {
  color: #4ec9b0;
}

.export-btn:hover {
  background: #2d4a3e;
  color: #4ec9b0;
}

/* View controls (Grid, Axes, Reset) */
.view-btn {
  color: #a0a0a0;
}

.view-btn:hover {
  background: #3c3c3c;
  color: #d4d4d4;
}

.view-btn.active {
  color: #ffcc00;
  border-color: #ffcc00;
}

.view-btn.active:hover {
  background: #3d3a2d;
  color: #ffcc00;
}

.toolbar-separator {
  width: 1px;
  height: 16px;
  background: #3c3c3c;
  margin: 0 4px;
}

/* VR Button */
.vr-btn {
  color: #b48eff;
}

.vr-btn:hover:not(:disabled) {
  background: #3d2d5a;
  color: #b48eff;
}

.vr-btn:disabled {
  color: #6a6a6a;
  cursor: not-allowed;
}

/* AR/Passthrough Button */
.ar-btn {
  color: #4ecdc4;
}

.ar-btn:hover:not(:disabled) {
  background: #2d4a47;
  color: #4ecdc4;
}

.ar-btn:disabled {
  color: #6a6a6a;
  cursor: not-allowed;
}

#viewport {
  flex: 1;
  width: 100%;
  min-height: 0;  /* Allow flex shrink */
  display: block;
  position: relative;
  z-index: 1;
}

/* Horizontal resizer between editor and viewport */
#panel-resizer {
  width: 5px;
  background: #3c3c3c;
  cursor: ew-resize;
  flex-shrink: 0;
}

#panel-resizer:hover {
  background: #007acc;
}

/* Vertical resizer styling enhancement */
.section-divider:hover {
  background: #007acc;
}

/* Prevent text selection while dragging */
body.resizing-v,
body.resizing-h {
  user-select: none;
  -webkit-user-select: none;
}

body.resizing-v {
  cursor: ns-resize;
}

body.resizing-h {
  cursor: ew-resize;
}

body.resizing-v *,
body.resizing-h * {
  cursor: inherit !important;
}

/* Sync button styles */
.sync-btn {
  background: #2d5a27 !important;
}

.sync-btn:hover {
  background: #3d7a37 !important;
}

.sync-btn.waiting {
  background: #5a5a27 !important;
  animation: pulse 1.5s infinite;
}

.sync-btn.active {
  background: #27a745 !important;
}

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

/* Sync status text */
.sync-status {
  color: #8a8;
  font-size: 11px;
  margin-left: 8px;
  font-family: "SF Mono", "Monaco", "Menlo", monospace;
}

/* Sync modal */
.sync-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.sync-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
}

.sync-modal-content {
  position: relative;
  background: #2d2d2d;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.sync-modal-content h3 {
  margin-bottom: 16px;
  color: #fff;
  font-size: 18px;
}

#sync-qr-code {
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: inline-block;
}

#sync-qr-code img {
  display: block;
  width: 200px;
  height: 200px;
}

.sync-url {
  font-family: monospace;
  font-size: 11px;
  color: #888;
  word-break: break-all;
  margin-bottom: 16px;
  padding: 8px;
  background: #1a1a1a;
  border-radius: 4px;
}

.sync-copy-btn,
.sync-close-btn {
  padding: 8px 16px;
  margin: 0 4px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.sync-copy-btn {
  background: #0066cc;
  color: #fff;
}

.sync-copy-btn:hover {
  background: #0077ee;
}

.sync-close-btn {
  background: #444;
  color: #fff;
}

.sync-close-btn:hover {
  background: #555;
}

.sync-code {
  font-family: monospace;
  font-size: 36px;
  font-weight: bold;
  letter-spacing: 8px;
  color: #fff;
  background: #1a1a1a;
  padding: 16px 24px;
  border-radius: 8px;
  margin: 16px 0;
}

.sync-code-input {
  font-family: monospace;
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  width: 180px;
  padding: 12px 16px;
  border: 2px solid #444;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  margin: 16px 0;
}

.sync-code-input:focus {
  outline: none;
  border-color: #0066cc;
}

.sync-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.sync-connect-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  background: #0066cc;
  color: #fff;
}

.sync-connect-btn:hover {
  background: #0077ee;
}

.sync-status {
  font-size: 13px;
  color: #888;
  margin-top: 8px;
}

/* ============================================================
   Manual Panel Styles
   ============================================================ */

.manual-btn {
  color: #ff9800;
}

.manual-btn:hover {
  background: #3d3520;
  color: #ffb84d;
}

.manual-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.manual-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #1e1e1e;
}

.manual-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.manual-title {
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.manual-nav {
  display: flex;
  gap: 8px;
}

.manual-btn {
  padding: 6px 12px;
  border: 1px solid #3c3c3c;
  background: #2d2d2d;
  color: #d4d4d4;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.manual-btn:hover {
  background: #3c3c3c;
  color: #fff;
}

.manual-btn-lang {
  font-weight: 600;
  min-width: 36px;
}

.manual-btn-close {
  font-size: 18px;
  line-height: 1;
  padding: 4px 10px;
}

.manual-btn-close:hover {
  background: #5a2d2d;
  color: #f48771;
}

.manual-content {
  padding: 20px;
  line-height: 1.7;
}

.manual-paragraph {
  color: #d4d4d4;
  margin-bottom: 16px;
}

.manual-paragraph strong {
  color: #fff;
  font-weight: 600;
}

.manual-paragraph code {
  background: #2d2d2d;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
  font-size: 0.9em;
  color: #9cdcfe;
}

.manual-list {
  color: #d4d4d4;
  margin: 0 0 16px 0;
  padding-left: 24px;
}

.manual-list li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.manual-list strong {
  color: #fff;
  font-weight: 600;
}

.manual-list code {
  background: #2d2d2d;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
  font-size: 0.9em;
  color: #9cdcfe;
}

.manual-code-block {
  background: #1a1a2e;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0;
  overflow-x: auto;
}

.manual-code-block code {
  font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
  font-size: 13px;
  color: #d4d4d4;
  white-space: pre;
}

.manual-examples {
  padding: 0 20px 20px;
}

.manual-example {
  background: #252526;
  border: 1px solid #3c3c3c;
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.manual-example-header {
  padding: 10px 16px;
  background: #2d2d2d;
  border-bottom: 1px solid #3c3c3c;
  font-weight: 600;
  color: #fff;
  font-size: 14px;
}

.manual-example-code {
  border-bottom: 1px solid #3c3c3c;
}

.manual-example-code .cm-editor {
  max-height: 200px;
}

.manual-example-buttons {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: #2d2d2d;
}

.manual-btn-run {
  background: #2d5a27;
  border-color: #3d7a37;
  color: #4ec9b0;
}

.manual-btn-run:hover {
  background: #3d7a37;
  color: #5eddcf;
}

.manual-btn-copy {
  background: #2d4a5a;
  border-color: #3d6a7a;
  color: #569cd6;
}

.manual-btn-copy:hover {
  background: #3d6a7a;
  color: #6eb3f7;
}

.manual-example-description {
  padding: 12px 16px;
  color: #a0a0a0;
  font-size: 13px;
  line-height: 1.5;
  border-top: 1px solid #3c3c3c;
  background: #1e1e1e;
  margin: 0;
}

.manual-page-nav {
  display: flex;
  justify-content: space-between;
  padding: 20px;
  border-top: 1px solid #3c3c3c;
  margin-top: auto;
}

.manual-btn-nav {
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manual-btn-next {
  margin-left: auto;
}

.manual-btn-back {
  font-weight: bold;
  padding: 6px 10px;
}

.manual-btn-up {
  font-weight: bold;
  padding: 6px 10px;
}

/* Table of Contents styles */
.manual-toc {
  padding: 20px;
}

.manual-toc-section {
  margin-bottom: 24px;
}

.manual-toc-section-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #3c3c3c;
}

.manual-toc-pages {
  list-style: none;
  padding: 0;
  margin: 0;
}

.manual-toc-pages li {
  margin-bottom: 8px;
}

.manual-toc-link {
  color: #569cd6;
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  display: block;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.manual-toc-link:hover {
  background: #2d4a5a;
  color: #6eb3f7;
}

/* See Also section */
.manual-see-also {
  padding: 16px 20px;
  border-top: 1px solid #3c3c3c;
  background: #252526;
}

.manual-see-also-title {
  font-size: 13px;
  font-weight: 600;
  color: #808080;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.manual-see-also-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.manual-see-also-link {
  color: #569cd6;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  background: #2d2d2d;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.manual-see-also-link:hover {
  background: #2d4a5a;
  border-color: #4a7a9a;
  color: #6eb3f7;
}
