/* ============================================================
   Mac Playground - styles.css
   Design language: warm dark editorial (inherits macstudio.meme)
   ============================================================ */

@import url("/shared/css/tokens.css");

:root {
    --topbar-h: 48px;
    --statusbar-h: 28px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Shell ────────────────────────────────────────────── */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── Top Bar ──────────────────────────────────────────────── */
.topbar {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
  z-index: 100;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: var(--topbar-h);
}

.topbar-row--secondary {
  height: 36px;
  border-top: 1px solid var(--divider);
  gap: 6px;
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-right: auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.topbar-brand-sub {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Main Layout ──────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Editor panel */
.panel-editor {
  flex: 6;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--divider);
  overflow: hidden;
}

.editor-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Upload gallery strip */
.upload-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  border-top: 1px solid var(--divider);
  min-height: 0;
  max-height: 80px;
  overflow-y: auto;
  background: var(--surface);
}

.upload-gallery:empty {
  display: none;
}

.upload-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--divider-strong);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.upload-thumb:hover {
  border-color: var(--teal);
  transform: scale(1.05);
}

/* Output panel */
.panel-output {
  flex: 4;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* ── Collapsible Panes ───────────────────────────────────── */
.panel-output {
  display: flex;
  flex-direction: column;
}

.output-pane,
.render-pane {
  border-top: 1px solid var(--divider);
  overflow: hidden;
}

/* When closed, only show the summary bar */
.output-pane:not([open]),
.render-pane:not([open]) {
  flex: 0 0 auto;
}

/* When open, fill available space */
.output-pane[open] {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.render-pane[open] {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
  max-height: 60%;
  overflow-y: auto;
  background: var(--surface);
}

.output-pane__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 32px;
  flex-shrink: 0;
  background: var(--surface);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.output-pane__toggle::-webkit-details-marker { display: none; }
.output-pane__toggle::before {
  content: '\25B6';
  font-size: 0.5rem;
  transition: transform 0.2s;
  color: var(--ink-faint);
}
.output-pane[open] > .output-pane__toggle::before,
.render-pane[open] > .output-pane__toggle::before {
  transform: rotate(90deg);
}

.output-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  background: var(--surface-active);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

.output-clear {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: auto;
  transition: color 0.15s, background 0.15s;
}
.output-clear:hover {
  color: var(--ink);
  background: var(--surface-active);
  margin-left: auto;
}

.output-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 0;
}

.output-stdout {
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-word;
}

.output-stderr {
  color: var(--red);
  white-space: pre-wrap;
  word-break: break-word;
}

.output-empty {
  color: var(--ink-faint);
  font-style: italic;
}

/* Render area */
.render-pane img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  display: block;
}

.render-images {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  width: 100%;
}

.render-image-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.render-image-wrap a {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--teal);
  text-decoration: none;
}

.render-image-wrap a:hover {
  text-decoration: underline;
}

/* ── Status Bar ───────────────────────────────────────────── */
.statusbar {
  flex-shrink: 0;
  height: var(--statusbar-h);
  background: var(--surface);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  z-index: 100;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
  transition: background 0.2s;
}

.status-dot.ready    { background: var(--green); }
.status-dot.running  { background: var(--gold); }
.status-dot.error    { background: var(--red); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 13px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-run {
  background: var(--accent);
  color: #fff;
}

.btn-run:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-render {
  background: var(--teal);
  color: #fff;
}

.btn-render:hover:not(:disabled) {
  background: var(--teal-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--divider-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-share {
  background: var(--surface-active);
  color: var(--ink-muted);
}

.btn-share:hover:not(:disabled) {
  background: var(--surface-active-strong);
  color: var(--ink);
}

.btn-sm {
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
}

/* ── Select Dropdown ──────────────────────────────────────── */
.select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-hover);
  color: var(--ink-muted);
  border: 1px solid var(--divider-strong);
  border-radius: var(--radius-sm);
  padding: 0 28px 0 10px;
  height: 30px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23e8e0d4' fill-opacity='0.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  transition: border-color 0.15s;
  min-width: 130px;
}

.select:hover {
  border-color: var(--ink-faint);
  color: var(--ink);
}

.select:focus {
  outline: none;
  border-color: var(--teal);
}

.select option {
  background: var(--surface-active);
  color: var(--ink);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--statusbar-h) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--surface-active-strong);
  color: var(--ink);
  border: 1px solid var(--divider-strong);
  border-radius: var(--radius);
  padding: 8px 18px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9999;
  white-space: nowrap;
}

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

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Scrollbar Styling (webkit) ───────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--divider-strong);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-faint);
}

/* ── Resizer ──────────────────────────────────────────────── */
.panel-resizer {
  width: 4px;
  flex-shrink: 0;
  background: var(--divider);
  cursor: col-resize;
  transition: background 0.15s;
}

.panel-resizer:hover {
  background: var(--teal);
}

/* ── Desktop: single-row topbar ──────────────────────────── */
@media (min-width: 601px) {
  .topbar {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    padding: 0 14px;
    gap: 8px;
  }

  .topbar-row,
  .topbar-row--secondary {
    display: contents;
  }

  .topbar-brand {
    margin-right: auto;
  }
}

/* ── Responsive: Tablet ──────────────────────────────────── */
@media (max-width: 900px) {
  .main {
    flex-direction: column;
  }

  .panel-editor {
    flex: 1;
    border-right: none;
    border-bottom: 1px solid var(--divider);
    min-height: 40vh;
  }

  .panel-output {
    flex: 1;
    min-height: 0;
  }

  .render-pane {
    max-height: 40%;
  }

  .topbar {
    gap: 6px;
    padding: 0 10px;
  }

  .btn {
    padding: 0 10px;
    font-size: 12px;
  }

  .select {
    min-width: 100px;
    font-size: 12px;
  }
}

/* ── Responsive: Mobile ──────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --topbar-h: 36px;
    --statusbar-h: 24px;
  }

  /* Single row: brand left, Run + Render right */
  .topbar-row {
    padding: 0 10px;
    height: var(--topbar-h);
  }

  .topbar-brand-name {
    font-size: 17px;
  }

  /* Second row: examples, upload, share, docs */
  .topbar-row--secondary {
    height: 32px;
    padding: 0 10px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .btn {
    padding: 0 8px;
    height: 26px;
    font-size: 11px;
  }

  .select {
    min-width: 0;
    width: 90px;
    font-size: 11px;
    padding: 0 20px 0 6px;
    height: 26px;
  }

  .panel-editor {
    min-height: 35vh;
  }

  .output-body {
    font-size: 11.5px;
    padding: 8px 10px;
  }

  .statusbar {
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px));
    font-size: 10px;
  }

  /* Prevent iOS zoom on focus */
  input[type="text"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px;
  }

  .upload-gallery {
    max-height: 60px;
    padding: 4px 8px;
  }

  .upload-thumb {
    width: 42px;
    height: 42px;
  }

  .render-pane img {
    max-height: 200px;
  }

  .toast {
    max-width: 90vw;
    font-size: 12px;
  }
}

/* Short/full button labels */
.btn-label-short { display: none; }

@media (max-width: 400px) {
  .btn-label-full { display: none; }
  .btn-label-short { display: inline; }

  .topbar-brand {
    margin-right: 4px;
  }
}
