:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5d6671;
  --border: #d6dae0;
  --accent: #c8102e;
  --accent-text: #ffffff;
  --alert-bg: #fdecee;
  --alert-text: #8a0b1f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2227;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --border: #343a42;
    --accent: #e8334f;
    --alert-bg: #3a1a20;
    --alert-text: #ffb3be;
  }
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { color: var(--text); font-weight: 700; text-decoration: none; }
.brand span { color: var(--accent); }

main { max-width: 900px; margin: 0 auto; padding: 24px 16px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 24px;
}
h1 { margin: 0 0 8px; font-size: 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
a { color: var(--accent); }

.alert {
  background: var(--alert-bg);
  color: var(--alert-text);
  border-radius: 6px;
  padding: 10px 14px;
}

.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  margin: 16px 0;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  overflow-wrap: anywhere;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); }
.dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

button, .button {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: progress; }
.button.secondary { background: transparent; color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Result page: the viewer takes all the screen below the header. */
.visor-page { height: 100dvh; display: flex; flex-direction: column; }
.visor-page main { flex: 1; min-height: 0; width: 100%; max-width: none; margin: 0; padding: 10px 16px 12px;
  display: flex; flex-direction: column; gap: 10px; }

.result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.result-info { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; overflow-wrap: anywhere; }
.result-bar .button { padding: 6px 14px; font-size: 0.9rem; }
.download-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0; }
.download-form .tool-check { font-size: 0.9rem; }
.name-field { display: flex; align-items: center; gap: 4px; font-size: 0.9rem; }
.name-field input {
  width: 13em;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.name-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.viewer-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.viewer-panel:fullscreen { background: var(--bg); padding: 12px; }
.viewer-panel:fullscreen .viewer-help { display: none; }

.viewer-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.tool-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tool-label { color: var(--muted); font-weight: 600; margin-right: 2px; }
.viewer-toolbar button {
  padding: 4px 10px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
}
.viewer-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.viewer-toolbar button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.tool-group output { min-width: 3.5em; text-align: center; font-variant-numeric: tabular-nums; }
.tool-check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.tool-end { margin-left: auto; }
.viewer-help { margin: 0; }

/* The viewer and, next to it, the minimap (on the right, or below when the picture is shown lying down). */
.viewer-wrap { flex: 1; min-height: 0; display: flex; gap: 8px; }
.viewer-wrap.minimap-bottom { flex-direction: column; }

/* The radiographs are long strips (e.g. 555x24021): scroll inside the viewer, not the page. */
.viewer {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stage { position: relative; }
.stage img { display: block; max-width: 100%; height: auto; }

/* With scripts: visor.js sizes and turns the image itself, and the stage is the size of the turned picture. */
.viewer.interactive { display: flex; scrollbar-gutter: stable; cursor: grab; user-select: none; }
.viewer.interactive.dragging { cursor: grabbing; }
.viewer.interactive .stage { margin: auto; flex: none; }
.viewer.interactive .stage img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; }

.minimap {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.minimap[hidden] { display: none; }
.minimap-map { position: relative; flex: none; overflow: hidden; cursor: pointer; user-select: none; }
.minimap-map img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.minimap-view {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid var(--accent);
  background: rgba(232, 51, 79, 0.2);
  pointer-events: none;
}

@media (max-width: 700px) {
  .visor-page { height: auto; min-height: 100dvh; }
  .viewer-panel { flex: none; }
  .viewer-wrap { flex: none; height: 70vh; }
}

/* Magnifier that follows the mouse (position is set by visor.js). */
.lens {
  position: fixed;
  z-index: 10;
  width: 200px;
  height: 200px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.lens canvas { display: block; width: 100%; height: 100%; }
.lens::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.6)) center / 1px 14px no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.6)) center / 14px 1px no-repeat;
}
