:root {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  /* Brand colors lifted from chandrashaker.in (blue #1565c0 headings,
     orange #ff8f00 nav accent), re-tuned for contrast on this app's dark
     background rather than the site's white one. Blue drives everyday
     navigation actions; orange is reserved for the final Submit action
     and heading accents, so it stays a highlight rather than the norm. */
  --accent: #3b82f6;
  --accent-text: #f8fafc;
  --highlight: #ff8f00;
  --highlight-text: #1c1300;
  --danger: #f87171;
  --warning: #fbbf24;
  --border: #334155;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.hidden { display: none; }

h1 {
  display: inline-block;
  font-size: 1.4rem;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--highlight);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 16px 0 6px;
}

input[type="text"], select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.button-row {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.button-row button { flex: 1; }

button {
  padding: 14px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

/* The final commit action gets the brand's orange highlight instead of
   the everyday navigation blue, so it visually stands apart as "this is
   the one that actually submits your data." */
#submitBtn {
  background: var(--highlight);
  color: var(--highlight-text);
}

.preview-area {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
}

.preview-area img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: 6px;
}

.preview-area .pdf-frame {
  width: 100%;
  height: 65vh;
  border: none;
  border-radius: 6px;
  background: #fff; /* the native PDF viewer renders its own white page background */
}

.preview-area .view-full-size {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
}

.preview-area .view-full-size:hover {
  text-decoration: underline;
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 24px auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#screen-processing, #screen-done {
  text-align: center;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 12px;
}

.hint-warning {
  color: var(--warning);
  font-size: 0.8rem;
  margin: 4px 0 0;
}

/* Confirm screen: certificate preview stacked above the form on mobile,
   side-by-side on wider viewports so students can visually cross-check
   fields (esp. Name/Event) against the certificate while editing. */
.confirm-layout {
  margin-top: 16px;
}

.confirm-preview {
  margin-bottom: 20px;
  max-height: 55vh;
}

.confirm-preview img {
  max-height: 52vh;
}

.confirm-preview .pdf-frame {
  height: 52vh; /* iframes need an explicit height, not max-height, to resize */
}

@media (min-width: 700px) {
  #app { max-width: 1000px; }

  .confirm-layout {
    display: flex;
    align-items: flex-start;
    gap: 24px;
  }

  .confirm-preview {
    flex: 0 0 48%;
    margin-bottom: 0;
    max-height: none;
    position: sticky;
    top: 16px;
  }

  .confirm-preview img {
    max-height: 85vh;
  }

  .confirm-preview .pdf-frame {
    height: 85vh;
  }

  .confirm-fields {
    flex: 1;
    min-width: 0;
  }
}

#doneFileLink {
  display: block;
  color: var(--accent);
  margin: 16px 0;
}

#submitAnotherBtn { margin-top: 12px; width: 100%; }

.done-nav {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.done-nav a {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.done-nav a:hover {
  color: var(--accent);
  text-decoration: underline;
}
