:root {
  --bg-primary: #f2f4f8;
  --bg-secondary: #fff;
  --text-primary: #384e77;
  --text-secondary: #6c7a89;
  --border-color: #bfcbe7;
  --shadow: rgba(0,0,0,0.07);
  --quote-bg: #e8f0fe;
  --quote-border: #5170a2;
  --quote-text: #2a3a72;
  --quote-author: #4661e6;
  --ideas-bg: #f0f6fd;
  --ideas-border: #35a57a;
  --ideas-text: #295c40;
  --task-bg: #ebf1fa;
  --task-border: #5170a2;
  --task-text: #2c365e;
  --complete-bg: #35a57a;
  --delete-bg: #ea4c46;
  --timeline-bg: #f5fafd;
  --timeline-border: #5170a2;
  --progress-bg: #f8f9fa;
  --progress-border: #dee2e6;
}

[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --border-color: #404040;
  --shadow: rgba(0,0,0,0.3);
  --quote-bg: #2a3a5c;
  --quote-border: #4a6fa5;
  --quote-text: #c0d0f0;
  --quote-author: #6b8ce8;
  --ideas-bg: #2a4a3a;
  --ideas-border: #4a8a5a;
  --ideas-text: #c0f0d0;
  --task-bg: #3a3a4a;
  --task-border: #4a6fa5;
  --task-text: #e0e0f0;
  --complete-bg: #4a8a5a;
  --delete-bg: #aa4a4a;
  --timeline-bg: #3a3a4a;
  --timeline-border: #4a6fa5;
  --progress-bg: #2a2a2a;
  --progress-border: #404040;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
  max-width: 600px;
  margin: 40px auto;
  padding: 24px;
  background: var(--bg-secondary);
  border-radius: 10px;
  box-shadow: 0 4px 14px var(--shadow);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  color: var(--text-primary);
}

.dark-mode-toggle {
  background: var(--text-primary);
  color: var(--bg-secondary);
  border: none;
  padding: 10px 15px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.3s ease;
}

.dark-mode-toggle:hover {
  transform: scale(1.1);
}

.quote-container {
  background: var(--quote-bg);
  border-left: 6px solid var(--quote-border);
  padding: 15px 20px;
  margin-bottom: 30px;
  border-radius: 8px;
  color: var(--quote-text);
  transition: all 0.3s ease;
}

.anime-quote {
  font-style: italic;
  font-size: 1.1em;
  margin-bottom: 6px;
}

.quote-author {
  text-align: right;
  font-weight: 600;
  color: var(--quote-author);
  margin-bottom: 10px;
}

#newQuoteBtn {
  background-color: var(--quote-border);
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
}

.study-ideas {
  background: var(--ideas-bg);
  border-left: 6px solid var(--ideas-border);
  padding: 15px 20px;
  border-radius: 8px;
  color: var(--ideas-text);
  margin-bottom: 30px;
  transition: all 0.3s ease;
}

.study-ideas ul {
  padding-left: 18px;
}

.study-ideas li {
  margin-bottom: 8px;
  line-height: 1.3em;
}

.progress-container {
  background: var(--progress-bg);
  border: 1px solid var(--progress-border);
  padding: 15px 20px;
  margin-bottom: 30px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.progress-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.progress-item {
  flex: 1;
}

.progress-label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.progress-bar {
  width: 100%;
  height: 20px;
  background: var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 5px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--complete-bg), #4CAF50);
  transition: width 0.5s ease;
  border-radius: 10px;
}

.progress-text {
  font-size: 0.9em;
  color: var(--text-secondary);
  text-align: center;
}

.pie-chart-container {
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: center;
}

.pie-chart-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
  color: var(--text-primary);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

form {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

form input, form button {
  padding: 10px;
  font-size: 16px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all 0.3s ease;
}

form button {
  background: var(--text-primary);
  color: var(--bg-secondary);
  border: none;
  cursor: pointer;
}

#tasksContainer {
  margin-bottom: 30px;
}

.task-card {
  background: var(--task-bg);
  border-left: 6px solid var(--task-border);
  padding: 14px 14px 10px 20px;
  margin-bottom: 16px;
  border-radius: 8px;
  position: relative;
  transition: all 0.3s ease;
}

.task-title {
  font-size: 1.1em;
  margin-bottom: 5px;
  color: var(--task-text);
}

.task-due {
  font-size: 0.95em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.task-status {
  font-size: 0.93em;
  color: var(--complete-bg);
}

.status-todo {
  color: var(--delete-bg);
}

.complete-btn {
  background: var(--complete-bg);
  color: #fff;
  border: none;
  padding: 4px 13px;
  border-radius: 6px;
  position: absolute;
  top: 15px;
  right: 60px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.delete-btn {
  background: var(--delete-bg);
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  position: absolute;
  top: 15px;
  right: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#timelineContainer {
  padding-top: 10px;
}

.timeline {
  list-style-type: none;
  padding-left: 0;
  border-left: 3px solid var(--timeline-border);
  margin: 0;
}

.timeline-item {
  margin-bottom: 16px;
  position: relative;
  padding-left: 18px;
}

.timeline-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text-primary);
  display: inline-block;
  position: absolute;
  left: -9px;
  top: 8px;
  transition: all 0.3s ease;
}

.timeline-content {
  display: inline-block;
  background: var(--timeline-bg);
  padding: 7px 13px;
  border-radius: 8px;
  margin-left: 7px;
  transition: all 0.3s ease;
}

.timeline-completed .timeline-dot {
  background: var(--complete-bg);
}

.timeline-completed .timeline-content {
  opacity: 0.6;
  text-decoration: line-through;
}

/* Enhanced responsive design */
@media (max-width: 768px) {
  .app-container {
    margin: 10px;
    padding: 15px;
    max-width: none;
    border-radius: 0;
  }
  
  .header-controls {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }
  
  h1 {
    font-size: 1.5em;
    text-align: center;
  }
  
  .dark-mode-toggle {
    align-self: center;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 20px;
  }
  
  .progress-stats {
    flex-direction: column;
    gap: 15px;
  }
  
  .pie-chart-container {
    flex-direction: column;
    gap: 15px;
    align-items: center;
  }
  
  #progressPieChart {
    width: 150px;
    height: 150px;
  }
  
  form {
    flex-direction: column;
    gap: 15px;
  }
  
  form input, form button {
    padding: 15px;
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 8px;
  }
  
  .task-card {
    padding: 15px 15px 15px 20px;
    margin-bottom: 20px;
  }
  
  .complete-btn, .delete-btn {
    padding: 8px 15px;
    font-size: 16px;
    border-radius: 8px;
    min-height: 44px; /* iOS touch target minimum */
    min-width: 44px;
  }
  
  .complete-btn {
    right: 70px;
  }
  
  .quote-container, .study-ideas, .progress-container {
    padding: 15px;
    margin-bottom: 20px;
  }
  
  .anime-quote {
    font-size: 1em;
    line-height: 1.4;
  }
  
  #newQuoteBtn {
    padding: 12px 20px;
    font-size: 16px;
    width: 100%;
    border-radius: 8px;
  }
  
  .study-ideas li {
    margin-bottom: 10px;
    line-height: 1.4;
  }
  
  .progress-label {
    font-size: 0.9em;
  }
  
  .progress-bar {
    height: 25px;
  }
  
  .progress-text {
    font-size: 0.85em;
  }
}

@media (max-width: 480px) {
  .app-container {
    margin: 5px;
    padding: 10px;
  }
  
  h1 {
    font-size: 1.3em;
  }
  
  .quote-container, .study-ideas, .progress-container {
    padding: 12px;
    margin-bottom: 15px;
  }
  
  .anime-quote {
    font-size: 0.95em;
  }
  
  .study-ideas li {
    font-size: 0.9em;
  }
  
  .task-card {
    padding: 12px 12px 12px 15px;
  }
  
  .task-title {
    font-size: 1em;
  }
  
  .task-due, .task-status {
    font-size: 0.9em;
  }
  
  #progressPieChart {
    width: 120px;
    height: 120px;
  }
  
  .legend-item {
    font-size: 0.8em;
  }
  
  .timeline-content {
    font-size: 0.9em;
    padding: 8px 12px;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .complete-btn:hover, .delete-btn:hover, 
  #newQuoteBtn:hover, .dark-mode-toggle:hover {
    transform: none;
  }
  
  .complete-btn:active, .delete-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
  
  .task-card {
    border-left-width: 8px;
  }
  
  .quote-container, .study-ideas {
    border-left-width: 8px;
  }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
  .app-container {
    margin: 5px;
    padding: 10px;
  }
  
  .header-controls {
    flex-direction: row;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  
  h1 {
    font-size: 1.2em;
    text-align: left;
  }
  
  .quote-container, .study-ideas, .progress-container {
    margin-bottom: 15px;
  }
  
  .progress-stats {
    flex-direction: row;
    gap: 10px;
  }
  
  .pie-chart-container {
    flex-direction: row;
    gap: 15px;
  }
}

/* High DPI display optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .progress-bar, .timeline-dot {
    transform: translateZ(0);
  }
}

/* Mobile-specific styles */
.touch-device button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.ios-device form input {
  -webkit-appearance: none;
  border-radius: 8px;
}

.android-device form input {
  border-radius: 8px;
}

/* Prevent zoom on input focus for iOS */
.ios-device input[type="text"],
.ios-device input[type="datetime-local"] {
  font-size: 16px !important;
}

/* Smooth scrolling for mobile */
.touch-device {
  -webkit-overflow-scrolling: touch;
}

/* Better focus states for mobile */
.touch-device button:focus,
.touch-device input:focus {
  outline: 2px solid var(--quote-border);
  outline-offset: 2px;
}

/* Loading states for better UX */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Improved task card spacing on mobile */
@media (max-width: 768px) {
  .task-card {
    position: relative;
    padding-bottom: 50px; /* Make room for buttons */
  }
  
  .complete-btn, .delete-btn {
    position: absolute;
    bottom: 10px;
    top: auto;
  }
  
  .complete-btn {
    right: 80px;
  }
  
  .delete-btn {
    right: 10px;
  }
}

/* Better pie chart on very small screens */
@media (max-width: 320px) {
  #progressPieChart {
    width: 100px;
    height: 100px;
  }
  
  .legend-item {
    font-size: 0.75em;
  }
  
  .legend-color {
    width: 10px;
    height: 10px;
  }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-container {
    max-width: 700px;
    margin: 30px auto;
  }
  
  .progress-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
  
  .pie-chart-container {
    flex-direction: row;
    justify-content: space-around;
  }
}

/* Large desktop optimization */
@media (min-width: 1200px) {
  .app-container {
    max-width: 800px;
  }
  
  .progress-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 30px;
  }
  
  .progress-item:nth-child(3) {
    display: block;
  }
}
