:root {
  --bg-app: #f8f8f8;
  --bg-outer: #f8f8f8;
  --top-safe-bg: #f8f8f8;
  --surface-frosted: rgba(255, 255, 255, 0.88);
  --surface-card: #ffffff;
  --surface-muted: rgba(120, 120, 128, 0.12);
  --text-primary: #1c1c1e;
  --text-secondary: #6e6e73;
  --border-subtle: rgba(60, 60, 67, 0.12);
  --accent: #ffcf00;
  --accent-text: #1c1c1e;
  --debug-hotspot: rgba(255, 59, 48, 0.22);
  --debug-hotspot-border: #ff3b30;
  --debug-active: rgba(52, 199, 89, 0.22);
  --debug-active-border: #34c759;
  --toast-bg: rgba(28, 28, 30, 0.88);
  --toast-text: #ffffff;
  --frame-height: 100%;
  --fade-duration: 220ms;
}

@media (min-width: 520px) {
  :root {
    --bg-outer: #ececef;
  }
}

:root[data-theme='dark'] {
  --bg-outer: #000000;
  --surface-frosted: rgba(28, 28, 30, 0.9);
  --surface-card: #2c2c2e;
  --surface-muted: rgba(142, 142, 147, 0.22);
  --text-primary: #f5f5f7;
  --text-secondary: #aeaeb2;
  --border-subtle: rgba(255, 255, 255, 0.14);
  --toast-bg: rgba(44, 44, 46, 0.94);
  --toast-text: #f5f5f7;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-outer);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
}

.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg-app);
}

.safe-top-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: env(safe-area-inset-top);
  pointer-events: none;
  visibility: hidden;
}

.status-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: 4.5vh;
  height: 4.5dvh;
  background-color: var(--top-safe-bg);
  z-index: 20;
  pointer-events: none;
}

.status-mask[hidden] {
  display: none;
}

/* Invisible 5-tap secret zone at top-center */
.debug-trigger {
  position: absolute;
  top: 0;
  left: 33%;
  width: 34%;
  height: calc(18px + env(safe-area-inset-top));
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  z-index: 30;
  cursor: default;
}

.debug-toolbar {
  position: absolute;
  top: calc(6px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-frosted);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.debug-toolbar[hidden] {
  display: none;
}

.debug-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.debug-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34c759;
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.25);
}

.debug-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.debug-btn {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-muted);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.debug-btn.is-on {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.debug-btn-close {
  color: #ff3b30;
}

.screen-viewport {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
}

.screen-canvas {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--bg-app);
}

/* Full uncropped image coordinate frame: top `cropTop` is clipped above canvas top */
.screen-full-frame {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--frame-height);
}

.screen-layers {
  position: absolute;
  inset: 0;
}

.screen-layer {
  position: absolute;
  inset: 0;
  display: none;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  will-change: opacity;
}

.screen-layer.is-under {
  display: block;
  opacity: 1;
  z-index: 1;
}

.screen-layer.is-entering {
  display: block;
  opacity: 0;
  z-index: 2;
}

.screen-layer.is-active {
  display: block;
  opacity: 1;
  z-index: 2;
  transition: opacity var(--fade-duration) cubic-bezier(0.22, 0.61, 0.36, 1);
}

.screen-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  pointer-events: none;
  -webkit-user-drag: none;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
}

.hotspot {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
}

.hotspot-tag {
  display: none;
}

body[data-debug='true'][data-show-boxes='true'] .hotspot {
  background: var(--debug-hotspot);
  border: 1.5px solid var(--debug-hotspot-border);
  border-radius: 10px;
}

body[data-debug='true'][data-show-boxes='true'] .hotspot.is-current-target {
  background: var(--debug-active);
  border-color: var(--debug-active-border);
}

body[data-debug='true'][data-show-boxes='true'] .hotspot-tag {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-block;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(28, 28, 30, 0.88);
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}

/* Interactive Coordinate Picker Overlay */
.picker-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  background: rgba(0, 122, 255, 0.08);
  cursor: crosshair;
  touch-action: none;
}

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

.picker-selection {
  position: absolute;
  border: 2px dashed #007aff;
  background: rgba(0, 122, 255, 0.2);
  border-radius: 6px;
  pointer-events: none;
}

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

/* Future iOS Push Sub-views */
.push-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}

.push-container:empty {
  display: none;
}

.push-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  pointer-events: auto;
  transform: translate3d(100%, 0, 0);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

.push-view.is-open {
  transform: translate3d(0, 0, 0);
}

.push-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--surface-frosted);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.push-back-btn {
  border: none;
  background: transparent;
  color: #007aff;
  font-size: 16px;
  font-weight: 500;
  padding: 4px 6px;
  cursor: pointer;
}

.push-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.push-spacer {
  width: 52px;
}

.push-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Bottom Sheet */
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.bottom-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  max-height: 76dvh;
  display: flex;
  flex-direction: column;
  border-radius: 20px 20px 0 0;
  background: var(--surface-frosted);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 1px solid var(--border-subtle);
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translate3d(0, 100%, 0);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

.bottom-sheet[hidden] {
  display: none;
}

.bottom-sheet.is-open {
  transform: translate3d(0, 0, 0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-subtle);
  margin: 8px auto 4px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.sheet-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.sheet-close-btn {
  border: none;
  background: transparent;
  color: #007aff;
  font-size: 15px;
  font-weight: 600;
  padding: 4px 6px;
  cursor: pointer;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 12px 16px;
}

.sheet-section {
  margin-bottom: 14px;
}

.sheet-section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-card);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.chip-btn.is-active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}

.code-box {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
}

.info-list {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.65;
}

.action-btn {
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: none;
  background: #007aff;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.action-btn.is-secondary {
  background: var(--surface-muted);
  color: var(--text-primary);
}

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate3d(-50%, 10px, 0);
  z-index: 70;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast[hidden] {
  display: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate3d(-50%, 0, 0);
}
