/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-primary);
}

.app > #viewfinder { flex: 1 1 auto; min-height: 0; }
.app > .controls   { flex: 0 0 auto; }
.app > #manual-mode { flex: 0 0 auto; }

/* Landing Page Layout */
.landing {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: var(--bg-primary);
}

/* Viewfinder */
.viewfinder {
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
  z-index: var(--z-viewfinder);
}

.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewfinder canvas {
  display: none;
}

/* HUD overlay on viewfinder */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-hud);
  pointer-events: none;
  padding: calc(var(--space-4) + var(--safe-top)) var(--space-4) var(--space-4);
}

.hud > * {
  pointer-events: auto;
}

/* EV display on viewfinder */
.ev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  margin-bottom: auto;
}

.ev-display {
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.ev-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-1);
}

/* Metering indicators */
.spot-indicator {
  position: absolute;
  width: 48px;
  height: 48px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-hud);
  transition: opacity var(--duration-fast) var(--ease-out);
}

.spot-indicator::before,
.spot-indicator::after {
  content: '';
  position: absolute;
  background: var(--accent);
}

.spot-indicator::before {
  width: 1px;
  height: 12px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.spot-indicator::after {
  width: 12px;
  height: 1px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.spot-indicator.visible {
  opacity: 1;
}

/* Centre-weighted indicator */
.center-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60%;
  aspect-ratio: 1;
  max-width: 240px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: var(--z-hud);
}

/* Controls Panel */
.controls {
  background: var(--bg-secondary);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  z-index: var(--z-controls);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Exposure Triangle */
.exposure-triangle {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-3);
  text-align: center;
}

.exposure-param {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
  min-height: 88px;
  justify-content: center;
}

.exposure-param:active {
  background: var(--bg-elevated);
}

.exposure-param.locked {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.exposure-param .value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}

.exposure-param .label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: var(--weight-medium);
}

.exposure-param.locked .label {
  color: var(--accent);
}

.exposure-param .lock-icon {
  font-size: var(--text-xs);
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.exposure-param.locked .lock-icon {
  opacity: 1;
}

/* Mode selector */
.metering-modes {
  display: flex;
  gap: var(--space-2);
  background: var(--bg-tertiary);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  position: relative;
}

.mode-btn {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-btn.active {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* Settings row */
.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  align-items: end;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.setting-group .label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Film selector button */
.film-select-btn {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: left;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color var(--duration-fast);
}

.film-select-btn:hover,
.film-select-btn:focus-visible {
  border-color: var(--border-light);
}

.film-select-btn::after {
  content: '\25BE';
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* EV Compensation */
.ev-comp-display {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-align: center;
  font-variant-numeric: tabular-nums;
  min-width: 3.5ch;
}

#ev-comp-display {
  color: var(--text-primary);
}

.ev-comp-slider {
  width: 100%;
  height: 44px;
}

.ev-comp-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

.ev-comp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 50%;
  margin-top: -8px;
  border: 2px solid var(--bg-secondary);
}

.ev-comp-slider::-moz-range-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  border: none;
}

.ev-comp-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

/* Lock button */
.lock-btn {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  min-height: 44px;
  min-width: 44px;
  transition: all var(--duration-fast) var(--ease-out);
}

.lock-btn.locked {
  background: var(--lock-dim);
  border-color: var(--lock-active);
  color: var(--lock-active);
}

/* Permission prompt */
.permission-prompt {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8);
  gap: var(--space-5);
}

.permission-prompt h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
}

.permission-prompt p {
  color: var(--text-secondary);
  max-width: 320px;
  line-height: 1.6;
}

.permission-prompt .camera-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
}

.start-btn {
  padding: var(--space-3) var(--space-6);
  background: var(--accent);
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  border-radius: var(--radius-full);
  min-height: 52px;
  min-width: 200px;
  transition: background var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

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

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

/* Film stock bottom sheet */
.film-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-modal);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  max-height: 60dvh;
  overflow-y: auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-out);
}

.film-sheet.open {
  transform: translateY(0);
}

.film-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) - 1);
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-out);
}

.film-sheet-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.film-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.film-sheet-header h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.film-sheet-close {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  color: var(--text-muted);
}

.film-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.film-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  min-height: 48px;
  transition: background var(--duration-fast);
  cursor: pointer;
}

.film-item:hover,
.film-item:focus-visible {
  background: var(--bg-tertiary);
}

.film-item.active {
  background: var(--accent-dim);
}

.film-item .film-name {
  font-weight: var(--weight-medium);
}

.film-item .film-iso {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.film-item .film-type {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-1) var(--space-2);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

/* Manual EV input fallback — inline panel, NOT a fullscreen overlay.
   The controls section underneath stays visible so the computed aperture/
   shutter/ISO readout updates live as the user types. */
.manual-mode {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4);
}

.manual-mode-inner {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  max-width: 560px;
  margin: 0 auto;
}

.manual-mode .camera-icon {
  flex: 0 0 auto;
  color: var(--text-muted);
}

.manual-mode-text {
  flex: 1 1 auto;
  min-width: 0;
}

.manual-mode-text h2 {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  margin: 0;
}

.manual-mode-text p {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: var(--space-1) 0 0;
  line-height: 1.3;
}

.manual-mode-input-group {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

.manual-mode-input-group .label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.manual-ev-input {
  width: 100px;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  text-align: center;
}

/* Landscape layout */
@media (orientation: landscape) and (min-width: 640px) {
  .app {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr 340px;
  }

  .controls {
    border-top: none;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-4);
    padding-right: calc(var(--space-4) + var(--safe-right));
  }

  .hud {
    padding: var(--space-4);
  }
}

/* Calibration access row */
.calibrate-row {
  margin-top: var(--space-3);
}

.calibrate-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  transition: background var(--duration-fast), color var(--duration-fast);
  cursor: pointer;
}

.calibrate-btn:hover,
.calibrate-btn:focus-visible {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.calibrate-offset-hint {
  margin-left: auto;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* Calibration sheet (extends .film-sheet) */
.calibrate-sheet {
  max-height: 80dvh;
}

.calibrate-live,
.calibrate-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

.calibrate-live .mono {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}

.calibrate-meta .mono {
  color: var(--text-secondary);
}

.calibrate-section {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
}

.calibrate-section:first-of-type {
  border-top: none;
}

.calibrate-section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.calibrate-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  line-height: 1.4;
}

.calibrate-reference-row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}

.calibrate-reference-input {
  flex: 0 0 96px;
  padding: var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  text-align: center;
}

.calibrate-action {
  flex: 1;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  background: var(--accent);
  color: var(--bg-primary);
  border-radius: var(--radius-md);
  font-weight: var(--weight-bold);
  cursor: pointer;
  transition: background var(--duration-fast), transform var(--duration-fast);
}

.calibrate-action:hover,
.calibrate-action:focus-visible {
  background: var(--accent-hover, var(--accent));
  filter: brightness(1.08);
}

.calibrate-action:active {
  transform: scale(0.98);
}

.calibrate-reset {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.calibrate-reset:hover,
.calibrate-reset:focus-visible {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  filter: none;
}

/* Tablet */
@media (min-width: 768px) and (orientation: portrait) {
  .controls {
    padding: var(--space-5) var(--space-8);
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
  }

  .exposure-param .value {
    font-size: var(--text-3xl);
  }
}
