:root {
  --bg: #F6F6F2;
  --bg-2: #EFEFE9;
  --surface: #FFFFFF;
  --ink: #12140F;
  --ink-2: #41463E;
  --ink-3: #838A80;
  --line: #E1E1D9;
  --accent: #C9F24A;
  --accent-ink: #161A0A;
  --dark: #12140F;
  --dark-2: #1B1E17;
  --green: #2E7D32;
  --red: #C62828;
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(18,20,15,.05), 0 12px 32px -18px rgba(18,20,15,.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; }
input, select { font-family: inherit; font-size: 16px; }
::selection { background: var(--accent); color: var(--accent-ink); }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: rgba(246,246,242,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }
.brand span { color: var(--ink-3); font-weight: 500; }
.top-right { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(201,242,74,.25); }
.pill.warn .dot { background: #FFB300; box-shadow: 0 0 0 3px rgba(255,179,0,.25); }
.btn-ghost {
  background: none; border: none; color: var(--ink-3); font-size: 13px;
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.btn-ghost:hover { color: var(--ink); background: var(--bg-2); }

#main { flex: 1; padding: 24px 20px 110px; }
.view-title { font-family: var(--font-display); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
.view-sub { color: var(--ink-2); margin: 0 0 22px; font-size: 15px; }

.field { margin-bottom: 14px; }
.field label, .field-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(201,242,74,.35); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn-primary {
  width: 100%; margin-top: 6px; padding: 14px;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 14px; font-weight: 700; font-size: 16px;
  cursor: pointer; transition: transform .08s ease, box-shadow .15s ease;
  box-shadow: var(--shadow);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .55; cursor: default; transform: none; }
.btn-dark { background: var(--dark); color: var(--bg); }
.form-msg { min-height: 22px; font-size: 13px; margin: 8px 0 0; }
.form-msg.err { color: var(--red); }
.form-msg.ok { color: var(--green); }
.dev-note { font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); background: var(--bg-2); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin-top: 8px; }

.arch-cards { display: grid; gap: 10px; margin-bottom: 16px; }
.arch-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; text-align: left; cursor: pointer; transition: border-color .12s ease, transform .12s ease;
}
.arch-card strong { font-family: var(--font-display); font-size: 16px; }
.arch-card span { font-size: 13px; color: var(--ink-3); }
.arch-card:hover { transform: translateY(-1px); }
.arch-card.active { border-color: var(--ink); background: var(--accent); }
.arch-card.active span { color: var(--accent-ink); }

.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 30;
  width: 100%; max-width: 520px;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; padding: 8px 0 6px;
  background: none; border: none; border-radius: 12px;
  font-size: 13px; font-weight: 600; color: var(--ink-3); cursor: pointer;
}
.tab.active { background: var(--bg-2); color: var(--ink); }
.tab.active::before { content: ""; display: block; width: 18px; height: 3px; border-radius: 2px; background: var(--accent); margin: 0 auto 3px; }

.today-card {
  background: var(--dark); color: var(--bg);
  border-radius: 24px; padding: 26px 22px; box-shadow: var(--shadow);
}
.today-kicker { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: rgba(246,246,242,.65); text-transform: uppercase; letter-spacing: .08em; }
.today-kind {
  display: inline-block; font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em;
  background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 3px 10px;
}
.today-kind.rest { background: transparent; border: 1px solid rgba(246,246,242,.4); color: rgba(246,246,242,.8); }
.today-title { font-family: var(--font-display); font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -0.015em; margin: 14px 0 8px; }
.today-meta { color: rgba(246,246,242,.7); font-size: 14px; }
.today-paces { display: grid; gap: 8px; margin-top: 18px; }
.pace-row { display: flex; justify-content: space-between; align-items: center; background: var(--dark-2); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.pace-row b { font-family: var(--font-mono); font-size: 16px; }
.today-vol { display: inline-block; margin-top: 14px; font-family: var(--font-mono); font-size: 12px; background: rgba(201,242,74,.12); color: var(--accent); border-radius: 999px; padding: 4px 12px; }
.today-actions { display: flex; gap: 10px; margin-top: 20px; }
.today-actions .btn-primary { margin: 0; flex: 1; }
.run-log { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.run-log input { background: var(--dark-2); border: 1px solid rgba(246,246,242,.15); color: var(--bg); }
.today-done {
  margin-top: 20px; display: flex; align-items: center; gap: 10px;
  background: rgba(201,242,74,.12); color: var(--accent); border-radius: 14px; padding: 14px 16px;
  font-weight: 600; font-size: 15px;
}
.today-done .check { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.today-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat-box b { display: block; font-family: var(--font-display); font-size: 22px; letter-spacing: -0.02em; }
.stat-box span { font-size: 12px; color: var(--ink-3); }
.stat-box.day1 { grid-column: 1 / -1; text-align: left; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; }
.stat-box.day1 b { font-size: 16px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 12px; }
.section-head h2 { font-family: var(--font-display); font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.section-head span { font-size: 13px; color: var(--ink-3); }

.weeks-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.week-cell {
  aspect-ratio: 1; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 13px; font-weight: 700; position: relative;
}
.week-cell small { font-size: 9px; font-weight: 600; color: var(--ink-3); font-family: var(--font-body); }
.week-cell.phase-0 { background: #E9F7BF; border-color: #D8EC9C; }
.week-cell.phase-1 { background: #D3EDE9; border-color: #B4DDD6; }
.week-cell.phase-2 { background: #FFE3C2; border-color: #FFD29B; }
.week-cell.now { outline: 2.5px solid var(--ink); outline-offset: 1.5px; }
.week-cell.done::after { content: ""; position: absolute; inset: 3px; border: 2px solid var(--ink); border-radius: 9px; opacity: .75; }
.week-cell.rest-week { opacity: .55; }
.week-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.week-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

.phase-cards { display: grid; gap: 10px; }
.phase-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.phase-card h3 { margin: 0 0 2px; font-family: var(--font-display); font-size: 15px; }
.phase-card .ph-theme { font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.phase-card ul { margin: 0; padding: 0; list-style: none; }
.phase-card li { font-size: 13.5px; color: var(--ink-2); padding: 5px 0; border-top: 1px dashed var(--line); display: flex; align-items: center; gap: 8px; }
.phase-card li.done-item::before { content: "✓"; color: var(--green); font-weight: 800; }
.phase-card li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.progress-line { margin-top: 14px; }
.pace-display {
  display: flex; justify-content: space-between; gap: 8px;
  background: var(--dark); color: var(--bg); border-radius: 14px; padding: 14px 16px;
}
.pace-display div { text-align: center; }
.pace-display b { display: block; font-family: var(--font-mono); font-size: 17px; }
.pace-display span { font-size: 11px; color: rgba(246,246,242,.6); text-transform: uppercase; letter-spacing: .06em; }

.rank-list { display: grid; gap: 8px; }
.rank-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.rank-pos { font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); width: 22px; text-align: center; }
.rank-name { flex: 1; font-weight: 600; font-size: 14.5px; }
.rank-name small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.rank-commit { font-family: var(--font-mono); font-size: 14px; font-weight: 700; }
.rank-row.you { background: var(--accent); border-color: var(--accent); }
.rank-row.you .rank-pos, .rank-row.you .rank-commit { color: var(--accent-ink); }
.rank-active { font-size: 11px; color: var(--green); font-weight: 700; }

.refer-box { margin-top: 16px; background: var(--dark); color: var(--bg); border-radius: 18px; padding: 18px; }
.refer-box h3 { font-family: var(--font-display); margin: 0 0 4px; font-size: 16px; }
.refer-box p { margin: 0 0 12px; font-size: 13px; color: rgba(246,246,242,.7); }
.refer-code { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--dark-2); border-radius: 12px; padding: 10px 14px; }
.refer-code code { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }
.refer-code button { background: var(--accent); color: var(--accent-ink); border: none; border-radius: 8px; padding: 6px 12px; font-weight: 700; font-size: 12px; cursor: pointer; }

.deck { position: relative; height: 400px; }
.match-card {
  position: absolute; inset: 0;
  background: var(--dark); color: var(--bg);
  border-radius: 24px; padding: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  touch-action: none; user-select: none;
}
.match-card .card-top { display: flex; justify-content: space-between; align-items: center; }
.match-card .card-top .status { font-size: 12px; color: var(--accent); font-weight: 700; }
.match-avatar {
  flex: 1; display: grid; place-items: center; margin: 8px 0;
  font-family: var(--font-display); font-size: 88px; font-weight: 700;
  background: radial-gradient(120% 120% at 30% 20%, #2A2E22 0%, var(--dark-2) 70%);
  border-radius: 18px; color: rgba(246,246,242,.9);
}
.match-meta h2 { font-family: var(--font-display); font-size: 24px; margin: 0 0 2px; letter-spacing: -0.01em; }
.match-meta .sub { color: rgba(246,246,242,.65); font-size: 13.5px; margin-bottom: 10px; }
.match-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 600; background: var(--dark-2); border: 1px solid rgba(246,246,242,.18); border-radius: 999px; padding: 4px 10px; }
.chip.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.stamp {
  position: absolute; top: 18px; right: 18px; z-index: 5;
  border: 3px solid var(--accent); color: var(--accent);
  font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: .12em;
  padding: 4px 14px; border-radius: 10px; transform: rotate(12deg);
  opacity: 0; pointer-events: none;
}
.stamp.nope { border-color: #FF6B6B; color: #FF6B6B; }
.swipe-btns { display: flex; gap: 12px; margin-top: 16px; }
.swipe-btns button { flex: 1; padding: 14px; border-radius: 14px; border: none; font-weight: 800; font-size: 17px; cursor: pointer; }
.btn-nope { background: var(--bg-2); color: var(--ink); }
.btn-like { background: var(--accent); color: var(--accent-ink); }
.deck-empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }
.deck-empty h2 { font-family: var(--font-display); color: var(--ink); margin: 0 0 8px; }

.matches-list { display: grid; gap: 8px; margin-top: 10px; }
.match-row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.match-row .m-av { width: 40px; height: 40px; border-radius: 50%; background: var(--dark); color: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; }
.match-row .m-name { flex: 1; font-weight: 600; font-size: 14.5px; }
.match-row .m-since { font-size: 12px; color: var(--ink-3); }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(18,20,15,.55); backdrop-filter: blur(4px); padding: 24px; }
.modal-card { background: var(--surface); border-radius: 22px; padding: 30px 24px; text-align: center; width: 100%; max-width: 360px; }
.modal-burst { font-family: var(--font-display); font-weight: 700; font-size: 34px; letter-spacing: .04em; background: var(--accent); color: var(--accent-ink); border-radius: 16px; padding: 12px 0; margin-bottom: 14px; }
.modal-card h2 { font-family: var(--font-display); margin: 0 0 4px; }
.modal-card p { color: var(--ink-2); font-size: 14px; margin: 0 0 18px; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--dark); color: var(--bg); font-size: 14px; font-weight: 600;
  border-radius: 999px; padding: 10px 18px; z-index: 60; box-shadow: var(--shadow);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (min-width: 700px) {
  #app { max-width: 560px; }
  .tabbar { max-width: 560px; border-radius: 16px 16px 0 0; }
}

/* ---------------- login brand ---------------- */
.login-box { max-width: 380px; margin: 6vh auto 0; }
.login-mark {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--dark); color: var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 24px;
  margin-bottom: 18px;
}
.login-trust { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 14px; font-size: 12.5px; color: var(--ink-3); }

/* ---------------- topbar gear ---------------- */
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
  transition: border-color .12s ease, color .12s ease;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------------- day progress ---------------- */
.day-progress { margin-top: 12px; }
.day-progress .dp-track { height: 6px; border-radius: 999px; background: rgba(246,246,242,.14); overflow: hidden; }
.day-progress .dp-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s ease; }
.day-progress .dp-label { margin-top: 6px; font-size: 11.5px; color: rgba(246,246,242,.55); letter-spacing: .04em; text-transform: uppercase; }

/* ---------------- run log labels ---------------- */
.run-log .rl-field { display: flex; flex-direction: column; gap: 4px; }
.run-log label { font-size: 11px; color: rgba(246,246,242,.55); text-transform: uppercase; letter-spacing: .06em; }
.run-log input { background: var(--dark-2); border: 1px solid rgba(246,246,242,.15); color: var(--bg); }
.run-log input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201,242,74,.2); }
.run-log .rl-hint { font-size: 12px; color: #FF8A8A; min-height: 16px; margin: 2px 0 -6px; }

/* ---------------- profile ---------------- */
.profile-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 14px; }
.profile-card h2 { font-family: var(--font-display); font-size: 16px; margin: 0 0 12px; letter-spacing: -0.01em; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--dark); color: var(--accent);
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 22px;
  flex-shrink: 0;
}
.profile-head .p-name { font-family: var(--font-display); font-size: 19px; font-weight: 700; margin: 0; }
.profile-head .p-meta { font-size: 13px; color: var(--ink-3); }
.profile-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.profile-row span { color: var(--ink-3); }
.profile-row b { font-weight: 600; text-align: right; }
.profile-actions { display: grid; gap: 10px; margin-top: 18px; }
.btn-danger {
  width: 100%; padding: 13px; border-radius: 14px;
  background: transparent; border: 1.5px solid var(--line); color: var(--red);
  font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn-danger:hover { border-color: var(--red); background: rgba(198,40,40,.04); }

/* ---------------- confirm modal ---------------- */
.modal-card-sm { max-width: 320px; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-row .btn-primary { margin: 0; }
.modal-card h2 { font-size: 19px; }

/* ---------------- empty state CTA ---------------- */
.deck-empty .btn-primary { max-width: 260px; margin: 14px auto 0; }
.crew-empty { text-align: center; padding: 40px 16px; }
.crew-empty .btn-primary { max-width: 260px; margin: 14px auto 0; }
.invite-copied { font-size: 12.5px; color: var(--green); min-height: 18px; margin-top: 8px; }

/* ---------------- focus & reduced motion ---------------- */
:focus-visible { outline: 3px solid rgba(201,242,74,.9); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
