:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e5edf7;
  --text-dim: #a7b4c7;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --err-bg: #3a1f22;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  padding: 1.5rem 1rem 0.5rem;
  text-align: center;
}
.app-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.tagline { margin: 0; color: var(--text-dim); font-size: 0.95rem; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
}

.tip-banner {
  background: var(--panel-2);
  border: 1px solid #33445c;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.step {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.step h2 { margin-top: 0; font-size: 1.1rem; }
.hint { color: var(--text-dim); font-size: 0.9rem; }

.file-picker {
  display: inline-block;
  cursor: pointer;
}
.file-picker input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  overflow: hidden;
}
.file-picker span {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  background: var(--accent-strong);
  color: #04202b;
  font-weight: 600;
  border-radius: var(--radius);
}

.canvas-wrap {
  width: 100%;
  overflow: auto;
  background: #000;
  border-radius: var(--radius);
  touch-action: manipulation;
}
#main-canvas { display: block; max-width: 100%; height: auto; cursor: crosshair; }

.status-line { color: var(--text-dim); font-size: 0.9rem; min-height: 1.2em; }

.error-box {
  background: var(--err-bg);
  border: 1px solid #7a3338;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
}
.error-box p { margin: 0 0 0.5rem; color: var(--err); font-weight: 600; }
.error-box ul { margin: 0 0 0.75rem; padding-left: 1.2rem; color: var(--text-dim); font-size: 0.9rem; }

.btn {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent-strong);
  color: #04202b;
  font-weight: 600;
  cursor: pointer;
  margin-right: 0.5rem;
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid #33445c; }

.manual-toggle { margin-top: 0.75rem; font-size: 0.9rem; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}
.result-field { display: flex; flex-direction: column; gap: 0.25rem; }
.result-field label, .result-label { font-size: 0.8rem; color: var(--text-dim); }
.result-value { font-size: 1.4rem; font-weight: 700; }
#species-select {
  padding: 0.5rem;
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #33445c;
}

.disclaimer { color: var(--text-dim); font-size: 0.85rem; }

.save-result { margin-top: 0.75rem; }
.share-row { display: flex; gap: 0.5rem; }
#share-url {
  flex: 1;
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid #33445c;
  background: var(--panel-2);
  color: var(--text);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.loading-overlay[hidden] { display: none; }
.loading-box { text-align: center; max-width: 280px; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid #33445c;
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track {
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.75rem;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s; }

.app-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}

/* r.php result page */
.result-page {
  max-width: 480px;
  margin: 3rem auto;
  padding: 1.5rem;
  background: var(--panel);
  border-radius: var(--radius);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
.result-page h1 { font-size: 1.3rem; }
.result-fields { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; }
.result-fields dt { color: var(--text-dim); }
.result-fields dd { margin: 0; font-weight: 600; }
.result-note { color: var(--text-dim); font-size: 0.85rem; margin-top: 1rem; }

body:has(.result-page) { background: var(--bg); }
