:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --bg: #ffffff;
  --bg-alt: #f4f6f9;
  --muted: #5a5a5a;
  --accent: #1d5c9e;
  --accent-dark: #164a80;
  --border: #e2e2e2;
  --ok: #1e8e3e;
  --bad: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f0f0f0;
    --bg: #14161a;
    --bg-alt: #1b1e24;
    --muted: #a3a3a3;
    --accent: #6ea8e8;
    --accent-dark: #8fbdf0;
    --border: #2a2d33;
    --ok: #4caf50;
    --bad: #e57373;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg-alt);
  line-height: 1.5;
}

header.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header.site-header a.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
}

header.site-header .status {
  font-size: 0.85rem;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.25rem;
  max-width: 1200px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
  align-items: start;
}

/* Grid items default to min-width: auto, so a wide table inside would force
   its whole column wider instead of scrolling within it. */
.layout > * {
  min-width: 0;
}

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

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  min-width: 0;
}

.panel h2 {
  margin-top: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.schema-table {
  margin-bottom: 1.25rem;
}

.schema-table h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.schema-table .table-scroll {
  overflow-x: auto;
}

.schema-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}

.schema-table th, .schema-table td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  text-align: left;
}

.schema-table th {
  background: var(--bg-alt);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  color: var(--fg);
  font-size: 0.9rem;
}

.tab-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.exercise-list {
  display: grid;
  gap: 0.6rem;
}

.exercise-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.exercise-item summary {
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.exercise-item summary::-webkit-details-marker { display: none; }

.exercise-item .skill-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  white-space: nowrap;
}

.exercise-item .mark {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}

.exercise-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}

.exercise-body p.prompt {
  margin: 0.75rem 0;
}

textarea.sql-input {
  width: 100%;
  min-height: 4.5rem;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.95rem;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--fg);
  resize: vertical;
}

.controls {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 0.6rem 0;
  flex-wrap: wrap;
}

button.run, button.reset {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

button.run:hover, button.reset:hover {
  background: var(--accent-dark);
}

button.hint-toggle, button.answer-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  color: var(--fg);
  font-size: 0.85rem;
}

.feedback {
  margin-top: 0.6rem;
  font-weight: 600;
}

.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.feedback.error { color: var(--bad); font-weight: 400; font-family: monospace; }

.hint, .model-answer {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  background: var(--bg-alt);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
}

.model-answer code {
  font-family: monospace;
}

.result-table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

table.result-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

table.result-table th, table.result-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
}

table.result-table th {
  background: var(--bg-alt);
}

.freeplay textarea.sql-input {
  min-height: 6rem;
}

footer.site-footer {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}
