/* =========================================================================
   Photo Walk Bingo by Storitellah — styles
   Mobile-first, touch-first, safe-area aware, dark mode, high contrast.
   ========================================================================= */

:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --ink: #221f2e;
  --ink-soft: #6b6580;
  --line: #ddd8cc;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --accent-soft: #ffe3db;
  --good: #2e9e57;
  --good-soft: #e2f5e8;
  --danger: #d84343;
  --focus: #2a6df4;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(34, 31, 46, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap: 44px;
  color-scheme: light;
}

:root[data-mode="dark"] {
  --bg: #16141f;
  --surface: #221f2e;
  --surface-2: #2c2839;
  --ink: #f0edf6;
  --ink-soft: #a49dbb;
  --line: #3a3549;
  --accent: #ff7a5c;
  --accent-ink: #1c0f0a;
  --accent-soft: #43261e;
  --good: #58c983;
  --good-soft: #1e3a2a;
  --danger: #ff7676;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

:root.high-contrast {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;
  --ink: #000000;
  --ink-soft: #1a1a1a;
  --line: #000000;
  --accent: #a52800;
  --accent-ink: #ffffff;
  --accent-soft: #ffd9cc;
  --good: #005c22;
  --good-soft: #d3f5de;
  --danger: #a30000;
  --shadow: none;
}

:root[data-mode="dark"].high-contrast {
  --bg: #000000;
  --surface: #000000;
  --surface-2: #141414;
  --ink: #ffffff;
  --ink-soft: #eaeaea;
  --line: #ffffff;
  --accent: #ffb199;
  --accent-ink: #000000;
  --accent-soft: #3d1200;
  --good: #7dffab;
  --good-soft: #00331a;
  --danger: #ff9c9c;
}

:root.large-text { font-size: 120%; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body.modal-open { overflow: hidden; }

/* ---- accessibility helpers ---- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px; top: -48px;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 8px;
  z-index: 100; transition: top 0.15s;
}
.skip-link:focus { top: calc(8px + env(safe-area-inset-top)); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* =====================================================================
   Header
   ===================================================================== */
.app-header {
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}

.header-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}

.logo-dot { color: var(--accent); }

.app-title small {
  font-weight: 500; font-size: 0.72em; color: var(--ink-soft);
}

.app-title a { color: var(--accent); text-decoration: none; }
.app-title a:hover, .app-title a:focus { text-decoration: underline; }

.header-actions { display: flex; gap: 8px; align-items: center; }

.clock {
  margin-top: 6px;
  font-size: 0.86rem;
  color: var(--ink-soft);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
}
.clock time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.clock-sep { opacity: 0.6; }

.location-row {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  min-height: 1.2em;
}

/* =====================================================================
   Layout
   ===================================================================== */
.app-main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px 32px;
  display: flex; flex-direction: column; gap: 18px;
}

@media (min-width: 900px) and (orientation: landscape) {
  .app-main { max-width: 760px; }
}

.panel-title { margin: 0 0 8px; font-size: 1.05rem; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { font-size: 1.12rem; padding: 14px 28px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.tiny { min-height: 30px; padding: 3px 10px; font-size: 0.78rem; border-radius: 8px; }
.btn.danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: wait; }

.icon-btn {
  font: inherit;
  font-size: 1.15rem;
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.icon-btn:active { transform: scale(0.94); }

.btn-row { display: flex; gap: 10px; margin: 10px 0; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

/* =====================================================================
   Empty state
   ===================================================================== */
.empty-state {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 22px;
  box-shadow: var(--shadow);
}
.empty-state h2 { margin: 0 0 8px; font-size: 1.5rem; }
.empty-state p { color: var(--ink-soft); margin: 0 auto 20px; max-width: 42ch; }

#saved-walks-wrap { margin-top: 26px; text-align: left; }
#saved-walks-wrap h3 { font-size: 0.95rem; margin: 0 0 8px; }

.saved-walks-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.saved-walks-list li { display: flex; gap: 8px; align-items: stretch; }

.saved-walk-btn {
  flex: 1;
  text-align: left;
  font: inherit;
  padding: 10px 14px;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
.saved-walk-btn small { color: var(--ink-soft); }

.saved-walk-del {
  font: inherit;
  width: var(--tap);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

/* =====================================================================
   Progress panel
   ===================================================================== */
.progress-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.progress-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap; margin-bottom: 8px;
}

.theme-chip {
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 12px;
}

.progress-stats { font-size: 0.9rem; color: var(--ink-soft); }
.progress-stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #ffc94a);
  transition: width 0.35s ease;
}

.walk-times {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0 0;
}
.walk-times dt { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.walk-times dd { margin: 0; font-size: 0.86rem; font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 380px) {
  .walk-times { grid-template-columns: repeat(2, 1fr); }
}

/* =====================================================================
   Bingo grid
   ===================================================================== */
.bingo-grid {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), 1fr);
  gap: 8px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
}

.cell-toggle {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  padding: 6px 4px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  touch-action: manipulation;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.cell-toggle:active { transform: scale(0.95); }

.cell-title {
  position: relative; z-index: 2;
  width: 100%;
  font-weight: 650;
  /* Scales down as the grid gets denser (5x5 on a phone) */
  font-size: clamp(0.52rem, calc(10.5vw / var(--n, 5)), 0.85rem);
  line-height: 1.15;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
  max-height: 100%;
}

.cell.done .cell-toggle {
  background: var(--good-soft);
  border-color: var(--good);
}

.cell-check {
  position: absolute; z-index: 3;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.cell.done .cell-check { display: inline-flex; animation: pop-in 0.25s ease; }

@keyframes pop-in {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.cell-photo {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 12px;
}
.cell.has-photo .cell-title {
  color: #fff;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.9);
}
.cell.has-photo .cell-photo { filter: brightness(0.62); }

.cell-info {
  position: absolute; z-index: 4;
  bottom: 2px; right: 2px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.cell.has-photo .cell-info { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }

/* Larger info target on bigger screens */
@media (min-width: 520px) {
  .cell-info { width: 34px; height: 34px; }
}

/* =====================================================================
   Route panel
   ===================================================================== */
.route-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
#route-svg {
  width: 100%; height: auto;
  background: var(--surface-2);
  border-radius: 12px;
}
.route-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-dasharray: 5 4; }
.route-dot { fill: var(--ink); }
.route-dot.start { fill: var(--accent); }
.route-meta { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.86rem; }

/* =====================================================================
   Action bar & workshop button
   ===================================================================== */
.action-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}
@media (min-width: 560px) { .action-bar { grid-template-columns: repeat(4, 1fr); } }

.workshop-btn { width: 100%; }

/* =====================================================================
   Support panel & footer
   ===================================================================== */
.support-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.support-panel > p { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 12px; }

.support-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.support-link {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
}
.support-link svg { flex-shrink: 0; color: var(--accent); }
.support-link span { display: flex; flex-direction: column; }
.support-link small { font-weight: 400; color: var(--ink-soft); }
a.support-link:hover, a.support-link:focus { border-color: var(--accent); }

.app-footer {
  text-align: center;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  color: var(--ink-soft);
  font-size: 0.82rem;
  border-top: 1px solid var(--line);
}
.app-footer p { margin: 4px 0; }
.app-footer a { color: var(--accent); }

/* =====================================================================
   Achievement toast & confetti
   ===================================================================== */
.achievement-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  z-index: 60;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--accent);
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.25);
  opacity: 0;
  max-width: min(92vw, 420px);
  pointer-events: none;
}
.achievement-toast[hidden] { display: none; }
.achievement-toast.show { animation: toast-in 3.2s ease forwards; }
.achievement-toast strong { font-size: 1rem; }
.achievement-toast p { margin: 0; font-size: 0.84rem; color: var(--ink-soft); }
.achievement-icon { font-size: 1.8rem; }

@keyframes toast-in {
  0% { opacity: 0; transform: translate(-50%, 20px); }
  10%, 88% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}

#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 55; overflow: hidden; }

.confetti {
  position: absolute;
  top: -12px;
  width: 9px; height: 14px;
  border-radius: 2px;
  animation: confetti-fall 2s ease-in forwards;
}

@keyframes confetti-fall {
  to { transform: translate(var(--drift, 0), 105vh) rotate(540deg); opacity: 0.7; }
}

/* =====================================================================
   Modals
   ===================================================================== */
.modal {
  position: fixed; inset: 0;
  z-index: 50;
  background: rgba(20, 16, 30, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal[hidden] { display: none; }
@media (min-width: 560px) {
  .modal { align-items: center; padding: 24px; }
}

.modal-card {
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 40px - env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.3);
  animation: sheet-up 0.22s ease;
}
@media (min-width: 560px) {
  .modal-card { border-radius: 22px; padding-bottom: 20px; }
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 8px;
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }

.detail-desc { margin: 4px 0; color: var(--ink); }
.detail-example { margin: 4px 0 10px; color: var(--ink-soft); font-style: italic; font-size: 0.9rem; }
.detail-status { font-size: 0.85rem; color: var(--good); font-weight: 650; margin: 8px 0; }
.detail-photo {
  width: 100%; max-height: 260px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  margin: 6px 0;
}

.privacy-note { font-size: 0.78rem; color: var(--ink-soft); margin: 10px 0 0; }
.hint { font-size: 0.84rem; color: var(--ink-soft); margin: 6px 0 12px; }

/* ---- form fields ---- */
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 0.82rem; font-weight: 650; margin-bottom: 4px; color: var(--ink-soft); }
.field input[type="text"], .field select, .field textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: var(--tap);
}
.field textarea { min-height: 64px; resize: vertical; }

.setting-group {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 14px;
  margin: 14px 0;
}
.setting-group legend { font-weight: 700; font-size: 0.92rem; padding: 0 6px; }
.setting-group legend small { font-weight: 400; color: var(--ink-soft); }

.segmented { display: flex; gap: 6px; margin: 6px 0 10px; }
.segmented button {
  flex: 1;
  font: inherit; font-weight: 650;
  min-height: var(--tap);
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.segmented button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.switch-row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap);
  font-size: 0.94rem;
  cursor: pointer;
}
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }

.plain-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plain-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.template-item { flex-wrap: wrap; }
.template-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.small.danger { background: transparent; border-color: var(--danger); color: var(--danger); }

/* =====================================================================
   Motion preferences
   ===================================================================== */
:root.no-anim *, :root.no-anim *::before, :root.no-anim *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =====================================================================
   Print (quick-print of the live card)
   ===================================================================== */
@media print {
  .app-header, .action-bar, .workshop-btn, .support-panel, .app-footer,
  .modal, .achievement-toast, #confetti-layer, .location-row, #btn-install { display: none !important; }
  body { background: #fff; color: #000; }
  .bingo-grid { gap: 4px; }
  .cell-toggle { border: 1.5px solid #000; }
}
