* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--al-bg);
  color: var(--al-ink);
  font-family: var(--al-font-ui);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#top-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  height: calc(var(--al-bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) calc(8px + env(safe-area-inset-right)) 0 calc(8px + env(safe-area-inset-left));
  background: var(--al-surface-1);
  border-bottom: var(--al-border);
}

.bar-button {
  appearance: none;
  min-height: var(--al-tap);
  padding: 0 var(--al-space-4);
  display: inline-flex;
  align-items: center;
  gap: var(--al-space-2);
  color: var(--al-ink);
  font: var(--al-weight-medium) var(--al-text-sm)/1 var(--al-font-ui);
  background: linear-gradient(180deg, var(--al-surface-2), var(--al-surface-1));
  border: var(--al-border);
  border-radius: var(--al-radius-md);
  box-shadow: var(--al-inner-top), var(--al-shadow-1);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--al-dur-instant) var(--al-ease-standard),
              transform var(--al-dur-instant) var(--al-ease-standard);
}

/* Icon-only button: a 44x44 target, the label lives in aria-label. */
.icon-button {
  flex: none;
  width: var(--al-tap);
  height: var(--al-tap);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--al-radius-md);
  background: transparent;
  color: var(--al-ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:active {
  background: var(--al-surface-3);
}

.icon-button:disabled {
  color: var(--al-ink-faint);
  opacity: .5;
  cursor: default;
}

.primary-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--al-ink);
  color: var(--al-ink-inverse);
}

.primary-icon:active {
  background: var(--al-ink);
  opacity: .8;
}

.project-chip {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--al-well);
  border: var(--al-border);
  border-radius: var(--al-radius-pill);
  color: var(--al-ink);
  font: var(--al-weight-semi) 14px/1 var(--al-font-ui);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.project-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-chip small {
  flex: none;
  color: var(--al-ink-faint);
  font-weight: var(--al-weight-medium);
  font-size: 12px;
}

.bar-button:active {
  background: var(--al-surface-3);
  transform: translateY(0.5px);
}

.bar-button:disabled {
  opacity: .38;
  cursor: default;
  box-shadow: none;
}

/* LOTE 4 §4: floating reading of the selected measurement, top-left of the canvas. The plaque
   is dark in both themes, so its text is light in both. Hidden when nothing is selected. */
.readout {
  position: absolute;
  top: 10px;
  left: calc(10px + env(safe-area-inset-left));
  z-index: 10;
  padding: 8px 12px 9px;
  background: var(--al-plaque);
  border: 1px solid var(--al-plaque-edge);
  border-radius: var(--al-radius-lg);
  color: #E9EDF3;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

.readout[hidden] {
  display: none;
}

.readout-label {
  font: var(--al-weight-semi) 11px/1.2 var(--al-font-ui);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #9AA6B4;
}

.readout-value {
  font: var(--al-weight-semi) 34px/36px var(--al-font-num);
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: var(--al-track-tight);
}

.readout-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font: var(--al-weight-medium) 12px/16px var(--al-font-num);
  color: #9AA6B4;
}

.quality-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

/* Same three colours the canvas labels use for quality (canvasRenderer.js QUALITY_COLOR). */
.quality-dot[data-level="good"] { background: #7cff6b; }
.quality-dot[data-level="ok"] { background: #ffd23f; }
.quality-dot[data-level="poor"] { background: #ff5f5f; }

/* BOTTOM TOOL BAR — six equal cells at thumb reach, in the page flow so the canvas ends where it
   begins (no fixed overlay, no padding hack on #canvas-area). */
#tool-bar {
  flex: 0 0 auto;
  padding: 6px calc(6px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left));
  background: var(--al-surface-1);
  border-top: var(--al-border);
}

#tool-group {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  height: calc(var(--al-toolbar-h) - 14px);
}

.tool-button {
  appearance: none;
  min-width: 0;
  min-height: var(--al-tap);
  padding: 0 2px;
  border: 0;
  border-radius: var(--al-radius-md);
  background: transparent;
  color: var(--al-ink-muted);
  font: var(--al-weight-medium) 10.5px/1 var(--al-font-ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--al-dur-instant) var(--al-ease-standard),
              color var(--al-dur-instant) var(--al-ease-standard);
}

.tool-button svg {
  flex: none;
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.tool-button .tool-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-button.active {
  background: var(--al-ink);
  color: var(--al-ink-inverse);
}

.tool-button:active:not(.active) {
  background: var(--al-surface-3);
}

.tool-button:disabled {
  color: var(--al-ink-faint);
  opacity: .5;
  cursor: default;
}

.danger-button {
  color: var(--al-danger);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--al-danger) 40%, transparent);
}

.danger-button:not(:disabled):active {
  background: color-mix(in srgb, var(--al-danger) 16%, transparent);
}

.danger-button:disabled {
  opacity: .38;
  cursor: default;
  box-shadow: none;
}

#canvas-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.magnifier {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.88);
  box-shadow: var(--al-shadow-3), inset 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 20;
}

.magnifier[hidden] {
  display: none;
}

/* LOTE 2 §2.3: the projection disclaimer is permanent, not a dismissible
   toast — it is not allowed to become something the user stops seeing. */
#disclaimer-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
  font-size: var(--al-text-xs);
  color: var(--al-ink-muted);
  background: var(--al-surface-1);
  border-bottom: var(--al-border);
}

#disclaimer-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#disclaimer-text strong {
  color: var(--al-ink);
  font-weight: var(--al-weight-semi);
}

.link-button {
  position: relative;
  flex: none;
  appearance: none;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--al-ink);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Invisible 44px-high hit area around the 12px text link. */
.link-button::after {
  content: "";
  position: absolute;
  inset: -8px -6px;
}

/* LOTE 2 §3: the single hint line that says what the next tap does (replaces #repeat-readout and
   #guide-readout, same plaque). The text ignores pointer events so it never eats a tap meant for
   the photo; only the ✕ (44x44) takes them. */
#hint {
  position: absolute;
  left: 50%;
  bottom: var(--al-space-4);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--al-space-3);
  /* left:50% leaves a shrink-to-fit width of half the canvas; max-content lets it use the room. */
  width: max-content;
  max-width: min(90%, 560px);
  background: var(--al-plaque);
  border: var(--al-border);
  border-radius: var(--al-radius-lg);
  padding: var(--al-space-4) var(--al-space-5);
  /* --al-plaque is dark in both themes, so the text must be light in both (--al-ink flips to dark in the light theme). */
  color: #E9EDF3;
  font-size: var(--al-text-sm);
  line-height: 1.5;
  text-align: center;
  z-index: 15;
  pointer-events: none;
}

#hint[hidden] {
  display: none;
}

#hint-cancel {
  flex: none;
  width: 44px;
  height: 44px;
  margin: calc(-1 * var(--al-space-3)) calc(-1 * var(--al-space-3)) calc(-1 * var(--al-space-3)) 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
}

#hint-cancel[hidden] {
  display: none;
}

#hint-cancel:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

/* LOTE 3: image-decode failures (§7) and storage-quota warnings (§3) both
   use this pair — error is a hard red, storage a softer amber, both
   dismissible unlike #disclaimer-bar, which is permanent by design. */
#error-bar,
#storage-bar {
  flex: 0 0 auto;
  padding: var(--al-space-3) var(--al-space-4);
  font-size: var(--al-text-sm);
  line-height: 1.4;
  border-bottom: var(--al-border);
}

#error-bar[hidden],
#storage-bar[hidden] {
  display: none;
}

#error-bar {
  background: color-mix(in srgb, var(--al-danger) 16%, var(--al-bg));
  color: var(--al-danger);
}

#storage-bar {
  background: color-mix(in srgb, var(--al-attention) 16%, var(--al-bg));
  color: var(--al-attention);
}

/* EMPTY STATE — the first screen anyone sees. */
.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--al-space-5);
  padding: var(--al-space-8);
  text-align: center;
}

.empty[hidden] {
  display: none;
}

.empty-mark {
  width: 72px;
  height: 72px;
  opacity: .85;
  stroke: var(--al-ink);
}

.empty-title {
  font: 400 var(--al-text-3xl)/var(--al-lh-3xl) var(--al-font-display);
  letter-spacing: var(--al-track-tight);
  color: var(--al-ink);
  margin: 0;
}

.empty-steps {
  display: flex;
  gap: var(--al-space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.empty-steps li {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--al-space-3);
  max-width: 104px;
  font: var(--al-text-sm)/1.3 var(--al-font-ui);
  color: var(--al-ink);
}

.empty-step-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: var(--al-border-strong);
  border-radius: 50%;
  font: var(--al-weight-semi) 13px var(--al-font-num);
  color: var(--al-ink-muted);
}

.empty-trust {
  margin: 0;
  font-size: var(--al-text-xs);
  color: var(--al-ink-faint);
}

.empty-actions {
  display: flex;
  gap: var(--al-space-3);
}

.empty-actions .bar-button {
  padding: 0 var(--al-space-6);
}

.ghost-button {
  background: transparent;
  box-shadow: none;
}

/* The one primary action of a screen: ink on the page colour, inverted. */
.primary-button {
  background: var(--al-ink);
  color: var(--al-ink-inverse);
  border-color: var(--al-ink);
  box-shadow: none;
}

.primary-button:active {
  background: var(--al-ink);
  opacity: .8;
}

/* LOTE 5 §3: one recipe for the four content dialogs (protocol, guides, history, export). A bottom
   sheet on a phone, a centred card elsewhere; ✕ (44x44) top right, closes on a tap outside too. */
.sheet-dialog {
  max-width: min(560px, 92vw);
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--al-surface-2);
  color: var(--al-ink);
  border: var(--al-border);
  border-radius: var(--al-radius-lg);
  padding: var(--al-space-6) var(--al-space-7);
  box-shadow: var(--al-shadow-3);
}

.sheet-dialog::backdrop {
  background: var(--al-scrim, rgba(5, 7, 10, .6));
}

#export-dialog {
  max-width: min(640px, 92vw);
}

.sheet-dialog h2 {
  font-size: var(--al-text-lg);
  margin: 0 0 var(--al-space-3);
}

.sheet-dialog > .bar-button {
  margin-top: var(--al-space-3);
}

.sheet-close {
  float: right;
  margin: calc(-1 * var(--al-space-4)) calc(-1 * var(--al-space-4)) var(--al-space-3) var(--al-space-3);
}

@media (max-width: 599px) {
  .sheet-dialog {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: none;
    max-height: 90dvh;
    border-width: 1px 0 0;
    border-radius: var(--al-radius-xl) var(--al-radius-xl) 0 0;
    padding: var(--al-space-5) calc(var(--al-space-5) + env(safe-area-inset-right)) calc(var(--al-space-5) + env(safe-area-inset-bottom)) calc(var(--al-space-5) + env(safe-area-inset-left));
  }

  #export-dialog {
    max-width: none;
  }

  .sheet-close {
    margin: calc(-1 * var(--al-space-3)) calc(-1 * var(--al-space-3)) var(--al-space-3) var(--al-space-3);
  }
}

/* The protocol text is long prose, with its own heading rhythm. */
#protocol-dialog h2 {
  margin: var(--al-space-5) 0 var(--al-space-3);
}

#protocol-dialog h2:first-of-type {
  margin-top: 0;
}

#protocol-dialog p,
#protocol-dialog li {
  font-size: var(--al-text-sm);
  line-height: 1.5;
  color: var(--al-ink-muted);
}

#protocol-dialog ul {
  padding-left: 20px;
  margin: var(--al-space-3) 0;
}

#guide-list {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-3);
}

#guide-list button {
  width: 100%;
  text-align: left;
}

#history-list {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-3);
}

/* LOTE 5 §4: two lines. Top: code field, then date + photo count on one line. Bottom, right:
   Open and Delete. Nothing wraps, so it holds at 320 px. */
.history-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--al-space-3);
  padding: var(--al-space-3);
  background: var(--al-surface-3);
  border: var(--al-border);
  border-radius: var(--al-radius-md);
}

.history-code-input {
  grid-column: 1;
  min-width: 0;
  background: var(--al-well);
  border: var(--al-border);
  color: var(--al-ink);
  border-radius: var(--al-radius-sm);
  padding: var(--al-space-2) var(--al-space-3);
  font-size: 16px; /* >=16px stops iOS Safari zooming the page on focus */
  min-height: var(--al-tap);
}

.history-meta {
  grid-column: 2 / -1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--al-text-xs);
  color: var(--al-ink-muted);
}

.history-row button:nth-of-type(1) {
  grid-column: 3;
}

.history-row button:nth-of-type(2) {
  grid-column: 4;
}

.export-hint {
  font-size: var(--al-text-xs);
  line-height: 1.5;
  color: var(--al-ink-muted);
  margin: 0 0 var(--al-space-5);
}

.export-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--al-space-4);
  margin-bottom: var(--al-space-5);
}

.export-fields label {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-2);
  font-size: var(--al-text-xs);
  color: var(--al-ink-muted);
}

.export-fields input,
.export-fields select {
  background: var(--al-well);
  border: var(--al-border);
  color: var(--al-ink);
  border-radius: var(--al-radius-sm);
  padding: var(--al-space-3);
  font-size: var(--al-text-lg);
  min-height: var(--al-tap);
}

#export-readings {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-3);
  margin-bottom: var(--al-space-4);
}

.export-reading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--al-space-3);
  background: var(--al-surface-3);
  border: var(--al-border);
  border-radius: var(--al-radius-md);
  padding: var(--al-space-3) var(--al-space-4);
}

.export-reading-label {
  flex: 1 1 140px;
  font-size: var(--al-text-sm);
  font-variant-numeric: tabular-nums;
  font-family: var(--al-font-num);
  color: var(--al-ink);
}

.export-reading-row select {
  background: var(--al-well);
  border: var(--al-border);
  color: var(--al-ink);
  border-radius: var(--al-radius-sm);
  padding: var(--al-space-2) var(--al-space-3);
  font-size: var(--al-text-xs);
  min-height: var(--al-tap);
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--al-space-3);
  margin-top: var(--al-space-3);
}

/* FOCUS RING — global. */
:where(button,[role="button"],a,input,select,textarea,summary):focus-visible {
  outline: 2px solid var(--al-focus);
  outline-offset: 2px;
  border-radius: inherit;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* REDUCED MOTION — global. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* F6: calibration. The panel is anchored to the TOP of the canvas area on purpose — the iOS
   keyboard shrinks the visual viewport from the bottom, so a bottom-anchored or centred panel
   would end up behind it with no way to reach Confirm. */
#calibration-panel {
  position: absolute;
  top: var(--al-space-3);
  left: 50%;
  transform: translateX(-50%);
  width: min(94%, 460px);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--al-space-3);
  background: var(--al-surface-2);
  border: var(--al-border);
  border-radius: var(--al-radius-lg);
  padding: var(--al-space-4);
  box-shadow: var(--al-shadow-1);
  z-index: 20;
}

#calibration-panel[hidden] {
  display: none;
}

.calibration-field {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-1);
  flex: 1 1 140px;
  font-size: var(--al-text-xs);
  color: var(--al-ink-muted);
}

#calibration-panel input,
#calibration-panel select,
.bar-select {
  min-height: var(--al-tap);
  font-size: 16px; /* >=16px stops iOS Safari zooming the page on focus */
  color: var(--al-ink);
  background: var(--al-well);
  border: var(--al-border);
  border-radius: var(--al-radius-md);
  padding: 0 var(--al-space-3);
}

.bar-select:disabled,
.bar-button:disabled {
  opacity: 0.4;
}

#calibration-error {
  flex: 1 1 100%;
  margin: 0;
  font-size: var(--al-text-sm);
  color: var(--al-danger);
}

#calibration-error[hidden] {
  display: none;
}

/* ---- LOTE 4: status chips, selection bar, menu sheet ---- */

.status-chips {
  position: absolute;
  top: 10px;
  right: calc(10px + env(safe-area-inset-right));
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.chip {
  position: relative;
  height: 26px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--al-plaque);
  border: 1px solid var(--al-plaque-edge);
  border-radius: var(--al-radius-pill);
  color: #E9EDF3;
  font: var(--al-weight-medium) 12px/1 var(--al-font-num);
  white-space: nowrap;
}

.chip[hidden] {
  display: none;
}

button.chip {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* The zoom chip is a button: give it a 44px-high hit area. */
button.chip::after {
  content: "";
  position: absolute;
  inset: -9px -6px;
}

.chip-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7cff6b;
}

.chip.warn {
  color: #FFB020;
  border-color: rgba(255, 176, 32, .45);
}

.selection-bar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 16;
  display: flex;
  gap: 6px;
  padding: 5px;
  background: var(--al-surface-2);
  border: var(--al-border-strong);
  border-radius: var(--al-radius-pill);
  box-shadow: var(--al-shadow-2);
}

.selection-bar[hidden] {
  display: none;
}

.selection-bar button {
  white-space: nowrap;
  min-height: var(--al-tap);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: var(--al-radius-pill);
  background: transparent;
  color: var(--al-ink);
  font: var(--al-weight-semi) 13px var(--al-font-ui);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.selection-bar button.danger {
  color: var(--al-danger);
}

.selection-bar button[hidden] {
  display: none;
}

.selection-bar button:disabled {
  opacity: .4;
}

.selection-bar svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* With a selection the hint rides above the selection bar instead of under it. */
#canvas-area.has-selection #hint {
  bottom: 74px;
}

/* Menu sheet: anchored to the bottom, centred and capped on wide screens. */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  padding: 0;
  overflow: auto;
  border: 0;
  border-top: var(--al-border-strong);
  border-radius: var(--al-radius-xl) var(--al-radius-xl) 0 0;
  background: var(--al-surface-2);
  color: var(--al-ink);
  box-shadow: var(--al-shadow-3);
}

.sheet::backdrop {
  background: rgba(5, 7, 10, .6);
}

.sheet-body {
  padding: 8px calc(14px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

.sheet-head {
  position: relative;
  height: 44px;
}

.grabber {
  width: 38px;
  height: 4px;
  margin: 4px auto 0;
  border-radius: 2px;
  background: var(--al-line-strong);
}

.sheet-head .icon-button {
  position: absolute;
  top: -4px;
  right: -8px;
}

.sheet h2 {
  margin: 10px 2px 8px;
  font: var(--al-weight-semi) 11px/1.2 var(--al-font-ui);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--al-ink-faint);
}

.rows {
  overflow: hidden;
  background: var(--al-surface-1);
  border: var(--al-border);
  border-radius: var(--al-radius-lg);
}

.row {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-top: var(--al-border);
  background: transparent;
  color: var(--al-ink);
  font: 15px/1.2 var(--al-font-ui);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rows > :first-child {
  border-top: 0;
}

.row:disabled {
  opacity: .4;
  cursor: default;
}

.row:active:not(:disabled) {
  background: var(--al-surface-3);
}

.row svg {
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--al-ink-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.row .value {
  margin-left: auto;
  color: var(--al-ink-muted);
  font-size: 14px;
}

.seg {
  margin-left: auto;
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--al-well);
  border: var(--al-border);
  border-radius: var(--al-radius-md);
}

.seg button {
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--al-radius-sm);
  background: transparent;
  color: var(--al-ink-muted);
  font: var(--al-weight-medium) 13px var(--al-font-num);
  cursor: pointer;
}

.seg button[aria-checked="true"] {
  background: var(--al-ink);
  color: var(--al-ink-inverse);
}

.seg.is-disabled button {
  opacity: .4;
  cursor: default;
}

/* Short landscape phone: a slimmer top bar, tool cells side by side (icon + label), a smaller
   readout, so the chrome leaves most of the height to the photo. */
@media (max-height: 480px) {
  #top-bar {
    height: calc(48px + env(safe-area-inset-top));
  }

  #tool-bar {
    padding-top: 3px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }

  #tool-group {
    height: var(--al-tap);
  }

  .tool-button {
    flex-direction: row;
    gap: 6px;
    font-size: 12px;
  }

  .readout {
    padding: 6px 10px 7px;
  }

  .readout-value {
    font-size: 26px;
    line-height: 28px;
  }
}

/* Narrow phone (320 px): the project chip keeps the code and shows the photo position as n/m. */
@media (max-width: 360px) {
  .project-chip {
    gap: 6px;
    padding: 0 10px;
    font-size: 13px;
  }

  .project-chip small {
    font-size: 0;
  }

  .project-chip small::after {
    content: attr(data-short);
    font-size: 12px;
  }
}

/* LOTE 5 §6: pressed states for the new controls (focus is the global :focus-visible ring). */
.project-chip:active,
.seg button:active:not(:disabled),
.selection-bar button:active:not(:disabled),
#hint-cancel:active {
  background: var(--al-surface-3);
}

button.chip:active {
  background: var(--al-surface-3);
  color: var(--al-ink);
}

.link-button:active {
  opacity: .6;
}

.tool-button:focus-visible,
.icon-button:focus-visible,
.row:focus-visible {
  outline-offset: -2px;
}

/* LOTE 6: strip of this project's photos in the menu sheet. */
.thumbs {
  display: flex;
  gap: 8px;
  padding: 2px 2px 6px;
  overflow-x: auto;
}

.thumb-cell {
  position: relative;
  flex: none;
}

.thumb {
  position: relative;
  flex: none;
  width: 72px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  border: var(--al-border);
  border-radius: var(--al-radius-md);
  background: var(--al-well);
  color: #fff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

.thumb small {
  position: absolute;
  left: 5px;
  bottom: 4px;
  font: var(--al-weight-semi) 10px var(--al-font-num);
  text-shadow: 0 1px 2px #000;
}

.thumb.current {
  outline: 2px solid var(--al-mark-active);
  outline-offset: 1px;
}

.thumb:active {
  opacity: .8;
}

.thumb.add {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: var(--al-ink-muted);
  font-size: 26px;
}

/* Small ✕ in the corner of a photo; its hit area is the 44px around it. */
.thumb-delete {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(11, 14, 19, .72);
  color: #fff;
  font: 12px/1 var(--al-font-ui);
  cursor: pointer;
}

.thumb-delete::after {
  content: "";
  position: absolute;
  inset: -11px;
}

.thumb-delete:active {
  background: var(--al-danger);
}

/* LOTE 7: guide detail view, name field of the Label dialog, name field of an export row. */
.guide-detail-title {
  margin: 0 0 var(--al-space-3);
  font-size: var(--al-text-lg);
}

#guide-detail h4 {
  margin: var(--al-space-5) 0 var(--al-space-2);
  font: var(--al-weight-semi) 11px/1.2 var(--al-font-ui);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--al-ink-faint);
}

#guide-detail p,
.guide-points {
  margin: 0 0 var(--al-space-3);
  font-size: var(--al-text-sm);
  line-height: 1.5;
  color: var(--al-ink-muted);
}

.guide-points {
  padding-left: 20px;
}

.guide-points strong {
  color: var(--al-ink);
}

.label-field {
  display: flex;
  flex-direction: column;
  gap: var(--al-space-2);
  margin-bottom: var(--al-space-4);
  font-size: var(--al-text-xs);
  color: var(--al-ink-muted);
}

.label-field input,
.export-name-input {
  min-height: var(--al-tap);
  padding: 0 var(--al-space-3);
  background: var(--al-well);
  border: var(--al-border);
  border-radius: var(--al-radius-sm);
  color: var(--al-ink);
  font-size: 16px; /* >=16px stops iOS Safari zooming the page on focus */
}

.export-name-input {
  flex: 1 1 140px;
  min-width: 0;
}
