:root {
  --pa-terracotta: #c15b45;
  --pa-terracotta-dark: #984331;
  --pa-teal: #3e8c7f;
  --pa-teal-dark: #28685e;
  --pa-gold: #c7902f;
  --pa-cream: #fbf6ee;
  --pa-paper: #fffdf8;
  --pa-ink: #362d2a;
  --pa-muted: #756762;
  --pa-border: rgba(96, 67, 58, 0.14);
  --pa-shadow: 0 20px 50px rgba(87, 51, 41, 0.11);
  --pa-radius: 24px;
  color-scheme: light dark;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--pa-ink);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 8% 4%, rgba(199, 144, 47, 0.12), transparent 24rem),
    radial-gradient(circle at 94% 18%, rgba(62, 140, 127, 0.1), transparent 28rem),
    var(--pa-cream);
}

h1, h2, h3 {
  margin-top: 0;
  color: var(--pa-ink);
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  letter-spacing: -0.025em;
}

a, button, input { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--pa-gold) 75%, white);
  outline-offset: 3px;
}

.app-main { min-height: 100vh; }
.app-main.with-bottom-nav { padding: 1.25rem 0 calc(7.5rem + env(safe-area-inset-bottom)); }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: max(0.6rem, env(safe-area-inset-top)) 1.1rem 0.6rem;
  border-bottom: 1px solid var(--pa-border);
  background: color-mix(in srgb, var(--pa-paper) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand-link img { display: block; width: 142px; height: auto; }
.header-action {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  color: var(--pa-terracotta);
  border: 1px solid var(--pa-border);
  border-radius: 50%;
  background: var(--pa-paper);
}
.header-action svg { width: 21px; fill: currentColor; }

.home-shell { max-width: 760px; }
.welcome-card {
  position: relative;
  display: flex;
  overflow: hidden;
  align-items: center;
  justify-content: space-between;
  min-height: 190px;
  margin-top: 1rem;
  padding: clamp(1.5rem, 5vw, 2.5rem);
  color: #fffaf2;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--pa-terracotta-dark), var(--pa-terracotta));
  box-shadow: var(--pa-shadow);
}
.welcome-card::after {
  position: absolute;
  right: -70px;
  bottom: -90px;
  width: 220px;
  height: 220px;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 48% 52% 58% 42%;
}
.welcome-card h1 { margin-bottom: 0.45rem; color: #fff; font-size: clamp(2rem, 7vw, 3.15rem); }
.welcome-card p { max-width: 29rem; margin-bottom: 0; color: rgba(255, 255, 255, 0.85); }
.welcome-mark {
  z-index: 1;
  display: grid;
  flex: 0 0 74px;
  height: 74px;
  margin-left: 1rem;
  place-items: center;
  color: var(--pa-gold);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 46% 54% 42% 58%;
  font-family: "Palatino Linotype", serif;
  font-size: 1.55rem;
  font-style: italic;
  background: rgba(255, 255, 255, 0.1);
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--pa-gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.welcome-card .eyebrow { color: #f4d28f; }

.foundation-card {
  margin-top: 1.25rem;
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 1px solid var(--pa-border);
  border-radius: var(--pa-radius);
  background: color-mix(in srgb, var(--pa-paper) 94%, transparent);
  box-shadow: 0 12px 32px rgba(87, 51, 41, 0.07);
}
.section-heading { display: flex; align-items: center; gap: 0.85rem; }
.section-heading h2 { margin-bottom: 0; font-size: 1.45rem; }
.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--pa-teal);
  box-shadow: 0 0 0 7px rgba(62, 140, 127, 0.13);
}
.foundation-grid { display: grid; gap: 0.75rem; margin-top: 1.35rem; }
.foundation-grid article {
  display: grid;
  gap: 0.15rem;
  padding: 1rem 1.05rem;
  border-left: 3px solid var(--pa-teal);
  border-radius: 0 14px 14px 0;
  background: color-mix(in srgb, var(--pa-teal) 7%, var(--pa-paper));
}
.foundation-grid span { color: var(--pa-muted); font-size: 0.9rem; }
.phase-note { margin: 1.25rem 0 0; color: var(--pa-muted); text-align: center; font-size: 0.85rem; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(72px + env(safe-area-inset-bottom));
  padding: 0.35rem 0.35rem env(safe-area-inset-bottom);
  border-top: 1px solid var(--pa-border);
  background: color-mix(in srgb, var(--pa-paper) 94%, transparent);
  box-shadow: 0 -10px 32px rgba(70, 42, 34, 0.08);
  backdrop-filter: blur(20px);
}
.nav-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  color: var(--pa-muted);
  border-radius: 14px;
  font-size: 0.69rem;
  font-weight: 700;
  text-decoration: none;
}
.nav-tab svg { width: 22px; height: 22px; fill: currentColor; }
.nav-tab.active { color: var(--pa-terracotta); }
.nav-tab.disabled { cursor: not-allowed; opacity: 0.52; }
.sell-tab { transform: translateY(-15px); }
.sell-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: white;
  border: 5px solid var(--pa-paper);
  border-radius: 50%;
  background: var(--pa-terracotta);
  box-shadow: 0 8px 18px rgba(193, 91, 69, 0.28);
}
.sell-icon svg { width: 24px; }

.login-page { background: var(--pa-cream); }
.login-shell {
  display: grid;
  min-height: 100vh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  place-items: center;
}
.login-card {
  width: min(100%, 430px);
  padding: clamp(1.5rem, 6vw, 2.5rem);
  border: 1px solid var(--pa-border);
  border-radius: 32px;
  background: var(--pa-paper);
  box-shadow: var(--pa-shadow);
}
.login-brand { margin-bottom: 2rem; text-align: center; }
.login-brand img { width: 180px; height: auto; }
.login-copy h1 { margin-bottom: 0.5rem; font-size: clamp(2rem, 8vw, 2.7rem); }
.login-copy > p:last-child { color: var(--pa-muted); }
.login-form { display: grid; gap: 1rem; margin-top: 1.5rem; }
.form-field { display: grid; gap: 0.4rem; }
.form-field label { color: var(--pa-ink); font-size: 0.86rem; font-weight: 800; }
.form-control {
  min-height: 52px;
  color: var(--pa-ink);
  border-color: var(--pa-border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--pa-cream) 55%, white);
}
.form-control:focus {
  border-color: var(--pa-teal);
  box-shadow: 0 0 0 0.25rem rgba(62, 140, 127, 0.16);
}
.btn-primary {
  --bs-btn-bg: var(--pa-terracotta);
  --bs-btn-border-color: var(--pa-terracotta);
  --bs-btn-hover-bg: var(--pa-terracotta-dark);
  --bs-btn-hover-border-color: var(--pa-terracotta-dark);
  --bs-btn-active-bg: var(--pa-terracotta-dark);
  min-height: 52px;
  border-radius: 14px;
  font-weight: 800;
}
.field-error { color: #a2382c; font-size: 0.82rem; }
.login-footnote { margin: 1.5rem 0 0; color: var(--pa-muted); text-align: center; font-size: 0.78rem; }

@media (min-width: 700px) {
  .foundation-grid { grid-template-columns: repeat(3, 1fr); }
  .app-header { padding-right: max(2rem, calc((100vw - 760px) / 2)); padding-left: max(2rem, calc((100vw - 760px) / 2)); }
  .bottom-nav { right: 50%; left: auto; width: min(640px, 100%); transform: translateX(50%); border: 1px solid var(--pa-border); border-bottom: 0; border-radius: 24px 24px 0 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .welcome-card, .foundation-card, .login-card { animation: rise-in 420ms ease-out both; }
  .foundation-card { animation-delay: 80ms; }
  @keyframes rise-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
}

@media (prefers-color-scheme: dark) {
  :root {
    --pa-cream: #191614;
    --pa-paper: #24201d;
    --pa-ink: #f7eee4;
    --pa-muted: #c4b6ae;
    --pa-border: rgba(255, 244, 233, 0.13);
    --pa-shadow: 0 22px 52px rgba(0, 0, 0, 0.3);
  }
  body { background: radial-gradient(circle at 10% 0%, rgba(193, 91, 69, 0.18), transparent 25rem), var(--pa-cream); }
  .form-control { background: #302a26; }
  .alert-danger { color: #ffd7d1; border-color: rgba(255, 128, 111, 0.32); background: rgba(148, 49, 38, 0.35); }
}
