/* ------------------------------------------------------------------
   styles.css — one file, no preprocessor.

   Theme is driven by [data-theme] on <html>; every colour is a custom
   property so light/dark is a single attribute swap.
------------------------------------------------------------------ */

:root {
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 940px;
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, 'Courier New', monospace;

  /* system bars: notch on top, gesture bar at the bottom */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* minimum comfortable touch target (Android asks for 48dp) */
  --tap: 44px;
}

html[data-theme='dark'] {
  --bg: #0c0e14;
  --bg-lift: #131722;
  --surface: #171c28;
  --surface-2: #1e2432;
  --border: #272e3d;
  --border-soft: #202736;
  --text: #e8ecf5;
  --text-dim: #98a2b8;
  --text-faint: #667089;
  --accent: #6c8cff;
  --accent-soft: rgba(108, 140, 255, 0.14);
  --accent-line: rgba(108, 140, 255, 0.4);
  --ok: #45d19a;
  --ok-soft: rgba(69, 209, 154, 0.13);
  --warn: #e8b347;
  --danger: #f0685f;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

html[data-theme='light'] {
  --bg: #f6f7fb;
  --bg-lift: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e0e4ef;
  --border-soft: #eaeef7;
  --text: #16192a;
  --text-dim: #5c6479;
  --text-faint: #8b93a8;
  --accent: #3b5bdb;
  --accent-soft: rgba(59, 91, 219, 0.09);
  --accent-line: rgba(59, 91, 219, 0.35);
  --ok: #14945f;
  --ok-soft: rgba(20, 148, 95, 0.1);
  --warn: #b57d0d;
  --danger: #d1382c;
  --shadow: 0 10px 30px rgba(20, 30, 70, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  /* Android: never let a wide child push the layout sideways */
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* subtle ambient wash behind everything */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(700px 380px at 12% -6%, var(--accent-soft), transparent 70%),
    radial-gradient(600px 320px at 92% 4%, var(--ok-soft), transparent 72%);
  pointer-events: none;
  z-index: 0;
}

h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }

/* ============================ TOPBAR ============================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + var(--safe-t)) calc(clamp(16px, 4vw, 34px) + var(--safe-r)) 14px calc(clamp(16px, 4vw, 34px) + var(--safe-l));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { font-size: 1.8rem; line-height: 1; }
.brand h1 { font-size: 1.12rem; font-weight: 700; }
.brand-sub { margin: 0; font-size: 0.79rem; color: var(--text-faint); }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.level-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s;
}
.icon-btn:hover { transform: translateY(-1px); border-color: var(--accent-line); }

/* ============================ LAYOUT ============================ */

.wrap {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(22px, 4vw, 40px) clamp(16px, 4vw, 26px) calc(90px + var(--safe-b));
}

.picker { display: grid; gap: 26px; animation: rise .35s ease both; }

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

.field { display: grid; gap: 11px; }
.field-label { font-size: 0.9rem; font-weight: 650; color: var(--text); }
.hint { font-weight: 400; color: var(--text-faint); font-size: 0.79rem; }

/* ============================ CHIPS ============================ */

.chips { display: flex; flex-wrap: wrap; gap: 9px; }

.chip {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
  transition: border-color .14s, background .14s, transform .14s, box-shadow .14s;
}
.chip:hover { transform: translateY(-1px); border-color: var(--accent-line); }
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.chip-emoji { font-size: 1.05rem; line-height: 1; }
.chip-body { display: grid; }
.chip-body strong { font-weight: 600; }
.chip-body small { color: var(--text-faint); font-size: 0.72rem; }

.chip.active .chip-body small { color: var(--text-dim); }

/* ============================ BUTTONS ============================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 19px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.89rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s, opacity .12s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--accent-line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme='light'] .btn.primary { color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }

.btn.ghost { background: transparent; }
.btn.big { padding: 14px 26px; font-size: 0.97rem; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.picker-actions {
  display: flex; flex-wrap: wrap; gap: 11px; align-items: center;
  padding-top: 6px;
}
.pool-note { margin: 0; font-size: 0.8rem; color: var(--text-faint); }

/* ============================ CHALLENGE ============================ */

.challenge { display: grid; gap: 22px; animation: rise .35s ease both; }

.challenge-head { display: grid; gap: 12px; }
.challenge-meta { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  font-size: 0.76rem;
  font-weight: 650;
  white-space: nowrap;
}
.badge.dim {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 500;
}

.challenge-head h2 { font-size: clamp(1.5rem, 4vw, 2.05rem); }
.mission { margin: 0; color: var(--text-dim); font-size: 1rem; max-width: 62ch; }

.tag {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  font-size: 0.75rem;
  color: var(--text-dim);
}
.stack-tag { font-family: var(--mono); font-size: 0.72rem; color: var(--accent); }

/* progress */
.progress-bar {
  height: 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width .3s ease;
}
.progress-label {
  margin: -12px 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* panels */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(275px, 100%), 1fr));
  gap: 15px;
}

.panel {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel.slim { box-shadow: none; }
.panel h3 { font-size: 0.92rem; margin-bottom: 13px; }

/* checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }

.check-item {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}
.check-item:hover { background: var(--surface-2); }

.check-box {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  margin-top: 1px;
  display: grid; place-items: center;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--bg-lift);
  color: transparent;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s, transform .14s;
}
.check-box:hover { border-color: var(--accent-line); transform: scale(1.06); }
.check-item.checked .check-box {
  background: var(--ok);
  border-color: var(--ok);
  color: #04150e;
}
.check-text { cursor: pointer; font-size: 0.9rem; }
.check-item.checked .check-text { color: var(--text-faint); text-decoration: line-through; }

/* live url */
.submit-row { display: grid; gap: 9px; }
.submit-input { display: flex; gap: 9px; flex-wrap: wrap; }
.submit-input input {
  flex: 1 1 300px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-lift);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* below 16px Android auto-zooms the whole page on focus */
}
.submit-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.challenge-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.complete-note { margin: 0; font-size: 0.83rem; color: var(--ok); min-height: 1.2em; }

/* ============================ DRAWER ============================ */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
}

.drawer {
  position: fixed; top: 0; right: 0; z-index: 50;
  width: min(430px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  padding: calc(22px + var(--safe-t)) calc(clamp(18px, 4vw, 26px) + var(--safe-r)) calc(60px + var(--safe-b)) clamp(18px, 4vw, 26px);
  background: var(--bg-lift);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .22s ease;
  display: grid;
  gap: 20px;
  align-content: start;
}
.drawer.open { transform: none; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { font-size: 1.15rem; }
.drawer-sub { font-size: 0.87rem; margin-top: 4px; color: var(--text-dim); }

.level-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid; gap: 11px;
}
.level-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.level-current { font-size: 1.05rem; font-weight: 700; }
.level-count {
  font-size: 1.6rem; font-weight: 800;
  font-family: var(--mono);
  color: var(--accent);
}
.muted { color: var(--text-faint); font-size: 0.83rem; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.stat {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}
.stat-num { font-size: 1.5rem; font-weight: 800; font-family: var(--mono); }
.stat-label { font-size: 0.75rem; color: var(--text-faint); }

.achievements { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.achievement {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: grid; gap: 3px;
  text-align: center;
  transition: border-color .14s, transform .14s;
}
.achievement.on { border-color: var(--accent-line); background: var(--accent-soft); }
.achievement.on:hover { transform: translateY(-2px); }
.achievement.off { opacity: .48; }
.ach-emoji { font-size: 1.35rem; }
.ach-label { font-size: 0.78rem; font-weight: 650; }
.ach-desc { font-size: 0.67rem; color: var(--text-faint); line-height: 1.35; }

.completed-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.completed-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 13px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.85rem;
}
.completed-list a { color: var(--accent); text-decoration: none; font-size: 0.78rem; }
.completed-list a:hover { text-decoration: underline; }

/* ============================ TOASTS ============================ */

.toasts {
  position: fixed;
  right: calc(18px + var(--safe-r));
  bottom: calc(18px + var(--safe-b));
  left: auto;
  z-index: 60;
  display: grid; gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  opacity: 0;
  transform: translateX(18px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast-emoji { font-size: 1.15rem; line-height: 1.2; }
.toast small { color: var(--text-dim); }

/* ============================ RESPONSIVE ============================ */

/* ---- ANDROID / MOBILE PASS -------------------------------------
   Three tiers: phones, small phones, and coarse-pointer tuning.
   The goal is comfortable thumbs, no stray horizontal scroll, and
   nothing hidden under the system bars. */

/* chips and buttons: comfortable to tap, comfortable to read */
.chip { min-height: var(--tap); }
.btn  { min-height: var(--tap); }
.icon-btn { min-width: var(--tap); min-height: var(--tap); }
.check-item { min-height: var(--tap); align-items: center; }
.check-box { width: 24px; height: 24px; }

/* a long chip label must not blow out the row */
.chip-body strong, .chip-body small { overflow-wrap: anywhere; }

/* any stray wide content scrolls inside itself instead of the page */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (hover: none) {
  /* touch devices: kill hover-only lifts that feel stuck after a tap */
  .chip:hover, .btn:hover:not(:disabled), .icon-btn:hover,
  .check-box:hover, .achievement.on:hover { transform: none; }
  /* and give every tap target a little more breathing room */
  .chip { padding: 12px 15px; }
}

@media (max-width: 720px) {
  .columns { grid-template-columns: 1fr; }
  .challenge-head h2 { font-size: clamp(1.4rem, 6vw, 1.9rem); }
  .mission { font-size: 0.95rem; }
  .stat-grid, .achievements { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 660px) {
  .brand-sub { display: none; }
  .brand h1 { font-size: 1rem; }
  .brand-mark { font-size: 1.5rem; }
  .topbar { gap: 10px; }
  .level-pill { padding: 6px 10px; font-size: 0.76rem; }
  .btn.big { width: 100%; }
  .picker-actions { flex-direction: column; align-items: stretch; }
  .challenge-actions .btn { flex: 1 1 100%; }
  .panel { padding: 16px; }
  .challenge-meta { gap: 6px; }
  .badge { font-size: 0.72rem; padding: 5px 10px; }
  /* the input row stacks, and the button goes full width under it */
  .submit-input { flex-direction: column; }
  .submit-input input { flex: 1 1 auto; width: 100%; }
  .submit-input .btn { width: 100%; }
  .drawer { width: 100%; border-left: none; }
  .toasts { left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); max-width: none; }
}

@media (max-width: 420px) {
  /* small Android phones: tighten everything, still tappable */
  .wrap { padding-left: calc(14px + var(--safe-l)); padding-right: calc(14px + var(--safe-r)); }
  .topbar { padding-left: calc(14px + var(--safe-l)); padding-right: calc(14px + var(--safe-r)); }
  .brand h1 { font-size: 0.94rem; }
  .brand-mark { font-size: 1.35rem; }
  .level-pill { display: none; }        /* level lives in the progress drawer anyway */
  .chip { font-size: 0.82rem; }
  .chip-body small { display: none; }   /* keep chip labels to one line */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 11px 8px; }
  .stat-num { font-size: 1.25rem; }
  .achievements { grid-template-columns: 1fr; }
  .completed-list li { flex-wrap: wrap; }
  .progress-label { font-size: 0.72rem; }
}

/* landscape phones have very little height: keep the drawer usable */
@media (max-height: 460px) and (orientation: landscape) {
  .topbar { position: static; }
  .drawer { padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

/* focus visibility, everywhere */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
