/* ============================================================
   dackel — "calm companion" theme
   Warm paper, a relaxed dachshund, gentle motion. Mobile-first.
   ============================================================ */

/* Self-hosted variable fonts (no external CDN). woff2 lives under
   /static/fonts and is embedded in the binary. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;        /* variable weight range */
  font-display: swap;
  src: url("/static/fonts/fraunces-opsz.woff2") format("woff2");
  /* opsz axis present -> font-optical-sizing: auto applies */
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 200 1000;       /* variable weight range */
  font-display: swap;
  src: url("/static/fonts/nunito.woff2") format("woff2");
}

:root {
  /* Warm paper palette */
  --bg: #f3ecdd;
  --bg-warm: #efe6d3;
  --card: #fffdf7;
  --ink: #33291e;
  --muted: #857a69;
  --line: #e6dcc8;
  --line-soft: #efe7d6;

  /* Brand: moss green (calm/outdoors) + biscuit (warmth) */
  --accent: #43704f;
  --accent-dark: #2f5238;
  --accent-soft: #e6efe3;
  --biscuit: #c98a44;
  --biscuit-soft: #f6e8d3;

  /* Semantic */
  --calm: #43704f;
  --uneasy: #bd8526;
  --aborted: #b04a3a;
  --recovery: #a4682f;
  --rest: #4a6275;

  /* Dog fur tones (mascot + motifs) */
  --fur: #bd8049;
  --fur-dark: #8a5a30;
  --fur-light: #ddb27e;
  --snout: #3a2a1b;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(74,53,30,0.05), 0 10px 30px -16px rgba(74,53,30,0.22);
  --shadow-lg: 0 2px 6px rgba(74,53,30,0.06), 0 24px 50px -24px rgba(74,53,30,0.3);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  font-size: 17px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
  background-color: var(--bg);
  /* Soft warm glow at the top + a faint, sparse paw-print texture. */
  background-image:
    radial-gradient(120% 70% at 50% -10%, rgba(255,250,238,0.9), rgba(255,250,238,0) 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150' viewBox='0 0 150 150'%3E%3Cg fill='%23a4682f' fill-opacity='0.05'%3E%3Cellipse cx='75' cy='84' rx='15' ry='12'/%3E%3Ccircle cx='56' cy='57' r='7'/%3E%3Ccircle cx='67' cy='46' r='7'/%3E%3Ccircle cx='83' cy='46' r='7'/%3E%3Ccircle cx='94' cy='57' r='7'/%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed, scroll;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Leave room for the fixed bottom tab bar on touch layouts. */
body.has-tabbar { padding-bottom: calc(4.6rem + env(safe-area-inset-bottom)); }

a, button, label, summary { -webkit-tap-highlight-color: transparent; }
::selection { background: var(--biscuit-soft); }

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

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.25rem 1.1rem 4rem;
}
/* Standalone app uses a translucent status bar (content runs under it). Pages
   with the sticky topbar handle the inset there; pages without one (home, login,
   register) must pad for the status bar / notch themselves. */
body:not(.has-tabbar) .container { padding-top: calc(1.25rem + env(safe-area-inset-top)); }

/* ---------- Typography ---------- */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  font-optical-sizing: auto;
}
h1 { font-size: clamp(1.7rem, 6vw, 2.15rem); margin: 0.4rem 0 0.7rem; }
h2 { font-size: 1.3rem; margin: 0 0 0.6rem; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.lead { font-size: 1.12rem; color: #4a3f30; }

/* Content links — warm, not default browser blue. Buttons/tabs/brand set their
   own colours via higher-specificity class rules, so they're unaffected. */
a { color: var(--accent-dark); font-weight: 700; text-underline-offset: 2px; text-decoration-color: var(--biscuit); }
a:hover { color: var(--accent); }

/* ---------- Top app bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.05rem;
  padding-top: calc(0.65rem + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 18px -10px rgba(47,82,56,0.7);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
}
.brand-paw {
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.16);
  border-radius: 50%;
  padding: 0.28rem;
  color: #fbe8d3;
}
.brand-paw svg { width: 100%; height: 100%; }
.brand-mark { font-size: 1.2rem; } /* fallback if emoji used */

.topbar-logout button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.32);
  color: #f1f6ef;
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: 40px;
  touch-action: manipulation;
  transition: background 0.15s;
}
.topbar-logout button:hover { background: rgba(255,255,255,0.2); }
.topbar-logout button:active { background: rgba(255,255,255,0.28); }

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255,253,247,0.92);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -6px 24px -14px rgba(74,53,30,0.4);
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  min-height: 60px;
  padding: 0.45rem 0.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  touch-action: manipulation;
  transition: color 0.18s;
}
.tab svg { width: 25px; height: 25px; transition: transform 0.18s; }
.tab.active { color: var(--accent); }
.tab.active svg { transform: translateY(-1px); }
/* little paw-dot indicator under the active tab */
.tab.active::after {
  content: "";
  position: absolute;
  bottom: 0.45rem;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--biscuit);
}
.tab:active { color: var(--accent-dark); }

@media (min-width: 720px) {
  body.has-tabbar { padding-bottom: 4rem; }
  .tabbar {
    position: static;
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    background: var(--accent-dark);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: none;
    box-shadow: none;
    padding: 0 1rem 0.55rem;
  }
  .tab {
    flex-direction: row;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0.4rem 0.95rem;
    border-radius: 999px;
    font-size: 0.95rem;
    color: #cdd9cc;
  }
  .tab svg { width: 19px; height: 19px; }
  .tab.active { color: #fff; background: rgba(255,255,255,0.14); }
  .tab.active::after { display: none; }
  .tab:hover { color: #fff; }
}

/* ---------- Hero / page head ---------- */
.hero {
  text-align: center;
  padding: 1.5rem 0 1rem;
}
.hero .lead { max-width: 34ch; margin-left: auto; margin-right: auto; }
.page-head { margin-bottom: 1.1rem; }
.page-head h1 { margin-bottom: 0.2rem; }
.status {
  font-size: 1.05rem;
  color: var(--accent-dark);
  font-weight: 700;
}

/* Mascot: a calm, relaxed dachshund */
.mascot {
  display: block;
  margin: 0 auto 0.4rem;
  width: 132px; height: 132px;
  filter: drop-shadow(0 12px 18px rgba(138,90,48,0.22));
}
.mascot-sm { width: 84px; height: 84px; }
@media (prefers-reduced-motion: no-preference) {
  .mascot { animation: breathe 5.5s ease-in-out infinite; transform-origin: 50% 90%; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.card-hero {
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
/* faint paw watermark in the corner of hero cards */
.card-hero::after {
  content: "";
  position: absolute;
  right: -18px; bottom: -22px;
  width: 120px; height: 120px;
  background: no-repeat center/contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2343704f'%3E%3Cellipse cx='12' cy='16' rx='5.2' ry='4.2'/%3E%3Ccircle cx='6.5' cy='9.7' r='2.4'/%3E%3Ccircle cx='10.2' cy='6.4' r='2.4'/%3E%3Ccircle cx='13.8' cy='6.4' r='2.4'/%3E%3Ccircle cx='17.5' cy='9.7' r='2.4'/%3E%3C/svg%3E");
  opacity: 0.06;
  transform: rotate(-12deg);
  pointer-events: none;
}
.card-recovery { border-left: 5px solid var(--recovery); }
.card-rest { border-left: 5px solid var(--rest); }
.card-muted { background: transparent; box-shadow: none; border-style: dashed; }
.unit-title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  margin: 0.15rem 0 0.3rem;
}
.eyebrow {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--biscuit);
  margin-bottom: 0.1rem;
}

.banner {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.95rem;
  color: var(--accent-dark);
  margin: 0.7rem 0;
  font-size: 0.97rem;
}
.card-recovery .banner { background: #f6e9da; color: #774a1f; }
.card-rest .banner { background: #e6edf2; color: #36495a; }

/* Duration chips */
.dur-list {
  list-style: none;
  padding: 0;
  margin: 0.7rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.dur-list li {
  background: var(--biscuit-soft);
  color: #855325;
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.actions > .btn, .actions > form { flex: 1 1 100%; }
.actions > form > .btn { width: 100%; }
@media (min-width: 480px) {
  .actions > .btn, .actions > form { flex: 0 1 auto; }
  .actions > form > .btn { width: auto; }
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 46px;
  background: #efe6d4;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.7rem 1.25rem;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  transition: background 0.16s, transform 0.06s, box-shadow 0.16s;
}
.btn:hover { background: #e7dcc6; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px -10px rgba(47,82,56,0.8);
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-big { width: 100%; padding: 1rem; font-size: 1.12rem; margin-top: 0.9rem; }
.btn-small { min-height: 36px; padding: 0.4rem 0.85rem; font-size: 0.9rem; }

/* ---------- Forms ---------- */
.form label, .form > label { display: block; margin: 0.95rem 0; font-weight: 700; }
.form input, .form textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.8rem 0.85rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdf8;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus, .form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Auth screens: centered, with a small mascot */
.auth { max-width: 26rem; margin: 0 auto; text-align: center; }
.auth .card { text-align: left; }
.auth h1 { margin-top: 0.4rem; }

/* ---------- Flash ---------- */
.flash {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  margin: 0.9rem 0;
  font-weight: 700;
}
.flash-ok { background: var(--accent-soft); color: var(--accent-dark); }
.flash-error { background: #f6e1dd; color: var(--aborted); }

/* ---------- Training attempts ---------- */
.attempt {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0.9rem 0;
  background: var(--card);
  box-shadow: var(--shadow);
}
.attempt-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}
.attempt .dur { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.radios { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.6rem 0; }
.radio, .check {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 50px;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  background: #fffdf8;
  touch-action: manipulation;
  transition: background 0.14s, border-color 0.14s;
}
.radio:active, .check:active { background: var(--bg-warm); }
.radio input, .check input { width: 1.45rem; height: 1.45rem; flex: none; accent-color: var(--accent); }
.radio-calm:has(:checked) { background: var(--accent-soft); border-color: var(--calm); }
.radio-uneasy:has(:checked) { background: #f8efd7; border-color: var(--uneasy); }
.radio-aborted:has(:checked) { background: #f6e1dd; border-color: var(--aborted); }
.check:has(:checked) { background: var(--accent-soft); border-color: var(--calm); }
.note {
  width: 100%;
  margin-top: 0.55rem;
  padding: 0.65rem 0.7rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  background: #fffdf8;
}
.note:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.timer-wrap { margin-top: 0.85rem; }
.timer-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.timer { display: flex; align-items: center; gap: 0.6rem; }
.timer-display { font-variant-numeric: tabular-nums; font-size: 1.45rem; font-weight: 800; }
.timer.done .timer-display { color: var(--accent); }

.fineprint { margin-top: 1rem; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
.table-scroll table { min-width: 32rem; }
.card table, table.attempts-table { min-width: 0; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rec-cell { color: var(--muted); }
.note-cell { word-break: break-word; }
.res-calm { color: var(--calm); font-weight: 700; }
.res-uneasy { color: var(--uneasy); font-weight: 700; }
.res-aborted { color: var(--aborted); font-weight: 700; }

/* ---------- Result badge ---------- */
.badge {
  display: inline-block;
  padding: 0.22rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}
.badge-passed   { background: var(--accent-soft); color: var(--accent-dark); }
.badge-repeat   { background: #eef2e7; color: var(--accent-dark); }
.badge-failed   { background: #f8efd7; color: #8a6212; }
.badge-recovery { background: var(--biscuit-soft); color: #855325; }

/* ---------- History: cards on mobile, table on wider screens ---------- */
.history-table-wrap { display: none; }
.history-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.history-card { margin: 0; padding: 0; overflow: hidden; }
.history-card-link {
  display: block;
  padding: 1rem 1.1rem;
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
  transition: background 0.14s;
}
.history-card-link:active { background: var(--bg-warm); }
.history-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.history-card-title { font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; }
.history-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.history-card-rec { margin: 0.6rem 0 0; color: var(--muted); font-size: 0.95rem; }

@media (min-width: 720px) {
  .history-table-wrap { display: block; }
  .history-cards { display: none; }
}

/* ---------- Gentle page-load reveal ---------- */
@media (prefers-reduced-motion: no-preference) {
  .container > * {
    animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .container > *:nth-child(1) { animation-delay: 0.02s; }
  .container > *:nth-child(2) { animation-delay: 0.09s; }
  .container > *:nth-child(3) { animation-delay: 0.16s; }
  .container > *:nth-child(4) { animation-delay: 0.23s; }
  .container > *:nth-child(n+5) { animation-delay: 0.3s; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
