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

/* Light theme (default) */
:root {
  --bg: #fafafa;
  --surface: #fff;
  --border: #ddd;
  --text: #1a1a1a;
  --text-secondary: #555;
  --accent: #0066cc;
  --accent-hover: #0052a3;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --field-bg: #f0f4ff;
  --field-border: #c2d4f0;
  --radius: 6px;
}

/* Dark theme values */
[data-theme="dark"] {
  --bg: #111;
  --surface: #1a1a1a;
  --border: #333;
  --text: #e5e5e5;
  --text-secondary: #999;
  --accent: #4da3ff;
  --accent-hover: #7dbdff;
  --error-bg: #2d1515;
  --error-text: #f87171;
  --field-bg: #1a2233;
  --field-border: #2a3a55;
}

/* System preference when no explicit choice */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #111;
    --surface: #1a1a1a;
    --border: #333;
    --text: #e5e5e5;
    --text-secondary: #999;
    --accent: #4da3ff;
    --accent-hover: #7dbdff;
    --error-bg: #2d1515;
    --error-text: #f87171;
    --field-bg: #1a2233;
    --field-border: #2a3a55;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

main {
  max-width: 700px;
  margin: 0 auto;
  padding: 3rem 1rem;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

#theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* Explainer */
.explainer {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.explainer p + p {
  margin-top: 0.5rem;
}

.explainer code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
}

/* Input */
.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.input-group {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}

#cron-input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

#cron-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}

#explain-btn {
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

#explain-btn:hover {
  background: var(--accent-hover);
}

#preset-select {
  padding: 0.6rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  min-width: 100px;
}

#preset-select:focus {
  border-color: var(--accent);
}

/* Error */
#error {
  margin-top: 1.5rem;
  padding: 0.8rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* Results */
#results {
  margin-top: 1.5rem;
}

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

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Description */
.description {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.6;
}

/* Field breakdown */
.field-breakdown {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.field-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  min-width: 0;
}

.field-value {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.5rem 0.3rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 1rem;
  font-weight: 600;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  word-break: break-all;
}

.field-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Next runs */
.runs-list {
  list-style: none;
  counter-reset: run-counter;
}

.runs-list li {
  counter-increment: run-counter;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.9rem;
}

.runs-list li::before {
  content: counter(run-counter) ".";
  display: inline-block;
  width: 1.8em;
  color: var(--text-secondary);
  font-weight: 600;
}

.runs-list li:last-child {
  border-bottom: none;
}

/* Timezone select in header */
#tz-select {
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

#tz-select:focus {
  border-color: var(--accent);
}

/* Permalink */
.permalink-card {
  word-break: break-all;
}

.permalink {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

.permalink:hover {
  text-decoration: underline;
}

/* Footer */
footer {
  max-width: 700px;
  margin: 2rem auto 0;
  padding: 1rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Utility */
.hidden {
  display: none !important;
}

@media (max-width: 500px) {
  .input-row {
    flex-direction: column;
  }

  .input-group {
    flex-direction: column;
  }

  .field-breakdown {
    flex-wrap: wrap;
  }

  .field-cell {
    flex: 0 0 calc(33.333% - 0.35rem);
  }

  .runs-list li {
    font-size: 0.8rem;
  }
}
