/* ==========================================================================
   A4 Landscape Poster UI — Optimized for screen & export (PNG/PDF/Print)
   Works with index.html (birthday) and school.html (exam)
   ========================================================================== */

/* --- PRINT: A4 landscape, centered, with safe inner margins --- */
@page {
  size: A4 landscape;
  margin: 0;
}

@media print {
  :root {
    --print-margin: 10mm;
  }

  html,
  body {
    width: 297mm;
    height: 210mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .panel {
    display: none !important;
  }

  .app,
  .stage-wrap {
    width: 297mm !important;
    height: 210mm !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
  }

  .sheet {
    width: calc(297mm - 2 * var(--print-margin)) !important;
    height: calc(210mm - 2 * var(--print-margin)) !important;
    margin: 0 !important;
    padding: 8mm !important;
    border-radius: 4mm !important;
    box-shadow: none !important;
    page-break-before: avoid !important;
    page-break-after: avoid !important;
    break-inside: avoid !important;
  }

  .code-card {
    overflow: hidden !important;
    /* اسکرول نباشد */
    padding: 8mm !important;
    break-inside: avoid !important;
  }

  .code-card pre {
    white-space: pre-wrap !important;
    /* خطوط بشکند */
    display: block !important;
    overflow: visible !important;
    max-height: none !important;
    /* اندازهٔ فونت در پرینت را JS تطبیقی می‌کند */
  }

  * {
    break-inside: auto !important;
  }
}

:lang(fa) {
  font-family: "Vazirmatn", sans-serif !important;
  line-height: 1.95;
  word-spacing: .2px;
  letter-spacing: 0;
}

/* ========== Export-only (html.exporting روی <html>) ========== */
html.exporting .panel {
  display: none !important;
}

html.exporting .sheet {
  box-shadow: none !important;
}

html.exporting .code-card {
  overflow: hidden !important;
  /* بدون اسکرول‌بار در PNG/PDF */
  padding-right: 8mm;
}

html.exporting .code-card::-webkit-scrollbar {
  display: none !important;
}

html.exporting .code-card {
  scrollbar-width: none !important;
}

html.exporting .code-card pre {
  white-space: pre-wrap !important;
  overflow: visible !important;
  max-height: none !important;
}

/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --bg: #ffffff;
  --ink: #111111;
  --kw: #ff5722;
  --mod: #6a1b9a;
  --func: #2e7d32;
  --str: #1565c0;
  --num: #d32f2f;
  --accent: #212121;
  --border: #dfe3ea;
  --codebg: #fafafa;
  --punct: #444444;

  --app-bg: #eef1f5;
  --surface: #f7f8fb;
  --surface-2: #ffffff;

  --btn: #2e7d32;
  --btn-text: #ffffff;
  --btn-border: #cfd6e3;
  --btn-neutral: #f0f3f8;

  --focus: rgba(46, 125, 50, .25);

  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --gap: 16px;
  --gap-sm: 8px;

  --panel-bg: var(--surface);
  --panel-border: #d9dde6;
  --card-bg: var(--surface-2);

  --avatar-size: 48px;
  --avatar-radius: 12px;
  --drop-border: #d9dde6;
  --drop-bg: var(--surface-2);
  --drop-hover: #eef1f5;
}

/* ==========================================================================
   Global & Layout
   ========================================================================== */
* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  margin: 0;
  background: var(--app-bg);
  color: var(--ink);
  font-family:
    "Vazirmatn",
    "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular,
    Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


::selection {
  background: #ffe0d3;
  color: #111;
}

.app {
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  gap: var(--gap);
  padding: var(--gap);
  align-content: start;
  padding-bottom: 60px;
}

.panel,
.stage-wrap {
  align-self: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  box-shadow: 0 10px 25px rgba(17, 24, 39, .06);
  margin-bottom: 5%;
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 18px;
}

.panel label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.panel input[type="text"],
.panel input[type="date"] {
  padding: 10px 12px;
  border: 1px solid #d8dee9;
  border-radius: var(--radius-sm);
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.panel input[type="text"]:focus,
.panel input[type="date"]:focus {
  border-color: #b8c2d6;
  box-shadow: 0 0 0 4px var(--focus);
}

.panel button {
  padding: 10px 12px;
  border: 1px solid var(--btn-border);
  background: var(--btn-neutral);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s ease, transform .04s ease, box-shadow .15s ease;
}

.panel button:hover {
  background: #e7ebf3;
}

.panel button:active {
  transform: translateY(1px);
}

.panel details {
  background: var(--surface-2);
  border: 1px dashed #d9dde6;
  border-radius: var(--radius-md);
  padding: 10px;
  overflow: hidden;
  transition: all .2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .03);
}

.panel details[open] {
  background: var(--surface-2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .05);
  border: 1px solid #ccd3de;
}

.panel details summary {
  cursor: pointer;
  font-weight: 600;
  color: #333;
  list-style: none;
  outline: none;
  margin-bottom: 6px;
}

.panel details summary::-webkit-details-marker {
  display: none;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stick-bottom {
  margin-top: auto;
}

.row.stick-bottom button {
  background: var(--btn);
  color: var(--btn-text);
  border-color: transparent;
  box-shadow: 0 8px 16px rgba(46, 125, 50, .18);
}

.row.stick-bottom button:hover {
  filter: brightness(1.05);
  box-shadow: 0 10px 22px rgba(46, 125, 50, .22);
}

.grid.colors {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.grid.colors::-webkit-scrollbar {
  width: 6px;
}

.grid.colors::-webkit-scrollbar-thumb {
  background: #c3cad4;
  border-radius: 4px;
}

.grid.colors label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid #e1e6ee;
  transition: background .2s ease;
}

.grid.colors label:hover {
  background: #eef1f5;
}

.grid.colors input[type="color"] {
  width: 40px;
  height: 28px;
  border: 1px solid #cfd6e3;
  border-radius: 6px;
  padding: 0;
  background: #fff;
  transition: transform .06s ease;
}

.grid.colors input[type="color"]:active {
  transform: scale(.95);
}

.stage-wrap {
  display: grid;
  place-items: center;
  overflow: auto;
  min-height: 0;
}

/* ========================================================================== */
.sheet {
  width: 277mm;
  height: 190mm;
  border: .6mm solid var(--border);
  border-radius: 5mm;
  padding: 12mm;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1mm;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .06);
  color: var(--ink);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand .tag {
  font-size: 7mm;
  font-weight: 800;
  letter-spacing: .3mm;
}

.icons {
  display: flex;
  align-items: center;
  gap: 4mm;
}

.icon {
  width: 14mm;
  height: 14mm;
}

/* Code card */
.code-card {
  flex-grow: 1;
  border: .5mm solid var(--border);
  border-radius: 4mm;
  background: var(--codebg);
  padding: 10mm;
  display: flex;
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
  min-height: 0;
  position: relative;
}

.code-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, var(--codebg) 80%);
  opacity: .9;
  transition: opacity .2s ease;
}

.code-card.is-scrolled-to-end::after {
  opacity: 0;
}

/* Code text */
pre {
  margin: 0;
  font-size: 4.3mm;
  line-height: 1.4;
  color: var(--punct);
  white-space: pre;
  max-width: 100%;
  overflow: visible;
  max-height: none;
  font-family: "Fira Code", ui-monospace, SFMono-Regular,
    Menlo, Monaco, Consolas, "Liberation Mono", monospace, "Vazirmatn";
}

.sheet .kw {
  color: var(--kw);
  font-weight: 700;
}

.sheet .mod {
  color: var(--mod);
  font-weight: 700;
}

.sheet .func {
  color: var(--func);
  font-weight: 700;
}

.sheet .str {
  color: var(--str);
  font-weight: 700;
}

.sheet .num {
  color: var(--num);
  font-weight: 800;
}

.sheet .brand .tag,
.sheet .username {
  color: var(--ink);
}

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 5mm;
  margin-top: 8mm;
}

.username {
  font-weight: 700;
  border: .6mm solid var(--border);
  padding: 2mm 5mm;
  border-radius: 3mm;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width:980px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
  }

  .stage-wrap {
    order: -1;
  }

  .sheet {
    width: 100%;
    height: auto;
  }

  pre {
    font-size: 4.6mm;
  }
}

@media (max-width:560px) {
  pre {
    font-size: 4.2mm;
  }

  .brand .tag {
    font-size: 6mm;
  }
}

/* Small tweaks */
.color-actions {
  margin-top: 10px;
  gap: 6px;
}

.color-actions button {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.logo-group {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.logo-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  margin: 10px 0 0;
  background: var(--surface-2);
  border: 1px solid #e6ebf3;
  border-radius: 10px;
}

.logo-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

/* Drop zone / button for file input */
.file-drop {
  display: grid;
  align-items: center;
  justify-items: start;
  gap: 4px;
  padding: 12px 14px;
  margin: 2px 0 8px;
  border: 1px dashed var(--drop-border);
  border-radius: var(--radius-sm);
  background: var(--drop-bg);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}


.file-drop:hover,
.file-drop:focus {
  background: var(--drop-hover);
  border-color: #c8d0dc;
}

.file-drop:active {
  transform: translateY(1px);
}

.file-drop__title {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
}

.file-drop__hint {
  font-size: 12px;
  line-height: 1.2;
  opacity: .75;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hide-on-export checkbox tidy */
.logo-hide {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 2px;
}

/* Remove button emphasis */
.btn-danger {
  border-color: #f2c9c9;
  background: #fff5f5;
}

.file-drop.is-dragover {
  background: var(--drop-hover);
  border-color: #c8d0dc;
  border-style: solid;
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(17, 24, 39, .06);
  animation: softPulse .7s ease-out;
}

@keyframes softPulse {
  0% {
    outline: 0
  }

  50% {
    outline: 3px solid #c8d0dc
  }

  100% {
    outline: 0
  }
}


.btn-danger:hover {
  background: #ffe9e9;
}

/* ---------- Avatar in header ---------- */
.header .avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  object-fit: cover;
  border-radius: var(--avatar-radius);
  border: 1px solid var(--border, #ddd);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
  margin-inline-start: 8px;
  inline-size: auto;
  opacity: 0;
  transform: scale(.98);
  transition: opacity .2s ease, transform .2s ease;
}

.header .avatar.is-visible {
  opacity: 1;
  transform: scale(1);
}

html.exporting .hide-on-export {
  display: none !important;
}


/* Hide on real print */
@media print {
  .hide-on-export {
    display: none !important;
  }

  .sheet .hide-on-export {
    display: none !important;
  }
}


@media (max-width: 680px) {
  :root {
    --avatar-size: 40px;
  }
}

/* --- Modern compact switch --- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  line-height: 1;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  inline-size: 36px;
  block-size: 20px;
  border-radius: 999px;
  background: #e9edf5;
  border: 1px solid #d6dce7;
  position: relative;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.switch .slider::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  inline-size: 16px;
  block-size: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
  transition: transform .15s ease;
}

.switch:hover .slider {
  border-color: #c8d0dc;
  background: #eef2f8;
}

.switch input:focus-visible+.slider {
  box-shadow: 0 0 0 3px var(--focus, rgba(46, 125, 50, .25));
}

.switch input:checked+.slider {
  background: rgba(46, 125, 50, .22);
  border-color: rgba(46, 125, 50, .45);
}

.switch input:checked+.slider::after {
  transform: translateX(16px);
}

.switch-label {
  color: #2b2f36;
  line-height: 1;
  opacity: .9;
}

.switch.is-disabled {
  opacity: .55;
  cursor: not-allowed;
}

.switch.is-disabled .slider {
  background: #f2f4f8;
  border-color: #e3e7ef;
}

.switch.is-disabled .switch-label {
  opacity: .7;
}

/* very small screens */
@media (max-width:420px) {
  .logo-actions {
    padding: 6px 8px;
  }

  .switch {
    gap: 8px;
    font-size: 12px;
  }
}

/* ===== Site Shell (Header/Footer) ===== */
.site-container {
  width: min(1080px, 100% - 2*var(--gap));
  margin-inline: auto;
  padding-inline: 0;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--surface) 90%, white 10%);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: saturate(120%) blur(6px);
  margin-bottom: 6px;
  transition: box-shadow .7s ease, transform .7s ease, background .7s;
}

.site-header.is-compact {
  background: color-mix(in oklab, var(--surface) 85%, white 15%);
  box-shadow: 0 6px 18px rgba(17, 24, 39, .06);
  transform: translateY(-100%);
}

.site-header .site-container {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  /* کمی جمع‌وجورتر */
  padding-block: 6px;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: .2px;
  color: var(--ink);
  text-decoration: none;
}

.site-header .nav-toggle {
  display: none;
  place-items: center;
  width: 36px;
  height: 32px;
  border: 1px solid var(--btn-border);
  background: var(--btn-neutral);
  border-radius: 8px;
  cursor: pointer;
}

.site-header .nav-toggle svg {
  width: 16px;
  height: 16px;
}

@media (min-width: 781px) {
  .site-header .nav-toggle {
    display: none !important;
  }
}

.nav-link {
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: #2b2f36;
  line-height: 1;
  /* هم‌ارتفاع با کپسول */
}

.nav-link:hover {
  background: var(--btn-neutral);
}

.site-nav {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(17, 24, 39, .04);
}

.btn-ghost {
  padding: 8px 12px;
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

.btn-ghost:hover {
  background: #f8fafc;
}

button,
.btn-ghost {
  transition: transform .08s ease, box-shadow .18s ease, background .18s ease;
  will-change: transform;
}

button:hover,
.btn-ghost:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(17, 24, 39, .08);
}

button:active,
.btn-ghost:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(17, 24, 39, .06);
}

.nav-toggle {
  display: none;
  border: 1px solid var(--btn-border);
  background: #fff;
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
}

/* Mobile */
@media (max-width: 780px) {

  /* کانتینر هدر مرجع پوزیشن منو و دکمه باشد */
  .site-header .site-container {
    position: relative;
    min-height: 56px;
  }

  /* دکمه منو: بالا-راست */
  .nav-toggle,
  .site-header .nav-toggle {
    display: grid;
    place-items: center;
    position: absolute;
    right: var(--gap);
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 32px;
    border: 1px solid var(--btn-border);
    background: var(--btn-neutral);
    border-radius: 10px;
    z-index: 120;
    /* بالاتر از منو */
  }

  .site-header .nav-toggle svg {
    width: 16px;
    height: 16px;
  }

  @keyframes popIn {
    from {
      opacity: 0;
      transform: scale(.96);
    }

    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  .site-nav {
    position: absolute;
    top: calc(100% + 8px);
    right: var(--gap);
    left: auto;
    background: var(--surface-2);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(17, 24, 39, .12);
    display: none;
    padding: 8px;
    grid-auto-flow: row;
    gap: 4px;
    z-index: 110;
    transform-origin: top right;
    opacity: 0;
    transform: scale(.98);
    transition: opacity .18s ease, transform .18s ease;
  }

  .site-nav.open {
    display: grid;
    opacity: 1;
    transform: scale(1);
    animation: popIn .18s ease both;
  }

  /* لمس/فوکوس بهتر آیتم‌ها */
  .site-nav .nav-link,
  .site-nav .btn-ghost {
    padding: 10px 12px;
    border-radius: 10px;
  }

  .site-nav .nav-link:focus-visible,
  .nav-toggle:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
  }
}

/* موبایل باریک‌تر: کمی فشرده‌تر */
@media (max-width: 560px) {
  .site-header .nav-toggle {
    width: 32px;
    height: 30px;
    border-radius: 8px;
  }

  .site-header .nav-toggle svg {
    width: 15px;
    height: 15px;
  }
}


/* Footer */
.site-footer {
  margin-top: 16px;
  border-top: 1px solid var(--panel-border);
  background: var(--surface);
  bottom: 0;
  z-index: 10;
  opacity: .0;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
}

.site-footer.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.site-footer .site-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-block: 12px;
  font-size: 14px;
}

.site-footer a {
  color: #333;
  text-decoration: none;
}

a:hover {
  background-size: 100% 1px;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer .dot {
  opacity: .5;
  margin-inline: 6px;
}

a:not(.btn-ghost):not(.nav-link) {
  text-decoration: none;
  background:
    linear-gradient(currentColor, currentColor) left bottom / 0 1px no-repeat;
  transition: background-size .18s ease;
}



/* Back-to-top – animated & accessible */
.to-top {
  margin-left: 10px;
  border: 1px solid var(--btn-border);
  background: var(--btn-neutral);
  border-radius: 10px;
  padding: 6px 9px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}

.to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.to-top:hover {
  background: #e7ebf3;
}

.btn--ripple {
  position: relative;
  overflow: hidden;
}

.btn--ripple::after {
  content: "";
  position: absolute;
  inset: auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0;
  transform: scale(0);
}

.btn--ripple.is-rippling::after {
  animation: ripple .4s ease-out;
}

/* Ripple feedback on click */
@keyframes ripple {
  from {
    transform: scale(0);
    opacity: .3;
  }

  to {
    transform: scale(12);
    opacity: 0;
  }
}

.to-top.rippling::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: currentColor;
  animation: ripple .36s ease-out;
}

@media (max-width: 560px) {
  .nav-toggle {
    width: 32px;
    height: 32px;
  }

  .nav-toggle svg {
    width: 16px;
    height: 16px;
  }
}

/* Print/Export safety */
@media print {

  .site-header,
  .site-footer {
    display: none !important;
  }
}

html.exporting .site-header,
html.exporting .site-footer {
  display: none !important;
}

@keyframes mountIn {
  from {
    opacity: .0;
    transform: translateY(8px) scale(.992);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.sheet,
.panel {
  animation: mountIn 2.3s cubic-bezier(.2, .6, .2, 1) both;
}