:root {
  /* Vibrant palette */
  --bg: #0b0c10;
  --bg-grad-1: #0f1020;
  --bg-grad-2: #0b122b;
  --bg-grad-3: #09111f;
  --panel: rgba(18, 20, 31, 0.65);
  --panel-soft: rgba(18, 20, 31, 0.8);
  --border: rgba(120, 130, 255, 0.25);
  --text: #f3f6fb;
  --muted: #b9c0cf;
  --primary: #7c3aed; /* violet */
  --primary-600: #6d28d9;
  --accent: #22d3ee;  /* cyan */
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 12px 40px rgba(0,0,0,.45);
}

/* Light theme overrides (applied when html or body has .light) */
.light {
  --bg: #f7f8fb;
  --bg-grad-1: #ffffff;
  --bg-grad-2: #f4f6fb;
  --bg-grad-3: #eef1f7;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-soft: rgba(255, 255, 255, 0.98);
  --border: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #334155;
  --primary: #7c3aed;
  --primary-600: #6d28d9;
  --accent: #0ea5e9;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 8px 24px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(124,58,237,0.35), transparent 60%),
    radial-gradient(900px 500px at 85% -20%, rgba(236,72,153,0.25), transparent 60%),
    radial-gradient(900px 600px at 50% 110%, rgba(34,211,238,0.25), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 60%, var(--bg-grad-3) 100%);
  color: var(--text);
}

/* Ensure background gradients look lighter in light mode */
.light body {}

.app-header {
  padding: 32px 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 44px;
  letter-spacing: 0.3px;
  background: linear-gradient(92deg, #ffffff 0%, #e9e9ff 35%, #a78bfa 70%, #f472b6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
}

.header-actions { display: flex; gap: 12px; align-items: center; justify-content: center; }

.apikey-wrap { display: flex; gap: 8px; align-items: center; }
.apikey-wrap input {
  width: 280px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.container {
  display: grid;
  grid-template-columns: 1fr 0.8fr 1.2fr;
  gap: 18px;
  padding: 8px 20px 24px;
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  transition: border-color .2s ease, transform .15s ease;
}
.panel:hover { border-color: rgba(167,139,250,0.45); transform: translateY(-1px); }

.panel-header { display:flex; align-items:center; gap:10px; padding:14px 14px; border-bottom:1px solid var(--border); }
.panel-header.centered { flex-direction: column; align-items: center; text-align: center; }
.panel-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.panel-icon { font-size: 18px; }
.sub { margin:4px 0 0; color: var(--muted); font-size: 13px; }

.panel-body { padding: 0; height: 100%; display: flex; flex-direction: column; }
.panel-body.formatted { padding: 0; }

.tabs { display:flex; align-items:center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: rgba(13,17,25,0.5); }
.light .tabs { background: rgba(255,255,255,0.7); }
.tab { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.tab.active { color: #fff; border-color: var(--border); background: rgba(255,255,255,0.06); }
.tab.disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.2); }
.light .tab { color: #475569; }
.light .tab.active { color: #111827; background: rgba(0,0,0,0.06); border-color: rgba(15,23,42,0.18); }
.tabs .grow { flex: 1; }
.template-label { font-size: 12px; color: var(--muted); }
.template-select { background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

.panel-footer { padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; display:flex; align-items:center; justify-content: space-between; gap: 12px; }
.panel-footer.actions { justify-content: flex-end; }

textarea#jobDescription {
  width: 100%;
  flex: 1;
  padding: 14px;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
}

.dropzone {
  margin: 18px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,0.02);
}
.dropzone:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.upload-icon { font-size: 42px; margin-bottom: 8px; }
.file-btn { display:inline-block; margin: 10px 0; }
.file-btn input { display:none; }
.file-btn span { background: linear-gradient(135deg, var(--primary), #ec4899); color:#fff; padding:10px 16px; border-radius: 999px; cursor:pointer; box-shadow: 0 8px 24px rgba(124,58,237,.35); }
.file-btn span:hover { filter: brightness(1.05); }
.file-info { margin-top: 8px; font-size: 12px; color: var(--muted); }
progress { width: 100%; height: 8px; accent-color: var(--primary); }

.resume-content {
  padding: 18px;
  min-height: 62vh;
  max-height: 65vh;
  overflow: auto;
  line-height: 1.5;
  background: rgba(9, 12, 20, 0.6);
  border-top: 1px solid rgba(255,255,255,0.04);
}
.light .resume-content { background: rgba(255,255,255,0.85); border-top: 1px solid rgba(0,0,0,0.04); }
.resume-content h1, .resume-content h2, .resume-content h3 { font-weight: 700; letter-spacing: 0.2px; }
.resume-content h3 { margin-top: 16px; text-transform: none; }
.resume-content ul li { margin: 4px 0; }
.resume-content:focus { outline: 2px solid var(--primary-600); }
.resume-content .placeholder { color: var(--muted); display:flex; flex-direction:column; align-items:center; gap:8px; padding-top: 60px; }
.placeholder-icon { font-size: 36px; }

.toolbar { display:flex; gap:8px; padding: 10px 12px; border-bottom:1px solid var(--border); background: rgba(13,17,25,0.85); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 3; }
.light .toolbar { background: rgba(255,255,255,0.85); }

/* Typography rendered from PDF text content */
.resume-content h1, .resume-content h2, .resume-content h3 { margin: 18px 0 8px; }
.resume-content p { margin: 8px 0; }
.resume-content ul { margin: 8px 0 8px 20px; }

.btn { border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.primary { background: linear-gradient(135deg, var(--primary), #ec4899); color: #fff; box-shadow: 0 10px 26px rgba(236,72,153,.25), 0 6px 20px rgba(124,58,237,.25); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.secondary { background: #1f2937; color: #e5e7eb; border: 1px solid var(--border); box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.btn.secondary:disabled { opacity: 0.5; cursor:not-allowed; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px dashed var(--border); }

.muted { color: var(--muted); }
.hidden { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 1px, 1px); white-space: nowrap; border: 0; }

/* Tailor progress */
.status { display:flex; align-items:center; gap:8px; margin-left: 10px; }
.status.hidden { display: none !important; }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.15); border-top-color: #a78bfa; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: rgba(18,20,31,0.95); border:1px solid var(--border); border-radius: 14px; padding: 20px; width: 360px; text-align: center; box-shadow: var(--shadow); }
.light .modal-card { background: #ffffff; }
.modal-actions { display:flex; gap: 10px; justify-content: center; margin-top: 12px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0d1117; border: 1px solid var(--border); padding: 10px 14px; border-radius: 10px; color: var(--text); box-shadow: var(--shadow); }
.light .toast { background: #ffffff; }

/* Theme toggle control */
.theme-toggle { position: fixed; left: 12px; top: 12px; z-index: 60; }
.theme-toggle select { background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.light .theme-toggle select { background: rgba(0,0,0,0.03); }

/* Template styles */
.template-original {}
.template-clean { font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial; }
.template-clean h3 { color: #e5e7eb; border-bottom: 1px solid rgba(255,255,255,0.08); padding-bottom: 4px; }
.template-modern { font-family: 'Inter', system-ui; }
.template-modern h3 { color: #a78bfa; text-transform: uppercase; letter-spacing: 1px; }
.template-modern ul { list-style: disc inside; }
.template-minimal { font-family: Georgia, 'Times New Roman', serif; }
.template-minimal h3 { font-style: italic; color: #d1d5db; }
.template-elegant { font-family: 'Georgia', serif; }
.template-elegant h3 { color: #f472b6; border-left: 3px solid #f472b6; padding-left: 8px; }
.template-ats { font-family: Arial, Helvetica, sans-serif; }
.template-ats * { letter-spacing: 0; }

/* Market fit section */
.market-fit { border-top: 1px solid var(--border); padding: 10px 12px 14px; }
.mf-controls { display:flex; gap:8px; align-items:center; flex-wrap: wrap; margin-bottom: 10px; }
.mf-controls input { background: rgba(255,255,255,0.06); border:1px solid var(--border); color: var(--text); border-radius:8px; padding:8px 10px; }
.mf-score { margin-left: 6px; }
.mf-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mf-card { background: rgba(255,255,255,0.04); border:1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.mf-card-title { position: relative; font-weight: 700; margin-bottom: 8px; padding-right: 28px; }
.info-icon { position:absolute; right: 6px; top: 50%; transform: translateY(-50%); display:inline-flex; align-items:center; justify-content:center; width:16px; height:16px; font-size:10px; line-height:1; border-radius:50%; border:1px solid var(--border); color:#aeb6c5; background: rgba(255,255,255,0.05); cursor:pointer; font-weight: 600; }
.info-icon:hover { filter: brightness(1.06); }
.info-box { position:absolute; right: 32px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); background: rgba(13,17,25,0.85); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; max-width: 260px; width: max-content; box-shadow: var(--shadow); }
.bar { height: 12px; background: rgba(255,255,255,0.06); border:1px solid var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.bar.small { height: 8px; }
.bar.salary { height: 10px; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #ec4899); width: 0%; transition: width .4s ease; }
.bar-fill.p25 { background: linear-gradient(90deg, #22d3ee, #60a5fa); }
.bar-fill.p50 { background: linear-gradient(90deg, #34d399, #10b981); }
.bar-fill.p75 { background: linear-gradient(90deg, #f59e0b, #ef4444); }
.chips { display:flex; flex-wrap: wrap; gap:6px; max-height: 90px; overflow:auto; }
.chip-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chips span { background: rgba(255,255,255,0.06); border:1px solid var(--border); color: var(--text); border-radius: 999px; padding: 4px 8px; font-size: 12px; }
.mf-list { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: 13px; }
.mf-salary { display:flex; flex-direction: column; gap: 6px; }
.mf-salary-labels { display:flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.badge { background: rgba(124,58,237,0.25); color: #fff; border:1px solid var(--border); border-radius: 999px; padding: 4px 8px; }

@media (max-width: 1100px) {
  .mf-grid { grid-template-columns: 1fr; }
}

/* Responsive */
@media (max-width: 1100px) {
  .container { grid-template-columns: 1fr; }
  .panel { min-height: auto; }
  .resume-content { max-height: 50vh; }
}

/* Pro Photo */
.photo .photo-grid { display:grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.photo .photo-box { position: relative; display:flex; align-items:center; justify-content:center; background: rgba(255,255,255,0.04); border:1px solid var(--border); border-radius: 12px; min-height: 260px; overflow: hidden; }
.photo img { max-width: 100%; height: auto; display:block; }
.photo canvas { max-width: 100%; display:block; }
.photo .photo-actions { margin-top: 8px; display:flex; gap: 8px; }
.photo .mask-guide { position:absolute; inset: 0; pointer-events: none; }
.mask-controls { display:grid; grid-template-columns: repeat(4, 1fr); gap: 8px; align-items: center; margin: 8px 12px; }
.mask-controls label { display:flex; gap: 8px; align-items: center; }

@media (max-width: 1100px) {
  .photo .photo-grid { grid-template-columns: 1fr; }
}

/* Landing page */
.landing { min-height: 100vh; display:flex; flex-direction: column; gap: 26px; align-items: center; justify-content: center; padding: 32px 18px; }
.landing .hero { text-align: center; max-width: 880px; }
.landing .hero h1 { font-size: 56px; margin: 0 0 10px; background: linear-gradient(92deg, #ffffff 0%, #e9e9ff 35%, #a78bfa 70%, #f472b6 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.landing .hero .tag { color: var(--muted); font-size: 18px; margin: 0 0 18px; }
.landing .cta-row { display:flex; gap: 12px; justify-content: center; margin-bottom: 10px; }
.landing .feature-grid { display:grid; grid-template-columns: repeat(4, 1fr); gap: 12px; max-width: 1000px; width: 100%; }
.landing .feat { background: rgba(255,255,255,0.06); border:1px solid var(--border); border-radius: 12px; padding: 14px; text-align: left; }
.landing .fineprint { font-size: 12px; }
@media (max-width: 900px) { .landing .feature-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .landing .feature-grid { grid-template-columns: 1fr; } .landing .hero h1 { font-size: 36px; } }


