/* ===== Design tokens ===== */
:root {
  --bg: #faf8f5;
  --bg-elevated: #f2efe9;
  --bg-card: #ffffff;
  --text: #201f2b;
  --text-muted: #6c6b7a;
  --accent: #ff6b4a;
  --accent-deep: #e2492f;
  --accent-2: #ffb020;
  --accent-contrast: #201f2b;
  --success: #16a34a;
  --danger: #e5484d;
  --border: rgba(32, 31, 43, 0.1);
  --shadow-sm: 0 2px 6px rgba(32, 31, 43, 0.05);
  --shadow-md: 0 12px 32px rgba(32, 31, 43, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --spin-dock-height: 96px;
  --font-display: "Bricolage Grotesque", -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  width: 100%;
  overflow-x: hidden;
}

button {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* ===== App shell ===== */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--spin-dock-height) + var(--safe-bottom) + 12px);
}

.app-header {
  padding: calc(14px + var(--safe-top)) 20px 12px;
  text-align: center;
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 420px;
  margin: 0 auto 8px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 30px;
}

.account-btn--signed-in {
  border-color: var(--accent);
  color: var(--accent);
}

.app-tagline {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* ===== Mode selector ===== */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
}

.mode-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.mode-btn-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.mode-btn-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.mode-btn--active {
  border-color: var(--accent);
  background: rgba(255, 107, 74, 0.08);
}

.mode-btn--active .mode-btn-title {
  color: var(--accent);
}

/* ===== Main content ===== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px 0;
  gap: 18px;
}

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

.wheel-wrap {
  position: relative;
  width: min(92vw, 440px, 62dvh);
  aspect-ratio: 1 / 1;
  margin: 4px auto 0;
}

.wheel-svg {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 50% 50%;
  transition: transform 4.2s cubic-bezier(0.12, 0.72, 0.1, 1);
  filter: drop-shadow(0 14px 30px rgba(32, 31, 43, 0.18));
}

.wheel-slice {
  transition: opacity 0.25s ease;
}

.wheel-slice--done {
  opacity: 0.28;
}

.slice-number {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  fill: rgba(255, 255, 255, 0.8);
  pointer-events: none;
  user-select: none;
}

.category-label {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.01em;
  fill: rgba(20, 19, 26, 0.85);
  pointer-events: none;
  user-select: none;
}

.wheel-hub {
  fill: var(--bg-card);
  stroke: rgba(32, 31, 43, 0.1);
  stroke-width: 2;
}

.wheel-center-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  pointer-events: none;
}

.wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 22px solid var(--accent-2);
  z-index: 5;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.4));
}

.wheel-pointer::after {
  content: "";
  position: absolute;
  top: -22px;
  left: -14px;
  width: 28px;
  height: 10px;
}

.empty-state {
  margin-top: 14px;
  padding: 12px 16px;
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.35);
  border-radius: var(--radius-sm);
  color: #b91c1c;
  font-size: 14px;
  text-align: center;
  max-width: 420px;
}

/* ===== Progress ===== */
.progress-block {
  width: 100%;
  max-width: 420px;
}

.progress-text {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 2px;
}

.progress-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.progress-xp,
.progress-streak {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
}

.progress-xp {
  color: #b8790f;
}

.progress-streak {
  color: #d64545;
}

.icon.icon--star {
  color: var(--accent-2);
}

.icon.icon--flame {
  color: #ef5350;
}

.progress-track {
  height: 10px;
  background: var(--bg-card);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease;
  border-radius: 999px;
}

.progress-toggle {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  min-height: 44px;
}

.progress-by-category {
  display: none;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.progress-by-category.open {
  display: flex;
}

.category-progress-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-progress-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.category-progress-label span:nth-child(2) {
  color: var(--text);
  font-weight: 600;
  flex: 1;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.category-progress-count {
  font-variant-numeric: tabular-nums;
}

.category-progress-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.category-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ===== Result panel ===== */
.result-panel {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  animation: resultIn 0.35s ease;
  box-shadow: var(--shadow-md);
}

@keyframes resultIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-category {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--category-color, var(--accent));
  background: color-mix(in srgb, var(--category-color, var(--accent)) 18%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.result-name {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 800;
  margin: 0 0 8px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.result-description {
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
  margin: 0 0 14px;
}

/* ===== Meta chips (time / difficulty / xp) ===== */
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

/* One neutral tag style for all three chips — difficulty is conveyed by a
   small colored dot, not a differently-tinted badge for every state. */
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.difficulty-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--success);
}

.meta-chip--easy .difficulty-dot {
  background: var(--success);
}

.meta-chip--medium .difficulty-dot {
  background: #c9820b;
}

.meta-chip--hard .difficulty-dot {
  background: var(--danger);
}

/* ===== Show Me How button ===== */
.btn--show-how {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 52px;
  background: var(--bg-card);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

.show-how-chevron {
  transition: transform 0.2s ease;
}

.btn--show-how-expanded .show-how-chevron {
  transform: rotate(180deg);
}

/* ===== Lesson (expanded content) ===== */
.lesson {
  margin-top: 16px;
  padding-top: 4px;
  animation: resultIn 0.3s ease;
}

.lesson-section {
  margin-bottom: 20px;
}

.lesson-section:last-child {
  margin-bottom: 8px;
}

.lesson-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.lesson-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.lesson-text {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}

.lesson-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lesson-steps li {
  counter-increment: step;
  display: flex;
  gap: 10px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
}

.lesson-steps li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lesson-tips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lesson-tips li {
  display: flex;
  gap: 8px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
  padding: 10px 12px;
  background: rgba(255, 176, 32, 0.07);
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius-sm);
}

.lesson-tips li::before {
  content: "";
  width: 5px;
  height: 5px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  flex-shrink: 0;
}

/* ===== Related challenge chips ===== */
.related-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-width: 100%;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--category-color, var(--accent));
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.related-chip:active {
  transform: scale(0.98);
}

.related-chip-category {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--category-color, var(--accent));
}

.related-chip-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

/* ===== Resources ===== */
.resource-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.resource-item:not(.resource-item--static):active {
  transform: scale(0.98);
}

.resource-item--static {
  opacity: 0.7;
}

.resource-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
}

.resource-label-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.resource-type {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.resource-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.resource-arrow {
  font-size: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.resource-soon {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  flex: 1 1 auto;
  min-height: 46px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.1s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.footer-actions {
  padding: 4px 0 8px;
}

/* ===== Spin dock (fixed, thumb zone) ===== */
.spin-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 20px calc(14px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent 0%, var(--bg) 26%);
  display: flex;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

.spin-btn {
  pointer-events: auto;
  width: min(100%, 420px);
  min-height: 60px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(226, 73, 47, 0.32);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease, background 0.12s ease;
}

.spin-btn:active {
  transform: scale(0.96);
  background: var(--accent-deep);
  box-shadow: 0 4px 14px rgba(226, 73, 47, 0.28);
}

.spin-btn--spinning {
  opacity: 0.75;
}

.spin-btn--disabled,
.spin-btn:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  box-shadow: none;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 26, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 70;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 22px 22px calc(22px + var(--safe-bottom));
  width: 100%;
  max-width: 420px;
  box-shadow: 0 -8px 30px rgba(32, 31, 43, 0.12);
}

/* On wider screens the sheet no longer touches the true edges, so give it
   all four corners back and a floating shadow instead of a top-only one. */
@media (min-width: 480px) {
  .modal-overlay {
    padding: 20px;
  }

  .modal-card {
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-md);
  }
}

.modal-card h3 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.modal-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
}

.modal-actions--stacked {
  flex-direction: column;
}

/* ===== Auth modal ===== */
.auth-card {
  position: relative;
  padding-top: 18px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.auth-view {
  padding-right: 26px;
}

.auth-subtitle {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 18px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  border-radius: calc(var(--radius-sm) - 4px);
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.auth-tab--active {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.auth-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 12px 0 6px;
}

.auth-label:first-of-type {
  margin-top: 0;
}

.auth-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(229, 72, 77, 0.1);
  border: 1px solid rgba(229, 72, 77, 0.3);
  color: #c62828;
  font-size: 13px;
  line-height: 1.5;
}

.auth-message {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(22, 163, 74, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.3);
  color: #15803d;
  font-size: 13px;
  line-height: 1.5;
}

.auth-submit {
  width: 100%;
  margin-top: 16px;
}

.auth-link {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 8px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.auth-link--muted {
  color: var(--text-muted);
}

.auth-account-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-synced-note {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 4px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--spin-dock-height) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Larger phones / small tablets ===== */
@media (min-width: 480px) {
  .app-tagline {
    font-size: 28px;
  }
}

/* ===== Desktop ===== */
@media (min-width: 860px) {
  :root {
    --spin-dock-height: 0px;
  }

  .app {
    padding-bottom: 40px;
  }

  .app-header {
    padding-top: 32px;
  }

  .app-tagline {
    font-size: 32px;
  }

  .app-main {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 20px;
  }

  .wheel-wrap {
    width: min(56vw, 460px);
  }

  .spin-dock {
    position: static;
    background: none;
    padding: 4px 0 0;
  }

  .spin-btn {
    box-shadow: 0 10px 24px rgba(226, 73, 47, 0.24);
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .wheel-svg {
    transition-duration: 0.6s;
  }
}
