/* Cessna 172 Pre-Flight Checklist — mobile-first, responsive */

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  /* --accent: #38bdf8; */
  --accent: #22c55e;
  --accent-dim: #0ea5e9;
  --success: #22c55e;
  --border: #334155;
  --radius: 12px;
  --radius-sm: 8px;
  --touch-min: 44px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  --safe-right: env(safe-area-inset-right, 0);
  --header-h: 160px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  min-height: 100vh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--header-h);
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  flex-shrink: 0;
  padding: 10px 12px 10px;
  padding-top: calc(10px + var(--safe-top));
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: clamp(6px, 2vw, 12px);
  margin-bottom: 8px;
  min-height: 0;
}

.header-titles {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.header h1 {
  margin: 0;
  font-size: clamp(1rem, 4.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtitle {
  margin: 2px 0 0;
  font-size: clamp(0.7rem, 2.2vw, 0.9rem);
  line-height: 1.3;
  color: var(--text-muted);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-header {
  flex-shrink: 0;
  width: auto;
  min-width: 0;
  max-width: min(160px, 42%);
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px);
  min-height: 32px;
  font-size: clamp(0.75rem, 2.2vw, 0.875rem);
  font-weight: 600;
  background: var(--surface-hover);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.btn-header:hover,
.btn-header:focus-visible {
  background: #475569;
  outline: none;
}

.btn-header:active {
  background: #64748b;
}

/* Checklist complete — in flow between header-top and progress, only visible at 100% */
.checklist-complete {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 0;
  margin-top: 4px;
  margin-bottom: 0;
  pointer-events: none;
}

.header.is-complete .checklist-complete {
  display: flex;
  animation: checklist-complete-in 0.5s ease forwards;
}

@keyframes checklist-complete-in {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.checklist-complete-icon {
  width: clamp(28px, 8vw, 36px);
  height: clamp(28px, 8vw, 36px);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2322c55e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E") center/contain no-repeat;
  animation: checkmark-pop 0.4s ease 0.15s both;
}

@keyframes checkmark-pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.checklist-complete-text {
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
  font-weight: 600;
  color: var(--success);
  letter-spacing: 0.02em;
  animation: checklist-text-in 0.4s ease 0.2s both;
}

@keyframes checklist-text-in {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.progress {
  height: 20px;
  margin-top: clamp(10px, 2.5vw, 16px);
  background: var(--bg);
  border-radius: 999px;
  overflow: visible;
  position: relative;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.3s ease;
  position: relative;
  z-index: 0;
}

.progress-text {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  padding-right: 4px;
  z-index: 1;
  line-height: 1;
}

/* Main content */
.main {
  flex: 1;
  padding: 12px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.section {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.section-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  min-height: var(--touch-min);
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
}

.section-header:hover,
.section-header:focus-visible {
  background: var(--surface-hover);
  outline: none;
}

.section-header:active {
  background: var(--surface-hover);
}

.section-title {
  flex: 1;
  font-weight: 600;
  font-size: 1rem;
}

.section-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.section[data-complete="true"] .section-badge {
  color: var(--success);
}

.section-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: transform 0.2s ease;
}

.section[aria-expanded="true"] .section-icon {
  transform: rotate(180deg);
}

.checklist {
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
  border-top: 1px solid var(--border);
}

.section[aria-expanded="false"] .checklist {
  display: none;
}

.checklist li {
  border-bottom: 1px solid var(--border);
}

.checklist li:last-child {
  border-bottom: none;
}

.checklist label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  min-height: var(--touch-min);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
  user-select: none;
}

.checklist label:hover {
  background: var(--surface-hover);
}

.checklist input[type="checkbox"] {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checklist input[type="checkbox"]:checked + *,
.checklist label:has(input:checked) {
  color: var(--text-muted);
}

/* Footer */
.footer {
  flex-shrink: 0;
  padding: 16px 20px 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--touch-min);
  padding: 12px 20px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  background: #475569;
  outline: none;
}

.btn-secondary:active {
  background: #64748b;
}

.disclaimer {
  margin: 12px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  text-align: center;
}

/* Responsive: larger screens */
@media (min-width: 480px) {
  .app {
    max-width: 520px;
    box-shadow: 0 0 0 1px var(--border);
  }

  .header {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .footer {
    border-radius: 0 0 var(--radius) var(--radius);
  }
}

@media (min-width: 768px) {
  body {
    padding-top: 24px;
    padding-bottom: 24px;
  }

  .app {
    max-width: 560px;
    border-radius: var(--radius);
    overflow: hidden;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
