/* ===== Pran Plearn — สามพรานเพลินเมือง (Mobile) ===== */
:root {
  --teal-dark: #0C4A57;
  --teal: #17707E;
  --teal-light: #2E97A0;
  --yellow: #F5B301;
  --yellow-dark: #D99A00;
  --bg: #F4F7F7;
  --ink: #12343C;
  --muted: #6B8288;
  --radius: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Anuphan", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(160deg, var(--teal-dark) 0%, var(--teal) 60%, var(--teal-light) 100%);
  color: #fff;
  text-align: center;
  padding: 18px 16px 22px;
  border-radius: 0 0 28px 28px;
  box-shadow: 0 6px 18px rgba(12, 74, 87, .35);
}
.logo-sub { color: var(--yellow); font-size: 13px; letter-spacing: 2px; margin-bottom: 2px; }
.logo-main { font-size: 28px; font-weight: 700; }
.logo-main .hl { color: var(--yellow); }

/* ---------- Layout ---------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 96px;
}
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.page-title .hl { color: var(--teal); }

/* ---------- Cards ---------- */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 4px 14px rgba(18, 52, 60, .08);
  margin-bottom: 16px;
}

/* ---------- Buttons ---------- */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 15px 20px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease;
}
.btn:active { transform: scale(.97); }
.btn-yellow { background: linear-gradient(135deg, var(--yellow), var(--yellow-dark)); color: var(--teal-dark); box-shadow: 0 6px 14px rgba(245, 179, 1, .45); }
.btn-teal { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; box-shadow: 0 6px 14px rgba(12, 74, 87, .35); }
.btn-ghost { background: #fff; color: var(--teal); border: 2px solid var(--teal-light); }
.btn + .btn, .btn + a.btn, a.btn + .btn { margin-top: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--teal-dark); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 2px solid #D8E4E6;
  border-radius: 14px;
  padding: 13px 14px;
  font-family: inherit;
  font-size: 16px;
  background: #FBFDFD;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--teal-light); }
.gender-row { display: flex; gap: 10px; }
.gender-row label {
  flex: 1; text-align: center; padding: 12px 0; border: 2px solid #D8E4E6;
  border-radius: 14px; font-weight: 600; cursor: pointer; background: #FBFDFD;
}
.gender-row input { display: none; }
.gender-row input:checked + span { color: #fff; }
.gender-row label:has(input:checked) { background: var(--teal); border-color: var(--teal); color: #fff; }
.pin-input { letter-spacing: 14px; text-align: center; font-size: 24px !important; font-weight: 700; }
.form-error { color: #C0392B; font-size: 14px; margin: 6px 0 10px; min-height: 18px; text-align: center; }
.form-link { text-align: center; margin-top: 14px; font-size: 15px; color: var(--muted); }
.form-link a { color: var(--teal); font-weight: 600; }

/* ---------- Home ---------- */
.hello-card {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
}
.hello-card .hello-name { font-size: 22px; font-weight: 700; }
.hello-stats { display: flex; gap: 12px; margin-top: 14px; }
.hello-stat { flex: 1; background: rgba(255, 255, 255, .14); border-radius: 14px; padding: 10px; text-align: center; }
.hello-stat .num { font-size: 20px; font-weight: 700; color: var(--yellow); }
.hello-stat .lbl { font-size: 12px; opacity: .85; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.menu-tile {
  background: #fff; border-radius: var(--radius); padding: 20px 14px; text-align: center;
  text-decoration: none; color: var(--ink); box-shadow: 0 4px 14px rgba(18, 52, 60, .08);
  transition: transform .08s ease;
}
.menu-tile:active { transform: scale(.96); }
.menu-tile .ico { font-size: 34px; display: block; margin-bottom: 8px; }
.menu-tile .t { font-weight: 700; font-size: 16px; }
.menu-tile .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Capture ---------- */
.shot-preview {
  width: 100%; border-radius: var(--radius); display: none; margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(18, 52, 60, .15);
}
.gps-status { text-align: center; font-size: 14px; color: var(--muted); margin: 10px 0; }
.gps-status.ok { color: var(--teal); font-weight: 600; }
.gps-status.err { color: #C0392B; }

/* ---------- Drafts ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-cell { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; box-shadow: 0 2px 8px rgba(18,52,60,.12); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .badge {
  position: absolute; left: 6px; bottom: 6px; background: rgba(12, 74, 87, .85); color: #fff;
  font-size: 10px; padding: 3px 8px; border-radius: 999px;
}
.photo-cell .badge.pub { background: var(--yellow); color: var(--teal-dark); font-weight: 700; }
.empty-hint { text-align: center; color: var(--muted); padding: 30px 0; font-size: 15px; }

/* ---------- Editor ---------- */
.editor-wrap { position: relative; width: 100%; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 14px rgba(18,52,60,.15); background: #dfe9ea; }
.editor-wrap canvas { display: block; }
.sticker-tray {
  display: flex; gap: 10px; overflow-x: auto; padding: 12px 4px;
  -webkit-overflow-scrolling: touch;
}
.sticker-item {
  flex: 0 0 auto; width: 56px; height: 56px; background: #fff; border-radius: 14px;
  border: 2px solid #D8E4E6; padding: 6px; cursor: pointer;
}
.sticker-item:active { border-color: var(--yellow); transform: scale(.94); }
.sticker-item img { width: 100%; height: 100%; object-fit: contain; }
.editor-tools { display: flex; gap: 8px; margin: 10px 0; }
.tool-btn {
  flex: 1; border: 2px solid var(--teal-light); background: #fff; color: var(--teal-dark);
  border-radius: 12px; padding: 10px 4px; font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.tool-btn:active { background: var(--teal); color: #fff; }
.tool-btn input[type="color"] { width: 100%; height: 22px; border: none; background: none; padding: 0; cursor: pointer; }

/* ---------- Map ---------- */
.map-box { width: 100%; height: calc(100dvh - 210px); min-height: 380px; border-radius: var(--radius); overflow: hidden; box-shadow: 0 4px 14px rgba(18,52,60,.15); }
.map-fallback { text-align: center; color: var(--muted); padding: 40px 16px; }
.photo-marker {
  width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--yellow);
  overflow: hidden; box-shadow: 0 3px 10px rgba(0,0,0,.35); cursor: pointer; background: #fff;
}
.photo-marker img { width: 100%; height: 100%; object-fit: cover; }
.map-popup { max-width: 230px; font-family: "Anuphan", sans-serif; }
.map-popup img { width: 100%; border-radius: 10px; margin-bottom: 6px; }
.map-popup .cap { font-size: 14px; }
.map-popup .by { font-size: 12px; color: #6B8288; margin-top: 4px; }

/* ---------- Run ---------- */
.run-hero { text-align: center; padding: 26px 18px; }
.run-dist { font-size: 64px; font-weight: 700; color: var(--yellow); line-height: 1; }
.run-dist small { font-size: 22px; }
.run-time { font-size: 20px; color: #fff; opacity: .9; margin-top: 8px; font-variant-numeric: tabular-nums; }
.run-state { font-size: 14px; color: #fff; opacity: .75; margin-top: 6px; }
.run-map { width: 100%; height: 220px; border-radius: 16px; overflow: hidden; margin-top: 16px; background: #dfe9ea; }
.run-list-item { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); }
.run-list-item .ric {
  flex: 0 0 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.run-list-item .rinfo { flex: 1; }
.run-list-item .rdate { font-weight: 700; font-size: 15px; }
.run-list-item .rsub { font-size: 12px; color: var(--muted); }
.run-list-item .rdist { font-weight: 700; color: var(--teal); font-size: 17px; }
.stat-row { display: flex; gap: 12px; }
.stat-box { flex: 1; background: #fff; border-radius: 16px; padding: 14px; text-align: center; box-shadow: 0 4px 14px rgba(18,52,60,.08); }
.stat-box .num { font-size: 22px; font-weight: 700; color: var(--teal); }
.stat-box .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Me ---------- */
.me-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed #D8E4E6; font-size: 15px; }
.me-row:last-child { border-bottom: none; }
.me-row .k { color: var(--muted); }
.me-row .v { font-weight: 600; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: var(--teal-dark);
  border-radius: 22px 22px 0 0; box-shadow: 0 -4px 18px rgba(12, 74, 87, .4);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1; text-align: center; color: rgba(255, 255, 255, .65); text-decoration: none;
  font-size: 11px; font-weight: 600; padding: 6px 0 4px; border-radius: 14px;
}
.bottom-nav a span { display: block; font-size: 20px; margin-bottom: 1px; }
.bottom-nav a.on { color: var(--yellow); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(20px);
  background: var(--teal-dark); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease; z-index: 99; max-width: 84vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: #C0392B; }
