/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--white);
}
body {
  height: 100%;
  font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--white);
  color: #1a1a1a;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Prevent iOS Safari auto-zoom on input focus */
input, select, textarea {
  font-size: 16px !important;
}

/* ── CSS VARIABLES ── */
:root {
  --green: #2D8659;
  --green-dark: #0d3d22;
  --green-light: #40B67A;
  --green-bg: #f0f5f1;
  --blue: #1a6fb5;
  --blue-bg: #eff6ff;
  --pink: #be185d;
  --pink-bg: #fdf2f8;
  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --amber: #d97706;
  --amber-bg: #fff7ed;
  --gray: #6b7280;
  --gray-light: #f2f2f7;
  --white: #ffffff;
  --border: #e0e8e0;
  --border-light: #e0e8e0;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;

  /* Layout */
  --tab-bar-height: calc(60px + max(env(safe-area-inset-bottom), var(--safe-area-bottom, 0px), 34px));
  --status-bar-height: env(safe-area-inset-top, 44px);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --header-height: 56px;

  /* Results gradient */
  --results-bg: linear-gradient(145deg, #0a3d22, #1a5c35);
}

/* ── APP LAYOUT ── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--white);
  position: relative;
  touch-action: pan-y;
}

/* ── SCREENS ── */
#app-screens {
  min-height: 0;
}
.screen {
  display: none;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background: var(--gray-light);
}
.screen.active { display: flex; }

/* ── STATUS BAR SPACER ── */
.status-spacer {
  height: var(--status-bar-height);
  flex-shrink: 0;
}

/* ── PAGE HEADER ── */
.page-header {
  background: var(--white);
  padding: 0 16px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}
.page-header.dark {
  background: var(--green-dark);
  border-bottom: none;
}
.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.page-header.dark .page-title { color: var(--white); }

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 0;
}
.back-btn svg { flex-shrink: 0; }

/* ── SCROLL CONTENT ── */
.scroll-content {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: var(--tab-bar-height);
  touch-action: pan-y;
}
.scroll-content::-webkit-scrollbar { display: none; }

/* ── TAB BAR ── */
#tab-bar, .tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  padding-bottom: max(env(safe-area-inset-bottom), var(--safe-area-bottom, 0px), 34px);
  height: auto;
  z-index: 1000;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.tab-item::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 24px;
  height: 3px;
  background: var(--green);
  border-radius: 0 0 3px 3px;
  transition: transform .2s ease;
}
.tab-item.active::before { transform: translateX(-50%) scaleX(1); }
.tab-item svg { transition: opacity .15s; }
.tab-item span {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  transition: color .15s;
}
.tab-item.active span { color: var(--green); font-weight: 600; }

/* ── CARDS ── */
.card {
  background: var(--white);
  border-radius: 16px;
  border: 1.5px solid #e0e8e0;
  overflow: clip;
  box-shadow: 0 2px 8px rgba(45,134,89,.06);
}
.card-body { padding: 14px; }

/* ── SECTION HEADER ── */
.section-title {
  font-size: 1rem;
  font-family: 'Bebas Neue', cursive;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-secondary);
  padding: 16px 16px 8px;
}

/* ── TIER BADGES ── */
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}
.badge-free  { background: #f3f4f6; color: var(--gray); }
.badge-basic { background: #1a6fb5; color: #fff; }
.badge-plus  { background: #7c3aed; color: #fff; }
.badge-pro   { background: #2D8659; color: #fff; }
.badge-locked { background: #f3f4f6; color: var(--text-tertiary); }

/* ── CALC LIST ITEM ── */
.calc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--white);
  border-bottom: 0.5px solid var(--border-light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.calc-item:last-child { border-bottom: none; }
.calc-item:active { background: var(--gray-light); }
.calc-item.locked { opacity: .5; cursor: default; }
.calc-item-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.calc-item-info { flex: 1; min-width: 0; }
.calc-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.calc-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.chevron {
  color: var(--text-tertiary);
  font-size: 18px;
  font-weight: 300;
  flex-shrink: 0;
}

/* ── IFRAME WRAPPER ── */
.iframe-screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: var(--white);
}
.iframe-screen.active { display: flex; }

.calc-iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: var(--white);
}

/* ── HOME HEADER ── */
.home-header {
  background: linear-gradient(135deg, #0d3d22 0%, #1a5c35 100%);
  padding: 20px 20px 28px;
}
.home-greeting { font-size: 13px; color: rgba(255,255,255,.55); font-weight: 500; }
.home-name { font-size: 24px; font-weight: 700; color: var(--white); margin-top: 3px; letter-spacing: -0.3px; }
.home-tier {
  display: inline-block;
  background: rgba(45,134,89,.35);
  color: var(--green-light);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  margin-top: 10px;
  letter-spacing: 0.2px;
}

/* ── QUICK ACCESS GRID ── */
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 4px;
}
.quick-card {
  background: var(--white);
  border-radius: 16px;
  padding: 14px 12px;
  border: 1px solid var(--border-light);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.quick-card:active { background: var(--gray-light); }
.quick-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.quick-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.quick-tier { font-size: 11px; font-weight: 500; margin-top: 3px; }
.quick-desc { font-size: 11px; color: var(--text-secondary); margin-top: 2px; line-height: 1.3; }
.quick-type-badge { margin-top: 6px; }
.quick-edit-link { background: none; border: none; color: var(--green); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; padding: 0; }
.quick-remove-btn { background: none; border: none; color: var(--text-secondary); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 8px; flex-shrink: 0; }
.quick-remove-btn:active { color: #dc2626; }
.quick-add-btn { background: none; border: none; color: var(--green); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; flex-shrink: 0; font-weight: 300; }
.quick-add-btn:active { opacity: .7; }


/* ── PROGRESS BAR ── */
.progress-track {
  height: 4px;
  background: var(--green-bg);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width .3s ease;
}

/* ── INSTALL BANNER ── */
.install-banner {
  display: none;
  margin: 0 16px 8px;
  background: var(--green-dark);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--white);
}
.install-banner.visible { display: flex; align-items: center; gap: 12px; }
.install-banner-text { flex: 1; }
.install-banner-title { font-size: 13px; font-weight: 600; }
.install-banner-sub { font-size: 11px; color: rgba(255,255,255,.7); margin-top: 2px; }
.install-banner-btn {
  background: var(--green-light);
  color: var(--green-dark);
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}
.install-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

/* ── A2HS BANNER ── */
@keyframes a2hs-slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.a2hs-banner {
  display: none;
  position: fixed;
  bottom: calc(var(--tab-bar-height) + 8px);
  left: 16px;
  right: 16px;
  background: #fff;
  border-radius: 14px;
  border-top: 3px solid #2D8659;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 14px 16px 14px 16px;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  z-index: 990;
}
.a2hs-banner.visible {
  display: flex;
  animation: a2hs-slide-up 0.3s ease;
}
.a2hs-dismiss {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.a2hs-icon { font-size: 28px; flex-shrink: 0; }
.a2hs-text { flex: 1; padding-right: 20px; }
.a2hs-title { font-size: 14px; font-weight: 700; color: var(--text); }
.a2hs-sub { font-size: 12px; color: var(--text-secondary); margin-top: 3px; line-height: 1.4; }

/* ── OFFLINE INDICATOR ── */
.offline-bar {
  display: none;
  background: #f59e0b;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 6px;
}
.offline-bar.visible { display: block; }

/* ── LOGIN SCREEN ── */
#screen-login {
  display: flex;
  flex-direction: column;
  background: var(--white);
}
.login-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 28px 32px;
  gap: 22px;
}
.login-logo {
  width: 200px;
  height: auto;
  display: block;
}
.login-title { font-size: 24px; font-weight: 700; color: var(--text); text-align: center; letter-spacing: -0.3px; }
.login-sub { font-size: 14px; color: var(--text-secondary); text-align: center; line-height: 1.55; }
.login-fields { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.login-input {
  width: 100%;
  height: 52px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0 16px;
  font-size: 15px;
  color: var(--text);
  background: #f8faf9;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background .15s;
}
.login-input:focus { border-color: var(--green); background: var(--white); }
.login-btn {
  width: 100%;
  height: 54px;
  background: #2D8659;
  border-radius: 16px;
  border: none;
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.1px;
  box-shadow: 0 4px 14px rgba(13,61,34,.25);
  transition: background .15s, opacity .15s, box-shadow .15s;
}
.login-btn:hover { background: #0d3d22; }
.login-btn:active { opacity: .88; box-shadow: 0 2px 8px rgba(13,61,34,.2); }
.login-btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.login-error {
  display: none;
  background: #fee2e2;
  color: #dc2626;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  text-align: center;
}
.login-error.visible { display: block; }
.login-forgot {
  font-size: 13px;
  color: var(--green);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  text-decoration: none;
}

/* ── LOADING SCREEN ── */
#screen-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0a3320 0%, #0d3d22 60%, #1a5c35 100%);
  gap: 28px;
}
.loading-logo {
  width: 200px;
  height: auto;
  display: block;
  filter: brightness(0) invert(1);
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid rgba(255,255,255,.2);
  border-top-color: var(--green-light);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
  gap: 12px;
  text-align: center;
}
.empty-state-icon {
  width: 56px;
  height: 56px;
  background: var(--green-bg);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.empty-state-title { font-size: 17px; font-weight: 600; color: var(--text); }
.empty-state-sub { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }

/* ── UPGRADE PROMPT ── */
.upgrade-card {
  margin: 0 16px 16px;
  background: var(--green-dark);
  border-radius: 16px;
  padding: 18px;
  color: var(--white);
}
.upgrade-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.upgrade-sub { font-size: 13px; color: rgba(255,255,255,.7); line-height: 1.4; margin-bottom: 14px; }
.upgrade-btn {
  background: var(--green-light);
  color: var(--green-dark);
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

/* ── COURSE VIEW ── */
.course-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── COURSE PROGRESS HEADER ── */
.course-progress-header {
  background: var(--white);
  padding: 12px 16px 14px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}

/* ── COURSE CARDS ── */
.course-card {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .1s;
}
.course-card:active:not(.locked) { opacity: .82; }
.course-card.locked { opacity: .55; cursor: default; }

/* ── LESSON ITEMS ── */
.lesson-item {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 0.5px solid var(--border-light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
  gap: 12px;
}
.lesson-item:last-child { border-bottom: none; }
.lesson-item:active { background: var(--gray-light); }
.lesson-item.lesson-next { background: rgba(45,134,89,.07); }
.lesson-title {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}
.lesson-title.lesson-done-title { color: var(--text-tertiary); }
.lesson-title.lesson-next-title { color: var(--green); font-weight: 600; }

/* ── UTILITIES ── */
.pb-safe { padding-bottom: calc(var(--tab-bar-height) + 16px); }
.mt-0 { margin-top: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
