:root {
  --bg: #f7f7f5;
  --fg: #1d1d1b;
  --muted: #5f5f5a;
  --line: #d9d9d4;
  --accent: #1f5f99;
  --accent-fg: #ffffff;
  --error-bg: #fbeaea;
  --error-fg: #8a1c1c;
  --ok-bg: #e7f3ea;
  --ok-fg: #1c5e2c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header, main, footer { max-width: 44rem; margin: 0 auto; padding: 0 16px; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 1.25rem; color: var(--fg); text-decoration: none; }
nav { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
nav a { margin-left: 16px; color: var(--accent); }
.nav-form { display: inline; margin-left: 16px; }
button.link {
  margin: 0;
  padding: 0;
  font-weight: 400;
  color: var(--accent);
  background: none;
  border: none;
  text-decoration: underline;
}

pre.csv-header { overflow-x: auto; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
input[type="file"] { border: none; padding-left: 0; background: none; }

select {
  width: 100%;
  max-width: 24rem;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
textarea {
  width: 100%;
  max-width: 32rem;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
fieldset.question { margin: 16px 0 0; padding: 8px 12px 12px; border: 1px solid var(--line); border-radius: 4px; }
fieldset.question legend { font-weight: 600; padding: 0 4px; }
label.option { display: flex; gap: 8px; align-items: baseline; font-weight: 400; margin-top: 6px; }
label.option input { width: auto; }
.badge a { display: inline-block; padding: 2px 10px; border: 1px solid var(--accent); border-radius: 999px; text-decoration: none; font-size: 0.875rem; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.details dt { font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; }

main { padding-top: 24px; padding-bottom: 48px; }
footer { color: var(--muted); font-size: 0.875rem; padding-bottom: 24px; }

h1 { font-size: 1.75rem; margin: 0 0 12px; }
.meta { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.875rem; }

label { display: block; margin-top: 12px; font-weight: 600; }
input, textarea {
  width: 100%;
  max-width: 24rem;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

button, .button {
  display: inline-block;
  margin-top: 16px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-fg);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
}
.button.secondary { color: var(--accent); background: transparent; }

.actions .button { margin-right: 8px; }

form.inline { margin-top: 24px; }
form.inline input { max-width: 12rem; }

.errors, .notice { padding: 12px 16px; border-radius: 4px; margin-bottom: 16px; }
.errors { background: var(--error-bg); color: var(--error-fg); }
.errors ul { margin: 0; padding-left: 20px; }
.notice { background: var(--ok-bg); color: var(--ok-fg); }
.ica-number { font-size: 1.25rem; }

table.ratings { width: 100%; border-collapse: collapse; margin-top: 16px; }
.ratings th, .ratings td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.ratings th { font-size: 0.875rem; color: var(--muted); }
.ratings .num { font-variant-numeric: tabular-nums; }

/* Tournament manager */
.player .ica { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
form.result { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
form.result select, form.result input { width: auto; max-width: 14rem; padding: 4px 6px; }
form.result button, .inline-row button { margin-top: 0; padding: 4px 10px; }
form.inline-row { display: inline-flex; gap: 6px; margin-left: 8px; }
form.inline-row input { width: auto; padding: 4px 6px; }
button.secondary { color: var(--accent); background: transparent; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
form.confirm { padding: 12px 16px; border: 1px solid var(--accent); border-radius: 4px; margin-top: 16px; }
.saved { margin-right: 8px; }
details summary { cursor: pointer; color: var(--accent); }
.ratings.pairings td, .ratings.standings td { vertical-align: top; }

.mode-banner { padding: 8px 16px; font-size: 0.9rem; text-align: center; background: #fff4d6; color: #5c4400; border-bottom: 1px solid #e3c766; }
.mode-banner.demo { background: #fbeaea; color: var(--error-fg); border-bottom-color: #d9a0a0; font-weight: 600; }

@media print {
  .mode-banner.pilot { display: none !important; }
  header, footer, nav, form, details, .no-print { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  main { max-width: none; padding: 0; }
  .ratings th, .ratings td { border-bottom: 1px solid #000; padding: 4px 6px; }
  .player .ica { color: #000; }
}

/* Public round results */
.round-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.round-tabs a[aria-current="page"] { color: var(--accent-fg); background: var(--accent); }
.pager { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 600px) { .ratings.pairings th, .ratings.pairings td { padding: 6px 4px; font-size: 0.9rem; } }

textarea { max-width: 32rem; }
.profile-photo { max-width: 160px; height: auto; border-radius: 4px; border: 1px solid var(--line); }
.bio { white-space: pre-line; max-width: 40rem; }
.join-box { border: 1px solid var(--line); border-radius: 4px; padding: 12px 16px; margin: 16px 0; }
.join-box p { margin: 4px 0; }
