:root {
  color-scheme: light dark;
  --bg: #f6f4f0;
  --surface: #ffffff;
  --text: #1d2125;
  --muted: #5d646c;
  --border: #dcd8d0;
  --accent: #2c6b5a;
  --accent-hover: #245a4b;
  --accent-contrast: #ffffff;
  --accent-soft: #e4f0ec;
  --user-bg: #ece9e3;
  --assistant-bg: #e6f0ed;
  --error: #b42318;
  --focus: #1a73e8;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e7e5e2;
    --muted: #a1a8b0;
    --border: #353a40;
    --accent: #6cc1a6;
    --accent-hover: #86d0b8;
    --accent-contrast: #0e1a16;
    --accent-soft: #1c2f29;
    --user-bg: #272a2f;
    --assistant-bg: #1b2b26;
    --error: #f97066;
    --focus: #8ab4f8;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.55;
}

.page {
  max-width: 42rem;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

[hidden] {
  display: none !important;
}

h1 {
  font-size: 1.6rem;
  line-height: 1.25;
  margin: 8px 0 16px;
}

p {
  margin: 0 0 12px;
}

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

.error {
  color: var(--error);
  font-weight: 500;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Buttons and inputs */

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 12px 20px;
  min-height: 48px;
  border: 1px solid transparent;
}

button.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
  font-weight: 500;
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

#screen-welcome button,
#screen-pause button,
#screen-error button {
  margin-top: 8px;
}

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

textarea {
  resize: vertical;
  min-height: 5rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Conversation */

.conversation {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.conversation > #show-previous {
  align-self: flex-start;
  min-height: 40px;
  padding: 8px 16px;
  font-size: 0.95rem;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  border-radius: var(--radius);
  padding: 12px 16px;
  overflow-wrap: anywhere;
}

.message.user {
  background: var(--user-bg);
  margin-right: 12%;
}

.message.assistant {
  background: var(--assistant-bg);
  margin-left: 12%;
}

.message.rated {
  margin-left: 0;
  background: var(--surface);
  border: 2px solid var(--accent);
}

.message-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
}

.message.rated .message-label {
  color: var(--accent);
}

.message-body > :last-child {
  margin-bottom: 0;
}

.message-body p,
.message-body ul,
.message-body ol {
  margin: 0 0 10px;
}

.message-body ul,
.message-body ol {
  padding-left: 1.4em;
}

.message-body pre {
  white-space: pre-wrap;
}

/* Questions */

fieldset.question {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.question-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  padding: 0;
}

.statement {
  font-size: 1.1rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.hint {
  font-size: 0.95rem;
  margin-top: -4px;
}

.rating-options,
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rating-option,
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: 48px;
  cursor: pointer;
}

.rating-option:has(input:checked),
.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rating-option input,
.choice input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
}

.rating-number {
  order: 1;
  font-weight: 700;
  min-width: 1ch;
}

.rating-option .choice-text {
  order: 2;
}

.rating-option input {
  order: 0;
}

.choice.none-of-these {
  margin-top: 4px;
  border-style: dashed;
}

#submit {
  margin-top: 4px;
}

@media (min-width: 640px) {
  .page {
    padding-top: 40px;
  }

  .rating-options {
    flex-direction: row;
  }

  .rating-option {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 4px;
    padding: 10px 6px;
    font-size: 0.95rem;
  }

  .rating-option input {
    order: 2;
  }

  .rating-number {
    order: 0;
  }

  .rating-option .choice-text {
    order: 1;
    line-height: 1.25;
  }

  #submit,
  #screen-welcome button,
  #screen-key button {
    align-self: flex-start;
  }
}

/* Admin */

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 0;
}

a.button {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}

a.button.primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

a.button.secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
}

.admin-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-nav a {
  padding: 10px 14px;
  margin-bottom: -1px;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.admin-nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.admin h2 {
  font-size: 1.2rem;
  line-height: 1.3;
  margin: 28px 0 12px;
}

.admin .stack > button {
  align-self: flex-start;
}

.admin code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.panel {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 4px 16px 16px;
  margin: 20px 0;
}

.panel h2 {
  margin-top: 12px;
}

.panel h2:focus {
  outline: none;
}

.panel p {
  margin: 0;
}

.notice {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 500;
}

.field-label {
  font-weight: 600;
  margin-bottom: -6px;
}

.secret {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.secret code {
  flex: 1 1 18rem;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  user-select: all;
}

.secret button {
  flex: none;
  min-width: 7.5rem;
}

.table-wrap {
  overflow-x: auto;
}

table.coaches {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table.coaches th,
table.coaches td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.coaches th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

table.coaches td:not(:first-child) {
  white-space: nowrap;
}

table.coaches code {
  font-size: 0.85rem;
}

.signed-in {
  margin-top: 32px;
}
