@import url("./fonts/fonts.css");

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0c1222;
  --bg-surface: #131c2e;
  --bg-card: #1e2a48;
  --bg-elevated: #2a3858;
  --text: #eef2f7;
  --text-muted: #c3cddc;
  --text-dim: #a6b3c8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --red: #ef4444;
  --border: rgba(148, 163, 184, 0.18);
  --border-hover: rgba(148, 163, 184, 0.32);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
  --toggle-bg: var(--bg-card);
  --pad: 16px;
  --pad-lg: 24px;
  --max-w: 820px;
  /* type scale — use these, never raw px */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-base: 16px;
  --fs-lg: 18px;
  --fs-xl: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 100px;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-surface: #fff;
  --bg-card: #f8fafc;
  --bg-elevated: #e2e8f0;
  --text: #0f172a;
  --text-muted: #334155;
  --text-dim: #4b5a6e;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.10);
  --border: rgba(15, 23, 42, 0.11);
  --border-hover: rgba(15, 23, 42, 0.22);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --toggle-bg: var(--bg-elevated);
}

html,
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  font-size: var(--fs-base);
  line-height: 1.5;
  transition: background .3s, color .3s
}

body {
  display: flex;
  flex-direction: column;
  align-items: center
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring)
}

@media(prefers-reduced-motion:reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important
  }
}

.app {
  width: 100%;
  max-width: var(--max-w);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 var(--pad)
}

@media(min-width:640px) {
  .app {
    padding: 0 var(--pad-lg)
  }
}

/* Header */
header {
  padding: 16px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0
}

.logo {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--text)
}

.logo sup {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-muted);
  vertical-align: top;
  margin-left: 1px
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px
}

.header-link {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all .2s var(--ease)
}

.header-link:hover {
  color: var(--text-muted);
  border-color: var(--border-hover);
  background: var(--bg-card)
}

.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, border-color .2s;
  color: var(--text-muted);
  flex-shrink: 0
}

.theme-toggle:hover {
  background: var(--bg-elevated);
  border-color: var(--border-hover);
  color: var(--text)
}

.theme-toggle svg {
  transition: transform .3s var(--ease)
}

.theme-toggle:hover svg {
  transform: rotate(15deg)
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: block
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeUp .35s var(--ease) both
}

.screen.active {
  display: flex
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

/* Preview */
.preview-section {
  margin-bottom: 20px
}

.preview-card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative
}

.preview-dismiss {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #fff;
  font-size: var(--fs-lg);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .2s var(--ease);
}

.preview-dismiss:hover {
  background: rgba(0, 0, 0, .8);
}

.preview-card img {
  width: 100%;
  display: block
}

[data-theme="dark"] .preview-img-light,
[data-theme="light"] .preview-img-dark {
  display: none;
}

.preview-overlay {
  position: absolute;
  top: 12px;
  left: 12px
}

.preview-badge {
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  letter-spacing: .5px;
  text-transform: uppercase
}

.preview-caption {
  padding: 12px 16px;
  font-size: var(--fs-md);
  color: var(--text-muted);
  text-align: center
}

.preview-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%,
      rgba(0, 0, 0, .65) 0%,
      rgba(0, 0, 0, .45) 25%,
      rgba(0, 0, 0, .15) 55%,
      rgba(0, 0, 0, 0) 80%);
  z-index: 1;
}

.preview-cta {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 18px 34px;
  font-family: inherit;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent, #4f8cff) 0%, #7a3dff 100%);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius-pill, 999px);
  cursor: pointer;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, .5),
    0 0 0 8px rgba(255, 255, 255, .05),
    0 0 60px rgba(122, 61, 255, .45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform .2s var(--ease, ease), box-shadow .2s var(--ease, ease), filter .2s var(--ease, ease);
  white-space: nowrap;
  z-index: 2;
}

.preview-cta:hover {
  transform: translate(-50%, -50%) scale(1.05);
  filter: brightness(1.1);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, .6),
    0 0 0 10px rgba(255, 255, 255, .07),
    0 0 80px rgba(122, 61, 255, .65);
}

.preview-cta:active {
  transform: translate(-50%, -50%) scale(0.98);
}

.preview-cta svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

@media (max-width: 480px) {
  .preview-cta {
    font-size: var(--fs-md);
    padding: 15px 24px;
    gap: 10px;
  }

  .preview-cta svg {
    width: 18px;
    height: 18px;
  }
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: all .25s var(--ease);
  background: var(--bg-surface)
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow)
}

.upload-zone.dragover {
  transform: scale(1.005)
}

.upload-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--accent)
}

.upload-zone h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: 6px
}

.upload-zone p {
  font-size: var(--fs-md);
  color: var(--text-dim)
}

.upload-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap
}

.upload-btn {
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: all .2s var(--ease);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px
}

.upload-btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, .3)
}

.upload-btn.primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(59, 130, 246, .4);
  transform: translateY(-1px)
}

.upload-btn.secondary {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border)
}

.sticker-size-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 18px;
}

.sticker-size-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.sticker-size-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-muted);
}

.sticker-size-field>span:first-child {
  min-width: 12px;
}

.sticker-size-field input[type="number"] {
  width: 86px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hover);
  background: var(--bg-surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--fs-md);
  text-align: center;
}

.sticker-size-field input[type="number"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.sticker-size-unit {
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

/* Detected color + calibration card (result & history detail) */
.calib-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 18px 0 14px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.calib-card:empty {
  display: none;
}

.detected-color-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.detected-color-text {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.detected-color-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.color-swatch {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border-hover);
  box-shadow: inset 0 0 0 2px var(--bg-card);
}

.detected-color-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-chip {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  background: var(--bg-elevated);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  white-space: nowrap;
}

.recalculate-row {
  justify-content: flex-start;
  margin-top: 0;
}

.detected-color-block+.recalculate-row {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.recalculate-btn {
  font-size: var(--fs-md);
  font-weight: 600;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  cursor: pointer;
  transition: background .2s var(--ease);
}

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

/* Narrow screens: label on its own line, the two fields side by side,
   the Recalculate button full width — otherwise W and H wrap apart. */
@media (max-width: 560px) {
  .sticker-size-row {
    gap: 10px;
  }

  .sticker-size-row .sticker-size-label {
    flex: 1 0 100%;
    text-align: center;
  }

  .recalculate-row .sticker-size-label {
    text-align: left;
  }

  .sticker-size-row .sticker-size-field {
    flex: 1 1 0;
    min-width: 0;
  }

  .sticker-size-row .sticker-size-field input[type="number"] {
    width: 100%;
    min-width: 0;
  }

  .recalculate-btn {
    flex: 1 0 100%;
  }
}

.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--red);
  background: rgba(239, 68, 68, .10);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
}

.upload-btn.secondary:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--bg-elevated)
}

/* Crop Overlay */
.crop-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1100;
  display: none;
  flex-direction: column;
}

.crop-overlay.active {
  display: flex;
}

.crop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.crop-header h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
}

.crop-header p {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

.crop-stage {
  flex: 1;
  min-height: 0;
  background: #000;
  display: flex;
  padding: 28px 20px;
}

.crop-stage-inner {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crop-stage-inner img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Cropper.js clips handles at .cropper-container edges by default; let them
   render into the surrounding padding instead. */
.crop-stage .cropper-container {
  overflow: visible !important;
}

.crop-actions {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.crop-actions button {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .2s var(--ease);
  min-height: 44px;
}

.crop-actions .crop-skip {
  background: var(--bg-card);
  color: var(--text-muted);
}

.crop-actions .crop-skip:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.crop-actions .crop-apply {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(59, 130, 246, .3);
}

.crop-actions .crop-apply:hover {
  background: var(--accent-hover);
}

.crop-sticker-row {
  margin-top: 0;
  padding: 12px 16px 2px;
  flex-shrink: 0;
}

.crop-tools {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  justify-content: center;
  flex-shrink: 0;
}

.crop-tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.crop-tool-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Processing Overlay */
.processing-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s
}

.processing-overlay.active {
  opacity: 1;
  pointer-events: auto
}

.spinner-wrap {
  position: relative;
  width: 56px;
  height: 56px
}

.spinner {
  width: 56px;
  height: 56px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite
}

.spinner-pulse {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .08;
  animation: pulse 2s ease-in-out infinite
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(.8);
    opacity: .05
  }

  50% {
    transform: scale(1.2);
    opacity: .12
  }
}

.processing-overlay p {
  font-size: var(--fs-base);
  color: var(--text-muted);
  font-weight: 500
}

/* Result */
.result-header {
  display: flex;
  align-items: center;
  padding: 8px 0 14px;
  gap: 12px;
  flex-shrink: 0
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
  color: var(--text-muted);
  text-decoration: none
}

.icon-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-hover);
  color: var(--text)
}

.result-header-text {
  flex: 1
}

.result-header-text h2 {
  font-size: var(--fs-lg);
  font-weight: 600
}

.result-header-text p {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-top: 2px
}

.result-actions {
  display: flex;
  gap: 8px
}

.result-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding-bottom: 32px
}

@media(min-width:768px) {
  .result-layout {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: stretch;
  }

  .result-data-panel {
    grid-column: 1 / -1;
  }
}

.result-image-panel,
.result-scene-panel,
.result-data-panel {
  min-width: 0;
}

.result-data-panel {
  overflow: hidden
}

.result-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-image-wrap img {
  width: 100%;
  display: block
}

.scene-card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 8px;
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.scene-card .plotly-graph-div {
  width: 100% !important;
}

.result-scene-panel {
  display: flex;
  flex-direction: column;
}

.scene-caption {
  padding: 10px 6px 2px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: center;
}

/* View tabs — mobile only, switch between 2D image and 3D scene */
.view-tabs {
  display: none;
  gap: 6px;
  margin-bottom: 12px;
}

.view-tab {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all .2s var(--ease);
}

.view-tab.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

@media(max-width:767px) {
  .view-tabs.has-scene {
    display: flex;
  }

  .result-layout.view-image .result-scene-panel {
    display: none;
  }

  .result-layout.view-scene .result-image-panel {
    display: none;
  }
}

/* Shape Tabs */
.shape-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 4px 0 0;
}

.shape-row .shape-tabs {
  padding: 0;
  flex: 1 1 auto;
}

.shape-tabs {
  display: flex;
  gap: 6px;
  padding: 4px 0 0;
  flex-wrap: wrap
}

.shape-tab {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all .2s var(--ease);
  min-height: 38px;
  display: inline-flex;
  align-items: center
}

.shape-tab:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--bg-card)
}

.shape-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(59, 130, 246, .25)
}

/* Metrics */
.metrics {
  padding: 8px 0 0
}

.unit-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.unit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.unit-toggle input {
  accent-color: var(--accent);
}

.unit-toggle.disabled {
  opacity: .55;
  cursor: not-allowed;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px
}

.metric-grid.cols-1 {
  grid-template-columns: 1fr
}

.metric-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid var(--border);
  transition: background .15s
}

.metric-card:hover {
  background: var(--bg-elevated)
}

.metric-label {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600
}

.metric-value {
  font-family: var(--mono);
  font-size: var(--fs-xl);
  font-weight: 500;
  margin-top: 4px;
  color: var(--text);
  word-break: break-all
}

.empty-metric {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: var(--fs-md)
}

/* Notes */
.notes-section {
  margin-top: 16px
}

.notes-label {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 600;
  margin-bottom: 8px
}

.notes-input {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-sm);
  resize: vertical;
  transition: border-color .2s;
  line-height: 1.5
}

.notes-input:focus {
  border-color: var(--accent);
  outline: none
}

.notes-input::placeholder {
  color: var(--text-dim)
}

/* Buttons */
.download-full {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: all .2s var(--ease);
  min-height: 44px;
  box-shadow: 0 2px 10px rgba(59, 130, 246, .3);
  margin-top: 16px;
  text-decoration: none
}

.download-full:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 18px rgba(59, 130, 246, .4);
  transform: translateY(-1px)
}

.download-full:active {
  transform: translateY(0)
}

.save-next-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 20px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .2s var(--ease);
  min-height: 40px;
  margin-top: 8px
}

.save-next-btn:hover {
  background: var(--bg-card);
  border-color: var(--border-hover);
  color: var(--text)
}

.delete-result-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 24px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--red);
  font-size: var(--fs-md);
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid rgba(239, 68, 68, .2);
  cursor: pointer;
  transition: all .2s;
  min-height: 44px;
  margin-top: 8px
}

.delete-result-btn:hover {
  background: rgba(239, 68, 68, .08);
  border-color: rgba(239, 68, 68, .4)
}

/* History */
.history-section {
  margin: 24px 0;
  padding: 20px 20px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex: 1
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px
}

.history-header h3 {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .8px
}

.history-clear {
  font-size: var(--fs-sm);
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: all .15s;
  min-height: 44px;
  display: inline-flex;
  align-items: center
}

.history-clear:hover {
  color: var(--red);
  background: rgba(239, 68, 68, .08)
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px
}

@media(min-width:640px) {
  .history-grid {
    grid-template-columns: repeat(4, 1fr)
  }
}

.history-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--bg-card);
  transition: transform .2s var(--ease), box-shadow .2s;
  border: 1px solid var(--border)
}

.history-item:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow)
}

.history-item:active {
  transform: scale(.97)
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover
}

.history-item .meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 8px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, .85);
  font-weight: 500
}

.history-item .del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: var(--fs-base);
  line-height: 1;
  transition: background .15s
}

.history-item .del-btn:hover {
  background: rgba(239, 68, 68, .8)
}

.history-item:hover .del-btn {
  display: flex
}

@media(hover:none) {
  .history-item .del-btn {
    display: flex
  }
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
  font-size: var(--fs-md)
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  opacity: .5
}

.history-hint {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-align: center;
  padding: 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px
}

.history-hint svg {
  opacity: .5;
  flex-shrink: 0
}

/* Instance content sections (1.6.0) — only rendered when instance.json provides data */
.intro-text {
  font-size: var(--fs-base);
  color: var(--text);
  line-height: 1.55;
  margin: 2px 0 20px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  max-width: 600px;
  text-align: left
}

.link-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0
}

@media(max-width:520px) {
  .link-row {
    grid-template-columns: 1fr
  }
}

/* an odd last button (e.g. the calibration download) takes the full row */
.link-row .link-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1
}

.link-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 40px 16px 18px;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-weight: 700;
  font-size: var(--fs-md);
  text-decoration: none;
  text-align: left;
  transition: border-color .15s, transform .15s
}

.link-btn:hover {
  background: var(--bg-card);
  transform: translateY(-1px)
}

/* small direction hint top right: ↗ for external links, ↓ for downloads */
.link-btn::after {
  content: "\2197";
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--accent)
}

.link-btn[download]::after {
  content: "\2193"
}

.link-btn-text {
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.45
}

/* The theme background stays; the instance image is only a faint texture on top.
   Dark mode inverts it so a light photo reads as dark with light highlights. */
body.has-bg {
  position: relative;
  z-index: 0   /* own stacking context, so the ::before paints above body's background */
}

body.has-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--instance-bg) center/cover no-repeat;
  filter: blur(6px);
  transform: scale(1.04);   /* hides the blurred edge */
  opacity: .55;
  pointer-events: none
}

[data-theme="dark"] body.has-bg::before {
  mix-blend-mode: overlay;   /* texture only, no grey wash over the dark theme */
  opacity: .35
}

/* Footer */
.app-footer {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 24px 0;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  margin-top: auto
}

.footer-link {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: .5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s
}

.footer-link:hover {
  color: var(--text-muted);
  background: var(--bg-card)
}

.footer-counter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: .5px;
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.footer-counter svg {
  opacity: .7;
}

#upload-form,
#camera-input {
  position: fixed;
  top: -9999px;
  left: -9999px
}

::-webkit-scrollbar {
  width: 6px
}

::-webkit-scrollbar-track {
  background: transparent
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 3px
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim)
}