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

:root {
  /* Dark mode default (per SPEC) */
  --bg-primary: #08090d;
  --bg-card: #141620;
  --bg-input: #1c1e2a;
  --accent: #c4384a;
  --accent-hover: #d94a5c;
  --text: #e8eaf0;
  --text-muted: #8b90a0;
  --border: #2a2d3a;
  --success: #2ecc71;
  --error: #e74c3c;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
  --preview-stage: #0e1018;
}

[data-theme="light"] {
  --bg-primary: #f4f5f8;
  --bg-card: #ffffff;
  --bg-input: #eef0f5;
  --text: #1a1d27;
  --text-muted: #5c6270;
  --border: #dde1ea;
  --success: #1f9d57;
  --error: #d64545;
  --shadow: 0 8px 28px rgba(24, 28, 40, 0.08);
  --preview-stage: #e9ebf1;
}

html {
  font-size: 16px;
  color-scheme: dark;
}

[data-theme="light"] html,
html[data-theme="light"] {
  color-scheme: light;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

a {
  color: inherit;
  text-decoration: none;
}

/* HEADER */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.logo {
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0;
  letter-spacing: 1.5px;
}

.logo span {
  color: var(--text);
  font-weight: 400;
  margin-left: 0.4rem;
  font-family: 'Outfit', sans-serif;
  letter-spacing: 0;
}

.logo-icon {
  color: var(--accent);
}

.site-header nav a {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 1.5rem;
  transition: color 0.3s;
}

.site-header nav a:hover {
  color: var(--accent);
}

.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 1rem;
  transition: background 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* TOOL GRID */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.2rem;
  max-width: 1100px;
  width: 90%;
  margin: 0 auto 4rem;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 1.2rem;
  text-align: center;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.tool-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 12px 32px rgba(196, 56, 74, 0.12);
}

.tool-icon {
  font-size: 2rem;
  margin-bottom: 0.6rem;
}

.tool-card h2,
.tool-card h3 {
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.seo-intro,
.seo-footer-blurb {
  max-width: 780px;
  width: 92%;
  margin: 0 auto 2rem;
  text-align: center;
}

.seo-intro h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.seo-intro p,
.seo-footer-blurb p {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.7;
  font-weight: 400;
}

.seo-intro a,
.seo-footer-blurb a,
.site-footer a {
  color: var(--accent);
  font-weight: 500;
}

.seo-intro a:hover,
.seo-footer-blurb a:hover,
.site-footer a:hover {
  text-decoration: underline;
}

.seo-footer-blurb {
  margin-top: 0.5rem;
  margin-bottom: 2.5rem;
}

.seo-footer-blurb h2 {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

.tool-card p {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 300;
}

/* TOOL PAGE */
.tool-page {
  max-width: 720px;
  width: 92%;
  margin: 2rem auto 1.5rem;
}

.tool-page h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
}

/* Wider shell: preview LEFT, controls RIGHT on desktop */
.tool-layout {
  width: min(1200px, 94%);
  margin: 0 auto 2rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

.tool-layout .tool-page {
  order: 1;
}

.tool-layout .preview-panel {
  order: 2;
}

@media (min-width: 960px) {
  .tool-layout {
    /* left preview | right controls */
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 1.75rem;
  }

  .tool-layout .preview-panel {
    order: 1;
    position: sticky;
    top: 1rem;
    margin-top: 2rem;
  }

  .tool-layout .tool-page {
    order: 2;
    max-width: none;
    width: 100%;
    margin: 2rem 0 1rem;
  }

  .tool-layout .preview-scroll {
    max-height: calc(100vh - 8rem);
  }
}

.tool-page .subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-weight: 300;
}

.back-link {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
}

.back-link:hover {
  text-decoration: underline;
}

/* UPLOAD ZONE */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1.5rem;
  position: relative;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(196, 56, 74, 0.06);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-zone .upload-label {
  font-size: 1rem;
  color: var(--text-muted);
}

.upload-zone .upload-label strong {
  color: var(--accent);
}

.file-list {
  list-style: none;
  margin-bottom: 1rem;
}

.file-list li {
  background: var(--bg-input);
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.file-list .remove-file {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 1rem;
}

/* FORM OPTIONS */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888a0'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 8px;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 1rem;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

/* STATUS */
.status {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  display: none;
}

.status.loading {
  display: block;
  background: var(--bg-input);
  color: var(--text-muted);
}

.status.success {
  display: block;
  background: rgba(46, 204, 113, 0.1);
  color: var(--success);
  border: 1px solid rgba(46, 204, 113, 0.3);
}

.status.error {
  display: block;
  background: rgba(231, 76, 60, 0.1);
  color: var(--error);
  border: 1px solid rgba(231, 76, 60, 0.3);
}

/* ===== PDF / Image Preview ===== */
.preview-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 0 1rem;
  min-height: 0;
  box-shadow: var(--shadow);
}

.preview-panel[hidden] {
  display: none !important;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
}

.preview-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.preview-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.preview-scroll {
  /* Desktop: big readable preview */
  max-height: 70vh;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  background:
    radial-gradient(circle at 50% 0%, rgba(196, 56, 74, 0.05), transparent 55%),
    var(--preview-stage);
}

.preview-page {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  box-shadow: 0 6px 20px rgba(24, 28, 40, 0.1);
  max-width: 100%;
}

.preview-page-num {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  z-index: 2;
  font-size: 0.68rem;
  color: #fff;
  background: rgba(26, 29, 39, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  pointer-events: none;
}

.preview-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  background: #fff;
}

.preview-image {
  display: block;
  max-width: min(100%, 820px);
  max-height: 65vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}

.preview-loading,
.preview-placeholder,
.preview-error {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 2rem 1rem;
  text-align: center;
}

.preview-file-divider {
  width: 100%;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.5rem 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  margin: 0.5rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-error {
  color: var(--error);
}

@media (max-width: 768px) {
  .preview-panel {
    margin: 0.25rem 0 1rem;
  }

  .preview-scroll {
    /* Mobile: compact but usable */
    max-height: 45vh;
    padding: 0.65rem;
    gap: 0.75rem;
  }

  .preview-page {
    padding: 0.35rem;
    width: 100%;
  }

  .preview-image {
    max-height: 40vh;
    width: 100%;
  }

  .preview-toolbar {
    padding: 0.55rem 0.75rem;
  }
}

@media (min-width: 960px) {
  .tool-layout .preview-scroll {
    max-height: calc(100vh - 8rem);
  }
}

/* FOOTER */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 300;
  margin-top: auto;
}

/* ADS — non-intrusive, after content only */
.ad-region {
  width: min(960px, 94%);
  margin: 2rem auto 1.5rem;
  padding: 0.75rem 0.5rem 1rem;
  background: transparent;
  border-top: 1px solid var(--border);
  min-height: 0;
}

.ad-region--tight {
  margin-top: 2.5rem;
  margin-bottom: 0.5rem;
}

.ad-label {
  display: block;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.7;
  margin-bottom: 0.45rem;
  user-select: none;
}

.ad-region .adsbygoogle {
  display: block;
  min-height: 90px;
  max-height: 280px;
  overflow: hidden;
  border-radius: 8px;
}

@media (max-width: 600px) {
  .ad-region {
    width: 96%;
    margin: 1.5rem auto 1rem;
    padding: 0.5rem 0;
  }

  .ad-region .adsbygoogle {
    min-height: 70px;
    max-height: 200px;
  }
}

/* RESPONSIVE */
@media (max-width: 600px) {
  .tool-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
  }

  .site-header {
    padding: 0.6rem 1rem;
  }

  .site-header nav a {
    margin-left: 1rem;
    font-size: 0.8rem;
  }

  .logo {
    font-size: 0.9rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
}
