:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #c9cdd3;
  --text: #1c2128;
  --muted: #626c77;
  --error: #c4302f;
  --error-bg: #fcf1f1;
  --accent: #3556c8;
  --accent-hover: #2a46a8;
  --accent-soft: #eef1fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(28, 33, 40, 0.06), 0 4px 12px rgba(28, 33, 40, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0 auto;
  max-width: 56rem;
  padding: 1rem 1rem 4rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

header {
  margin: 0.5rem 0 1rem;
}

h1 {
  font-size: 1.35rem;
  margin: 0;
}

h2,
h3 {
  margin: 0;
}

#repo-banner,
.muted,
footer {
  color: var(--muted);
}

#repo-banner {
  font-size: 0.9rem;
  margin: 0.15rem 0 0;
}

.panel,
.event,
.source-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 1rem;
}

/* The "what do you want to preview?" form. */
#source-form-panel h2 {
  font-size: 1.1rem;
  margin-bottom: 0.35rem;
}

#source-problem {
  margin: 0 0 0.75rem;
}

.source-kind {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 0 0 0.9rem;
  padding: 0;
  border: 0;
}

.source-kind legend {
  padding: 0;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.source-kind label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* `:not([hidden])` on purpose: a plain `display: grid` here would beat the UA
   stylesheet's `[hidden] { display: none }` and both field groups would show. */
.source-fields:not([hidden]) {
  display: grid;
  gap: 0.35rem;
}

.source-fields label {
  color: var(--muted);
  font-size: 0.9rem;
}

.source-fields input,
.source-fields select {
  min-height: 2.35rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.source-fields input:focus-visible,
.source-fields select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-note {
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
}

#source-form button[type="submit"] {
  min-height: 2.35rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
}

#source-form button[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

#change-source {
  margin: 0.5rem 0 0;
}

/*
 * The loading ellipsis. Three dots that appear one at a time, drawn by
 * animating the width of a fixed "…" so the line never reflows.
 */
.loading {
  overflow-wrap: anywhere;
}

.loading-dots {
  display: inline-block;
  width: 1.1em;
  overflow: hidden;
  vertical-align: bottom;
  /* Starts at one dot, never at none: a frame with an empty span reads as a
     line that finished loading and has nothing to say. */
  animation: loading-dots 1.2s steps(3, end) infinite;
}

@keyframes loading-dots {
  from {
    width: 0.37em;
  }
  to {
    width: 1.48em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-dots {
    animation: none;
    width: 1.1em;
  }
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.tab {
  min-height: 2.35rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.summary {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.summary p {
  margin: 0;
}

.summary dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
}

.summary dt {
  color: var(--muted);
}

.summary dd {
  margin: 0;
}

.calendar-panel {
  margin-bottom: 1rem;
  overflow-x: auto;
}

.calendar-host {
  min-width: 42rem;
}

.fc {
  color: var(--text);
  font-size: 0.9rem;
}

.fc .fc-toolbar {
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.fc .fc-toolbar-title {
  font-size: 1.05rem;
}

.fc .fc-button {
  border-radius: var(--radius);
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--accent);
  box-shadow: none;
  text-transform: none;
}

.fc .fc-button-primary:not(:disabled):hover,
.fc .fc-button-primary:not(:disabled).fc-button-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.fc .fc-daygrid-event,
.fc .fc-timegrid-event {
  border-color: var(--accent);
  background: var(--accent);
}

.fc .fc-event {
  cursor: pointer;
}

.calendar-event-title {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fc .fc-daygrid-event {
  padding: 1px 4px;
}

.fc .fc-daygrid-event .calendar-event-title,
.fc .fc-timegrid-event .calendar-event-title {
  color: #ffffff;
}

.fc .fc-list-event-title a,
.fc .fc-list-event-time {
  color: var(--text);
}

.event-list {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.event {
  padding: 0.85rem;
}

.event summary {
  cursor: pointer;
}

.event summary::marker {
  color: var(--muted);
}

.event h3 {
  display: inline;
  font-size: 1rem;
  line-height: 1.3;
}

.event dl {
  display: grid;
  gap: 0.25rem 0.7rem;
  grid-template-columns: max-content 1fr;
  margin: 0.6rem 0 0;
  font-size: 0.9rem;
}

.event dt {
  color: var(--muted);
}

.event dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.description {
  color: var(--muted);
  margin: 0.65rem 0 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
}

button.secondary,
a {
  color: var(--accent);
}

button.secondary {
  min-height: 2.15rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  cursor: pointer;
}

button.secondary:hover {
  border-color: var(--accent);
}

.source-block {
  margin-top: 0.8rem;
  padding: 0.75rem;
}

pre {
  max-height: 26rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  font-size: 0.82rem;
}

dialog.event-dialog {
  width: min(42rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(28, 33, 40, 0.25);
  color: var(--text);
  background: var(--surface);
  padding: 1rem;
}

dialog.event-dialog::backdrop {
  background: rgba(28, 33, 40, 0.45);
}

.event-dialog h2 {
  font-size: 1.15rem;
  line-height: 1.25;
}

.event-dialog dl {
  display: grid;
  gap: 0.3rem 0.75rem;
  grid-template-columns: max-content 1fr;
  margin: 0.8rem 0 0;
  font-size: 0.92rem;
}

.event-dialog dt {
  color: var(--muted);
}

.event-dialog dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.error {
  background: var(--error-bg);
  border-color: #f0c2c2;
}

.error h2,
.error h3 {
  color: var(--error);
}

footer {
  margin-top: 2rem;
  font-size: 0.9rem;
}
