:root {
  --brand: #d4145a;
  --brand-dark: #a80e45;
  --brand-soft: #fff0f6;
  --ink: #1d1d24;
  --muted: #6f6f7b;
  --line: #e4e4eb;
  --surface: #ffffff;
  --bg: #f5f5f8;
  --success: #14784a;
  --success-bg: #e9f8f0;
  --warning: #965800;
  --warning-bg: #fff5dc;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  --yellow: #ffdc4d;
  --shadow: 0 15px 42px rgba(28, 28, 38, .12);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at top right, rgba(212,20,90,.09), transparent 34%), var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

#appShell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(22px + env(safe-area-inset-bottom));
}
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 2px 14px; }
.eyebrow { margin-bottom: 4px; color: var(--brand); font-size: .7rem; font-weight: 900; letter-spacing: .14em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 6vw, 2rem); letter-spacing: -.035em; }
h2 { margin-bottom: 8px; font-size: 1.35rem; }
.muted { color: var(--muted); line-height: 1.5; }

.panel, .camera-card {
  border: 1px solid rgba(0,0,0,.05);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.center-panel { margin-top: min(12vh, 90px); padding: 34px 22px; text-align: center; }
.setup-panel { margin-top: min(7vh, 54px); padding: 28px 22px; }
.hero-mark { display: grid; width: 58px; height: 58px; margin-bottom: 18px; place-items: center; border-radius: 18px; color: #fff; background: linear-gradient(135deg, var(--brand), #f34f89); font-size: 1.8rem; box-shadow: 0 12px 28px rgba(212,20,90,.26); }

label { display: block; margin: 18px 0 7px; font-size: .86rem; font-weight: 800; }
input {
  width: 100%; min-height: 51px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 13px; outline: none;
  color: var(--ink); background: #fff;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(212,20,90,.12); }

.combobox { position: relative; }
.combobox input[type="search"] { padding-right: 46px; }
.clear-button { position: absolute; top: 7px; right: 7px; width: 37px; height: 37px; border: 0; border-radius: 10px; color: var(--muted); background: #f0f0f4; cursor: pointer; font-size: 1.25rem; }
.result-list {
  position: absolute; z-index: 15; top: calc(100% + 7px); right: 0; left: 0;
  max-height: min(42vh, 330px); overflow-y: auto; padding: 6px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff;
  box-shadow: 0 18px 40px rgba(26,26,35,.17);
}
.result-option { width: 100%; border: 0; border-radius: 10px; padding: 12px 11px; color: var(--ink); background: transparent; cursor: pointer; text-align: left; line-height: 1.3; }
.result-option:hover, .result-option.active { color: var(--brand-dark); background: var(--brand-soft); }
.no-results { padding: 15px 11px; color: var(--muted); text-align: center; }
.selected-card { margin-top: 12px; padding: 11px 13px; border-radius: 13px; color: var(--brand-dark); background: var(--brand-soft); }
.selected-card span { display: block; margin-bottom: 2px; font-size: .67rem; font-weight: 900; letter-spacing: .09em; }
.selected-card strong { display: block; line-height: 1.35; }

.primary-button, .secondary-button, .capture-button, .pill-button, .icon-button {
  border: 0; cursor: pointer; font-weight: 850;
}
.primary-button, .secondary-button { min-height: 50px; border-radius: 13px; padding: 12px 17px; }
.primary-button { color: #fff; background: linear-gradient(135deg, var(--brand), #ed3e7c); box-shadow: 0 10px 22px rgba(212,20,90,.22); }
.secondary-button { color: var(--ink); background: #efeff3; }
.primary-button:disabled, .capture-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .58; }
.wide { width: 100%; margin-top: 8px; }
.icon-button { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 13px; color: var(--brand); background: var(--brand-soft); font-size: 1.2rem; }
.form-error { min-height: 20px; margin: 9px 0 0; color: var(--danger); font-size: .85rem; }

.session-strip { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; margin-bottom: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.9); backdrop-filter: blur(12px); }
.session-dh { min-width: 0; }
.session-dh strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.strip-label { display: block; margin-bottom: 2px; color: var(--muted); font-size: .65rem; font-weight: 900; letter-spacing: .1em; }
.count-chip { min-width: 61px; padding: 7px 10px; border-radius: 13px; color: var(--brand); background: var(--brand-soft); text-align: center; }
.count-chip span, .count-chip small { display: block; }
.count-chip span { font-size: 1.08rem; font-weight: 950; }
.count-chip small { font-size: .63rem; }

.camera-card { overflow: hidden; }
.camera-viewport { position: relative; min-height: 480px; overflow: hidden; background: #101014; }
#cameraVideo { display: block; width: 100%; height: 100%; min-height: 480px; object-fit: cover; }
.live-overlay { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; pointer-events: none; }
.flex-guide { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; pointer-events: none; }
.guide-corners { width: min(84%, 430px); aspect-ratio: .73; border: 2px solid rgba(255,255,255,.82); border-radius: 22px; box-shadow: 0 0 0 999px rgba(0,0,0,.26); }
.guide-copy { position: absolute; top: 18px; left: 50%; width: calc(100% - 34px); transform: translateX(-50%); padding: 8px 12px; border-radius: 999px; color: #fff; background: rgba(0,0,0,.58); font-size: .76rem; text-align: center; }
.camera-status { position: absolute; z-index: 3; right: 50%; bottom: 17px; width: max-content; max-width: calc(100% - 32px); transform: translateX(50%); padding: 8px 12px; border-radius: 999px; color: #fff; background: rgba(0,0,0,.64); font-size: .76rem; text-align: center; }
.processing-overlay { position: absolute; inset: 0; z-index: 7; display: grid; align-content: center; justify-items: center; padding: 24px; color: #fff; background: rgba(14,14,18,.88); text-align: center; }
.spinner { width: 45px; height: 45px; margin-bottom: 14px; border: 5px solid rgba(255,255,255,.22); border-top-color: #fff; border-radius: 50%; animation: spin .85s linear infinite; }
.brand-spinner { margin: 0 auto 18px; border-color: rgba(212,20,90,.16); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track { width: min(270px,80%); height: 7px; margin-top: 14px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.22); }
.progress-bar { width: 3%; height: 100%; border-radius: inherit; background: #fff; transition: width .16s ease; }

.camera-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 12px 0; }
.pill-button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 13px; border-radius: 999px; color: var(--ink); background: #f0f0f4; font-size: .76rem; }
.file-pill { cursor: pointer; }
.capture-button { display: flex; align-items: center; justify-content: center; width: calc(100% - 24px); min-height: 58px; margin: 12px; border-radius: 16px; color: #fff; background: var(--brand); box-shadow: 0 10px 22px rgba(212,20,90,.23); }
.capture-dot { width: 19px; height: 19px; margin-right: 10px; border: 4px solid #fff; border-radius: 50%; }
.text-button { display: block; margin: 0 auto 16px; border: 0; padding: 5px 8px; color: var(--brand); background: transparent; cursor: pointer; font-weight: 800; }
.text-button.compact { margin: 0; font-size: .78rem; }
.banner { margin-top: 12px; padding: 12px 14px; border-radius: 14px; font-size: .86rem; font-weight: 750; }
.banner.success { color: var(--success); background: var(--success-bg); }
.banner.warning { color: var(--warning); background: var(--warning-bg); }
.banner.error { color: var(--danger); background: var(--danger-bg); }
.connection-row { display: flex; align-items: center; justify-content: space-between; min-height: 35px; padding: 8px 4px; color: var(--muted); font-size: .77rem; }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,20,27,.6); backdrop-filter: blur(4px); }
.modal-card { position: relative; z-index: 1; width: min(100%,760px); max-height: 92vh; margin: 0 auto; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 14px 20px calc(22px + env(safe-area-inset-bottom)); background: #fff; box-shadow: 0 -18px 50px rgba(0,0,0,.22); }
.modal-handle { width: 48px; height: 5px; margin: 0 auto 18px; border-radius: 999px; background: #d7d7dd; }
.modal-dh { padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); }
.modal-dh span { display: block; color: var(--brand-dark); font-size: .65rem; font-weight: 900; letter-spacing: .09em; }
.modal-dh strong { display: block; margin-top: 2px; }
.number-input { font-size: 1.35rem; font-weight: 900; letter-spacing: .08em; }
.modal-actions { display: grid; grid-template-columns: .9fr 1.35fr; gap: 10px; margin-top: 20px; }
.three-actions { grid-template-columns: .72fr .9fr 1.55fr; }
.candidate-wrap { margin: 12px 0; }
.candidate-wrap > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.candidate-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
.candidate-button { border: 1px solid #f0a5bf; border-radius: 999px; padding: 8px 11px; color: var(--brand-dark); background: var(--brand-soft); cursor: pointer; font-weight: 850; letter-spacing: .03em; }

.crop-card { max-height: 96vh; }
.crop-editor-wrap { width: 100%; max-height: 62vh; overflow: hidden; border-radius: 15px; background: #111; }
#cropEditorCanvas { display: block; width: 100%; height: auto; max-height: 62vh; touch-action: none; }
.crop-help { margin: 9px 0 0; color: var(--muted); font-size: .76rem; text-align: center; }

@media (max-width: 470px) {
  .three-actions { grid-template-columns: 1fr 1fr; }
  .three-actions .primary-button { grid-column: 1 / -1; }
}
@media (min-width: 680px) {
  .modal { align-items: center; padding: 20px; }
  .modal-card { border-radius: 24px; }
  .camera-viewport, #cameraVideo { min-height: 620px; }
}
