/* ============ Playground ============ */

.pg {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ---------- نوار ابزار ---------- */
.pg-bar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 9px var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.pg-bar .spacer { flex: 1; }

.pg-title { font-weight: 800; font-size: var(--fs-sm); display: flex; align-items: center; gap: 7px; }
.pg-title .em { font-size: 1.15rem; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 5px 13px; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-soft);
  white-space: nowrap;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-mute); flex-shrink: 0;
}
.status-pill.loading .dot { background: var(--accent-500); animation: pulse 1.1s ease-in-out infinite; }
.status-pill.ready   .dot { background: var(--mint-500); }
.status-pill.running .dot { background: var(--brand-400); animation: pulse .8s ease-in-out infinite; }
.status-pill.input   .dot { background: var(--violet-500); animation: pulse .8s ease-in-out infinite; }
.status-pill.error   .dot { background: var(--rose-500); }

@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.75); } }

.back-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 5px 13px; border-radius: var(--r-full);
  background: var(--info-bg); color: var(--info);
  text-decoration: none; border: 1px solid transparent;
}
.back-chip:hover { text-decoration: none; border-color: currentColor; }

/* ---------- تب‌های موبایل ---------- */
.pg-tabs { display: none; gap: 4px; background: var(--surface-3); padding: 3px; border-radius: var(--r-full); }
.pg-tabs button {
  padding: 6px 18px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-soft);
}
.pg-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--sh-sm); }

/* ---------- ستون‌ها ---------- */
.pg-split {
  flex: 1;
  display: grid;
  grid-template-columns: var(--pg-left, 1fr) 6px var(--pg-right, 1fr);
  min-height: 0;
  background: var(--bg-alt);
}

.pg-gutter {
  cursor: col-resize;
  background: var(--border);
  transition: background .15s;
}
.pg-gutter:hover, .pg-gutter.dragging { background: var(--brand-400); }

.pg-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--code-bg);
}

.pane-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px 13px;
  background: var(--code-bg-2);
  border-bottom: 1px solid var(--code-border);
  color: #9aa3c4; font-size: var(--fs-xs); font-weight: 700;
  flex-shrink: 0;
}
.pane-head .file { font-family: var(--font-mono); color: #cfd6ef; }
.pane-head .spacer { flex: 1; }
.pane-head button {
  font-size: var(--fs-xs); font-weight: 700; color: #b6bedd;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1);
  padding: 3px 11px; border-radius: var(--r-full);
}
.pane-head button:hover { background: rgba(255,255,255,.17); color: #fff; }
.pane-head button.on { background: rgba(63,97,242,.4); color: #fff; border-color: rgba(120,150,255,.5); }

/* ---------- ویرایشگر ---------- */
.editor-host { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.editor-host .CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  background: var(--code-bg);
  color: var(--code-text);
  direction: ltr;
  text-align: left;
}
.CodeMirror-gutters { background: var(--code-bg); border-inline-end: 1px solid var(--code-border); }
.CodeMirror-linenumber { color: var(--code-gutter); font-size: 12.5px; }
.CodeMirror-cursor { border-inline-start: 2px solid var(--brand-300); }
.CodeMirror-selected { background: rgba(99,134,251,.28) !important; }
.CodeMirror-focused .CodeMirror-selected { background: rgba(99,134,251,.34) !important; }
.CodeMirror-activeline-background { background: rgba(255,255,255,.045); }
.CodeMirror-matchingbracket {
  color: #fff !important; background: rgba(99,134,251,.45);
  border-radius: 2px; font-weight: 700;
}

.cm-s-pyclass .cm-keyword  { color: var(--code-kw); font-weight: 600; }
.cm-s-pyclass .cm-string   { color: var(--code-str); }
.cm-s-pyclass .cm-string-2 { color: var(--code-str); }
.cm-s-pyclass .cm-number   { color: var(--code-num); }
.cm-s-pyclass .cm-comment  { color: var(--code-comment); font-style: italic; }
.cm-s-pyclass .cm-def      { color: var(--code-fn); }
.cm-s-pyclass .cm-variable { color: var(--code-text); }
.cm-s-pyclass .cm-variable-2 { color: #ff9f6b; font-style: italic; }
.cm-s-pyclass .cm-builtin  { color: var(--code-builtin); }
.cm-s-pyclass .cm-operator { color: var(--code-op); }
.cm-s-pyclass .cm-property { color: var(--code-fn); }
.cm-s-pyclass .cm-meta     { color: var(--code-comment); }
.cm-s-pyclass .cm-error    { color: #fff; background: rgba(244,63,94,.5); }

/* ---------- ترمینال ---------- */
.term-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.terminal {
  flex: 1;
  overflow: auto;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.68;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  text-align: left;
  scrollbar-gutter: stable;
}
.terminal .s-stdout { color: #dfe4f6; }
.terminal .s-stderr { color: #ff8fa3; }
.terminal .s-stdin  { color: #7ee0b8; }
.terminal .s-note   { color: #8c96ba; font-style: italic; }
.terminal .s-sys    { color: #6f7899; }
.terminal .s-ok     { color: #6ee7a8; }

.term-empty {
  color: #5f6888; font-style: italic;
  direction: rtl; text-align: right; font-family: var(--font-fa);
}

.term-input {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--code-border);
  background: var(--code-bg-2);
  padding: 7px 12px;
  flex-shrink: 0;
  direction: ltr;
}
.term-input .caret { color: var(--violet-400); font-weight: 800; font-family: var(--font-mono); }
.term-input input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--code-text); font-family: var(--font-mono); font-size: 13.5px;
  direction: ltr; text-align: left;
}
.term-input input::placeholder { color: #5f6888; font-family: var(--font-fa); direction: rtl; }
.term-input.armed { background: rgba(139,92,246,.16); box-shadow: inset 0 0 0 1px rgba(167,139,250,.35); }
.term-input.armed .caret { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.term-input[data-disabled="true"] { opacity: .5; }

/* صف ورودی (حالت بدون SharedArrayBuffer) */
.stdin-queue {
  border-top: 1px solid var(--code-border);
  background: var(--code-bg-2);
  padding: 9px 12px;
  flex-shrink: 0;
  font-family: var(--font-fa);
  direction: rtl;
}
.stdin-queue label { display: block; font-size: var(--fs-xs); color: #9aa3c4; margin-bottom: 5px; font-weight: 700; }
.stdin-queue textarea {
  width: 100%; min-height: 56px; resize: vertical;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-border); border-radius: var(--r-sm);
  padding: 7px 10px; font-family: var(--font-mono); font-size: 13px;
  direction: ltr; text-align: left;
}

/* ---------- پنل فایل‌ها ---------- */
.files-panel {
  border-top: 1px solid var(--code-border);
  background: var(--code-bg-2);
  max-height: 38%;
  overflow: auto;
  flex-shrink: 0;
  font-family: var(--font-fa);
  direction: rtl;
  padding: 8px 12px 10px;
}
.files-panel h4 { font-size: var(--fs-xs); color: #9aa3c4; margin-bottom: 6px; }
.files-panel .empty { font-size: var(--fs-xs); color: #666f91; font-style: italic; }
.file-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; font-size: var(--fs-xs); color: #c3cae6;
}
.file-row .name { font-family: var(--font-mono); direction: ltr; color: #8fd0ff; }
.file-row .size { color: #6f7899; }
.file-row button {
  margin-inline-start: auto; font-size: var(--fs-xs); font-weight: 700;
  color: #b6bedd; background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1); padding: 2px 10px; border-radius: var(--r-full);
}
.file-view {
  margin-top: 7px; padding: 8px 10px;
  background: var(--code-bg); border: 1px solid var(--code-border);
  border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: 12.5px; color: #cfd6ef;
  white-space: pre-wrap; direction: ltr; text-align: left;
  max-height: 160px; overflow: auto;
}

/* ---------- نوار بارگذاری ---------- */
.boot-bar {
  position: absolute; inset-inline: 0; inset-block-start: 0;
  height: 3px; background: rgba(255,255,255,.08); overflow: hidden; z-index: 5;
}
.boot-bar i {
  display: block; height: 100%; width: 35%;
  background: linear-gradient(90deg, transparent, var(--brand-400), transparent);
  animation: slide 1.3s ease-in-out infinite;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(400%); } }

.warn-banner {
  padding: 9px var(--sp-5);
  background: var(--warn-bg); color: var(--warn);
  font-size: var(--fs-sm); font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---------- ریسپانسیو ---------- */
@media (max-width: 900px) {
  .pg { height: auto; min-height: calc(100vh - var(--header-h)); }
  .pg-tabs { display: flex; }
  .pg-gutter { display: none; }
  .pg-split { grid-template-columns: 1fr; }
  .pg-pane { height: 62vh; }
  .pg-pane[hidden] { display: none; }
  .pg-bar { padding-inline: var(--sp-4); }
  .pg-bar .btn { padding: 8px 14px; }
  .pg-title { display: none; }
}

@media (max-width: 520px) {
  .pg-bar .btn-label { display: none; }
  .pg-bar .btn { padding: 8px 12px; }
}
