:root {
  --bg: #121314;
  --surface: #1c1e20;
  --line: #2c2f33;
  --text: #e8e9ea;
  --muted: #8d9399;
  --accent: #6cb6ff;
  --warn: #ffb454;
  --vertical: #5fd4ff;
  --horizontal: #ffb454;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

/* The whole screen. A height of 100 % falls short by the status bar's height in an installed
   app on iOS, which leaves a dead strip at the bottom. */
body {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  /* An app, not a page: nothing in it is text to select, and a long press opens no menu */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}

header.bar {
  justify-content: space-between;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}

#menu {
  position: absolute;
  z-index: 2;
  top: calc(max(8px, env(safe-area-inset-top)) + 46px);
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
  max-width: calc(100vw - 16px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgb(0 0 0 / 55%);
}

#menu[hidden] {
  display: none;
}

#menu p {
  margin: 0;
}

#menu .links {
  display: flex;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

#menu a {
  color: var(--accent);
}

/* Full view: the picture alone */
body.full header,
body.full #menu,
body.full #panel,
body.full #tools {
  display: none;
}

h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  touch-action: manipulation;
}

button:active {
  border-color: var(--accent);
}

/* A label that opens a file picker, made to look and behave like the buttons beside it */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select {
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

button:disabled,
input:disabled {
  opacity: 0.4;
}

button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#view,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

#message[hidden],
#loupe[hidden],
#badge[hidden],
.mode-on[hidden],
.mode-off[hidden],
#no-snapshots[hidden],
#panel[hidden],
.toolset[hidden],
.effect[hidden],
.tool[hidden] {
  display: none;
}

/* The finished picture being made, and then offered */
#saving {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: min(300px, calc(100% - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgb(0 0 0 / 55%);
  transform: translate(-50%, -50%);
}

#saving[hidden],
#saving [hidden] {
  display: none;
}

#saving p {
  margin: 0 0 12px;
  text-align: center;
}

#saving progress {
  display: block;
  width: 100%;
  height: 8px;
  margin-bottom: 12px;
  accent-color: var(--accent);
}

#saving .row {
  min-height: 0;
}

#saving .row:not(:has(> :not([hidden]))) {
  display: none;
}

#saving .button {
  flex: 1;
  text-decoration: none;
}

#badge {
  position: absolute;
  top: 10px;
  left: 50%;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgb(0 0 0 / 65%);
  color: #fff;
  font-size: 13px;
  transform: translateX(-50%);
  pointer-events: none;
}

#loupe {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 132px;
  height: 132px;
  border: 2px solid var(--text);
  border-radius: 50%;
  box-shadow: 0 2px 12px rgb(0 0 0 / 60%);
  pointer-events: none;
}

#loupe.right {
  left: auto;
  right: 12px;
}

.shade {
  fill: var(--bg);
  pointer-events: none;
}

.crop,
.corners,
.thirds,
.guide,
.guide-outline,
.guide-end {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.crop {
  fill: none;
  stroke: #fff;
  stroke-width: 1;
}

.crop.faint {
  stroke-opacity: 0.5;
  stroke-dasharray: 4 4;
}

.corners {
  fill: none;
  stroke: #fff;
  stroke-width: 4;
}

.thirds {
  fill: none;
  stroke: #fff;
  stroke-opacity: 0.5;
  stroke-width: 1;
  filter: drop-shadow(0 0 1px rgb(0 0 0 / 70%));
}

.target,
.target-line {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.target-line {
  stroke-width: 36;
  stroke-linecap: round;
}

.guide-outline,
.centre-outline {
  fill: none;
  stroke: rgb(0 0 0 / 55%);
  stroke-width: 4;
}

.curve-box,
.curve-grid,
.curve-outline,
.curve-line,
.curve-point {
  pointer-events: none;
}

.curve-box {
  fill: none;
  stroke: rgb(255 255 255 / 70%);
  stroke-width: 1;
  filter: drop-shadow(0 0 1px rgb(0 0 0 / 80%));
}

.curve-grid {
  fill: none;
  stroke: rgb(255 255 255 / 40%);
  stroke-width: 1;
  filter: drop-shadow(0 0 1px rgb(0 0 0 / 70%));
}

.curve-grid.diagonal {
  stroke-dasharray: 4 4;
}

.curve-outline {
  fill: none;
  stroke: rgb(0 0 0 / 60%);
  stroke-width: 5;
  stroke-linejoin: round;
}

.curve-line {
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linejoin: round;
}

.curve-point {
  fill: var(--bg);
  stroke: #fff;
  stroke-width: 2;
}

.curve-point-outline {
  fill: rgb(0 0 0 / 55%);
  pointer-events: none;
}

.curve-point.selected {
  fill: var(--accent);
}

.curve-point.leaving {
  opacity: 0.35;
}

.centre {
  fill: none;
  stroke: #fff;
  stroke-width: 1.5;
}

.centre,
.centre-outline {
  pointer-events: none;
}

.guide {
  stroke-width: 2;
}

.guide.selected {
  stroke-width: 3;
}

.guide.vertical {
  stroke: var(--vertical);
}

.guide.horizontal {
  stroke: var(--horizontal);
}

.guide-end {
  fill: var(--bg);
  stroke-width: 2;
}

.guide-end.vertical {
  stroke: var(--vertical);
}

.guide-end.horizontal {
  stroke: var(--horizontal);
}

.guide-end.selected {
  fill: #fff;
}

#panel {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 36px;
  margin: 0;
  accent-color: var(--accent);
}

.row output {
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row button {
  flex: 1;
  padding: 0 6px;
  white-space: nowrap;
}

.row .toggle {
  flex: 3;
}

.row label[for] {
  min-width: 92px;
}

#snapshot-list {
  max-height: 40vh;
  overflow-y: auto;
}

#snapshot-list .name {
  flex: 3;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row.swatches {
  justify-content: space-between;
  gap: 4px;
}

.row .swatch {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 3px solid var(--swatch);
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.row .swatch[aria-pressed="true"] {
  background: var(--swatch);
  box-shadow: inset 0 0 0 5px var(--surface);
}

/* A range that a picked spot takes from: filled, with its share written in it */
.row .swatch.shared {
  background: color-mix(in srgb, var(--swatch) 45%, var(--surface));
}

.row .swatch.spot {
  border-style: double;
  border-width: 5px;
}

.row .swatch[hidden] {
  display: none;
}

.row.tabs button {
  padding: 0 4px;
  font-size: 14px;
}

/* More tabs than fit: one line that scrolls sideways */
#effect-tabs {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

#effect-tabs::-webkit-scrollbar {
  display: none;
}

#effect-tabs button {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 0 12px;
}

.row.tabs {
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  padding-bottom: 6px;
}

.sliders .row {
  min-height: 36px;
}

.sliders label,
.sliders output {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

header.bar #save {
  margin-right: auto;
}

header.bar {
  gap: 6px;
}

header.bar button {
  padding: 0 9px;
  font-size: 14px;
}

#panel .hint {
  margin: 4px 0;
  font-size: 13px;
}

#tools {
  border-top: 1px solid var(--line);
}

/* Half of the safe area below the buttons: the picture needs the height more */
#tools {
  gap: 8px;
  padding-bottom: max(8px, calc(env(safe-area-inset-bottom) / 2));
}

#tools button {
  flex: 1;
  padding: 0 4px;
  font-size: 13px;
  white-space: nowrap;
}

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

.status {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--text);
}

.toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

#refresh-status[data-state="offline"] {
  color: var(--warn);
}

