:root {
  --navy: #0B3269;
  --navy-dark: #062553;
  --gold: #F9C300;
  --gold-deep: #c99300;
  --white: #ffffff;
  --ink: #10233d;
  --muted: #65758a;
  --line: #e7ebf0;
  --bg: #f5f7fa;
  --shadow: 0 18px 50px rgba(11, 50, 105, 0.10);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 0 0, rgba(249,195,0,.06), transparent 28rem),
    var(--bg);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.site-header {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 64px; height: 64px; object-fit: contain; }
.eyebrow { margin: 0 0 3px; color: var(--navy); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--navy); font: 700 clamp(22px, 3vw, 34px)/1.05 Georgia, "Times New Roman", serif; }
.privacy-pill {
  padding: 10px 14px;
  border: 1px solid rgba(11,50,105,.14);
  border-radius: 999px;
  background: rgba(255,255,255,.75);
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.layout {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 34px;
  display: grid;
  grid-template-columns: minmax(330px, .82fr) minmax(420px, 1.18fr);
  gap: 24px;
  align-items: start;
}
.editor-card, .preview-card {
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(11,50,105,.08);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.editor-card { padding: 26px; }
.preview-card { padding: 22px; position: sticky; top: 18px; }

.section-heading { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 18px; }
.section-heading.compact { margin-top: 28px; }
.section-heading h2, .preview-title-row h2 { margin: 0 0 6px; color: var(--navy); font-size: 19px; }
.section-heading p, .preview-title-row p { margin-bottom: 0; color: var(--muted); line-height: 1.55; font-size: 14px; }
.step {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--navy-dark);
  background: var(--gold);
  font-weight: 900;
}

.drop-zone {
  min-height: 118px;
  border: 1.5px dashed rgba(11,50,105,.32);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  background: #fbfcfe;
  transition: .18s ease;
  text-align: left;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--navy); background: rgba(11,50,105,.035); transform: translateY(-1px); }
.upload-icon {
  width: 46px; height: 46px; border-radius: 15px;
  display: grid; place-items: center;
  background: var(--navy); color: var(--white); font-size: 25px; font-weight: 900;
}
.drop-zone strong { display: block; color: var(--navy); font-size: 16px; }
.drop-zone span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }

.controls { margin-top: 20px; }
.control-row { display: grid; grid-template-columns: 54px 1fr 56px; gap: 10px; align-items: center; }
.control-row label { color: var(--navy); font-weight: 800; font-size: 14px; }
.control-row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
input[type="range"] { width: 100%; accent-color: var(--navy); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 15px; }
button {
  border: 0;
  border-radius: 13px;
  padding: 13px 16px;
  font-weight: 800;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
button:not(:disabled):hover { transform: translateY(-1px); }
.primary { color: white; background: var(--navy); box-shadow: 0 8px 20px rgba(11,50,105,.17); }
.primary:not(:disabled):hover { background: var(--navy-dark); }
.secondary { color: var(--navy); background: #eef3f8; }
.secondary:not(:disabled):hover { background: #e5ecf4; }
.hint { color: var(--muted); margin: 10px 0 0; font-size: 12px; line-height: 1.45; }

.download-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.download-grid button { min-height: 70px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.download-grid small { margin-top: 4px; opacity: .72; font-size: 12px; font-weight: 700; }
.facts { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 17px; display: grid; gap: 12px; }
.facts div { display: flex; justify-content: space-between; gap: 20px; font-size: 12px; }
.facts strong { color: var(--navy); }
.facts span { color: var(--muted); text-align: right; }

.preview-title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.preview-title-row .eyebrow { margin-bottom: 4px; }
.switch-label { display: inline-flex; align-items: center; gap: 7px; color: var(--navy); font-size: 12px; font-weight: 800; white-space: nowrap; }
.switch-label input { accent-color: var(--navy); }
.preview-stage {
  border-radius: 20px;
  background:
    linear-gradient(45deg, #edf0f4 25%, transparent 25%),
    linear-gradient(-45deg, #edf0f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf0f4 75%),
    linear-gradient(-45deg, transparent 75%, #edf0f4 75%),
    #f7f8fa;
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  padding: clamp(14px, 3vw, 28px);
  display: grid;
  place-items: center;
}
.canvas-shell {
  width: min(100%, 660px);
  aspect-ratio: 1;
  position: relative;
  background: white;
  box-shadow: 0 18px 42px rgba(0,0,0,.15);
  overflow: hidden;
  transition: border-radius .2s ease;
  touch-action: none;
  user-select: none;
}
.canvas-shell.circle { border-radius: 50%; }
canvas { width: 100%; height: 100%; display: block; cursor: grab; }
canvas.dragging { cursor: grabbing; }
.empty-message { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.empty-message span { padding: 9px 13px; border-radius: 999px; background: rgba(255,255,255,.92); color: var(--navy); font-weight: 800; font-size: 12px; box-shadow: 0 5px 15px rgba(11,50,105,.10); }
.preview-note { margin-top: 14px; display: flex; gap: 9px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.dot { width: 8px; height: 8px; flex: 0 0 auto; margin-top: 5px; border-radius: 50%; background: var(--gold); }

footer { width: min(1180px, calc(100% - 32px)); margin: 0 auto 30px; text-align: center; color: #7a8797; font-size: 12px; }
footer p { margin-bottom: 0; }

@media (max-width: 900px) {
  .site-header { align-items: flex-start; }
  .privacy-pill { display: none; }
  .layout { grid-template-columns: 1fr; }
  .preview-card { position: static; grid-row: 1; }
}
@media (max-width: 560px) {
  .site-header { margin-top: 16px; }
  .brand-logo { width: 52px; height: 52px; }
  .editor-card, .preview-card { border-radius: 18px; padding: 17px; }
  .layout { width: min(100% - 20px, 1180px); margin-top: 16px; gap: 14px; }
  .site-header, footer { width: min(100% - 20px, 1180px); }
  .download-grid, .button-row { grid-template-columns: 1fr; }
  .facts div { display: block; }
  .facts span { display: block; text-align: left; margin-top: 2px; }
  .preview-title-row { align-items: flex-end; }
}

/* Ensure the empty-state label disappears after a photo is loaded. */
.empty-message[hidden] { display: none !important; }

/* ============================================================
   Trilingual support: language switcher, RTL, Arabic-script type
   ============================================================ */

.langSwitch {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 3px;
  margin-inline-start: auto;
}
.langBtn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 34px;
}
.langBtn:hover { background: rgba(255,255,255,.12); }
.langBtn[aria-pressed="true"] { background: #F9C300; color: #0B3269; font-weight: 600; }
.langBtn:focus-visible { outline: 2px solid #F9C300; outline-offset: 2px; }

/* Arabic-script faces are taller; give them room and a suitable stack. */
html[lang="ps"], html[lang="fa"] {
  font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, "Iranian Sans", Arial, sans-serif;
}
html[lang="ps"] body, html[lang="fa"] body { line-height: 1.85; }
html[lang="ps"] h1, html[lang="fa"] h1,
html[lang="ps"] h2, html[lang="fa"] h2 { line-height: 1.5; }

/* Right-to-left layout. Most of the sheet uses logical properties already;
   these are the physical cases that need mirroring. */
html.rtl .drop-zone,
html.rtl .hint,
html.rtl .feature,
html.rtl .panel { text-align: right; }
html.rtl .langSwitch { margin-inline-start: auto; }
html.rtl .brand { flex-direction: row-reverse; }
html.rtl .action { flex-direction: row-reverse; }

/* Latin strings inside RTL text (JPG, PNG, 1080 × 1080) must stay LTR. */
html.rtl .dlSize,
html.rtl [data-i18n="dlHdSize"],
html.rtl [data-i18n="dlSmSize"],
html.rtl [data-i18n="f1s"] { direction: ltr; unicode-bidi: embed; display: inline-block; }

.camHint {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  opacity: .72;
}

/* ============================================================
   Responsive: phones and tablets
   ============================================================ */

/* Tablets and small laptops: single column, preview above the controls. */
@media (max-width: 1024px) {
  .langSwitch { order: 3; }
  .brand { flex-wrap: wrap; }
}

/* Tablets in portrait */
@media (max-width: 820px) {
  .site-header { flex-wrap: wrap; gap: 10px; }
  .langSwitch { margin-inline-start: 0; }
  .stage-wrap { max-width: 520px; margin-inline: auto; }
}

/* Phones */
@media (max-width: 560px) {
  .site-header { padding: 12px 14px; }
  .langBtn { padding: 8px 11px; font-size: 12.5px; }
  .stage-wrap { max-width: 100%; }

  /* Comfortable tap targets: 44px is the accepted minimum. */
  .action, .primary, .secondary, .download {
    min-height: 48px;
    font-size: 15px;
    width: 100%;
  }
  input[type="range"] { height: 34px; }

  .features { grid-template-columns: 1fr; gap: 10px; }
  .panel { padding: 16px 14px; }
  h1 { font-size: 24px; }
  h2 { font-size: 19px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .langBtn { padding: 7px 9px; font-size: 12px; }
  h1 { font-size: 21px; }
}

/* Stop iOS Safari zooming the page when a control is focused. */
@media (max-width: 820px) {
  input, select, textarea, button { font-size: 16px; }
}

/* Landscape phones: keep the preview visible rather than pushing it off-screen. */
@media (max-height: 520px) and (orientation: landscape) {
  .site-header { position: static; }
  .stage-wrap { max-width: 46vh; }
}

/* ---- photo source buttons (gallery / camera) ---- */
.sourceRow {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.sourceRow .action { flex: 1 1 0; justify-content: center; }

/* The camera button is only meaningful on a touch device. On a mouse-driven
   machine the capture attribute is ignored, so hide it there. */
.touchOnly { display: none; }
@media (pointer: coarse) {
  .touchOnly { display: inline-flex; }
}

@media (max-width: 560px) {
  .sourceRow { flex-direction: column; gap: 8px; }
  .sourceRow .action { width: 100%; min-height: 48px; }
}
