/* ============================================================
   MERIK PLAYGROUND — playground.php
   ============================================================ */

:root {
  --pg-bg:      #1e1e2e;
  --pg-surface: #252535;
  --pg-border:  rgba(255,255,255,0.08);
  --pg-text:    #cdd6f4;
  --pg-muted:   #6c7086;
  --primary:    #00bcd4;
  --nav-h:      48px;
  --toolbar-h:  46px;
}

.pg-body {
  background: var(--pg-bg);
  color: var(--pg-text);
  overflow: hidden;
  height: 100vh;
}

/* ── Playground Nav ─────────────────────────────────────── */
.pg-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: #11111b;
  border-bottom: 1px solid var(--pg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

.pg-nav-left, .pg-nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pg-nav-logo img { height: 28px; border-radius: 5px; }

.pg-nav-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 7px;
}

.pg-online-chip, .pg-user-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.7);
  border: 1px solid var(--pg-border);
}

.pg-nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  transition: all 0.2s;
}
.pg-nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }

.pg-theme-btn {
  width: 32px; height: 32px;
  border-radius: 7px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--pg-border);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.pg-theme-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* ── Toolbar ────────────────────────────────────────────── */
.pg-toolbar {
  position: fixed;
  top: var(--nav-h); left: 0; right: 0;
  height: var(--toolbar-h);
  background: #181825;
  border-bottom: 1px solid var(--pg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  z-index: 99;
}
.pg-toolbar-left { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; overflow-x: auto; }
.pg-toolbar-right { flex-shrink: 0; }

.pg-tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 7px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--pg-border);
  color: rgba(255,255,255,0.72);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: 'DM Sans', sans-serif;
}
.pg-tool-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.pg-tool-primary { background: rgba(0,188,212,0.15); border-color: rgba(0,188,212,0.4); color: #00bcd4; }
.pg-tool-primary:hover { background: rgba(0,188,212,0.25); color: #fff; }
.pg-tool-danger { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #ef4444; }
.pg-tool-danger:hover { background: rgba(239,68,68,0.2); }
.pg-tool-sm { padding: 4px 9px; font-size: 0.75rem; }
.pg-tool-divider { width: 1px; height: 20px; background: var(--pg-border); margin: 0 4px; flex-shrink: 0; }

.pg-error-log {
  font-size: 0.75rem;
  color: #ef4444;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Editor Layout ──────────────────────────────────────── */
.pg-editor-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - var(--nav-h) - var(--toolbar-h));
  margin-top: calc(var(--nav-h) + var(--toolbar-h));
  overflow: hidden;
}

.pg-code-panels {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  border-right: 1px solid var(--pg-border);
  overflow: hidden;
}

.pg-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--pg-border);
  overflow: hidden;
}
.pg-panel:last-child { border-bottom: none; }

.pg-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #11111b;
  border-bottom: 1px solid var(--pg-border);
  flex-shrink: 0;
}
.pg-panel-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 7px;
  color: rgba(255,255,255,0.65);
}

/* Override CodeMirror to fill panel */
.pg-panel .CodeMirror {
  flex: 1;
  height: 100%;
  font-family: 'Fira Code', 'JetBrains Mono', monospace !important;
  font-size: 13px !important;
  line-height: 1.6 !important;
}

/* Preview */
.pg-preview-panel {
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}
.pg-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #11111b;
  border-bottom: 1px solid var(--pg-border);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  flex-shrink: 0;
}

#pg-output {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}

/* ── Projects Modal ─────────────────────────────────────── */
.pg-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pg-modal.open { display: flex; }
.pg-modal-inner {
  background: var(--pg-surface);
  border: 1px solid var(--pg-border);
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pg-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--pg-border);
}
.pg-modal-header h3 {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pg-modal-close {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--pg-border);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.pg-modal-close:hover { background: rgba(239,68,68,0.2); color: #ef4444; }
.pg-modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

/* Light theme overrides */
.pg-body.light {
  --pg-bg:      #f4f6f9;
  --pg-surface: #ffffff;
  --pg-border:  #d1d5db;
  --pg-text:    #1a1a2e;
  --pg-muted:   #6b7280;
}
.pg-body.light .pg-nav,
.pg-body.light .pg-mobile-tabs { background: #e8eaed !important; border-color: #d1d5db; }
.pg-body.light .pg-toolbar      { background: #f0f0f5 !important; border-color: #d1d5db; }
.pg-body.light .pg-panel-header,
.pg-body.light .pg-preview-header { background: #e8eaed !important; border-color: #d1d5db; }
.pg-body.light .pg-modal-inner  { background: #fff; }
.pg-body.light .pg-tool-btn     { color: #374151; border-color: #d1d5db; background: rgba(0,0,0,.04); }
.pg-body.light .pg-tool-btn:hover { background: rgba(0,0,0,.08); color: #111; }
.pg-body.light .pg-nav-title,
.pg-body.light .pg-nav-link     { color: #374151; }
.pg-body.light .pg-nav-link:hover { background: rgba(0,0,0,.07); }
.pg-body.light .pg-online-chip,
.pg-body.light .pg-user-chip    { background: rgba(0,0,0,.06); color: #374151; border-color: #d1d5db; }
.pg-body.light .pg-theme-btn    { background: rgba(0,0,0,.06); color: #374151; border-color: #d1d5db; }
.pg-body.light .pg-mobile-tab   { color: #6b7280; }
.pg-body.light .pg-mobile-tab.active { color: #111; }
.pg-body.light .CodeMirror      { background: #fff !important; color: #1a1a2e !important; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  /* ── Nav ──────────────────────────────────────────────── */
  .pg-body { overflow: hidden; height: 100vh; }

  /* Nav becomes single scrollable row */
  .pg-nav {
    padding: 0;
    height: 44px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    display: flex;
    align-items: center;
    white-space: nowrap;
    gap: 0;
  }
  .pg-nav::-webkit-scrollbar { display: none; }

  /* Both sides inline in one row */
  .pg-nav-left, .pg-nav-right {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    padding: 0 6px;
  }
  .pg-nav-left  { border-right: 1px solid rgba(255,255,255,.1); }

  .pg-nav-logo img { height: 24px; }
  .pg-nav-title    { font-size: .78rem; white-space: nowrap; }
  .pg-online-chip  { font-size: .68rem; padding: 3px 8px; }
  .pg-user-chip    { font-size: .68rem; padding: 3px 8px; }
  .pg-nav-link     { padding: 5px 8px; font-size: .75rem; white-space: nowrap; }
  .pg-nav-link i   { display: inline; }

  /* ── Toolbar ──────────────────────────────────────────── */
  .pg-toolbar {
    top: 44px;
    height: auto;
    min-height: 40px;
    padding: 0;
    overflow: hidden;
    flex-direction: column;
    gap: 0;
  }

  .pg-toolbar-left {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 6px 8px;
    gap: 4px;
    flex-wrap: nowrap;
  }
  .pg-toolbar-left::-webkit-scrollbar { display: none; }

  .pg-tool-btn { padding: 5px 10px; font-size: .74rem; gap: 4px; }
  .pg-tool-btn span { display: none; }
  .pg-tool-divider { display: none; }

  /* ── Editor layout — full height below nav+toolbar ────── */
  :root { --nav-h: 44px; --toolbar-h: 40px; }

  .pg-editor-wrap {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
    height: calc(100vh - var(--nav-h) - var(--toolbar-h) - 44px);
    margin-top: calc(var(--nav-h) + var(--toolbar-h));
    position: relative;
  }

  /* ── Mobile code tabs ─────────────────────────────────── */
  .pg-mobile-tabs {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 44px;
    background: #11111b;
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 100;
  }

  .pg-mobile-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 4px;
    font-size: .72rem;
    font-weight: 700;
    color: rgba(255,255,255,.4);
    background: none;
    border: none;
    border-top: 2px solid transparent;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
    letter-spacing: .02em;
  }
  .pg-mobile-tab.active {
    color: #fff;
    border-top-color: var(--primary);
  }
  .pg-mobile-tab i { font-size: .85rem; }

  /* Hide all panels by default on mobile */
  .pg-code-panels { display: none; height: 100%; }
  .pg-preview-panel { display: none; height: 100%; }

  /* Show active panel */
  .pg-code-panels.mobile-active { display: grid !important; grid-template-rows: 1fr; grid-template-columns: 1fr; }
  .pg-preview-panel.mobile-active { display: flex !important; }

  /* Single editor panel visible at a time */
  .pg-panel { display: none; }
  .pg-panel.mobile-active { display: flex !important; height: 100%; }

  /* Preview full height */
  #pg-output { height: 100%; }
}

@media (max-width: 480px) {
  .pg-nav-title { display: none; }
  .pg-tool-btn  { padding: 5px 8px; font-size: .72rem; }
}

/* ── Project list items in modal ──────────────────────────── */
.pg-project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--pg-border);
}
.pg-project-item:last-child { border-bottom: none; }

.pg-proj-info { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.pg-proj-title { font-weight: 600; font-size: .9rem; color: var(--pg-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pg-proj-date  { font-size: .75rem; color: var(--pg-muted); }

.pg-proj-actions { display: flex; gap: 8px; flex-shrink: 0; }
.pg-proj-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: .8rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--pg-border); background: rgba(255,255,255,.06);
  color: var(--pg-text); transition: all .2s;
}
.pg-proj-btn:hover  { background: rgba(255,255,255,.12); }
.pg-proj-load:hover { border-color: var(--primary); color: var(--primary); }
.pg-proj-post:hover { border-color: #10b981; color: #10b981; }

/* Toast spinner reuse */
.notif-spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Playground input fields */
.pg-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  color: #fff;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: .9rem;
  outline: none;
  transition: border-color .2s;
  resize: vertical;
}
.pg-input:focus { border-color: var(--primary); }
.pg-input::placeholder { color: rgba(255,255,255,.3); }

/* ── Privacy toggle in toolbar ────────────────────────────── */
.pg-privacy-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.6);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  user-select: none;
}
.pg-privacy-toggle:hover { background: rgba(255,255,255,.1); color: #fff; }
.pg-privacy-toggle input { display: none; }
.pg-privacy-toggle i { font-size: .78rem; transition: color .2s; }

/* ── Pro-gated privacy button ────────────────────────────── */
.pg-privacy-toggle-active { cursor: pointer; }

.pg-privacy-pro-lock {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  background: rgba(245,158,11,.07);
  border: 1px solid rgba(245,158,11,.2);
  color: rgba(245,158,11,.7);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  font-family: inherit;
}
.pg-privacy-pro-lock:hover {
  background: rgba(245,158,11,.15);
  color: #f59e0b;
  border-color: rgba(245,158,11,.4);
}
.pg-pro-hint {
  background: #f59e0b;
  color: #fff;
  font-size: .6rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 50px;
  letter-spacing: .04em;
}
