:root {
  --bg: #050a0f;
  --surface: #0a141c;
  --surface-alt: #0f1d28;
  --text: #dcf2f8;
  --text-dim: #7f9fab;
  --border: #14303f;
  --border-strong: #1f4a5e;
  --accent: #06b6d4;
  --accent-hover: #22d3ee;
  --on-accent: #031014;
  --highlight: #67e8f9;
  --blue: #06b6d4;
  --success: #67e8f9;
  --success-bg: rgba(6,182,212,.14);
  --success-border: rgba(6,182,212,.5);
  --success-solid: #06b6d4;
  --danger: #f87171;
  --danger-bg: rgba(244,63,94,.12);
  --danger-border: rgba(220,38,38,.5);
  --danger-solid: #b91c1c;
  --empty-cell: #14303f;
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; min-height: 100vh; -webkit-font-smoothing: antialiased; }
h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 14px; font-weight: 600; }
h3 { font-size: 18px; }
.muted { color: var(--text-dim); font-size: 13px; }

.topbar { display: flex; justify-content: space-between; align-items: center; height: 56px; padding: 0 28px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: var(--text); }
.day-timer { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.5fr) minmax(0, 1fr); gap: 28px; max-width: 1400px; margin: 0 auto; padding: 28px; align-items: start; }
.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.controls { display: flex; gap: 6px; }

.btn { display: inline-block; background: var(--accent); color: var(--on-accent); font-family: inherit; font-weight: 600; font-size: 13px; border: 1px solid var(--accent); padding: 8px 16px; border-radius: 6px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--surface-alt); border-color: var(--border-strong); }
.btn.block { width: 100%; padding: 11px; }

textarea { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 6px; font-family: inherit; font-size: 14px; width: 100%; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(6,182,212,.25); }

/* stats */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 12px; }
.stat-box .num { color: var(--text); font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-box .label { font-size: 11px; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }

/* calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 13px; color: var(--text-dim); background: var(--surface); font-variant-numeric: tabular-nums; }
.day-cell:hover { border-color: var(--text-dim); }
.day-cell.success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); font-weight: 600; }
.day-cell.relapse { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); font-weight: 600; }
.day-cell.today { outline: 2px solid var(--blue); outline-offset: -2px; }
.day-cell { position: relative; }
.day-cell.has-note::after { content: ''; position: absolute; bottom: 5px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .7; }
.day-cell.goal { color: #fbbf24; border-color: #fbbf24; background: rgba(251,191,36,.12); font-weight: 700; box-shadow: 0 0 14px rgba(251,191,36,.55), inset 0 0 8px rgba(251,191,36,.25); animation: goalGlow 3s ease-in-out infinite; }
@keyframes goalGlow { 0%,100% { box-shadow: 0 0 10px rgba(251,191,36,.4), inset 0 0 6px rgba(251,191,36,.2); } 50% { box-shadow: 0 0 20px rgba(251,191,36,.75), inset 0 0 10px rgba(251,191,36,.3); } }
.mini-grid .goal { background: #fbbf24; box-shadow: 0 0 6px rgba(251,191,36,.9); }
.goal-note { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 12px; color: var(--text-dim); }
.goal-dot { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; box-shadow: 0 0 8px rgba(251,191,36,.8); }
.day-cell.empty { visibility: hidden; }
.month-card { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px; }
.month-card strong { font-size: 12px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-top: 8px; }
.mini-grid div { aspect-ratio: 1; border-radius: 2px; background: var(--empty-cell); }
.mini-grid .success { background: var(--success-solid); }
.mini-grid .relapse { background: var(--danger-solid); }

/* goals */
.goal-hint { color: var(--text-dim); font-size: 13px; margin: 0 0 10px; }
.goal-list { display: flex; flex-direction: column; gap: 10px; }
.goal-card { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 8px; padding: 12px 14px; box-shadow: none; font-weight: 500; overflow-wrap: anywhere; }
.locked-note { margin-top: 12px; font-size: 12px; color: var(--text-dim); }

/* modals */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.65); align-items: center; justify-content: center; z-index: 20; padding: 20px; }
.modal-box { background: var(--surface); border-radius: 12px; padding: 28px; max-width: 460px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.5); border: 1px solid var(--border); }
.modal-box .muted { margin: 4px 0 16px; }
.modal-actions { margin-top: 14px; text-align: right; display: flex; gap: 8px; justify-content: flex-end; }
.choice-row { display: flex; gap: 10px; }
.choice-row .btn { flex: 1; padding: 11px; }
.btn.choice.success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.btn.choice.danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn.choice.success:hover { background: rgba(6,182,212,.24); border-color: var(--success); }
.btn.choice.danger:hover { background: rgba(244,63,94,.24); border-color: var(--danger); }
.btn.choice.success.on { background: var(--success-solid); border-color: var(--success-solid); color: #031014; }
.btn.choice.danger.on { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.review-goal { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.review-goal .goal-text { font-weight: 500; margin-bottom: 10px; overflow-wrap: anywhere; }
.review-goal .btn { padding: 7px 10px; }
.step-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin-bottom: 6px; }

/* left column: rewire */
.col-left { align-self: stretch; display: flex; }
.rewire-frame { display: block; flex: 1; width: 100%; min-height: 620px; border: 0; background: #050a0f; color-scheme: dark; }

/* diary */
.diary { --paper: #fbf6e9; --ink: #2b2620; --rule: #d9cfb8; --margin: #e0a39a; --line: 34px;
  width: 100%; max-width: 780px; background: var(--paper); color: var(--ink); border-radius: 6px 12px 12px 6px; border-left: 10px solid #7c5a3c;
  box-shadow: 0 24px 60px rgba(0,0,0,.55); padding: 26px 32px 20px 30px; max-height: 92vh; display: flex; flex-direction: column; font-family: 'Lora', Georgia, serif; }
.diary-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 12px; border-bottom: 2px solid var(--rule); margin-bottom: 4px; }
.diary-eyebrow { font-family: var(--font); font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: #8a7a5c; }
.diary h3 { font-family: 'Lora', Georgia, serif; font-size: 24px; font-weight: 600; color: var(--ink); margin-top: 2px; }
.diary-badge { font-family: var(--font); font-size: 11px; font-weight: 600; text-transform: capitalize; padding: 3px 10px; border-radius: 99px; background: #e9e2cf; color: #6b5e45; }
.diary-badge.success { background: #d4ecd6; color: #1f6b34; }
.diary-badge.relapse { background: #f4d3cf; color: #9b2c22; }
.diary textarea { flex: 1; min-height: 340px; height: 52vh; border: none; border-radius: 0; box-shadow: none; resize: none; color: var(--ink);
  font-family: 'Lora', Georgia, serif; font-size: 17px; line-height: var(--line); padding: 0 8px 0 44px; margin-top: 0;
  background-color: transparent;
  background-image: linear-gradient(to right, transparent 34px, var(--margin) 34px, var(--margin) 36px, transparent 36px),
                    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--rule) calc(var(--line) - 1px), var(--rule) var(--line));
  background-attachment: local; }
.diary textarea:focus { outline: none; box-shadow: none; border: none; }
.diary textarea::placeholder { color: #a99b7e; font-style: italic; }
.diary-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; border-top: 2px solid var(--rule); }
.diary-count { font-family: var(--font); font-size: 12px; color: #8a7a5c; }
.diary-foot .modal-actions { margin: 0; }
.diary-btn { background: #5b3f27; border-color: #5b3f27; color: #fbf6e9; }
.diary-btn:hover { background: #46301d; border-color: #46301d; }
.diary-btn.secondary { background: transparent; border-color: var(--rule); color: #5b4a35; }
.diary-btn.secondary:hover { background: #f1e9d3; border-color: #c9bd9e; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .col-left { align-self: auto; }
  .rewire-frame { height: 900px; }
  .col-right { order: -1; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
