:root {
  --teal: #0f766e;
  --teal-dark: #115e56;
  --teal-light: #14b8a6;
  --bg: #f5f7f7;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --due: #f59e0b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header / footer ---------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--teal);
  color: #fff;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  text-decoration: none;
}
.brand-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .25);
}
.header-link { color: #d1fae5; text-decoration: none; font-size: 14px; }

.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.app-footer {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px);
}
.disclaimer {
  margin: 0 auto;
  max-width: 720px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

/* Avatar ------------------------------------------------------------------- */
.view-toggle {
  display: inline-flex;
  margin: 0 auto 12px;
  background: #e2e8e7;
  border-radius: 999px;
  padding: 3px;
  width: 100%;
  max-width: 240px;
}
.avatar-section { text-align: center; }
.toggle-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.toggle-btn.active { background: #fff; color: var(--teal); box-shadow: var(--shadow); }

.avatar-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
#avatar { width: 100%; height: auto; max-height: 56vh; display: block; touch-action: manipulation; }

.region {
  fill: #cfe6e3;
  stroke: #9cc6c1;
  stroke-width: 1.2;
  cursor: pointer;
  transition: fill .12s ease;
}
.region:hover, .region:focus { fill: #b3dbd6; outline: none; }
.region.has-moles { fill: #6fc7bd; stroke: var(--teal); }

.badge-circle { fill: var(--teal); stroke: #fff; stroke-width: 1.5; pointer-events: none; }
.badge-text { fill: #fff; font-size: 11px; font-weight: 700; text-anchor: middle; pointer-events: none; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* Mole list ---------------------------------------------------------------- */
.list-section { margin-top: 26px; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; }
.list-head h2 { font-size: 17px; margin: 0; }
.due-summary { font-size: 13px; color: var(--due); font-weight: 600; }

.mole-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.empty {
  text-align: center; color: var(--muted); font-size: 14px;
  background: var(--card); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 28px 16px;
}

.mole-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; cursor: pointer;
  border: 1px solid var(--line);
}
.mole-thumb {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover;
  background: #eef2f1; flex: 0 0 auto;
}
.mole-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 20px; }
.mole-info { flex: 1; min-width: 0; }
.mole-name { font-weight: 600; font-size: 15px; }
.mole-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin-left: 6px;
}
.pill.due { background: #fef3c7; color: #92400e; }
.pill.ok { background: #d1fae5; color: #065f46; }

/* Sheets / modals ---------------------------------------------------------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 22px);
  max-height: 88vh; overflow-y: auto;
  max-width: 720px; margin: 0 auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 4px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; }
.sheet-header h3 { margin: 6px 0 12px; font-size: 18px; }
.icon-btn { border: 0; background: #f1f5f4; width: 32px; height: 32px; border-radius: 50%; font-size: 14px; cursor: pointer; color: var(--muted); }

.region-moles { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.region-mole-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.region-mole-row:hover { background: #f8fafa; }

/* Buttons ------------------------------------------------------------------ */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn.block { width: 100%; display: block; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:active { background: var(--teal-dark); }
.btn-ghost { background: #f1f5f4; color: var(--ink); }
.btn-danger-ghost { background: #fef2f2; color: var(--danger); }
.mole-actions { display: flex; gap: 10px; margin: 6px 0 18px; }
.mole-actions .btn { flex: 1; }

/* Forms -------------------------------------------------------------------- */
.section-label { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.field-label { font-size: 13px; color: var(--muted); display: block; margin: 8px 0 4px; }
.photo-form { display: flex; flex-direction: column; gap: 10px; }
.photo-form input[type="file"],
.photo-form input[type="text"],
.photo-form textarea {
  width: 100%; padding: 11px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px; font-family: inherit; background: #fff;
}
.photo-form textarea { resize: vertical; }
.mole-meta { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }

/* Photo history ------------------------------------------------------------ */
.photo-history { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photo-item { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.photo-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #eef2f1; }
.photo-body { padding: 8px 10px; }
.photo-date { font-size: 12px; font-weight: 600; }
.photo-notes { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.photo-del { font-size: 12px; color: var(--danger); background: none; border: 0; cursor: pointer; padding: 4px 0 0; }

/* About -------------------------------------------------------------------- */
.about h1 { font-size: 22px; }
.about h2 { font-size: 16px; margin-top: 22px; }
.about p, .about li { line-height: 1.6; color: #374151; }
.callout { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 14px; margin: 14px 0; line-height: 1.55; }
.back-link a { color: var(--teal); text-decoration: none; font-weight: 600; }

/* Toast -------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90%;
}
.toast[hidden] { display: none; }

/* Change analysis ---------------------------------------------------------- */
.analysis-head { display: flex; align-items: center; justify-content: space-between; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.analysis-section { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }

.analysis-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff;
}
.analysis-card.latest { border-color: #cbd5d3; box-shadow: var(--shadow); }
.analysis-card.past { opacity: .92; }

.badge {
  display: inline-block; font-size: 12.5px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
}
.badge-none { background: #d1fae5; color: #065f46; }
.badge-moderate { background: #fef3c7; color: #92400e; }
.badge-significant { background: #fee2e2; color: #991b1b; }

.analysis-text { margin: 8px 0 0; font-size: 14px; line-height: 1.5; color: #374151; }
.analysis-meta { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.analysis-disclaimer {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 11.5px; line-height: 1.45; color: var(--muted); font-style: italic;
}
.analysis-fail { font-size: 13.5px; color: var(--danger); }
.analysis-retry { margin-top: 8px; }

.analysis-row { display: flex; align-items: center; gap: 10px; }
.analysis-pending { font-size: 14px; color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--teal);
  animation: spin .8s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
