/* R3-CAD's page. No framework; light and dark follow the system setting. */
:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #5b6470;
  --line: #d9dde3;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --warn-bg: #fff4d6;
  --warn-line: #d9a400;
  --good: #1a7f37;
  --viewer: #e9edf2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --card: #1d2127;
    --text: #e6e9ed;
    --muted: #9aa4b1;
    --line: #343a43;
    --accent: #6ea8fe;
    --accent-text: #0b1220;
    --bad: #ff8a80;
    --bad-bg: #3a1f1d;
    --warn-bg: #3a3116;
    --warn-line: #b8901a;
    --good: #5fd27d;
    --viewer: #262b33;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.top {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.top h1 { margin: 0; font-size: 1.25rem; letter-spacing: 0.02em; }
.top .tagline { margin: 0; color: var(--muted); flex: 1; }
.top button { margin-left: auto; }

@media (max-width: 40rem) {
  .top .tagline { display: none; }
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 78rem;
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 60rem) {
  main { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
}

.column { display: grid; gap: 1rem; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
h3 { margin: 1rem 0 0.25rem; font-size: 0.95rem; }
p { margin: 0.25rem 0; }
ul { margin: 0.25rem 0; padding-left: 1.25rem; }

label { display: block; font-weight: 600; margin-bottom: 0.35rem; }

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

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

textarea:focus-visible, input:focus-visible, button:focus-visible, a.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

button, a.button {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

button:hover:not(:disabled), a.button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.55; cursor: progress; }

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

button.quiet { border-color: var(--line); color: var(--muted); font-weight: 500; padding: 0.3rem 0.8rem; }

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

.status::before {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5em;
  vertical-align: -0.1em;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .status::before { animation: none; }
}

.hint { color: var(--muted); font-size: 0.9rem; }

.error { border-color: var(--bad); background: var(--bad-bg); }
.error button { margin-top: 0.5rem; }
.error-text { color: var(--bad); }

.warning { border-color: var(--warn-line); background: var(--warn-bg); }

.question { margin: 0.75rem 0; }
.question label { font-weight: 500; }

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

th, td {
  padding: 0.35rem 0.5rem 0.35rem 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

td.value { overflow-wrap: anywhere; } /* long lists of hole positions wrap; row names never break mid-word */

thead th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
tbody th { font-weight: 500; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }

td.value { font-variant-numeric: tabular-nums; }
td.mark { width: 1.5rem; text-align: center; color: var(--good); font-weight: 700; }

tr.bad th, tr.bad td { color: var(--bad); }
tr.bad td.mark { color: var(--bad); }
tr.bad { background: var(--bad-bg); }

.viewer {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: var(--viewer);
  overflow: hidden;
  touch-action: none;
}

.viewer canvas { display: block; width: 100%; height: 100%; }

body.login main {
  display: block;
  max-width: 22rem;
  margin: 12vh auto 0;
}

body.login h1 { margin: 0 0 1rem; font-size: 1.4rem; }
body.login button { margin-top: 0.9rem; width: 100%; }
body.login .error-text { margin-top: 0.75rem; }
