@font-face {
  font-family: 'StamFont';
  src: url("pft_stam-פונט אורות הרב קוק.woff2") format('woff2'),
       url("pft_stam-פונט אורות הרב קוק.woff") format('woff'),
       url("pft_stam-פונט אורות הרב קוק.ttf") format('truetype');
  font-weight: normal;
  font-style: normal;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #325339;
  --green-light: #4a7a54;
  --green-pale: #e8f0e9;
  --cream: #faf8f4;
  --border: #c8d8c9;
  --text: #1a2e1c;
  --muted: #6b846d;
  --radius: 10px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'Arial Hebrew', Arial, sans-serif;
  background: var(--cream);
  color: var(--text);
  direction: rtl;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: var(--green);
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
header h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.subtitle-header { font-size: 0.9rem; opacity: 0.75; }
.credit-header { font-size: 0.78rem; opacity: 0.55; margin-right: auto; }

/* ── Main layout ── */
main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Preview section ── */
.preview-section {
  background: #d4cfc7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  position: relative;
  height: 100%;
  overflow: hidden;
}

.preview-notice {
  font-size: 0.70rem;
  color: rgba(0,0,0,0.42);
  text-align: center;
  direction: rtl;
  max-width: 540px;
  line-height: 1.6;
  font-style: italic;
  padding: 0 8px;
  flex-shrink: 0;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  width: 100%;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  border-radius: 2px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--green);
  transition: opacity 0.2s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

/* ── Controls sidebar ── */
.controls-section {
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
}

/* ── Field groups ── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-group label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field-group textarea {
  line-height: 1.3;
}

.field-group textarea,
.field-group input[type="text"] {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--cream);
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: none;
  direction: rtl;
  text-align: right;
}

.field-group textarea:focus,
.field-group input[type="text"]:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(50, 83, 57, 0.12);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Buttons ── */
.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  letter-spacing: 0.02em;
}

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

.btn-primary {
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 12px rgba(50, 83, 57, 0.3);
}
.btn-primary:hover { background: var(--green-light); box-shadow: 0 4px 16px rgba(50, 83, 57, 0.4); }

.btn-secondary {
  background: var(--green-pale);
  color: var(--green);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: #d6e8d8; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Status message ── */
.status-msg {
  font-size: 0.85rem;
  color: var(--green);
  min-height: 20px;
  text-align: center;
}

/* ── Quote bar ── */
.quote-bar {
  background: var(--green);
  color: rgba(255,255,255,0.82);
  text-align: center;
  padding: 9px 24px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  direction: rtl;
  flex-shrink: 0;
}
.quote-text {
  font-family: 'StamFont', serif;
  font-size: 1rem;
  letter-spacing: 0.05em;
}
.quote-source {
  font-size: 0.60rem;
  opacity: 0.65;
  white-space: nowrap;
}

/* ── AI Mockup modal ── */
.ai-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.ai-modal-backdrop.hidden { display: none; }

.ai-modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 28px 26px 24px;
  max-width: 480px;
  width: 100%;
  position: relative;
  direction: rtl;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.ai-modal-close {
  position: absolute;
  top: 14px;
  left: 14px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}
.ai-modal-close:hover { background: var(--green-pale); color: var(--green); }

.ai-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 4px;
  padding-left: 28px;
}

.ai-modal-step {
  font-size: 0.88rem;
  color: var(--text);
  margin-top: 6px;
}

.ai-modal-tip {
  font-size: 0.80rem;
  color: var(--muted);
  background: var(--green-pale);
  border-radius: 8px;
  padding: 7px 11px;
}

.ai-modal-btn { width: 100%; }

.ai-prompt-box {
  width: 100%;
  height: 148px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text);
  background: var(--cream);
  resize: none;
  direction: ltr;
  text-align: left;
  line-height: 1.5;
}

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

.ai-link-btn {
  flex: 1;
  min-width: 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  background: var(--green);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
  text-align: center;
}
.ai-link-btn:hover { background: var(--green-light); }

/* ── Responsive: narrow screens ── */
@media (max-width: 780px) {
  html, body { height: auto; }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    flex: none;
    overflow: visible;
  }

  .controls-section {
    order: -1;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
    padding: 16px;
    gap: 16px;
  }

  .preview-section {
    height: 82vw;
    min-height: 260px;
    padding: 16px;
  }

  header {
    padding: 11px 16px;
    gap: 6px 12px;
    flex-wrap: wrap;
  }
  header h1 { font-size: 1.2rem; }
  .subtitle-header { font-size: 0.78rem; }
  .credit-header { display: none; }

  .btn { padding: 11px 14px; font-size: 0.95rem; }

  .quote-bar { padding: 7px 12px; flex-wrap: wrap; row-gap: 2px; }
  .quote-text { font-size: 0.85rem; }
  .quote-source { font-size: 0.56rem; }
}
