/* ============================================
   JB Challenge Tracker — Aug 3 – Sep 2 2026
   ============================================ */

:root {
  --bg: #0f0e17;
  --bg-soft: #1a1825;
  --surface: #232032;
  --surface-2: #2c2940;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f2ff;
  --muted: #a89fc0;
  --jasmine: #f472b6;
  --jasmine-soft: rgba(244, 114, 182, 0.15);
  --jasmine-glow: rgba(244, 114, 182, 0.35);
  --bernard: #38bdf8;
  --bernard-soft: rgba(56, 189, 248, 0.15);
  --bernard-glow: rgba(56, 189, 248, 0.35);
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --reward: #fcd34d;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "SF Mono", "Menlo", ui-monospace, monospace;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  background-image:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(244, 114, 182, 0.18), transparent),
    radial-gradient(ellipse 70% 40% at 90% 0%, rgba(56, 189, 248, 0.15), transparent),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(167, 139, 250, 0.08), transparent);
  background-attachment: fixed;
}

/* ----- Header ----- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  background: rgba(15, 14, 23, 0.75);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--jasmine), var(--bernard));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: -0.02em;
  box-shadow: 0 0 24px var(--jasmine-glow);
}

.logo h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo .period {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.badge.edit {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
}

.badge.view {
  border-color: var(--border);
  color: var(--muted);
}

/* ----- Buttons ----- */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn:not(:disabled):active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #a78bfa, #818cf8);
  color: #fff;
  box-shadow: 0 4px 16px rgba(129, 140, 248, 0.35);
}

.btn-primary:not(:disabled):hover {
  box-shadow: 0 6px 22px rgba(129, 140, 248, 0.5);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:not(:disabled):hover {
  background: var(--surface);
  color: var(--text);
}

.btn-save {
  background: linear-gradient(135deg, #4ade80, #22c55e);
  color: #052e16;
  box-shadow: 0 4px 16px rgba(74, 222, 128, 0.3);
}

.btn-sm {
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
}

/* ----- Main layout ----- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.hero {
  text-align: center;
  margin-bottom: 1.75rem;
  padding: 1.5rem 1rem 0.5rem;
}

.hero h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
  background: linear-gradient(90deg, var(--jasmine), #c4b5fd, var(--bernard));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto;
  font-size: 0.95rem;
}

.deal-banner {
  margin: 1.25rem auto 0;
  max-width: 640px;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--jasmine-soft), var(--bernard-soft));
  border: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text);
}

.deal-banner strong {
  color: var(--reward);
}

/* ----- Person tabs ----- */
.person-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.person-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.2s ease;
}

.person-tab:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.person-tab.active.jasmine {
  border-color: var(--jasmine);
  background: var(--jasmine-soft);
  box-shadow: 0 0 0 1px var(--jasmine), 0 8px 28px var(--jasmine-glow);
  color: var(--text);
}

.person-tab.active.bernard {
  border-color: var(--bernard);
  background: var(--bernard-soft);
  box-shadow: 0 0 0 1px var(--bernard), 0 8px 28px var(--bernard-glow);
  color: var(--text);
}

.person-tab .name {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.person-tab.active.jasmine .name {
  color: var(--jasmine);
}

.person-tab.active.bernard .name {
  color: var(--bernard);
}

.person-tab .sub {
  font-size: 0.78rem;
  opacity: 0.85;
}

/* ----- Overall progress strip ----- */
.overall-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 700px) {
  .overall-strip {
    grid-template-columns: 1fr;
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-card .bar {
  margin-top: 0.65rem;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.stat-card .bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.stat-card.ok .value {
  color: var(--success);
}

.stat-card.mid .value {
  color: var(--warning);
}

.stat-card.low .value {
  color: var(--muted);
}

/* ----- Task cards ----- */
.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.task-card.done {
  border-color: rgba(74, 222, 128, 0.35);
}

.task-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.task-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  flex-shrink: 0;
}

.panel-jasmine .task-num {
  background: var(--jasmine-soft);
  color: var(--jasmine);
}

.panel-bernard .task-num {
  background: var(--bernard-soft);
  color: var(--bernard);
}

.task-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  flex: 1;
  min-width: 200px;
}

.task-title .en {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 0.25rem;
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.progress-pill.met {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.4);
  color: var(--success);
}

.reward {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(252, 211, 77, 0.08);
  border: 1px solid rgba(252, 211, 77, 0.2);
  font-size: 0.85rem;
  color: var(--reward);
  margin-bottom: 1rem;
}

.reward .icon {
  font-size: 1.1rem;
}

/* ----- Day calendar grid ----- */
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.cal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.dot.done {
  background: var(--success);
}

.dot.miss {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.dot.today {
  outline: 2px solid var(--warning);
  outline-offset: 1px;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 0.45rem;
}

.day-cell {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 10px;
  padding: 0.45rem 0.2rem;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: default;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-height: 52px;
  user-select: none;
}

.day-cell .md {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.day-cell .wd {
  font-size: 0.62rem;
  opacity: 0.7;
  text-transform: uppercase;
}

.day-cell.checked {
  background: rgba(74, 222, 128, 0.2);
  border-color: rgba(74, 222, 128, 0.5);
  color: var(--success);
}

.day-cell.partial {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.45);
  color: var(--warning);
}

.day-cell.study-cell {
  min-height: 58px;
}

.day-cell.study-cell .count {
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: inherit;
}

.day-cell.study-cell.checked .count {
  color: var(--success);
}

.day-cell.study-cell.partial .count {
  color: var(--warning);
}

.day-cell.today {
  box-shadow: 0 0 0 2px var(--warning);
}

/* Future days: dimmed, locked — click shows "come back" toast */
.day-cell.future {
  opacity: 0.4;
  cursor: pointer;
}

body.edit-mode .day-cell:not(.future) {
  cursor: pointer;
}

body.edit-mode .day-cell:not(.future):hover {
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.04);
}

body.edit-mode .day-cell.future:hover {
  border-color: rgba(251, 191, 36, 0.45);
}

body.edit-mode .day-cell.checked:not(.future):hover {
  background: rgba(74, 222, 128, 0.3);
}

/* Pull-up number cells */
.day-cell.pullup {
  min-height: 58px;
}

.day-cell.pullup .count {
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.day-cell.pullup.met .count {
  color: var(--success);
}

.day-cell.pullup input {
  width: 100%;
  max-width: 40px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  text-align: center;
  outline: none;
  appearance: textfield;
  -moz-appearance: textfield;
}

.day-cell.pullup input::-webkit-outer-spin-button,
.day-cell.pullup input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

body:not(.edit-mode) .day-cell.pullup input {
  pointer-events: none;
}

/* ----- Toggle / notes ----- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
}

.toggle-row label {
  font-weight: 600;
  font-size: 0.9rem;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  background: #3f3a55;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--success);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

body:not(.edit-mode) .switch .slider {
  cursor: default;
  opacity: 0.9;
}

body:not(.edit-mode) .switch input {
  pointer-events: none;
}

.field {
  margin-bottom: 0.75rem;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.field input[type="text"],
.field textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.65rem 0.85rem;
  resize: vertical;
  transition: border-color 0.15s;
}

.field input[type="text"]:focus,
.field textarea:focus {
  outline: none;
  border-color: #818cf8;
}

body:not(.edit-mode) .field input,
body:not(.edit-mode) .field textarea {
  pointer-events: none;
  opacity: 0.9;
}

.book-block {
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.book-block h4 {
  font-size: 0.85rem;
  color: var(--bernard);
  margin-bottom: 0.65rem;
}

/* ----- Footer ----- */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.updated {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}

.modal h3 {
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}

.modal p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 1.1rem;
}

.modal input[type="password"] {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.modal input[type="password"]:focus {
  outline: none;
  border-color: #818cf8;
}

.modal-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1.2em;
  margin-bottom: 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ----- Toast ----- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 300;
  box-shadow: var(--shadow);
  transition: transform 0.3s ease;
  max-width: 90vw;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: rgba(74, 222, 128, 0.45);
  background: #14532d;
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.45);
  background: #7f1d1d;
}

/* ----- Loading ----- */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 500;
  transition: opacity 0.3s;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface-2);
  border-top-color: #818cf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ----- Month labels ----- */
.month-label {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
}

.month-label:first-child {
  margin-top: 0;
  padding-top: 0;
}

/* ----- Sticky save bar ----- */
.save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.85rem 1.25rem;
  background: rgba(15, 14, 23, 0.9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: none;
  z-index: 90;
  justify-content: center;
  gap: 0.75rem;
  align-items: center;
}

body.edit-mode .save-bar {
  display: flex;
}

body.edit-mode main {
  padding-bottom: 5.5rem;
}

.save-bar .hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.save-bar .hint.dirty {
  color: var(--warning);
}

/* ----- Responsive ----- */
@media (max-width: 560px) {
  .person-tabs {
    grid-template-columns: 1fr;
  }

  .day-grid {
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  }

  .header-inner {
    justify-content: center;
  }

  .logo h1 {
    font-size: 1rem;
  }
}
