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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f0f23;
  --accent: #6c5ce7;
  --accent-hover: #5b4cdb;
  --text-primary: #edf2f7;
  --text-secondary: #a0aec0;
  --success: #48bb78;
  --warning: #ed8936;
  --error: #fc8181;
  --border: #2d3748;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover,
.icon-btn:focus {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
}

/* Connection status */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-top: 12px;
  font-size: 0.875rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--error);
  transition: background 0.3s;
}

.connection-status.connected .status-dot {
  background: var(--success);
}

.connection-status.connecting .status-dot {
  background: var(--warning);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Settings panel */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.settings-panel[hidden] {
  display: none;
}

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

.settings-content h2 {
  margin-bottom: 20px;
  font-size: 1.25rem;
}

.settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

/* Main content */
.main {
  flex: 1;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="url"],
input[type="text"],
input[type="number"],
select,
textarea {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--text-primary);
  font-size: 1rem;
  width: 100%;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

select {
  cursor: pointer;
}

.seed-controls {
  display: flex;
  gap: 8px;
}

.seed-controls input {
  flex: 1;
}

.hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
  flex: 1;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-small {
  padding: 8px 12px;
  font-size: 1.25rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-generate {
  background: linear-gradient(135deg, var(--accent), #a29bfe);
  color: white;
  padding: 16px;
  font-size: 1.125rem;
  margin-top: 8px;
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

/* Progress */
.progress-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px;
}

.progress-section[hidden] {
  display: none;
}

.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a29bfe);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Results */
.results-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px;
}

.results-section[hidden] {
  display: none;
}

.results-section h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.result-image {
  width: 100%;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.2s;
}

.result-image:hover {
  transform: scale(1.02);
}

/* Fullscreen image viewer */
.image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--bg-secondary);
  border: none;
  color: var(--text-primary);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 300;
  animation: slideUp 0.3s ease;
}

.toast.error {
  background: var(--error);
  color: var(--bg-primary);
}

.toast.success {
  background: var(--success);
  color: var(--bg-primary);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  
  .main {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
