:root {
  --bg: #f4eee5;
  --surface: #fffaf4;
  --surface-strong: #ffffff;
  --text: #1e2a31;
  --muted: #66727a;
  --accent: #c96f2d;
  --accent-dark: #9f4f18;
  --accent-soft: #f6dfcd;
  --trust: #2d7168;
  --trust-soft: #dceeea;
  --danger: #a83f2d;
  --danger-soft: #f6ded9;
  --line: rgba(30, 42, 49, 0.11);
  --shadow: 0 16px 42px rgba(62, 43, 27, 0.12);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(201, 111, 45, 0.13), transparent 28rem),
    linear-gradient(180deg, #f8f2e9 0%, var(--bg) 100%);
  color: var(--text);
}

button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 68px;
  padding: 0.65rem max(1rem, env(safe-area-inset-left)) 0.65rem max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.9);
  backdrop-filter: blur(18px);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
}

.app-brand img {
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(71, 42, 19, 0.14);
}

.app-brand span, .app-brand strong, .app-brand small { display: block; }
.app-brand strong { font-size: 0.98rem; }
.app-brand small { margin-top: 0.12rem; color: var(--muted); font-size: 0.72rem; }

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
}

main {
  width: min(980px, calc(100% - 1.4rem));
  margin: 0 auto;
  padding: 1rem 0 calc(7.2rem + var(--safe-bottom));
}

section { margin-bottom: 1rem; }

.welcome-card,
.quick-diagnostic,
.help-card,
.module-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 244, 0.95);
  box-shadow: var(--shadow);
}

.welcome-card {
  position: relative;
  overflow: hidden;
  padding: 1.4rem;
}

.welcome-card::after {
  content: "";
  position: absolute;
  right: -3rem;
  bottom: -4rem;
  width: 11rem;
  height: 11rem;
  border-radius: 50%;
  background: rgba(201, 111, 45, 0.12);
}

.eyebrow {
  margin: 0 0 0.42rem;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  max-width: 16ch;
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 8vw, 3.4rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0.65rem;
  font-size: clamp(1.45rem, 5vw, 2.15rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

h3 {
  font-size: 1.1rem;
  line-height: 1.25;
}

p { color: var(--muted); line-height: 1.62; }

.progress-summary {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-summary strong { color: var(--trust); font-size: 1.15rem; }

.text-button,
.back-button {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.quick-diagnostic,
.help-card {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.quick-diagnostic {
  background: linear-gradient(135deg, #1e3b3a, #285f58);
  color: #fff;
}

.quick-diagnostic .eyebrow,
.quick-diagnostic h2,
.quick-diagnostic p { color: #fff; }
.quick-diagnostic p { opacity: 0.82; }

.primary-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0.78rem 1rem;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(111, 49, 11, 0.2);
}

.quick-diagnostic .primary-button {
  background: #fff;
  color: #204f49;
  box-shadow: none;
}

.primary-button.full { width: 100%; }

.section-heading { padding: 0.75rem 0.25rem 0.2rem; }

.stage-grid {
  display: grid;
  gap: 0.75rem;
}

.stage-card {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 250, 244, 0.92);
  color: var(--text);
  text-align: left;
  box-shadow: 0 8px 24px rgba(60, 41, 26, 0.06);
}

.stage-card.available,
.stage-card.danger-card { cursor: pointer; }
.stage-card:disabled { opacity: 0.72; }
.stage-card.available:active,
.stage-card.danger-card:active { transform: scale(0.99); }

.stage-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 1.45rem;
  font-weight: 900;
}

.stage-card > span:nth-child(2),
.stage-card strong,
.stage-card small { display: block; }
.stage-card strong { margin-bottom: 0.22rem; }
.stage-card small { color: var(--muted); line-height: 1.35; }

.status-pill {
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: var(--trust-soft);
  color: var(--trust);
  font-size: 0.68rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.muted { background: #ebe6df; color: #7a746d; }
.status-pill.danger { background: var(--danger-soft); color: var(--danger); }
.danger-card .stage-icon { background: var(--danger-soft); color: var(--danger); }

.module-view { animation: enter 0.24s ease both; }
.back-button { padding: 0.6rem 0.15rem 0.9rem; }

.module-shell { overflow: hidden; }
.module-hero {
  padding: 1.35rem;
  background: linear-gradient(140deg, #f3e1d2, #fffaf4 70%);
}
.module-hero p:last-child { margin-bottom: 0; }

.topic-list { display: grid; gap: 0; }

.topic-card {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.topic-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  width: 100%;
  padding: 1rem 1.2rem;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.topic-toggle span { color: var(--accent-dark); font-size: 1.35rem; }
.topic-toggle small { display: block; margin-top: 0.28rem; color: var(--muted); font-weight: 500; line-height: 1.4; }
.topic-card.open .topic-toggle span { transform: rotate(45deg); }

.topic-content {
  display: none;
  padding: 0 1.2rem 1.2rem;
}
.topic-card.open .topic-content { display: block; }

.info-block,
.warning-block,
.design-block {
  margin-top: 0.8rem;
  padding: 0.95rem;
  border-radius: 15px;
}

.info-block { background: var(--trust-soft); }
.warning-block { background: var(--danger-soft); }
.design-block { background: #f2e9da; }

.info-block strong,
.warning-block strong,
.design-block strong { display: block; margin-bottom: 0.35rem; }
.info-block p,
.warning-block p,
.design-block p { margin-bottom: 0; color: inherit; }

.checklist {
  display: grid;
  gap: 0.58rem;
  margin: 0.9rem 0 0;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--text);
  line-height: 1.42;
}

.check-item input {
  width: 20px;
  height: 20px;
  margin-top: 0.05rem;
  accent-color: var(--trust);
  flex: 0 0 auto;
}

.help-card { align-items: center; }
.help-card .primary-button { width: 100%; }

.bottom-nav {
  position: fixed;
  right: 0.65rem;
  bottom: calc(0.55rem + var(--safe-bottom));
  left: 0.65rem;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 250, 244, 0.94);
  box-shadow: 0 18px 48px rgba(40, 26, 15, 0.2);
  backdrop-filter: blur(20px);
}

.bottom-nav a {
  display: grid;
  gap: 0.18rem;
  place-items: center;
  min-height: 54px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-decoration: none;
}
.bottom-nav a span { font-size: 1.15rem; }
.bottom-nav a.active { background: var(--accent-soft); color: var(--accent-dark); }

.diagnostic-dialog {
  width: min(560px, calc(100% - 1.2rem));
  max-height: calc(100vh - 1.2rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.diagnostic-dialog::backdrop { background: rgba(24, 31, 35, 0.62); backdrop-filter: blur(4px); }
.diagnostic-dialog form { padding: 1.2rem; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }

.diagnostic-dialog label,
.diagnostic-dialog legend {
  color: var(--text);
  font-weight: 800;
}

.diagnostic-dialog > form > label,
.diagnostic-dialog fieldset { display: block; margin: 1rem 0; }
.diagnostic-dialog select {
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--text);
}
.diagnostic-dialog fieldset { padding: 0.9rem; border: 1px solid var(--line); border-radius: 14px; }
.choice { display: inline-flex; align-items: center; gap: 0.45rem; margin: 0.65rem 1rem 0 0; font-weight: 600 !important; }

.diagnostic-result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 15px;
  background: var(--trust-soft);
}
.diagnostic-result h3 { margin-bottom: 0.55rem; }
.diagnostic-result ul { margin: 0; padding-left: 1.2rem; }
.diagnostic-result li { margin: 0.42rem 0; line-height: 1.5; }

@keyframes enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 720px) {
  main { padding-top: 1.5rem; }
  .quick-diagnostic,
  .help-card { grid-template-columns: minmax(0, 1fr) auto; }
  .quick-diagnostic .primary-button,
  .help-card .primary-button { width: auto; min-width: 190px; }
  .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-nav { width: min(560px, calc(100% - 2rem)); right: auto; left: 50%; transform: translateX(-50%); }
}
