:root {
  color-scheme: light;
  --bg: #edf1ee;
  --ink: #18212b;
  --muted: #62707b;
  --line: #d7ddd3;
  --surface: #ffffff;
  --teal: #007a7a;
  --teal-dark: #005f61;
  --amber: #f2b705;
  --red: #d9483b;
  --blue: #2454a6;
  --shadow: 0 16px 42px rgba(31, 42, 51, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(0, 122, 122, 0.1) 0, transparent 36%),
    linear-gradient(225deg, rgba(242, 183, 5, 0.11) 0, transparent 32%),
    linear-gradient(180deg, #fafbf8 0, var(--bg) 52%, #e7ecee 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow,
.step {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  white-space: nowrap;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.status-pill {
  min-width: 108px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill[data-mode="success"] {
  border-color: rgba(0, 122, 122, 0.45);
  background: rgba(0, 122, 122, 0.1);
  color: var(--teal-dark);
}

.status-pill[data-mode="error"] {
  border-color: rgba(217, 72, 59, 0.45);
  background: rgba(217, 72, 59, 0.09);
  color: #a32f25;
}

.price-button {
  min-height: 40px;
  border: 1px solid rgba(242, 183, 5, 0.65);
  background: var(--amber);
  color: #1d1a0b;
}

.price-button:hover {
  background: #d99e04;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel,
.results,
.pricing-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.panel {
  display: flex;
  min-height: clamp(420px, 54vh, 620px);
  flex-direction: column;
  overflow: hidden;
}

.panel-head,
.panel-foot,
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
}

.panel-foot {
  display: grid;
  align-items: stretch;
}

.foot-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.foot-line p {
  color: var(--muted);
  text-align: right;
}

.selection-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding-top: 12px;
}

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

.selection-tools label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.nudge-pad {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(2, 38px);
  gap: 6px;
}

.nudge-button {
  min-height: 38px;
  width: 38px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.nudge-button:hover {
  background: #f6f7f4;
}

.nudge-button[data-nudge="up"] {
  grid-column: 2;
}

.nudge-button[data-nudge="left"] {
  grid-column: 1;
  grid-row: 2;
}

.nudge-button[data-nudge="right"] {
  grid-column: 3;
  grid-row: 2;
}

.nudge-button[data-nudge="down"] {
  grid-column: 2;
  grid-row: 2;
}

.panel-foot {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.file-button,
button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  white-space: nowrap;
}

.file-button:hover,
button:hover {
  background: var(--teal-dark);
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover {
  background: #f6f7f4;
}

.canvas-wrap {
  position: relative;
  min-height: clamp(250px, 35vh, 420px);
  flex: 1;
  background:
    linear-gradient(45deg, rgba(24, 33, 43, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(24, 33, 43, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(24, 33, 43, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(24, 33, 43, 0.04) 75%);
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-size: 24px 24px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: clamp(250px, 35vh, 420px);
  touch-action: pan-y;
}

#manualCanvas {
  cursor: crosshair;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding: 16px;
}

.photo-tray {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  background: #f8faf7;
}

.photo-tray[hidden] {
  display: none;
}

.photo-strip {
  display: flex;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
}

.photo-thumb {
  position: relative;
  flex: 0 0 82px;
  width: 82px;
  min-height: 62px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 0;
  background: #e9eeea;
}

.photo-thumb:hover {
  background: #e9eeea;
}

.photo-thumb[aria-pressed="true"] {
  border-color: var(--teal);
  box-shadow: 0 0 0 1px var(--teal);
}

.photo-thumb canvas {
  width: 78px;
  height: 58px;
  min-height: 0;
  pointer-events: none;
  touch-action: auto;
}

.photo-quality {
  position: absolute;
  right: 3px;
  bottom: 3px;
  border-radius: 999px;
  padding: 2px 5px;
  background: rgba(24, 33, 43, 0.82);
  color: #fff;
  font-size: 10px;
  line-height: 1.35;
}

.photo-quality[data-level="good"] {
  background: rgba(0, 95, 97, 0.92);
}

.photo-quality[data-level="poor"] {
  background: rgba(163, 47, 37, 0.92);
}

#photoCount {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.controls label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input[type="range"] {
  accent-color: var(--teal);
}

.results {
  margin-top: 18px;
  padding-bottom: 16px;
}

.pricing-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(0, 1.25fr);
  gap: 16px;
  align-items: center;
  margin-top: 18px;
  padding: 16px;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.plan {
  display: grid;
  gap: 10px;
  min-height: 130px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.featured-plan {
  border-color: rgba(0, 122, 122, 0.55);
  box-shadow: inset 0 0 0 2px rgba(0, 122, 122, 0.08);
}

.plan-name {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.plan-price {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 900;
}

.plan p:last-child {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.pricing-dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(24, 33, 43, 0.26);
}

.pricing-dialog::backdrop {
  background: rgba(24, 33, 43, 0.42);
}

.pricing-dialog form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.icon-close {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

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

.paywall article {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.paywall span {
  font-size: 28px;
  font-weight: 900;
}

.best-value {
  border-color: rgba(242, 183, 5, 0.85);
  background: rgba(242, 183, 5, 0.12) !important;
}

.paywall-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.results-head {
  align-items: baseline;
  border-bottom: 1px solid var(--line);
}

.results-head p {
  color: var(--muted);
  font-size: 14px;
}

.candidate-grid {
  display: grid;
  grid-template-columns: minmax(0, 360px);
  gap: 12px;
  padding: 16px;
}

.candidate-grid:empty {
  display: none;
}

.candidate {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.candidate canvas {
  width: 100%;
  height: 112px;
  min-height: 112px;
  background: #eef1ec;
}

.candidate-info {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px 10px;
  font-size: 13px;
  font-weight: 800;
}

.rank {
  color: var(--blue);
}

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

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(242, 183, 5, 0.24);
  color: #715100;
}

.match-metrics {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.match-metrics span {
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(0, 122, 122, 0.1);
  color: #0a5f5f;
}

@media (max-width: 1100px) {
  .app-shell {
    padding: 18px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    align-items: flex-start;
    gap: 10px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .topbar > div:first-child {
    min-width: 0;
    flex: 1;
  }

  .eyebrow {
    white-space: nowrap;
  }

  .panel {
    min-height: 430px;
  }

  .canvas-wrap,
  canvas {
    min-height: 270px;
  }

  .controls button {
    width: 100%;
  }

  .pricing-panel,
  .paywall {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .workspace,
  .pricing-panel,
  .plan-grid,
  .paywall {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: 380px;
  }

  .canvas-wrap,
  canvas {
    min-height: 240px;
  }

  .foot-line,
  .selection-tools,
  .results-head {
    grid-template-columns: 1fr;
  }

  .foot-line {
    display: grid;
  }

  .foot-line p {
    text-align: left;
  }

  .selection-tools {
    grid-template-columns: 1fr;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .nudge-pad {
    grid-template-columns: repeat(4, minmax(48px, 1fr));
    grid-template-rows: 48px;
  }

  .nudge-button {
    width: 100%;
    min-height: 54px;
  }

  .nudge-button[data-nudge] {
    grid-row: 1;
  }

  .nudge-button[data-nudge="up"] {
    grid-column: 1;
  }

  .nudge-button[data-nudge="left"] {
    grid-column: 2;
  }

  .nudge-button[data-nudge="right"] {
    grid-column: 3;
  }

  .nudge-button[data-nudge="down"] {
    grid-column: 4;
  }
}

@media (pointer: coarse) {
  .file-button,
  button {
    min-height: 50px;
    touch-action: manipulation;
  }

  .selection-tools label {
    gap: 10px;
  }

  input[type="range"] {
    min-height: 38px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }

  .nudge-button {
    min-height: 56px;
  }
}

@media (max-width: 430px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .status-pill {
    justify-self: start;
  }

  .top-actions {
    justify-content: flex-start;
  }

  h1 {
    font-size: 26px;
  }

  .status-pill {
    min-width: 96px;
    padding-inline: 12px;
  }

  .panel-head,
  .panel-foot,
  .results-head {
    padding: 12px;
  }

  .empty-state strong {
    font-size: 16px;
  }
}
