:root {
  --blue: #1a73e8;
  --blue-dark: #0d47a1;
  --blue-light: #e8f0fe;
  --gray: #9e9e9e;
  --gray-light: #f5f5f5;
  --white: #ffffff;
  --text: #212121;
  --text-muted: #757575;
  --success: #34a853;
  --danger: #ea4335;
  --shadow: 0 2px 12px rgba(0,0,0,0.12);
  --radius: 16px;
  --node-size: 72px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f0f4ff;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
.app-header {
  background: var(--blue);
  color: var(--white);
  padding: 16px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.app-title { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.5px; }

.mode-toggle {
  background: rgba(255,255,255,0.2);
  color: var(--white);
  border: 2px solid rgba(255,255,255,0.5);
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, border-color 0.2s;
}
.mode-toggle:hover { background: rgba(255,255,255,0.3); border-color: rgba(255,255,255,0.8); }
.mode-toggle.active { background: var(--white); color: var(--blue); border-color: var(--white); }

/* ── Path ── */
.path-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 16px 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.section-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.section-title {
  background: var(--blue);
  color: var(--white);
  padding: 8px 24px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin: 24px 0 8px;
  text-align: center;
}

.path-line {
  width: 4px;
  height: 40px;
  background: var(--gray);
  border-radius: 2px;
}

.path-line.done { background: var(--blue); }

.node-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.node {
  width: var(--node-size);
  height: var(--node-size);
  border-radius: 50%;
  border: 4px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.node-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  max-width: 110px;
  margin-top: 6px;
  line-height: 1.3;
}

.node.locked {
  background: var(--gray-light);
  border-color: var(--gray);
  color: var(--gray);
  cursor: not-allowed;
}

.node.active {
  background: var(--white);
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 0 0 6px var(--blue-light), var(--shadow);
  animation: pulse 2s infinite;
}

.node.completed {
  background: var(--blue);
  border-color: var(--blue-dark);
  color: var(--white);
}

.node.active:hover { transform: scale(1.08); }
.node.completed:hover { transform: scale(1.05); background: var(--blue-dark); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 6px var(--blue-light), var(--shadow); }
  50%       { box-shadow: 0 0 0 14px rgba(26,115,232,0.12), var(--shadow); }
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Modal Overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid #eee;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  padding-right: 12px;
}

.quiz-progress { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--gray-light); }

.lives-bar {
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  justify-content: center;
  font-size: 1.4rem;
}

.modal-body {
  padding: 20px;
  flex: 1;
  line-height: 1.7;
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--blue);
  color: var(--white);
  border: none;
  padding: 12px 28px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { background: var(--gray); cursor: not-allowed; }

/* ── Quiz ── */
.quiz-question {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.5;
}

.quiz-options { display: flex; flex-direction: column; gap: 10px; }

.quiz-option {
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  background: var(--white);
  width: 100%;
  font-family: inherit;
}
.quiz-option:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-light); }
.quiz-option.selected { border-color: var(--blue); background: var(--blue-light); }
.quiz-option.correct  { border-color: var(--success); background: #e6f4ea; color: var(--success); font-weight: 600; }
.quiz-option.wrong    { border-color: var(--danger);  background: #fce8e6; color: var(--danger); }
.quiz-option:disabled { cursor: not-allowed; }

.fill-blank-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
  margin-top: 8px;
  font-family: inherit;
  /* Prevent iOS auto-zoom (requires font-size >= 16px) */
  font-size: max(1rem, 16px);
}
.fill-blank-input:focus   { border-color: var(--blue); }
.fill-blank-input.correct { border-color: var(--success); background: #e6f4ea; }
.fill-blank-input.wrong   { border-color: var(--danger);  background: #fce8e6; }

/* ── Celebration / Fail Modal ── */
.celebration-modal {
  text-align: center;
  padding: 40px 20px;
  align-items: center;
}
.celebration-icon { font-size: 3rem; margin-bottom: 12px; }
.celebration-modal h2 { font-size: 1.5rem; margin-bottom: 8px; }
.celebration-modal p  { color: var(--text-muted); margin-bottom: 20px; }

/* ── Feedback Toast ── */
.feedback {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--white);
  z-index: 200;
  animation: fadeUp 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.feedback.correct { background: var(--success); }
.feedback.wrong   { background: var(--danger); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .app-title { font-size: 1.25rem; }

  /* Bottom-sheet modal on mobile */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    animation: slideUp 0.25s ease;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Sticky footer so button never scrolls off screen */
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--white);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  /* Full-width button on mobile */
  .modal-footer .btn-primary,
  .celebration-modal .btn-primary {
    width: 100%;
    text-align: center;
  }

  /* Larger touch targets for quiz options */
  .quiz-option { padding: 14px 16px; min-height: 48px; }

  /* Slightly smaller nodes on very narrow screens */
  :root { --node-size: 64px; }

  .node { font-size: 1.4rem; }

  .node-label { font-size: 0.7rem; max-width: 90px; }

  .section-title { font-size: 0.8rem; padding: 7px 18px; }

  .path-container { padding: 20px 16px 80px; }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .path-container {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}
