:root {
  --primary: #c084fc;
  --primary-light: #e9d5ff;
  --secondary: #fb7185;
  --bg: #030712;
  --card: #111827;
  --card-light: #1f2937;
  --text: #f9fafb;
  --text-dim: #9ca3af;
  --border: rgba(255, 255, 255, 0.05);
  --accent-glow: rgba(192, 132, 252, 0.15);
  --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 100px; /* Space for bottom nav */
  background: radial-gradient(circle at top right, #1e1b4b, transparent),
              radial-gradient(circle at bottom left, #4c0519, transparent);
  background-attachment: fixed;
}

.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* Header Section */
header {
  padding: 20px 0 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand h1 {
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(to right, #fff, var(--text-dim));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.date-today {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Habit Cards */
.habit-grid {
  display: grid;
  gap: 16px;
}

.habit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, background 0.2s;
  cursor: pointer;
}

.habit-card:active {
  transform: scale(0.98);
}

.habit-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.habit-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.habit-stats-mini {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Action Button - Deliberate Interaction */
.action-area {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-log {
  flex: 1;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  border: none;
  border-radius: 18px;
  padding: 14px;
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-edit {
  width: 48px;
  height: 48px;
  border-radius: 18px;
  background: var(--card-light);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Undo Banner */
.undo-banner {
  position: fixed;
  bottom: 100px;
  left: 20px;
  right: 20px;
  background: #10b981;
  color: white;
  padding: 12px 20px;
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
  transform: translateY(200px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.undo-banner.show {
  transform: translateY(0);
}

/* Custom Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 12px 12px calc(12px + var(--safe-area-bottom));
  z-index: 900;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
}

.nav-item.active {
  color: var(--primary);
}

.nav-icon {
  font-size: 1.4rem;
}

/* Analysis Charts */
.analytics-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-card {
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  border: 1px solid var(--border);
}

.bar-grid {
  display: flex;
  align-items: flex-end;
  height: 160px; /* Increased height for better visibility */
  gap: 12px;
  margin-top: 30px;
  padding-bottom: 20px;
}

.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* Push bar to bottom */
  align-items: center;
  height: 100%; /* Anchor for percentage height */
  gap: 8px;
}

.bar {
  width: 100%;
  max-width: 28px;
  background-color: var(--primary); /* Fallback */
  background: linear-gradient(to top, var(--primary), var(--primary-light));
  border-radius: 6px 6px 2px 2px;
  min-height: 4px;
  transition: height 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cell {
  background: var(--card-light);
  transition: background 0.3s ease;
}

.cell.lvl-1 { background: #4c1d95; }
.cell.lvl-2 { background: #7c3aed; }
.cell.lvl-3 { background: #a78bfa; }
.cell.lvl-4 { background: #ddd6fe; }

.bar-label {
  font-size: 0.6rem;
  color: var(--text-dim);
}

/* Modals */
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-radius: 32px 32px 0 0;
  padding: 32px 24px calc(32px + var(--safe-area-bottom));
  z-index: 1001;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet::-webkit-scrollbar {
  width: 4px;
}

.sheet::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 1000;
}

.sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Inputs */
.input-group {
    margin-bottom: 24px;
}
.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}
input[type="text"] {
    width: 100%;
    background: var(--card-light);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 16px;
    color: white;
    font-size: 1rem;
}

.btn-full {
    width: 100%;
    padding: 18px;
    border-radius: 18px;
    font-weight: 700;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-full:active {
    transform: scale(0.96);
    filter: brightness(1.2);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

/* Log History List */
.log-history {
    max-height: 250px;
    overflow-y: auto;
    margin: 16px 0;
    padding-right: 4px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--card-light);
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.history-item span {
    color: var(--text-dim);
}

.btn-mini-del {
    background: #ef444422;
    color: #ef4444;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
}

/* Backfilling Section */
.backfill-section {
    background: var(--card-light);
    padding: 16px;
    border-radius: 16px;
    margin-top: 24px;
}

.backfill-controls {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

input[type="date"], input[type="time"] {
    background: var(--bg);
    border: 1px solid var(--border);
    color: white;
    padding: 8px;
    border-radius: 8px;
    font-size: 0.8rem;
    flex: 1;
}

/* Animations */
@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.habit-card {
    animation: popIn 0.3s ease-out forwards;
}

/* ========================================= */
/* Focus Timer (Pomodoro) UI                 */
/* ========================================= */
.focus-timer-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 40px 0;
}

.focus-mode-switcher {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
}

.focus-dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

.stat-card {
    background: var(--card-light);
    padding: 16px;
    border-radius: 16px;
    text-align: center;
}

.reward-status-card {
    background: var(--card-light);
    padding: 16px;
    border-radius: 16px;
    margin-top: 12px;
}

.progress-bar-bg {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.5s ease;
}

.mode-btn {
    background: var(--card-light);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.timer-circle {
    position: relative;
    width: 250px;
    height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.timer-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg); /* Start from top */
}

.timer-bg {
    fill: none;
    stroke: var(--card-light);
    stroke-width: 4;
}

.timer-progress {
    fill: none;
    stroke: var(--primary);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 283; /* 2 * pi * r (45) */
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease;
}

.timer-display {
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -0.05em;
    z-index: 10;
    font-variant-numeric: tabular-nums;
}

.timer-label {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-top: -5px;
    z-index: 10;
}

.focus-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

/* ========================================= */
/* Gacha Reward System UI                    */
/* ========================================= */
.gacha-container {
    text-align: center;
    margin-top: 40px;
}

.gacha-box {
    font-size: 8rem;
    filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.4));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.gacha-box:active {
    transform: scale(0.9) rotate(-5deg);
}

.gacha-box.animating {
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.inventory-list {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inv-item {
    background: var(--card-light);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.inv-item:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.05);
}

.inv-item.Rare { border-color: #10b981; color: #10b981; }
.inv-item.Epic { border-color: #3b82f6; color: #3b82f6; }
.inv-item.Legendary { border-color: #f59e0b; color: #f59e0b; font-weight: bold; background: rgba(245, 158, 11, 0.1); }
/* Toggle Switch Config Card */
.wake-lock-config {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-light);
    padding: 16px 20px;
    border-radius: 20px;
    margin: 20px 0;
    border: 1px solid var(--border);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--card-light);
  transition: .4s;
  border-radius: 24px;
  border: 1px solid var(--border);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

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

/* ========================================= */
/* Drag & Drop Import Zone                   */
/* ========================================= */
.drop-zone {
    margin-top: 16px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 28px 16px;
    text-align: center;
    transition: all 0.25s ease;
    cursor: pointer;
    background: transparent;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(192, 132, 252, 0.08);
    box-shadow: 0 0 20px rgba(192, 132, 252, 0.1);
}

.drop-zone-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    opacity: 0.7;
}

.drop-zone-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.drop-zone-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.drop-feedback {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
}

.drop-feedback.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.drop-feedback.error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Screen Protection Overlay (OLED Friendly) */
.screen-protection-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 2000;
    display: none; /* Hidden by default */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.screen-protection-overlay.active {
    display: flex;
}

.protected-clock {
    font-size: 6rem;
    font-weight: 900;
    color: #111; /* Very dark grey for OLED protection */
    letter-spacing: -0.05em;
    user-select: none;
    text-shadow: 0 0 10px rgba(192, 132, 252, 0.05);
}
