:root {
  --bg: #0b0f14;
  --surface: #141b24;
  --surface-elevated: #1b2430;
  --border: #2a3646;
  --text: #f3f6fa;
  --text-muted: #9aa7b8;
  --accent: #38d399;
  --accent-strong: #1fb880;
  --gold: #ffd45c;
  --amber: #ff9f43;
  --danger: #ff5d6c;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.45;
}

.app-shell {
  max-width: 780px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, #1b382a, #10171f);
  border: 1.5px solid var(--accent);
  display: grid;
  place-items: center;
  position: relative;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f4f6f8;
  box-shadow: 7px -3px 0 -2px rgba(255, 212, 92, 0.72);
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-cn {
  color: var(--accent);
  font-weight: 700;
}

.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-switch,
.lang-switch {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.preset-btn,
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.preset-btn.is-active {
  background: var(--accent);
  color: #06140e;
}

.lang-btn.is-active {
  background: var(--gold);
  color: #161103;
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 93, 108, 0.14);
  border: 1px solid rgba(255, 93, 108, 0.55);
  color: #ffd7dc;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.error-banner[hidden] {
  display: none;
}

.icon-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.view[hidden] {
  display: none;
}

.hero-card {
  background: radial-gradient(circle at top right, rgba(56, 211, 153, 0.12), transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card.is-dragover {
  border-color: var(--accent);
  background: rgba(56, 211, 153, 0.08);
}

.hero-badge {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: rgba(56, 211, 153, 0.12);
  border: 1px solid rgba(56, 211, 153, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}

.hero-heading {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
}

.hero-copy {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.capture-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .capture-actions {
    grid-template-columns: 1fr 1fr;
  }
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.guide-num {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 11px 16px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
  color: var(--text);
  background: var(--surface-elevated);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-lg {
  padding: 14px 18px;
  font-size: 1rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #05160e;
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 10px 12px;
}

/* Calibration mode bar */
.calib-mode-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calib-mode-switch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.mode-btn {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 7px 4px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-btn.is-active {
  background: rgba(56, 211, 153, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

.custom3-picker {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.custom3-picker[hidden] {
  display: none;
}

.custom3-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--gold);
}

.pocket-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #102018;
  border: 1px solid #264836;
  border-radius: 10px;
  padding: 8px;
}

.pocket-pick-btn {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
}

.pocket-pick-btn.is-selected {
  background: rgba(255, 212, 92, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

/* Calibration step banner */
.step-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-headline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.step-badge {
  background: rgba(255, 212, 92, 0.15);
  color: var(--gold);
  border: 1px solid rgba(255, 212, 92, 0.45);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.detect-badge {
  background: rgba(56, 211, 153, 0.14);
  color: var(--accent);
  border: 1px solid rgba(56, 211, 153, 0.42);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.detect-badge[hidden] {
  display: none;
}

.step-prompt {
  font-size: 0.95rem;
  font-weight: 700;
}

.step-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 6px;
}

.step-pill {
  appearance: none;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  padding: 7px 3px;
  border-radius: 9px;
  background: var(--surface-elevated);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease,
    box-shadow 0.14s ease, transform 0.08s ease;
}

.step-pill:hover {
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--text);
}

.step-pill:active {
  transform: scale(0.96);
}

.step-pill.is-done {
  background: rgba(56, 211, 153, 0.15);
  border-color: rgba(56, 211, 153, 0.55);
  color: var(--accent);
}

.step-pill.is-active {
  background: rgba(255, 212, 92, 0.22);
  border-color: var(--gold);
  color: #fff3c4;
  box-shadow: 0 0 0 2px rgba(255, 212, 92, 0.42);
}

.step-pill.is-done.is-active {
  background: rgba(56, 211, 153, 0.2);
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 212, 92, 0.5);
}

.canvas-stage {
  position: relative;
  background: #070a0e;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#calibCanvas {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 10px;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.magnifier-loupe {
  position: absolute;
  top: 0;
  left: 0;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 2.5px solid var(--accent);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.72),
    0 0 0 1.5px rgba(255, 255, 255, 0.14);
  background: #080c10;
  pointer-events: none;
  z-index: 15;
  will-change: transform;
}

.magnifier-loupe.is-dragging {
  border-color: var(--gold);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.8),
    0 0 0 2px rgba(255, 212, 92, 0.28);
}

.magnifier-loupe[hidden] {
  display: none;
}

.canvas-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Relative 6-pocket mini-table selector */
.target-pocket-card {
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.target-pocket-card.is-needs-pocket,
.target-pocket-card.is-pocket-active {
  border-color: rgba(255, 212, 92, 0.82);
  box-shadow: 0 0 0 2px rgba(255, 212, 92, 0.2);
}

.target-pocket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.target-pocket-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
}

.target-pocket-selected {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--gold);
}

.mini-table-felt {
  background: linear-gradient(180deg, #102a1d 0%, #0b2016 100%);
  border: 2px solid #2c4a3a;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini-table-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.mini-table-surface {
  position: relative;
  height: 20px;
  border-radius: 6px;
  background: rgba(56, 211, 153, 0.06);
  border: 1px dashed rgba(120, 225, 165, 0.24);
  display: flex;
  align-items: center;
}

.mini-table-line {
  position: absolute;
  left: 25%;
  top: 2px;
  bottom: 2px;
  width: 1px;
  background: rgba(120, 225, 165, 0.35);
}

.mini-table-spot {
  position: absolute;
  left: 75%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 212, 92, 0.55);
}

.target-pocket-btn {
  border: 1px solid rgba(120, 225, 165, 0.26);
  background: rgba(10, 16, 20, 0.78);
  color: var(--text-muted);
  font-size: clamp(0.68rem, 2.5vw, 0.8rem);
  font-weight: 700;
  padding: 9px 4px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, transform 0.08s ease;
}

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

.target-pocket-btn.is-selected {
  background: rgba(255, 212, 92, 0.2);
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 0 1px rgba(255, 212, 92, 0.35);
}

.action-bar {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.primary-action-row {
  display: grid;
  grid-template-columns: 1fr 1.65fr;
  gap: 8px;
}

.result-actions {
  grid-template-columns: 1fr 1.3fr 1fr;
}

/* Results screen */
.metric-hero {
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.metric-hero.is-impossible {
  border-color: var(--danger);
}

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

.thickness-cn {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.thickness-en {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.cut-side-badge {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 212, 92, 0.16);
  color: var(--gold);
  border: 1px solid rgba(255, 212, 92, 0.45);
  white-space: nowrap;
}

.metric-hero.is-impossible .cut-side-badge {
  background: rgba(255, 93, 108, 0.16);
  color: #ff98a2;
  border-color: rgba(255, 93, 108, 0.5);
}

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

.stat-box {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.cue-stick-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 159, 67, 0.14);
  border: 1px solid rgba(255, 159, 67, 0.48);
  font-size: 0.86rem;
  font-weight: 700;
}

.cue-stick-banner.is-on-target {
  background: rgba(56, 211, 153, 0.14);
  border-color: rgba(56, 211, 153, 0.48);
}

.cue-stick-banner[hidden] {
  display: none;
}

.cue-stick-badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  background: rgba(0, 0, 0, 0.28);
  color: var(--amber);
  white-space: nowrap;
}

.cue-stick-banner.is-on-target .cue-stick-badge {
  color: var(--accent);
}

.approx-note {
  font-size: 0.8rem;
  color: var(--gold);
  background: rgba(255, 212, 92, 0.1);
  border: 1px solid rgba(255, 212, 92, 0.35);
  border-radius: 9px;
  padding: 7px 11px;
}

.approx-note[hidden] {
  display: none;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0 0 10px 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.result-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  background: #080b10;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 14, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 50;
  font-weight: 700;
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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