/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --gold: #C49B5E;
  --gold-light: #D4B06A;
  --gold-pale: #F0E6D2;
  --cream: #FAF7F2;
  --white: #FFFFFF;
  --ink: #2C1810;
  --ink-light: #5C4033;
  --ink-muted: #8B7D6B;
  --border: #E8DDD0;
  --shadow: 0 2px 12px rgba(44,24,16,0.08);
  --shadow-lg: 0 4px 24px rgba(44,24,16,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  --font-serif: Georgia, "Noto Serif SC", serif;
  --header-h: 56px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html { height: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== App Shell ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ===== Header ===== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--cream);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}
#app-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 2px;
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  min-width: 48px;
}
.header-right { justify-content: flex-end; }
.btn-icon {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  color: var(--ink-light);
}
.btn-icon:active { background: var(--gold-pale); }
#btn-back { font-size: 24px; color: var(--ink-light); }

/* ===== Main Content ===== */
#app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding-bottom: 8px;
}

/* ===== Bottom Nav ===== */
#app-nav {
  display: flex;
  align-items: center;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.nav-item {
  flex: 1;
  background: none;
  border: none;
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 8px 4px;
  transition: color 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font);
}
.nav-item.active { color: var(--gold); font-weight: 600; }
.nav-item:active { opacity: 0.6; }

/* ===== Shared Components ===== */

/* Cards */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 12px 16px;
}
.card-gold {
  background: linear-gradient(135deg, #C49B5E 0%, #D4B06A 100%);
  color: var(--white);
}
.card-answer {
  background: var(--gold-pale);
  border-left: 4px solid var(--gold);
  padding: 16px;
  margin: 12px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Section title */
.section-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 20px 16px 8px;
  padding: 0 4px;
  letter-spacing: 0.5px;
}
.section-title:first-child { margin-top: 12px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(196,155,94,0.3);
}
.btn-primary:active { box-shadow: 0 1px 4px rgba(196,155,94,0.2); }
.btn-secondary {
  background: var(--white);
  color: var(--gold);
  border: 2px solid var(--gold);
}
.btn-text {
  background: none;
  color: var(--gold);
  font-weight: 600;
  width: auto;
  padding: 8px 4px;
}
.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
}

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink-light);
}
.form-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  background: var(--white);
  color: var(--ink);
  transition: border-color 0.2s;
  outline: none;
}
.form-input:focus { border-color: var(--gold); }
.form-textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.6;
}
.form-select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  background: var(--white);
  color: var(--ink);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%238B7D6B'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
.form-select:focus { border-color: var(--gold); }

/* Option chips */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--white);
  color: var(--ink-light);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.chip:active { transform: scale(0.96); }
.chip.selected {
  border-color: var(--gold);
  background: var(--gold-pale);
  color: var(--ink);
  font-weight: 600;
}
.chip-full { width: 100%; justify-content: center; }

/* Checkbox / Radio styled */
.option-list { display: flex; flex-direction: column; gap: 8px; }
.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
  transition: all 0.2s;
}
.option-item:active { transform: scale(0.98); }
.option-item.selected {
  border-color: var(--gold);
  background: var(--gold-pale);
}
.option-item .indicator {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  transition: all 0.2s;
}
.option-item.selected .indicator {
  border-color: var(--gold);
  background: var(--gold);
}
.option-item.selected .indicator::after {
  content: '✓';
  color: white;
  font-size: 12px;
  font-weight: bold;
}
.option-item .option-text { flex: 1; font-size: 14px; line-height: 1.5; }
.option-item .option-label {
  font-weight: 600;
  display: block;
  margin-bottom: 2px;
}

/* ===== Home View ===== */
.home-hero {
  padding: 32px 24px;
  text-align: center;
  background: linear-gradient(180deg, var(--cream) 0%, #F5EDE0 100%);
}
.home-hero h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  line-height: 1.3;
  margin-bottom: 12px;
  color: var(--ink);
}
.home-hero p {
  font-size: 15px;
  color: var(--ink-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}
.home-hero .btn { max-width: 280px; margin: 0 auto; }

.home-steps {
  padding: 8px 16px 16px;
}
.step-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}
.step-card:active { transform: scale(0.98); box-shadow: var(--shadow-lg); }
.step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gold-pale);
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-card .step-info { flex: 1; }
.step-card .step-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}
.step-card .step-info p {
  font-size: 13px;
  color: var(--ink-muted);
}
.step-card .step-arrow { color: var(--gold); font-size: 18px; }

/* ===== Module View ===== */
.modules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px 16px;
}
.module-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.module-card:active { transform: scale(0.96); box-shadow: var(--shadow-lg); }
.module-card .module-icon { font-size: 28px; margin-bottom: 8px; }
.module-card .module-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.module-card .module-desc {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* ===== Wizard View ===== */
.wizard-progress {
  display: flex;
  gap: 6px;
  padding: 16px 16px 0;
  justify-content: center;
}
.wizard-step-dot {
  flex: 1;
  max-width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.3s;
}
.wizard-step-dot.active { background: var(--gold); }
.wizard-step-dot.done { background: var(--gold-light); }

.wizard-content {
  padding: 8px 16px 16px;
}
.wizard-content .card { margin: 8px 0; }

.wizard-actions {
  position: sticky;
  bottom: 0;
  background: var(--cream);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

/* ===== Result View ===== */
.result-section {
  margin-bottom: 24px;
}
.result-section h3 {
  font-family: var(--font-serif);
  color: var(--gold);
  font-size: 16px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--gold-pale);
}
.result-section p, .result-section li {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-light);
}
.result-section ul { padding-left: 20px; }
.result-section li { margin-bottom: 6px; }

/* Decision framework tables */
.decision-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.decision-table th, .decision-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.decision-table th {
  background: var(--gold-pale);
  font-weight: 600;
  color: var(--ink);
}
.decision-table td:first-child { font-weight: 600; color: var(--ink-light); }

/* ===== History View ===== */
.history-empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--ink-muted);
}
.history-empty .icon { font-size: 48px; margin-bottom: 12px; }
.history-empty p { font-size: 14px; line-height: 1.6; }

.history-item {
  padding: 16px;
  margin: 8px 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.history-item h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.history-item .meta {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.history-item .preview {
  font-size: 13px;
  color: var(--ink-light);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-item .actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ===== About View ===== */
.about-content {
  padding: 16px;
  text-align: center;
}
.about-content h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  margin: 16px 0 8px;
  color: var(--ink);
}
.about-content .subtitle {
  font-size: 14px;
  color: var(--ink-muted);
  margin-bottom: 16px;
}
.about-content .book-cover {
  width: 140px;
  height: 200px;
  background: linear-gradient(135deg, #C49B5E 0%, #D4B06A 100%);
  border-radius: 8px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  color: white;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  padding: 20px;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
}
.about-content p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-light);
  margin-bottom: 12px;
}
.about-content .pillars {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}
.pillar {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: left;
  border-left: 3px solid var(--gold);
}
.pillar h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.pillar p { font-size: 13px; margin: 0; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: var(--white);
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  white-space: nowrap;
  pointer-events: none;
  max-width: 90%;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* ===== Scrollbar ===== */
#app-content::-webkit-scrollbar { width: 4px; }
#app-content::-webkit-scrollbar-track { background: transparent; }
#app-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Responsive ===== */
@media (min-width: 480px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
@media (max-width: 360px) {
  .modules-grid { grid-template-columns: 1fr; }
  .home-hero h2 { font-size: 24px; }
}
