:root {
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #252840;
  --border: #2e3250;
  --accent: #9b72cf;
  --accent2: #f8a84b;
  --green: #5ccc8d;
  --red: #e05c5c;
  --text: #e8e8f0;
  --text2: #8a8faa;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}

.modal-icon { font-size: 40px; margin-bottom: 16px; text-align: center; }

.modal-box h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.modal-box p {
  color: var(--text2);
  font-size: 13px;
  margin-bottom: 24px;
  text-align: center;
  line-height: 1.5;
}

.modal-box label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text2);
  margin-bottom: 6px;
}

.modal-box input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: monospace;
  padding: 10px 12px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.modal-box input:focus { border-color: var(--accent); }

.error-msg {
  background: rgba(224,92,92,0.15);
  border: 1px solid var(--red);
  border-radius: 6px;
  color: var(--red);
  font-size: 13px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ── Header ── */
header {
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky; top: 0; z-index: 10;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 18px; font-weight: 700; }

.header-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--text2);
}

.range-tabs { display: flex; gap: 4px; }

.tab-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 13px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover { border-color: var(--accent); color: var(--text); }
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.icon-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  padding: 5px 9px;
  cursor: pointer;
  transition: border-color 0.15s;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }

/* ── Loading ── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 24px;
  color: var(--text2);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main layout ── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Stat strip ── */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

/* ── Chart sections ── */
.chart-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.section-header {
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.section-sub {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap.tall {
  height: 320px;
}

.chart-wrap.short {
  height: 160px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 28px 0 12px;
  padding-left: 2px;
}

/* ── Footer ── */
footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px 32px;
  text-align: center;
  color: var(--text2);
  font-size: 13px;
}

/* ── Today grid ── */

.today-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.today-col {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.today-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.today-col-icon { font-size: 15px; }

.today-col-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 1;
}

.today-col-count {
  background: var(--border);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  color: var(--text2);
}

.today-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 420px;
  overflow-y: auto;
}

/* Habit card */
.habit-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg3);
  border-left: 3px solid transparent;
  transition: background 0.15s;
}
.habit-card:hover { background: var(--border); }

.habit-color-bar {
  width: 3px;
  height: 100%;
  border-radius: 2px;
}

.habit-name {
  flex: 1;
  font-size: 13px;
  line-height: 1.35;
}

.habit-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.habit-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  border: none;
  cursor: default;
}

.habit-btn.up   { background: rgba(92,204,141,0.18); color: #5ccc8d; }
.habit-btn.down { background: rgba(224,92,92,0.18);  color: #e05c5c; }

/* Daily card */
.daily-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg3);
  transition: background 0.15s;
}
.daily-card:hover { background: var(--border); }
.daily-card.completed { opacity: 0.5; }
.daily-card.not-due   { opacity: 0.4; }

.daily-check {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.daily-check.done  { background: var(--green); border-color: var(--green); color: #fff; }
.daily-check.due   { border-color: #5bc8f5; }
.daily-check.notdue{ border-color: var(--border); }

.daily-info { flex: 1; min-width: 0; }
.daily-name {
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.daily-streak {
  font-size: 11px;
  color: var(--text2);
  margin-top: 1px;
}
.daily-streak span { color: var(--accent2); font-weight: 600; }

/* Todo card */
.todo-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg3);
  transition: background 0.15s;
}
.todo-card:hover { background: var(--border); }

.todo-priority-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.todo-name {
  font-size: 13px;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .today-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .header-inner { padding: 0 16px; }
  .logo-text { display: none; }
  .range-tabs .tab-btn { padding: 4px 8px; font-size: 12px; }
  main { padding: 16px; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
}
