/* پلی‌گراند کد سایت — ویرایشگر تیره در هر دو تم، پنل‌ها با توکن‌های سایت */
.pg {
  --pg-accent: var(--color-primary);
  --pg-navy: #172c4d;
  --pg-navy-2: #10223d;
  --pg-line: rgba(255, 255, 255, 0.06);
  --pg-text: #c4d9f7;
  --pg-muted: #7f98bb;
  --pg-mono: Consolas, "Cascadia Mono", Menlo, "Liberation Mono", "Courier New", monospace;
}
.pg-section { padding-top: 2rem; }

/* ---------- Toolbar ---------- */
.pg-toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.pg-languages { display: flex; flex-wrap: wrap; gap: .5rem; }
.pg-lang {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  min-width: 5.5rem; min-height: 3.6rem; padding: .4rem .9rem;
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-muted); cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.pg-lang:hover { border-color: var(--lang-color, var(--color-primary)); color: var(--text-main); }
.pg-lang[aria-selected="true"] {
  border-color: var(--lang-color, var(--color-primary));
  background: var(--bg-surface-2); color: var(--text-main);
  box-shadow: inset 0 -3px 0 var(--lang-color, var(--color-primary));
}
.pg-lang:focus-visible, .pg-panels button:focus-visible, .pg-icon:focus-visible, .pg-files button:focus-visible, .pg-card-use:focus-visible { outline: 3px solid var(--color-primary-light); outline-offset: 2px; }
.pg-lang-short { font: 700 .95rem/1.2 var(--font-en); letter-spacing: .02em; }
/* Official logos sit on a white tile in both themes (the SQLite feather is dark navy). */
.pg-lang-icon { display: block; width: 32px; height: 32px; padding: 4px; margin-bottom: .15rem; object-fit: contain; background: #fff; border: 1px solid #e6ecf5; border-radius: 10px; }
.pg-lang[aria-selected="true"] .pg-lang-icon { border-color: var(--lang-color, var(--color-primary)); }
.pg-lang-title { font-size: .75rem; }
.pg-course { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; color: var(--text-muted); min-width: min(100%, 18rem); }
.pg-course select {
  min-height: 2.75rem; padding: .4rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); background: var(--bg-surface); color: var(--text-main); font: inherit; font-size: .9rem;
}

/* ---------- Layout ---------- */
.pg-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 991.98px) { .pg-grid { grid-template-columns: minmax(0, 1fr); } }
.pg-side { position: sticky; top: 5.5rem; }
@media (max-width: 991.98px) { .pg-side { position: static; } }

/* ---------- Editor ---------- */
.pg-editor { background: var(--pg-navy); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-md); }
.pg-editor-head { display: flex; align-items: center; gap: .75rem; padding: .35rem .75rem; border-bottom: 1px solid var(--pg-line); min-height: 2.9rem; }
.pg-dots { display: inline-flex; gap: .3rem; }
.pg-dots i { width: .45rem; height: .45rem; border-radius: 50%; background: #df8992; }
.pg-dots i:nth-child(2) { background: #e8c06b; }
.pg-dots i:nth-child(3) { background: #75b9a0; }
.pg-filename { display: inline-flex; align-items: center; gap: .45rem; color: #8ca2c2; font: .8rem/1 var(--pg-mono); }
.pg-file-icon, .pg-files img { display: inline-block; width: 18px; height: 18px; padding: 2px; object-fit: contain; background: #fff; border-radius: 5px; }
.pg-files button { display: inline-flex; align-items: center; gap: .4rem; }
.pg-files { display: flex; gap: .35rem; }
.pg-files button { border: 0; border-radius: 8px; padding: .35rem .7rem; background: transparent; color: var(--pg-muted); font: .8rem/1.2 var(--pg-mono); cursor: pointer; }
.pg-files button[aria-selected="true"] { background: #2a4265; color: #d2e4ff; }
.pg-editor-actions { margin-left: auto; display: inline-flex; gap: .15rem; }
.pg-icon { width: 2.2rem; height: 2.2rem; border: 0; border-radius: 8px; background: transparent; color: #8ca2c2; cursor: pointer; }
.pg-icon:hover { background: rgba(255, 255, 255, .07); color: #d2e4ff; }

.pg-code { display: flex; position: relative; height: clamp(18rem, 52vh, 34rem); font: 14px/24px var(--pg-mono); tab-size: 4; }
.pg-gutter {
  flex: 0 0 auto; min-width: 3rem; margin: 0; padding: 14px .6rem 14px .4rem; overflow: hidden;
  color: #526d91; text-align: right; font: inherit; user-select: none; background: var(--pg-navy);
  border-right: 1px solid var(--pg-line);
}
.pg-area { position: relative; flex: 1 1 auto; min-width: 0; }
.pg-highlight, .pg-input {
  position: absolute; inset: 0; margin: 0; padding: 14px 16px; border: 0;
  font: inherit; tab-size: inherit; white-space: pre; overflow-wrap: normal; word-break: normal;
  direction: ltr; text-align: left; letter-spacing: 0;
}
.pg-highlight { overflow: hidden; color: var(--pg-text); pointer-events: none; }
.pg-highlight code { font: inherit; color: inherit; background: none; padding: 0; white-space: inherit; }
.pg-input {
  width: 100%; height: 100%; resize: none; overflow: auto; outline: none;
  background: transparent; color: transparent; caret-color: #f8fafc; -webkit-text-fill-color: transparent;
}
.pg-input::selection { background: rgba(122, 179, 255, .35); -webkit-text-fill-color: transparent; }
.pg-input:focus-visible { box-shadow: inset 0 0 0 2px rgba(122, 179, 255, .55); }
.pg-editor-foot { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem .9rem; border-top: 1px solid var(--pg-line); color: #7189aa; font-size: .75rem; }
.pg-editor-foot #pg-save-state { color: #91b4a9; }
.pg-keys { margin: .5rem .25rem 0; font-size: .75rem; color: var(--text-soft); }

/* Token colours: the same palette as the lesson reader and the app. */
.tk-c { color: #8b949e; font-style: italic; }
.tk-s { color: #ffd866; }
.tk-n { color: #f78c6c; }
.tk-k { color: #c792ea; }
.tk-f { color: #82aaff; }

/* ---------- Input, run row, notes ---------- */
.pg-stdin { margin-top: 1rem; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-surface); padding: .25rem .9rem; }
.pg-stdin summary { cursor: pointer; padding: .55rem 0; font-weight: 600; font-size: .9rem; }
.pg-stdin summary small { color: var(--text-muted); font-weight: 400; }
.pg-stdin p { margin: 0 0 .5rem; font-size: .8rem; color: var(--text-muted); }
.pg-stdin textarea {
  width: 100%; margin-bottom: .75rem; padding: .6rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main);
  font: 14px/1.7 var(--pg-mono); resize: vertical;
}
.pg-run-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-top: 1rem; }
.pg-run { min-width: 11rem; min-height: 2.9rem; }
.pg-run:disabled { opacity: .65; cursor: progress; }
.pg-engine-note { margin: .75rem .25rem 0; font-size: .8rem; line-height: 1.9; color: var(--text-muted); }
.pg-message { margin: .75rem 0 0; padding: .65rem .9rem; border-radius: var(--radius-sm); background: var(--bg-surface-2); color: var(--color-primary); font-size: .85rem; line-height: 1.9; }
.pg-sync-hint { margin: .75rem .25rem 0; font-size: .8rem; color: var(--text-muted); }

/* ---------- Side panels ---------- */
.pg-panels { display: flex; gap: .25rem; padding: .25rem; border-radius: var(--radius-md); background: var(--bg-surface-2); margin-bottom: 1rem; }
.pg-panels button { flex: 1; min-height: 2.6rem; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); font: inherit; font-size: .9rem; cursor: pointer; }
.pg-panels button[aria-selected="true"] { background: var(--bg-surface); color: var(--color-primary); font-weight: 700; box-shadow: var(--shadow-sm); }

.pg-console { background: var(--pg-navy); border-radius: var(--radius-lg); padding: .9rem 1rem 1rem; }
.pg-console-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; font-size: .78rem; color: var(--pg-muted); }
.pg-console[data-tone="ok"] #pg-run-status { color: #92b9aa; }
.pg-console[data-tone="error"] #pg-run-status { color: #e2a59a; }
.pg-console-body {
  min-height: 12rem; max-height: 28rem; overflow: auto; margin: 0;
  color: var(--pg-text); font: 13.5px/1.75 var(--pg-mono); white-space: pre-wrap; overflow-wrap: anywhere;
  text-align: left; unicode-bidi: plaintext;
}
.pg-console-body:empty::before { content: "خروجی برنامه اینجا نمایش داده می‌شود."; color: var(--pg-muted); font-family: var(--font-fa); direction: rtl; display: block; text-align: right; }
.pg-console-body span { display: inline; }
.pg-out-err { color: #ffa198; }
.pg-out-in { color: #7ee2b8; }
.pg-out-note { color: var(--pg-muted); font-style: italic; }
.pg-out-img { display: block; max-width: 100%; height: auto; margin: .6rem 0; border-radius: var(--radius-sm); background: #fff; }
.pg-preview { width: 100%; height: 24rem; border: 1px solid var(--border-color); border-radius: var(--radius-lg); background: #fff; }

.pg-list { display: grid; gap: .9rem; max-height: 44rem; overflow: auto; padding: 2px; }
@media (max-width: 991.98px) { .pg-list { max-height: none; } }
.pg-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 1rem; }
.pg-card-head { display: flex; align-items: start; justify-content: space-between; gap: .75rem; }
.pg-card-title { margin: 0; font-size: .95rem; font-weight: 700; line-height: 1.7; }
.pg-badge { flex: 0 0 auto; max-width: 50%; padding: .15rem .55rem; border-radius: var(--radius-xs); background: var(--bg-surface-2); color: var(--color-primary); font-size: .7rem; line-height: 1.8; text-align: center; }
.pg-badge.is-general { color: var(--text-muted); }
.pg-card-text { margin: .5rem 0 0; font-size: .85rem; line-height: 2; color: var(--text-muted); white-space: pre-line; }
.pg-card-code {
  margin: .75rem 0 0; padding: .75rem .9rem; max-height: 16rem; overflow: auto; border-radius: var(--radius-sm);
  background: var(--pg-navy); color: var(--pg-text); font: 12.5px/1.75 var(--pg-mono); text-align: left;
}
.pg-card-code code { color: inherit; background: none; padding: 0; font: inherit; white-space: pre; }
.pg-card-use { display: inline-flex; align-items: center; gap: .4rem; margin-top: .7rem; min-height: 2.5rem; padding: 0 .25rem; border: 0; background: none; color: var(--color-primary); font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; }
.pg-card-use:hover { text-decoration: underline; }
.pg-empty { margin: 0; padding: 2rem 1rem; text-align: center; color: var(--text-muted); font-size: .9rem; line-height: 2; }
.pg-locked { margin: .9rem .25rem 0; font-size: .8rem; color: var(--text-muted); }

/* ---------- Dialog and hidden runner ---------- */
.pg-dialog { width: min(26rem, calc(100vw - 2rem)); border: 0; border-radius: var(--radius-lg); padding: 1.4rem; background: var(--bg-surface); color: var(--text-main); box-shadow: var(--shadow-lg); }
.pg-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.pg-dialog p { color: var(--text-muted); font-size: .9rem; line-height: 2; }
.pg-dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.pg-cancel { color: var(--text-muted); }
.pg-runner { position: absolute; width: 1px; height: 1px; border: 0; opacity: 0; pointer-events: none; left: -9999px; top: 0; }

@media (max-width: 575.98px) {
  .pg-lang { min-width: calc(50% - .25rem); flex: 1 1 calc(50% - .25rem); }
  .pg-code { font-size: 13px; }
  .pg-run { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .pg-lang { transition: none; } }
