/* Segment Anything demo. */
.segment-page { position: relative; }
.seg-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.seg-file { display: none; }

/* toolbar */
.seg-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg-toolbar__right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.seg-mode { display: inline-flex; align-items: center; gap: 6px; }
.seg-minus { width: 10px; height: 2px; border-radius: 2px; background: currentColor; }
.seg-notice:empty { display: none; }

/* stage */
.seg-stage-wrap { display: flex; justify-content: center; min-width: 0; }
.seg-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #101014;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.2s ease;
}
.seg-stage:not(.has-image) {
  background:
    radial-gradient(120% 90% at 50% 0%, var(--accent-soft), transparent 60%),
    var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  box-shadow: none;
  touch-action: auto;
}
.seg-stage.is-dropping { box-shadow: 0 0 0 3px var(--accent), var(--shadow-md); }
.seg-stage.is-dropping:not(.has-image) { background: var(--accent-soft); border-color: var(--accent); }
.seg-canvas, .seg-overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.seg-canvas { transition: filter 0.35s ease, transform 0.35s ease; }
.seg-overlay { cursor: crosshair; z-index: 1; }
.seg-stage.is-covered .seg-canvas { filter: blur(8px) brightness(0.62) saturate(1.1); transform: scale(1.04); }
.seg-stage.is-covered .seg-overlay { cursor: default; }
.seg-stage.is-encoding .seg-canvas { filter: saturate(0.55) brightness(0.86); }

.seg-sweep { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; display: none; }
.seg-stage.is-encoding .seg-sweep { display: block; animation: seg-fade-in 0.3s ease; }
@keyframes seg-fade-in { from { opacity: 0; } }
.seg-sweep::before {
  content: "";
  position: absolute;
  inset: -50% -100%;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, 0.05) 44%, rgba(255, 166, 120, 0.28) 50%, rgba(255, 255, 255, 0.05) 56%, transparent 62%);
}
.seg-sweep::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.22) 1px, transparent 1.4px);
  background-size: 18px 18px;
  mask-image: radial-gradient(60% 60% at 50% 50%, #000, transparent);
  -webkit-mask-image: radial-gradient(60% 60% at 50% 50%, #000, transparent);
}
.seg-stage.is-encoding .seg-sweep::before { animation: seg-sweep 1.6s cubic-bezier(0.45, 0, 0.35, 1) infinite; }
.seg-stage.is-encoding .seg-sweep::after { animation: blink 1.6s ease-in-out infinite; }
@keyframes seg-sweep { from { transform: translateX(-30%); } to { transform: translateX(30%); } }

/* chips over the image */
.seg-chip {
  position: absolute;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  color: #fff;
  background: rgba(14, 14, 18, 0.62);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg-chip[hidden], .seg-panel[hidden], .seg-tray[hidden], .seg-toolbar[hidden] { display: none; }
.seg-chip--hint { top: 12px; left: 12px; }
.seg-chip--status { top: 12px; left: 50%; transform: translateX(-50%); font-variant-numeric: tabular-nums; }
.seg-chip--stat { bottom: 12px; right: 12px; font-size: 11.5px; font-weight: 500; color: rgba(255, 255, 255, 0.82); padding: 4px 9px; }
.seg-kbd {
  font: 600 11px/1 var(--font);
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.12);
}
.seg-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  animation: seg-spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes seg-spin { to { transform: rotate(360deg); } }

/* panels that cover the stage */
.seg-panel { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 20px; overflow: auto; }
.seg-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  max-width: 440px;
  width: 100%;
  padding: 28px 26px;
}
.seg-card--glass {
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  color: var(--text);
}
.seg-card .btn--xl { margin-top: 6px; }
.seg-card .inline-error { align-self: stretch; }
.seg-card--loader { gap: 8px; align-items: stretch; text-align: left; }
.seg-card--loader .loader__title { text-align: center; }
.seg-card--loader .btn { align-self: center; margin-top: 4px; }
.seg-stage:not(.has-image) .seg-card { color: var(--text); }
.seg-reasons { margin: 4px 0 0; padding-left: 18px; text-align: left; font-size: 13px; color: var(--text-3); display: flex; flex-direction: column; gap: 4px; }

.seg-drop { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 12px; }
.seg-drop__icon { width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border); margin-bottom: 4px; }
.seg-drop__title { font-size: 20px; font-weight: 700; letter-spacing: -0.015em; }
.seg-drop__actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }

/* camera */
.seg-camera { position: absolute; inset: 0; background: #000; display: flex; flex-direction: column; }
.seg-video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.seg-camera__bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 12px 16px; background: rgba(0, 0, 0, 0.6); }
.seg-camera__bar .btn { justify-self: start; }
.seg-camera__spacer { display: block; }
.seg-shutter {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease, background 0.12s ease;
}
.seg-shutter:hover { background: rgba(255, 255, 255, 0.5); }
.seg-shutter:active { transform: scale(0.92); }

/* image tray */
.seg-tray { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 2px; }
.seg-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 84px;
  height: 60px;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 0;
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--border);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.seg-thumb:hover { transform: translateY(-2px); }
.seg-thumb.is-active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.seg-thumb__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.seg-thumb__label {
  position: absolute;
  inset: auto 0 0;
  padding: 10px 6px 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
}
.seg-tray__actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.seg-action {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 66px;
  height: 60px;
  padding: 0;
  border-radius: 12px;
  border: 1.5px dashed var(--border-strong);
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.seg-action:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }

/* side panel */
.seg-side { gap: 10px; }
.seg-objects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.seg-object {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px transparent;
  transition: box-shadow 0.15s ease, background 0.15s ease;
}
.seg-object.is-active { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--border-strong), var(--shadow-sm); }
.seg-object__main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 6px; border: 0; background: transparent; text-align: left; border-radius: 9px; }
.seg-swatch { width: 14px; height: 14px; border-radius: 5px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.seg-object.is-active .seg-swatch { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--border-strong); }
.seg-object__text { display: flex; flex-direction: column; min-width: 0; }
.seg-object__name { font-size: 14px; font-weight: 600; }
.seg-object__meta { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.seg-object__act { width: 32px; height: 32px; flex-shrink: 0; }
.seg-export { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-btn-label, .seg-tool-label { display: inline; }

@media (max-width: 900px) {
  .seg-toolbar { gap: 8px; }
  .seg-toolbar__right { margin-left: auto; gap: 6px; }
  .seg-tool-label { display: none; }
  .seg-toolbar > .segmented--sm { order: 2; }
  .seg-toolbar__right .btn--sm { padding: 7px 10px; }
  .seg-toolbar .segmented--sm .segmented__label { display: none; }
  .seg-chip--hint { font-size: 11.5px; }
  .seg-tray { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .seg-card--glass { padding: 22px 18px; }
  .seg-card .preload__title { font-size: 20px; }
}
