:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --text: #eceef1;
  --muted: #9aa1ac;
  --accent: #4ade80;
  --accent-dim: #22c55e33;
  --danger: #f87171;
  --border: #2a2e37;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1a1d24;
    --muted: #6b7280;
    --accent: #16a34a;
    --accent-dim: #16a34a22;
    --danger: #dc2626;
    --border: #e5e7eb;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timer {
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 12px;
}

.milestones {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.milestone {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  color: var(--muted);
}

.milestone.hit {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
}

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

.btn-primary {
  background: var(--accent);
  color: #06210f;
  font-weight: 600;
}

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

.total-row {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.total-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.event-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.event-row:last-child { border-bottom: none; }

.event-time { color: var(--muted); width: 80px; }
.event-name { flex: 1; }
.event-mg { font-weight: 600; }

.presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.preset-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
}

.log-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.log-form input, .log-form select {
  grid-column: span 2;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.log-form button {
  grid-column: span 2;
}

/* Prayer lock overlay */
#lock-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: 24px;
  z-index: 100;
}

#lock-overlay h1 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

#lock-overlay p {
  color: var(--muted);
  margin-bottom: 24px;
  max-width: 340px;
}

.hidden { display: none !important; }

/* Chat panel */
.chat-msg {
  display: flex;
  margin-bottom: 12px;
}

.chat-msg.user { justify-content: flex-end; }
.chat-msg.marcus { justify-content: flex-start; }

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.4;
}

.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: #06210f;
  border-bottom-right-radius: 4px;
}

.chat-msg.marcus .chat-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.voice-bars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 26px;
}

.voice-bars span {
  width: 3px;
  height: 4px;
  background: #06210f;
  border-radius: 2px;
  transition: height 0.05s ease;
}

.chat-play-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 6px;
  padding: 0;
}

/* Custom scrollbar for the chat panel - matches the dark theme + green accent */
#chat-panel {
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--bg);
}

#chat-panel::-webkit-scrollbar {
  width: 8px;
}

#chat-panel::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 8px;
}

#chat-panel::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 8px;
}

#chat-panel::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* Reset button - understated, not a big red slab */
.reset-link-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 6px;
}

.reset-link-btn:hover {
  color: var(--danger);
}

/* Milestone celebration popup */
#milestone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  overflow: hidden;
}

.milestone-card {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 18px;
  padding: 32px 28px;
  max-width: 360px;
  text-align: center;
  z-index: 2;
}

.milestone-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

.milestone-card h2 {
  margin: 0 0 12px;
  color: var(--accent);
}

.milestone-card p {
  color: var(--text);
  line-height: 1.5;
  font-size: 0.95rem;
}

#milestone-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#milestone-confetti span {
  position: absolute;
  top: -20px;
  font-size: 1.5rem;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0.3;
  }
}

/* Collapsible dashboard sections */
.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.collapsible-header h2 {
  margin: 0;
}

.header-value {
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
}

.collapsible-body {
  margin-top: 14px;
}

.view-all-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}

/* Chat-first home screen + swipe-to-dashboard */
.swipe-container {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  -webkit-overflow-scrolling: touch;
}

.panel {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  overflow-y: auto;
}

.dashboard-panel-view {
  background: var(--bg);
}

.chat-panel-view {
  background: #08090c;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-main-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.chat-main-header h1 {
  margin: 0;
  font-size: 1.1rem;
}

.chat-main-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-main-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

/* Main chat overrides - matches the ChatGPT reference: Marcus's replies sit
   directly on the background (no bubble), only the user's messages get a
   bubble, and it's gray, not the green used elsewhere in the app. */
.chat-main-messages .chat-msg.marcus {
  display: block;
  margin-bottom: 28px;
}

.chat-main-messages .chat-msg.marcus .chat-bubble {
  background: none;
  border: none;
  padding: 0;
  max-width: 100%;
  border-radius: 0;
  color: var(--text);
}

.chat-main-messages .chat-msg.user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 28px;
}

.chat-main-messages .chat-msg.user .chat-bubble {
  background: #3a3d45;
  color: var(--text);
  max-width: 75%;
  border-bottom-right-radius: 4px;
}

.chat-main-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chat-main-actions button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  padding: 4px;
  display: flex;
  align-items: center;
  cursor: pointer;
  line-height: 0;
}

.chat-main-actions button:hover, .chat-main-actions button.liked {
  color: #fff;
}

.chat-buddy-btn-bubble {
  background: none !important;
  padding: 0 !important;
}
.chat-buddy-btn {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.chat-buddy-btn:hover { background: var(--accent); color: #06210f; }
.chat-buddy-btn-count { font-size: 0.75rem; font-weight: 500; opacity: 0.75; }

.chat-main-attach {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.swipe-hint {
  color: var(--muted);
  font-size: 0.75rem;
}

.chat-main-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-main-input-row {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: #08090c;
}

.chat-main-input-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 28px;
  padding: 6px 8px 6px 18px;
}

.chat-main-input-pill input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 0;
  outline: none;
}

#chat-main-mic, #chat-main-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 1.05rem;
}

#chat-main-mic {
  background: transparent;
  color: var(--text);
}

#chat-main-mic.recording {
  background: var(--danger);
  color: white;
  animation: mic-pulse 1.4s ease-in-out infinite;
}

#chat-main-mic.thinking {
  background: var(--accent-dim);
  color: var(--accent);
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

#chat-main-send {
  background: var(--accent);
  color: #06210f;
  font-weight: 700;
  font-size: 1.2rem;
}

/* Morning Newspaper delivered as a chat message, with toggle sections */
.newspaper-msg {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin: 0 0 12px;
  max-width: 100%;
}

.newspaper-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.newspaper-section {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}

.newspaper-section:first-of-type {
  border-top: none;
}

.newspaper-section summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}

.newspaper-section summary::-webkit-details-marker {
  display: none;
}

.newspaper-section summary::before {
  content: '▸ ';
}

.newspaper-section[open] summary::before {
  content: '▾ ';
}

.newspaper-body {
  margin-top: 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

/* Woodpecker puzzle board, embedded as plain text/board directly on the
   page background - no card, no border, Notion-doc style. */
.woodpecker-embed {
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 12px;
  max-width: 100%;
  width: 100%;
}
.wp-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.wp-turn {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.wp-timer {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.wp-streak {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
  text-align: center;
}
.woodpecker-board {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  /* Without this, dragging a piece on touch devices scrolls/drags the
     whole page instead of just moving the piece. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
/* chessboard.js's own square/piece elements, recolored to match Chess Buddy */
.woodpecker-board .white-1e1d7 { background-color: #f4f8fb !important; }
.woodpecker-board .black-3c85d { background-color: #7bafd4 !important; }
.woodpecker-board img { touch-action: none; }
.woodpecker-status { margin-top: 14px; color: var(--muted); font-size: 0.9rem; font-weight: 600; }

/* "Marcus talk" block - the fun, colorful bottom area with the move-type
   call-out + tip, using the extra space below the board. */
.wp-marcus {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.wp-movetype {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 12px;
}
.wp-movetype b { color: var(--accent); }
.wp-theme-fork { color: #ff9f43; }
.wp-theme-pin { color: #54a0ff; }
.wp-theme-discoveredAttack { color: #ff6b6b; }
.woodpecker-tip {
  font-size: 0.9rem; line-height: 1.7; color: var(--muted);
}
.woodpecker-tip b { color: var(--text); }
.woodpecker-tip i { color: var(--accent); font-style: normal; }

/* Chat header layout with hamburger */
.chat-main-header { justify-content: space-between; }
#chat-main-menu-btn {
  background: transparent; border: none; color: var(--text); font-size: 1.3rem;
  width: 34px; height: 34px; cursor: pointer;
}

/* Previous-days sidebar */
.days-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 80vw;
  background: var(--card); border-right: 1px solid var(--border);
  z-index: 300; padding: 16px; overflow-y: auto;
  transform: translateX(0); transition: transform 0.2s ease;
}
.days-sidebar.hidden { transform: translateX(-100%); display: block; pointer-events: none; }
.days-sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 299;
}
.days-sidebar-backdrop.hidden { display: none; }
.days-sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.days-sidebar-header h2 { margin: 0; font-size: 1.1rem; }
#days-sidebar-close { background: transparent; border: none; color: var(--text); font-size: 1.4rem; cursor: pointer; }
.day-entry {
  padding: 12px; border-radius: 10px; cursor: pointer; margin-bottom: 6px; color: var(--text);
}
.day-entry:hover, .day-entry.active { background: var(--bg); }
.day-entry .day-label { font-weight: 700; }
.day-entry .day-count { color: var(--muted); font-size: 0.8rem; }

/* Message action row under Marcus's replies */
.chat-main-actions button { font-family: inherit; }

/* Attach button */
#chat-main-attach {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; border: none;
  background: transparent; color: var(--text); font-size: 1.4rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}

/* Thinking indicator (typing dots) */
.chat-thinking {
  display: inline-flex; gap: 4px; padding: 12px 14px !important;
}
.chat-thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: chat-thinking-bounce 1.2s infinite ease-in-out;
}
.chat-thinking span:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-thinking-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Voice wave indicator inside the input pill while recording */
.chat-main-input-pill { position: relative; }
.chat-main-wave {
  position: absolute; left: 18px; right: 60px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 3px; height: 20px; background: var(--card);
}
.chat-main-wave.hidden { display: none; }
.chat-main-wave span {
  width: 3px; background: var(--danger); border-radius: 2px;
  height: 6px; animation: wave-bounce 0.9s infinite ease-in-out;
}
.chat-main-wave span:nth-child(1) { animation-delay: 0s; }
.chat-main-wave span:nth-child(2) { animation-delay: 0.1s; }
.chat-main-wave span:nth-child(3) { animation-delay: 0.2s; }
.chat-main-wave span:nth-child(4) { animation-delay: 0.3s; }
.chat-main-wave span:nth-child(5) { animation-delay: 0.4s; }
@keyframes wave-bounce {
  0%, 100% { height: 6px; }
  50% { height: 18px; }
}

/* Full-screen buddy overlay (chess board, future: trade charts, workouts) */
.buddy-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 400;
  display: flex; flex-direction: column;
}
.buddy-overlay.hidden { display: none; }
.buddy-overlay-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 1.1rem;
}
#buddy-overlay-close { background: transparent; border: none; color: var(--text); font-size: 1.6rem; cursor: pointer; }
.buddy-overlay-content { flex: 1; overflow-y: auto; padding: 16px; }
.buddy-overlay-content .woodpecker-embed { max-width: 520px; margin: 0 auto; }
.buddy-overlay-iframe { width: 100%; height: 100%; border: none; display: block; }
.buddy-overlay-content:has(.buddy-overlay-iframe) { padding: 0; }

/* Voice recording pill - replaces the normal input entirely while active,
   matches the ChatGPT reference: full-width wave, X to cancel, square to stop */
.chat-main-voice-pill {
  justify-content: space-between;
  background: var(--card);
}
#chat-main-cancel-voice, #chat-main-stop-voice {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; border: none;
  background: #2c2f36; color: var(--text); font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
#chat-main-stop-voice { background: var(--text); color: var(--bg); font-size: 0.8rem; }
.chat-main-wave {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 4px; height: 24px;
}
.chat-main-wave.hidden { display: none; }
.chat-main-wave span {
  width: 3px; background: var(--muted); border-radius: 2px;
  height: 6px; animation: wave-bounce 0.9s infinite ease-in-out;
}
.chat-main-wave span:nth-child(odd) { animation-delay: 0.1s; }
.chat-main-wave span:nth-child(3n) { animation-delay: 0.25s; }
.chat-main-wave span:nth-child(4n) { animation-delay: 0.4s; }
.chat-main-voice-status {
  flex: 1; text-align: center; color: var(--muted); font-size: 0.9rem;
}
.chat-main-voice-status.hidden { display: none; }
