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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --primary: #0f3460;
  --accent: #6366f1;
  --text: #eee;
  --text-muted: #999;
  --radius: 12px;
  --gap: 16px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

/* Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--gap);
  padding-top: env(safe-area-inset-top, 16px);
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  gap: var(--gap);
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

/* Header */
.app-header {
  text-align: center;
  padding: 24px 0 8px;
}

.app-header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 2px;
}

.app-header p {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.app-status {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  transition: color 0.2s;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-secondary {
  background: var(--primary);
  color: var(--text);
  width: 100%;
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}

/* Form inputs */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 14px;
  color: var(--text-muted);
}

.input-group input {
  min-height: 48px;
  padding: 12px 16px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
  outline: none;
  transition: border-color 0.15s;
}

.input-group input:focus {
  border-color: var(--accent);
}

/* Photo grid */
.photo-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.photo-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}

.photo-item:active {
  transform: scale(0.97);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-item .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.photo-item .badge.done {
  background: #27ae60;
}

.photo-item .badge.error {
  background: #c0392b;
}

.photo-retake {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: 2px solid var(--accent);
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.photo-item:hover .photo-retake,
.photo-item:active .photo-retake {
  opacity: 1;
}

.photo-retake:active {
  background: var(--accent);
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  padding: 40px;
}

/* Preview textarea */
.preview-textarea {
  flex: 1;
  min-height: 200px;
  padding: 16px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.preview-textarea:focus {
  border-color: var(--accent);
}

/* Status bar */
.status-bar {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0;
  min-height: 32px;
}

/* Button group */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: var(--gap);
}

/* Hidden file input */
.hidden {
  display: none !important;
}

/* Screen title */
.screen-title {
  font-size: 18px;
  font-weight: 600;
}

/* Photo count */
.photo-count {
  font-size: 14px;
  color: var(--text-muted);
}

/* Send message toast */
.send-message {
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  padding: 0;
  border-radius: var(--radius);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s, opacity 0.3s, padding 0.3s;
}

.send-message.visible {
  max-height: 60px;
  opacity: 1;
  padding: 12px 16px;
}

.send-message.success {
  background: #27ae60;
  color: #fff;
}

.send-message.error {
  background: #c0392b;
  color: #fff;
}
