.gal-root {
  --tap: 44px;
  --bg: #14161a;
  --stage: #0b0c0e;
  --panel: #1e2126;
  --btn: #2a2e35;
  --line: #343941;
  --hover: #31353d;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --ink: #f2f3f5;
  --ink-text: #14161a;
  --warn: #f5b301;
  --danger: #ff6b6b;
  --ok: #5fcf8a;
  --r: 12px;
  --tile: 180px;
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.gal-root *,
.gal-root *::before,
.gal-root *::after {
  box-sizing: border-box;
}

.gal-root [hidden] {
  display: none !important;
}

.gal-root :where(button, input, select) {
  font: inherit;
  color: inherit;
}

.gal-root :focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.gal-root.gal-locked {
  overflow: hidden;
}

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

.gal-center {
  width: 100%;
  max-width: 392px;
  margin: 0 auto;
  padding: 64px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gal-center p {
  margin: 0;
}

.gal-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 600;
}

.gal-label {
  font-weight: 600;
}

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

.gal-small {
  font-size: 14px;
}

.gal-error {
  margin: 0;
  color: var(--danger);
}

.gal-error:empty {
  display: none;
}

.gal-pad {
  padding: 0 16px;
}

.gal-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.gal-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--stage);
  font-size: 16px;
}

.gal-select {
  min-width: 0;
  flex: 1 1 auto;
  padding-right: 8px;
  text-overflow: ellipsis;
}

.gal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: var(--r);
  background: var(--btn);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, transform 120ms ease;
}

.gal-btn:hover {
  background: var(--hover);
}

.gal-btn:active {
  transform: scale(0.97);
}

.gal-btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.gal-btn--primary {
  background: var(--ink);
  color: var(--ink-text);
}

.gal-btn--primary:hover {
  background: #fff;
}

.gal-btn--wide {
  width: 100%;
}

.gal-btn--small {
  min-height: var(--tap);
  padding: 0 12px;
  font-size: 15px;
}

.gal-btn--icon {
  padding: 0;
  width: 48px;
  flex: none;
}

.gal-toggle .gal-toggle-slash {
  display: none;
}

.gal-toggle[aria-pressed="false"] .gal-toggle-slash {
  display: inline;
}

.gal-toggle[aria-pressed="false"] {
  background: var(--ink);
  color: var(--ink-text);
}

.gal-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.gal-brand {
  font-weight: 700;
  white-space: nowrap;
}

.gal-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 720px;
}

.gal-top-end {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.gal-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.gal-seg {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--r);
  background: var(--stage);
  border: 1px solid var(--line);
  max-width: 100%;
}

.gal-seg button {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: none;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  color: var(--muted);
}

.gal-seg button[aria-pressed="true"] {
  background: var(--btn);
  color: var(--text);
}

.gal-seg--small button {
  min-width: 42px;
  padding: 0 10px;
}

.gal-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  opacity: 0.75;
}

.gal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 8px;
  padding: 0 16px 16px;
}

.gal-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.gal-pic {
  position: relative;
  display: block;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: var(--stage);
  outline: 1px solid rgba(255, 255, 255, 0.08);
  outline-offset: -1px;
}

.gal-tile:hover .gal-pic {
  outline-color: rgba(255, 255, 255, 0.45);
}

.gal-tile--labelled .gal-pic {
  outline-color: rgba(95, 207, 138, 0.7);
}

.gal-pic img:not([src]) {
  visibility: hidden;
}

.gal-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gal-over {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.gal-nolabels .gal-over {
  display: none;
}

.gal-over polygon {
  vector-effect: non-scaling-stroke;
  stroke-width: 1.5px;
  stroke-linejoin: round;
}

.gal-view .gal-over polygon {
  stroke-width: 2.5px;
}

.gal-over text {
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.85);
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: central;
}

.gal-cap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px 4px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 0;
}

.gal-cap-no {
  color: var(--text);
  font-weight: 600;
}

.gal-badge {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--btn);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.gal-badge--approved,
.gal-badge--corrected {
  background: rgba(95, 207, 138, 0.2);
  color: var(--ok);
}

.gal-badge--sent_back {
  background: rgba(245, 179, 1, 0.2);
  color: var(--warn);
}

.gal-badge--excluded {
  background: rgba(255, 107, 107, 0.2);
  color: var(--danger);
}

.gal-foot {
  display: flex;
  justify-content: center;
  padding: 8px 16px 40px;
}

.gal-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--stage);
}

.gal-view-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.gal-view-title {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.gal-view-tools {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex: none;
}

.gal-view-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.gal-view-stage {
  --room: calc(100dvh - 90px);
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
}

.gal-view-pic {
  --ar: 1.4;
  position: relative;
  flex: 0 1 auto;
  width: min(100%, calc(var(--room) * var(--ar)));
  aspect-ratio: var(--ar);
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.gal-view-pic img {
  display: block;
  width: 100%;
  height: 100%;
}

.gal-view-nav {
  align-self: center;
}

.gal-view-info {
  overflow-y: auto;
  padding: 16px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  font-size: 15px;
}

.gal-info-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

.gal-info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.gal-info-row > :first-child {
  color: var(--muted);
  flex: none;
}

.gal-info-row > :last-child {
  text-align: right;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.gal-info-h {
  margin: 20px 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.gal-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: baseline;
}

.gal-note {
  margin: 4px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 899px), (orientation: portrait) {
  .gal-view-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .gal-view-stage {
    --room: 52dvh;
    padding: 8px;
  }

  .gal-view-info {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 599px) {
  .gal-top {
    flex-wrap: wrap;
  }

  .gal-pick {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .gal-view-nav {
    width: 40px;
  }

  .gal-seg button {
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gal-btn {
    transition: none;
  }
}
