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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text-muted: #aaa;
  --red: #e74c3c;
  --blue: #3498db;
  --orange: #f39c12;
  --black-tile: #2c3e50;
  --joker: #9b59b6;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

header {
  text-align: center;
  padding: 20px 0 10px;
}

header h1 {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Steps */
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
}

.step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--surface);
  opacity: 0.5;
  transition: all 0.3s;
}

.step.active {
  opacity: 1;
  background: var(--surface2);
  box-shadow: 0 0 12px rgba(233, 69, 96, 0.3);
}

.step.done {
  opacity: 0.8;
  background: #1a5c3a;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
}

.done .step-num {
  background: #27ae60;
}

.step-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.step-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* Camera */
.camera-container {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 4/3;
}

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

#camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 16px;
  pointer-events: none;
}

#overlay-text {
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.camera-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.96);
}

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

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 1.1rem;
  padding: 14px 32px;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* Preview */
#preview-section {
  text-align: center;
}

#preview-img {
  width: 100%;
  border-radius: var(--radius);
  max-height: 360px;
  object-fit: contain;
  background: #000;
}

.preview-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

/* Loading */
#loading {
  text-align: center;
  padding: 40px 0;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Data panels */
.section {
  margin: 16px 0;
}

.data-panel {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.data-panel h2 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--text-muted);
}

/* Tile chips */
.tile-set {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.tile-set-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 100%;
  margin-bottom: 2px;
}

.tile-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 44px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: #f5f0e1;
}

.tile-chip.red { color: var(--red); border-color: var(--red); }
.tile-chip.blue { color: var(--blue); border-color: var(--blue); }
.tile-chip.orange { color: var(--orange); border-color: var(--orange); }
.tile-chip.black { color: var(--black-tile); border-color: var(--black-tile); }
.tile-chip.joker {
  color: var(--joker);
  border-color: var(--joker);
  font-size: 0.7rem;
}

.hand-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Action section */
#action-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* Results */
#results-section h2 {
  text-align: center;
  margin-bottom: 16px;
}

.move-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid var(--accent);
}

.move-card.add_to_group,
.move-card.extend_run {
  border-left-color: var(--accent2);
}

.move-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.move-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.move-points {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.move-description {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.move-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.no-moves {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 1.1rem;
}

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

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin-bottom: 12px;
}

.editor-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.editor-tile {
  position: relative;
}

.editor-tile .remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 0.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.editor-add {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.editor-add select {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Error toast */
.error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  z-index: 200;
  animation: fadeIn 0.3s;
  max-width: 90%;
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#btn-rescan {
  display: block;
  margin: 20px auto 0;
}
