:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242e;
  --border: #2b3140;
  --text: #e6e9ef;
  --muted: #8b93a4;
  --primary: #6c8cff;
  --primary-hover: #5a78f0;
  --secondary: #3a4253;
  --danger: #e0556a;
  --success: #4cc38a;
  --warning: #e0a855;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}

.nav {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.nav-links { display: flex; gap: 1rem; }
.nav-links a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.nav-links a:hover { color: var(--text); }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  flex: 1;
  width: 100%;
}

.site-footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin-bottom: 0.75rem; }
.flash { color: var(--success); padding: 0.5rem 0.75rem; background: rgba(76,195,138,0.1); border-radius: 6px; margin-bottom: 0.75rem; }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.stat { color: var(--muted); }
.stat strong { color: var(--text); }

/* Challenge card */
.challenge-label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.challenge-text {
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  padding: 1rem 1.25rem;
  border-radius: 6px;
  margin: 0.5rem 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.challenge-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-manual   { background: #3a4253; color: #c4cad6; }
.badge-llm      { background: rgba(108,140,255,0.2); color: var(--primary); }
.badge-internet { background: rgba(76,195,138,0.2); color: var(--success); }

/* Rewrite card */
.rewrite-card textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.75rem;
  resize: vertical;
}
.rewrite-card textarea:focus { outline: none; border-color: var(--primary); }
.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

/* Rewrite feedback (char counter + warning/error) */
.rewrite-feedback {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.4rem;
  min-height: 1.4em;
  font-size: 0.85rem;
}
.char-counter {
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}
.char-counter.near { color: var(--warning); }
.char-counter.at   { color: var(--danger); font-weight: 700; }
.char-warning {
  font-size: 0.85rem;
  text-align: right;
}
.char-warning.warning { color: var(--warning); }
.char-warning.error   { color: var(--danger); font-weight: 600; }
.rewrite-card textarea.over {
  border-color: var(--danger);
}
.rewrite-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

/* Buttons */
.btn {
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--text); }
.btn-secondary:hover { background: #454d61; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c94258; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

/* Spinner shown in a button while a backend operation is in flight. */
.btn.loading { display: inline-flex; align-items: center; gap: 0.5rem; opacity: 1; }
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result card */
.result-card { display: none; }
.result-card.visible { display: block; }

.overall-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.overall-score {
  font-size: 2.5rem;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1;
}
.overall-notes { color: var(--muted); font-size: 0.9rem; flex: 1; }

.metrics-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.metric {
  font-size: 0.85rem;
  color: var(--muted);
}
.metric strong { color: var(--text); font-family: var(--mono); }

.dimensions { display: flex; flex-direction: column; gap: 0.75rem; }
.dimension {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.dimension-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.dimension-label { color: var(--text); }
.dimension-score { font-family: var(--mono); font-weight: 600; }
.dimension-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.dimension-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.dimension-notes { font-size: 0.8rem; color: var(--muted); }

/* Score colour classes (used by static landing-page examples; the live JS
   sets inline colours directly). Keep thresholds in sync with scoreClass in
   helpers.go and colorForScore in app.js. */
.score-excellent { color: var(--success); }
.score-good { color: var(--primary); }
.score-fair { color: var(--warning); }
.score-poor { color: var(--danger); }
.dimension-bar-fill.score-excellent { background: var(--success); }
.dimension-bar-fill.score-good { background: var(--primary); }
.dimension-bar-fill.score-fair { background: var(--warning); }
.dimension-bar-fill.score-poor { background: var(--danger); }

/* Modal dialog (admin challenge preview) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal h3 { font-size: 1.2rem; }
.modal-text {
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  padding: 0.85rem 1rem;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  max-height: 45vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Landing page */
.home { display: flex; flex-direction: column; gap: 2rem; }
.home-hero {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.home-hero h1 { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.02em; }
.home-lede { max-width: 620px; color: var(--muted); font-size: 1.05rem; }
.btn-lg { padding: 0.8rem 2.2rem; font-size: 1.15rem; font-weight: 700; }
.home-example { display: flex; flex-direction: column; gap: 1rem; }
.home-example h2 { font-size: 1.3rem; }
.example-card { display: flex; flex-direction: column; gap: 0.75rem; }
.example-head { display: flex; align-items: center; }
.example-tag {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--primary);
}
.example-text {
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-style: normal;
}

/* History */
.history-list { list-style: none; }
.history-item { margin-bottom: 0.75rem; }
.history-item-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.overall-pill {
  background: var(--primary);
  color: #fff;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--mono);
}
.overall-pill.score-excellent { background: var(--success); }
.overall-pill.score-good { background: var(--primary); }
.overall-pill.score-fair { background: var(--warning); }
.overall-pill.score-poor { background: var(--danger); }
.history-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Admin submissions list (reuses history-cols, overall-pill, dimensions) */
.submission-list { list-style: none; }
.submission-item { margin-bottom: 0.5rem; }
.submission-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.submission-challenge-id {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}
.submission-challenge-preview {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.submission-summary .overall-pill { flex-shrink: 0; }
.submission-summary time { flex-shrink: 0; font-size: 0.8rem; }
.submission-toggle { flex-shrink: 0; }
.submission-details {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.submission-details[hidden] { display: none; }

/* Admin */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.admin-header h2 { display: inline; }
.inline { display: inline; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.admin-grid textarea,
.admin-grid input[type="text"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 0.6rem;
  margin-bottom: 0.6rem;
}
.admin-grid textarea:focus,
.admin-grid input:focus { outline: none; border-color: var(--primary); }

.verbosity-slider {
  margin: 0.5rem 0 0.8rem;
  padding: 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.verbosity-slider label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.verbosity-value { color: var(--primary); font-weight: 600; }
.verbosity-slider input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}
.verbosity-hint {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.4rem;
  min-height: 1.1em;
}

.challenge-list { list-style: none; }
.challenge-list-item { margin-bottom: 0.5rem; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.challenge-list-item:hover { border-color: var(--primary); }
.challenge-list-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.challenge-list-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.challenge-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.challenge-table th,
.challenge-table td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.challenge-table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.cell-text { max-width: 350px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-text.expanded { max-width: none; white-space: pre-wrap; overflow: visible; color: var(--text); word-break: break-word; }

.narrow { max-width: 380px; margin: 2rem auto; }
.narrow input { width: 100%; margin-bottom: 0.75rem; }
.narrow input[type="password"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.6rem;
  font-size: 1rem;
}
.narrow input:focus { outline: none; border-color: var(--primary); }

h2, h3 { margin-bottom: 0.75rem; }
h3 { font-size: 1.05rem; }

@media (max-width: 600px) {
  .history-cols { grid-template-columns: 1fr; }
  .stats-bar { flex-wrap: wrap; gap: 1rem; }
}
