* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #4CAF50;
  --green-light: #e8f5e9;
  --purple: #9C27B0;
  --purple-light: #f3e5f5;
  --gray: #f5f5f5;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-secondary: #666;
  --white: #ffffff;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--gray);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

/* ---- Screens ---- */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
  padding-bottom: 60px;
}
.screen.active { display: flex; }

/* ---- Nav Bar ---- */
.nav-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-back {
  background: none;
  border: none;
  font-size: 17px;
  color: var(--green);
  cursor: pointer;
  padding: 0 12px 0 0;
  font-weight: 500;
}
.nav-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  margin-right: 60px;
}

/* ---- HOME ---- */
#screen-home {
  background: linear-gradient(160deg, #e8f5e9 0%, #f3e5f5 100%);
}
.home-header {
  text-align: center;
  padding: 60px 24px 32px;
}
.home-logo { font-size: 64px; margin-bottom: 12px; }
.home-title { font-size: 28px; font-weight: 700; color: var(--text); }
.home-tagline { font-size: 14px; color: var(--text-secondary); margin-top: 6px; }

.home-cards { padding: 0 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.test-card {
  background: var(--white);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  transition: transform 0.15s, box-shadow 0.15s;
}
.test-card:active { transform: scale(0.98); box-shadow: 0 1px 6px rgba(0,0,0,0.1); }
.test-card-icon { font-size: 40px; flex-shrink: 0; }
.test-card-body { flex: 1; }
.test-card-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.test-card-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.4; margin-bottom: 6px; }
.test-card-stats { font-size: 12px; color: var(--green); font-weight: 500; }
.test-card-arrow { font-size: 24px; color: var(--border); flex-shrink: 0; }

/* ---- GENDER ---- */
#screen-gender { background: var(--white); }
.gender-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px;
}
.gender-heading { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.gender-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 40px; }
.gender-options {
  display: flex;
  gap: 24px;
  margin-bottom: 40px;
}
.gender-card {
  width: 140px;
  height: 140px;
  border-radius: 20px;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.gender-card:active { transform: scale(0.96); }
.gender-card.selected {
  border-color: var(--green);
  background: var(--green-light);
}
.gender-emoji { font-size: 48px; margin-bottom: 8px; }
.gender-label { font-size: 16px; font-weight: 600; color: var(--text); }

/* ---- Buttons ---- */
.btn-primary {
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: 12px;
  padding: 14px 48px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  width: 100%;
  max-width: 320px;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):active { transform: scale(0.97); }

/* ---- TEST ---- */
#screen-test { background: var(--gray); }
.test-content { padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 0; }

.test-header-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 8px;
}
.test-header-text { font-size: 16px; font-weight: 700; color: rgba(0,0,0,0.8); }
.test-header-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.progress-label { font-size: 16px; font-weight: 700; white-space: nowrap; color: rgba(0,0,0,0.8); }
.progress-track {
  flex: 1;
  height: 5px;
  background: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 1%;
}
.progress-calibration { font-size: 14px; font-weight: 700; color: var(--green); white-space: nowrap; }

.question-text {
  font-size: 17px;
  font-weight: 500;
  color: rgba(0,0,0,0.85);
  line-height: 1.55;
  padding: 8px 4px;
  min-height: 60px;
  margin-bottom: 8px;
}

.options-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.option-item {
  background: var(--white);
  border: 1px solid #777;
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: default;
}
.option-letter {
  font-size: 18px;
  font-weight: 700;
  width: 22px;
  flex-shrink: 0;
  line-height: 1.4;
}
.opt-a { color: var(--green); }
.opt-b { color: var(--purple); }
.option-content { font-size: 17px; color: rgba(0,0,0,0.8); line-height: 1.4; }

/* 5-point selector */
.selector-section { padding: 8px 0 16px; }
.selector-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
}
.selector-end-label {
  font-size: 20px;
  font-weight: 700;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}
.label-a { color: var(--green); }
.label-b { color: var(--purple); }

.dots-container {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}
.dot-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}
.dot {
  border-radius: 50%;
  border: 1.5px solid #999;
  background: var(--white);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.dot:active { transform: scale(0.9); }
.dot-xl { width: 40px; height: 40px; }
.dot-lg { width: 32px; height: 32px; }
.dot-md { width: 25px; height: 25px; }

.dot.selected-a { background: var(--green); border-color: var(--green); }
.dot.selected-b { background: var(--purple); border-color: var(--purple); }
.dot.selected-mid { background: #666; border-color: #666; }
.dot.selected-a::after,
.dot.selected-b::after,
.dot.selected-mid::after {
  content: '✓';
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.selector-hint {
  display: flex;
  justify-content: space-between;
  padding: 6px 32px 0;
  font-size: 10px;
  color: #aaa;
}

.test-prev-wrap { display: flex; justify-content: center; padding-top: 8px; }
.btn-prev {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: underline;
  cursor: pointer;
  padding: 6px 12px;
}

/* ---- LOADING ---- */
#screen-loading {
  background: var(--white);
  align-items: center;
  justify-content: center;
}
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
}
.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--green-light);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 24px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.loading-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.loading-status { font-size: 16px; color: var(--green); font-weight: 500; margin-bottom: 28px; }
.loading-dots::after {
  content: '';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

.loading-steps { width: 100%; display: flex; flex-direction: column; gap: 16px; }
.loading-step { display: flex; align-items: center; gap: 12px; }
.step-icon { font-size: 20px; width: 28px; flex-shrink: 0; }
.step-label { font-size: 14px; width: 100px; flex-shrink: 0; color: var(--text); }
.step-bar-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.step-bar {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  width: 0%;
  transition: width 0.4s ease;
}

/* ---- RESULT ---- */
#screen-result {
  background: var(--white);
  overflow-y: auto;
}
.result-close-bar {
  display: flex;
  justify-content: flex-start;
  padding: 12px 16px 0;
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 5;
}
.btn-close-result {
  background: none;
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-header {
  text-align: center;
  padding: 12px 16px 0;
}
.result-header-title { font-size: 18px; font-weight: 700; }
.result-header-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.result-type-card {
  margin: 20px 16px;
  background: linear-gradient(135deg, var(--green-light), var(--purple-light));
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
}
.result-type-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.result-type-code {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--green), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  margin-bottom: 6px;
}
.result-type-name { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.result-type-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }

/* Dimension bars */
.result-dimensions { padding: 0 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.dim-row { display: flex; align-items: center; gap: 10px; }
.dim-label-left { font-size: 13px; font-weight: 600; width: 52px; text-align: right; color: var(--green); flex-shrink: 0; }
.dim-label-right { font-size: 13px; font-weight: 600; width: 52px; text-align: left; color: var(--purple); flex-shrink: 0; }
.dim-track {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
  display: flex;
}
.dim-bar-left {
  height: 100%;
  background: var(--green);
  transition: width 0.8s ease;
}
.dim-bar-right {
  height: 100%;
  background: var(--purple);
  transition: width 0.8s ease;
}

/* Result tabs */
.result-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 0;
  position: sticky;
  top: 44px;
  background: var(--white);
  z-index: 4;
}
.result-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s, border-color 0.2s;
}
.result-tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
  font-weight: 700;
}

.result-tab-content { padding: 20px 16px; }
.result-tab-content.hidden { display: none; }

.result-section { margin-bottom: 24px; }
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
  padding-left: 10px;
  border-left: 3px solid var(--green);
}
.traits-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.traits-list li {
  font-size: 14px;
  color: var(--text);
  padding: 10px 14px;
  background: var(--gray);
  border-radius: 8px;
  line-height: 1.5;
}
.traits-strength li { background: var(--green-light); }
.traits-weakness li { background: #fff3e0; }

.result-detail-text {
  font-size: 14px;
  color: #444;
  line-height: 1.8;
  background: var(--gray);
  padding: 16px;
  border-radius: 10px;
}

.partners-list { display: flex; gap: 10px; flex-wrap: wrap; }
.partner-badge {
  background: var(--purple-light);
  color: var(--purple);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 16px;
  font-weight: 700;
}

.career-category { margin-bottom: 16px; }
.career-category-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.career-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.career-tag {
  background: var(--green-light);
  color: #2e7d32;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
}

.result-actions { padding: 8px 16px 40px; display: flex; justify-content: center; }

/* ---- Ref intro card ---- */
.ref-intro-card {
  background: linear-gradient(135deg, #e8f5e9, #e3f2fd);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 4px;
}
.ref-intro-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.ref-intro-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; line-height: 1.5; }
.name-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}
.name-input:focus { border-color: var(--green); }

/* ---- Submit status ---- */
.submit-status {
  margin: 0 16px 12px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
}
.submit-ok { background: var(--green-light); color: #2e7d32; }
.submit-err { background: #fff3e0; color: #e65100; }

/* ---- Responsive max-width ---- */
@media (min-width: 600px) {
  .screen { align-items: center; }
  .nav-bar, .test-content, .gender-content,
  .result-close-bar, .result-header, .result-type-card,
  .result-dimensions, .result-tabs, .result-tab-content,
  .result-actions, .home-header, .home-cards {
    width: 100%;
    max-width: 480px;
  }
  .result-type-card { margin-left: auto; margin-right: auto; }
  .result-tabs { max-width: 480px; margin: 0 auto; }
}

/* ---- Lang bar & picker ---- */
.lang-bar {
  position: relative;
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 0;
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-primary);
}
.lang-btn:active { background: var(--green-light); }
.lang-picker {
  position: absolute;
  top: 44px;
  right: 16px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.13);
  z-index: 100;
  max-height: 320px;
  overflow-y: auto;
  min-width: 180px;
}
.lang-picker.hidden { display: none; }
.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.lang-option:hover { background: var(--green-light); }
.lang-option.active { background: var(--green-light); font-weight: 600; color: var(--green); }
.lang-option-flag { font-size: 18px; }
.lang-option-name { flex: 1; }

/* ---- Invalid screen ---- */
.screen#screen-invalid {
  justify-content: center;
  align-items: center;
}
.invalid-content {
  text-align: center;
  padding: 40px 32px;
  max-width: 320px;
}
.invalid-icon { font-size: 56px; margin-bottom: 16px; }
.invalid-title { font-size: 20px; font-weight: 700; margin-bottom: 10px; }
.invalid-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }

/* ---- App footer ---- */
#app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom, 0);
  background: linear-gradient(to top, rgba(255,255,255,0.97) 80%, rgba(255,255,255,0));
  pointer-events: none;
}
#footer-app-link {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 10px;
  padding: 8px 18px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.10);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
#footer-app-link:hover, #footer-app-link:active {
  background: var(--green-light);
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
}
.footer-icon { font-size: 16px; }
.footer-store-badge {
  background: var(--green);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 2px;
}

/* ---- Already done banner ---- */
.result-already-done {
  display: none;
  margin: 0 16px 12px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--green-light);
  color: #2e7d32;
  font-size: 14px;
  text-align: center;
  font-weight: 500;
}
