:root {
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --card-bg: #ffffff;
    --primary: #007AFF;
    --primary-hover: #0062cc;
    --danger: #ef4444;
    --success: #10b981;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
}
body.dark {
    --bg-color: #111827;
    --text-color: #f9fafb;
    --card-bg: #1f2937;
    --primary: #409cff;
    --primary-hover: #007AFF;
    --border: #374151;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg-color); color: var(--text-color); margin: 0; padding: 20px; transition: background 0.3s, color 0.3s; line-height: 1.5; }
.container { max-width: 1000px; margin: 0 auto; display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
h1 { margin: 0; font-size: 1.75rem; font-weight: 800; letter-spacing: -0.025em; background: linear-gradient(135deg, var(--primary), #00C7FF); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.progress-container { background: var(--border); height: 10px; border-radius: 999px; overflow: hidden; margin-bottom: 30px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.1); }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), #00C7FF); width: 0%; transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 999px; }

.input-group { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
input[type="text"], input[type="number"], input[type="date"], select { flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); color: var(--text-color); outline: none; transition: all 0.2s; font-size: 0.95rem; box-shadow: var(--shadow-sm); }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2); }
input[type="color"] { border: none; width: 44px; height: 44px; cursor: pointer; background: transparent; padding: 0; border-radius: var(--radius); overflow: hidden; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; }

button { padding: 12px 24px; background: var(--primary); color: white; border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600; transition: all 0.2s; box-shadow: var(--shadow-sm); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
button:active { transform: translateY(0); }
button.icon-btn { padding: 8px; width: 40px; height: 40px; font-size: 1.2rem; background: var(--card-bg); color: var(--text-color); border: 1px solid var(--border); border-radius: 50%; }
button.icon-btn:hover { background: var(--border); }

.routine-list { list-style: none; padding: 0; }
.routine-item { background: var(--card-bg); padding: 16px; margin-bottom: 12px; border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow-sm); border: 1px solid var(--border); transition: all 0.2s ease; position: relative; z-index: 1; }
.routine-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }

.routine-info { display: flex; align-items: center; gap: 15px; flex: 1; }
input[type="checkbox"] { width: 22px; height: 22px; cursor: pointer; accent-color: var(--primary); border-radius: 6px; }

.details { display: flex; flex-direction: column; }
.routine-name { font-size: 1.05rem; font-weight: 600; color: var(--text-color); }
.streak { font-size: 0.75rem; color: #888; margin-top: 2px; }
.routine-note { font-size: 0.85rem; color: #666; margin-top: 2px; font-style: italic; }

.completed .routine-name { text-decoration: line-through; opacity: 0.6; }

/* Action Buttons in List */
.routine-item .routine-actions { display: flex; gap: 4px; align-items: center; }
.routine-item button { padding: 6px; width: 32px; height: 32px; font-size: 1rem; background: transparent; color: #6b7280; box-shadow: none; border-radius: 6px; }
.routine-item button:hover { background: var(--bg-color); color: var(--text-color); transform: none; }
.delete-btn:hover { color: var(--danger) !important; background: #fee2e2 !important; }
.edit-btn:hover { color: var(--primary) !important; background: #e0e7ff !important; }
.duplicate-btn:hover { color: var(--success) !important; background: #d1fae5 !important; }
.time-btn:hover { color: #f59e0b !important; background: #fef3c7 !important; }

/* Actions Dropdown Menu */
.actions-dropdown { position: relative; }
.menu-btn { font-size: 1.2rem !important; font-weight: bold; }
.actions-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--card-bg);
    min-width: 160px;
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    z-index: 10;
    padding: 8px 0;
    margin-top: 5px;
}
.actions-menu.show { display: block; }
.actions-menu a { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; font-size: 0.9rem; color: var(--text-color); text-decoration: none; transition: background 0.2s; user-select: none; }
.actions-menu a:hover { background: var(--bg-color); }
.actions-menu a.danger { color: var(--danger); }
.actions-menu a.danger:hover { background: #fee2e2; }
.actions-menu .separator { height: 1px; background: var(--border); margin: 4px 0; }

.routine-item.menu-open { z-index: 100; }

.controls { display: flex; gap: 10px; margin-top: 30px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 20px; }
.controls button { font-size: 0.9rem; background: var(--card-bg); color: var(--text-color); border: 1px solid var(--border); flex: 1; box-shadow: var(--shadow-sm); }
.controls button:hover { background: var(--bg-color); border-color: var(--text-color); }
.controls button.danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.controls button.danger:hover { background: var(--danger); color: white; }

/* New Features Styles */
.category-badge { font-size: 0.7rem; padding: 4px 10px; border-radius: 20px; background: var(--bg-color); color: var(--text-color); margin-right: 8px; font-weight: 600; border: 1px solid var(--border); }
select { cursor: pointer; }

.priority-badge { font-size: 0.65rem; padding: 3px 8px; border-radius: 6px; margin-right: 5px; font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: 0.5px; }
.priority-high { background-color: #ff5252; }
.priority-medium { background-color: #ff9800; }
.priority-low { background-color: #4caf50; }

.weekly-badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 6px; background: var(--bg-color); color: var(--text-color); margin-right: 5px; font-weight: 600; border: 1px solid var(--border); }
.weekly-badge.met { background: var(--primary); color: white; }

.due-date-badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 6px; background: var(--bg-color); color: var(--text-color); margin-right: 5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); }
.due-date-badge.overdue { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.due-date-badge.today { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }

.routine-item.dragging { opacity: 0.5; }
.routine-item.over { border: 2px dashed var(--primary); }
.routine-list.dragging-mode .routine-item * { pointer-events: none; }

/* Compact Mode */
.routine-list.compact .routine-item { padding: 8px 15px; }
.routine-list.compact .details > div:first-child { display: none !important; }
.routine-list.compact .routine-note { display: none; }
.category-header { font-size: 1.1rem; font-weight: bold; margin: 20px 0 10px; color: var(--primary); border-bottom: 2px solid var(--border); padding-bottom: 5px; list-style: none; }
.category-header.over { background: #e3f2fd; border: 2px dashed var(--primary); color: var(--primary); }

/* Filter Dropdown */
.filters { margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center; }
.filter-dropdown { position: relative; }
.filter-btn { background: var(--card-bg); border: 1px solid var(--border); color: var(--text-color); padding: 8px 16px; border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow-sm); }
.filter-btn:hover { background: var(--bg-color); }
.filter-content { display: none; position: absolute; right: 0; top: 100%; margin-top: 5px; background: var(--card-bg); min-width: 220px; box-shadow: var(--shadow); border-radius: var(--radius); border: 1px solid var(--border); z-index: 100; padding: 8px 0; overflow: hidden; max-height: 300px; overflow-y: auto; }
.filter-content.show { display: block; }
.filter-content label { display: flex; align-items: center; padding: 10px 16px; cursor: pointer; font-size: 0.9rem; color: var(--text-color); gap: 10px; transition: background 0.2s; user-select: none; }
.filter-content label:hover { background: var(--bg-color); }
.filter-content .separator { height: 1px; background: var(--border); margin: 4px 0; }

/* Confetti Animation */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}
.confetti {
    position: absolute;
    width: 8px;
    height: 16px;
    top: -20px;
    opacity: 0;
    animation: fall 3s ease-in forwards;
}
@keyframes fall {
    to { transform: translateY(100vh) rotate(720deg); opacity: 1; }
}

/* Stats Modal */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); align-items: center; justify-content: center; }
.modal-content { background-color: var(--card-bg); padding: 20px; border-radius: 10px; width: 90%; max-width: 400px; position: relative; box-shadow: 0 4px 10px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto; }
.close-modal { position: sticky; top: 0; float: right; font-size: 1.5rem; cursor: pointer; color: var(--text-color); z-index: 10; line-height: 1; margin-left: 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 15px; }
.stat-day { aspect-ratio: 1; border-radius: 4px; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: #888; }
.stat-day.completed { background: var(--primary); color: white; }
.stat-summary { display: flex; justify-content: space-between; margin-bottom: 15px; text-align: center; }
.stat-box { flex: 1; }
.stat-value { font-size: 1.2rem; font-weight: bold; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: #888; }

/* Streak Visualization */
.streak-visual { margin-bottom: 20px; }
.streak-bar-bg { background: var(--border); height: 12px; border-radius: 6px; position: relative; overflow: hidden; }
.streak-bar-fill { background: var(--primary); height: 100%; width: 0%; transition: width 0.5s ease; }
.streak-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: #888; margin-top: 5px; }

/* Calendar Styles */
.main-column { flex: 1; min-width: 300px; }
.calendar-column { flex: 0 0 320px; background: var(--card-bg); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); position: sticky; top: 20px; height: fit-content; }
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; font-weight: 700; font-size: 1.1rem; }
.calendar-header button { padding: 4px 10px; background: transparent; color: var(--text-color); border: 1px solid var(--border); border-radius: 6px; box-shadow: none; }
.calendar-header button:hover { background: var(--bg-color); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 15px; }
.calendar-day-label { font-size: 0.7rem; text-align: center; color: #888; font-weight: 600; margin-bottom: 5px; }
.calendar-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 0.85rem; cursor: default; transition: all 0.2s; font-weight: 500; }
.calendar-day:hover { transform: scale(1.1); }
.calendar-day.green { background-color: #4caf50; color: white; }
.calendar-day.yellow { background-color: #ff9800; color: white; }
.calendar-day.red { background-color: #ff5252; color: white; }
.calendar-day.black { background-color: #333; color: white; }
.calendar-day.today { border: 2px solid var(--primary); color: var(--primary); font-weight: bold; }
.calendar-day.today.green, .calendar-day.today.yellow, .calendar-day.today.red, .calendar-day.today.black { color: white; border-color: white; }
.calendar-legend { display: flex; gap: 10px; font-size: 0.75rem; justify-content: center; color: #888; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 3px; }
.dot.green { background: #4caf50; }
.dot.yellow { background: #ff9800; }
.dot.red { background: #ff5252; }
.dot.black { background: #333; }

@media (max-width: 800px) {
    .calendar-column { flex: 1 1 100%; position: static; order: 2; }
}

.settings-input { width: 100%; padding: 12px; margin-top: 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); color: var(--text-color); box-sizing: border-box; }

/* Modal Polish */
.modal-content { border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.close-modal:hover { color: var(--danger); }

/* Chart Controls */
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

.reset-confirm-box { display: none; margin-top: 15px; padding: 15px; border-radius: var(--radius); border: 1px solid var(--danger); background: rgba(239, 68, 68, 0.1); }
.reset-confirm-box p { margin: 0 0 10px; color: var(--danger); }
.reset-confirm-box p:first-child { font-weight: bold; }

/* Scratchpad */
.scratchpad-area { margin-top: 25px; border-top: 1px solid var(--border); padding-top: 20px; }
.scratchpad-area h3 { margin: 0 0 12px 0; font-size: 1rem; font-weight: 600; color: var(--text-color); display: flex; align-items: center; gap: 6px; }
textarea#scratchpad { width: 100%; height: 150px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-color); color: var(--text-color); resize: vertical; font-family: inherit; font-size: 0.9rem; outline: none; box-sizing: border-box; transition: border-color 0.2s, box-shadow 0.2s; }
textarea#scratchpad:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2); }

.quote-box { margin-bottom: 20px; padding: 12px 16px; background: var(--card-bg); border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); display: flex; flex-direction: column; }
.quote-text { margin: 0; font-size: 0.95rem; font-style: italic; color: var(--text-color); }
.quote-author { margin-top: 4px; font-size: 0.8rem; color: #888; align-self: flex-end; font-weight: 600; }

.level-container { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; }
.level-badge { background: linear-gradient(135deg, #0bb3f5, #0669d9); color: white; padding: 4px 12px; border-radius: 20px; font-weight: 800; font-size: 0.9rem; box-shadow: var(--shadow-sm); text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.xp-text { font-size: 0.7rem; color: #888; margin-top: 4px; font-weight: 600; }