*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #00e676;
  --amber: #ffab00;
  --red: #ff5252;
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #ffffffde;
  --text-dim: #ffffff80;
  --radius: 12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Camera */
#camera-container {
  position: fixed;
  inset: 0;
  background: #000;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#processing-canvas, #debug-canvas {
  display: none;
}

#debug-canvas.visible {
  display: block;
  position: fixed;
  bottom: 200px;
  left: 10px;
  width: 200px;
  border: 1px solid var(--amber);
  z-index: 100;
}

/* Start button */
#start-btn {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  padding: 18px 48px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--green);
  color: #000;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

#start-btn:active {
  opacity: 0.8;
}

#start-btn.hidden {
  display: none;
}

/* Status bar */
#status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  text-align: center;
  z-index: 30;
  color: var(--text-dim);
  display: none;
}

#status-bar.active {
  display: block;
}

/* Settings button */
#settings-btn {
  position: fixed;
  top: env(safe-area-inset-top, 8px);
  right: 12px;
  z-index: 35;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#settings-btn.active {
  display: flex;
}

/* Results panel (bottom sheet) */
#results-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(calc(100% - 64px));
  transition: transform 0.3s ease;
  max-height: 60vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: none;
}

#results-panel.active {
  display: block;
}

#results-panel.expanded {
  transform: translateY(0);
}

#panel-handle {
  width: 36px;
  height: 4px;
  background: var(--text-dim);
  border-radius: 2px;
  margin: 10px auto;
  cursor: pointer;
}

#current-plate {
  padding: 8px 20px 12px;
  text-align: center;
}

#plate-text {
  font-size: 32px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  letter-spacing: 4px;
  min-height: 42px;
  color: var(--text);
}

#plate-confidence {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

#plate-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 0 20px 12px;
}

#plate-actions button {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

#copy-btn {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

#send-btn {
  background: var(--green);
  color: #000;
}

#send-btn:disabled {
  opacity: 0.4;
}

#send-status {
  font-size: 12px;
  text-align: center;
  min-height: 18px;
  padding-bottom: 8px;
}

#history-section {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px 20px;
  max-height: 30vh;
  overflow-y: auto;
}

#history-section h3 {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 500;
}

#history-list {
  list-style: none;
}

#history-list li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

#history-list .plate-num {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  letter-spacing: 2px;
}

#history-list .plate-time {
  font-size: 11px;
  color: var(--text-dim);
}

/* Settings modal */
#settings-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#settings-modal.open {
  display: flex;
}

#settings-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}

#settings-content h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

#settings-content label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 12px;
}

#settings-content input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 44px;
}

#settings-content input::placeholder {
  color: var(--text-dim);
}

#settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

#settings-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

#settings-cancel {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

#settings-save {
  background: var(--green);
  color: #000;
}

#debug-toggle {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

#debug-toggle input {
  width: 20px;
  min-height: 20px;
}
