:root {
  --bg: #0f172a;
  --panel: #111827ee;
  --card: #1f2937;
  --muted: #94a3b8;
  --text: #e5e7eb;
  --accent: #22c55e;
  --accent2: #38bdf8;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(
      1200px 600px at 20% -10%,
      #0b1229,
      transparent
    ),
    radial-gradient(1000px 800px at 120% 0%, #0b2d1b, transparent),
    var(--bg);
  color: var(--text);
}

#riskOverlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: transparent;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
}

/* PWA install banner */
.pwa-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(2, 6, 23, 0.9);
  border: 1px solid #2b3a56;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  border-radius: 14px;
  padding: 10px 12px;
  z-index: 9999;
}
.pwa-content {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pwa-text {
  color: #cbd5e1;
  font-size: 13px;
}
.pwa-button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #2b3a56;
  background: linear-gradient(180deg, #0f2f1d, #0c2216);
  color: #e5e7eb;
  cursor: pointer;
}

/* Sleep Debt styling */
#sleepDebt {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sd-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #2b3a56;
  background: #0b1324;
  font-size: 12px;
  color: #cbd5e1;
}

.sd-chip.ok {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.35);
  color: #bbf7d0;
}

.sd-chip.warn {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fde68a;
}

.sd-chip.danger {
  background: rgba(153, 27, 27, 0.18);
  border-color: rgba(153, 27, 27, 0.45);
  color: #fecaca;
}

.sd-chip .label {
  opacity: 0.8;
}

.sd-chip .value {
  font-weight: 600;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.sub {
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.card {
  background: linear-gradient(180deg, #1f2937, #0f172a);
  border: 1px solid #263247;
  border-radius: 16px;
  padding: 14px;
  flex: 1 1 320px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.card h3 {
  margin: 0.2rem 0 0.6rem 0;
  font-size: 16px;
  letter-spacing: 0.3px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0b1223;
  border: 1px solid #1b2740;
  color: #cbd5e1;
  font-size: 12px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label.chk {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #0e162a;
  border: 1px solid #21304b;
  cursor: pointer;
}

label.chk input {
  transform: scale(1.2);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #2a3b59;
  background: #0e172a;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn.primary {
  background: linear-gradient(180deg, #0f2f1d, #0c2216);
  border-color: #1e3a2a;
}

.btn.accent {
  background: linear-gradient(180deg, #052433, #071a27);
  border-color: #113248;
}

.btn.red {
  background: linear-gradient(180deg, #2a0e12, #200b0e);
  border-color: #4a151b;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.bar {
  height: 8px;
  background: #0a1222;
  border: 1px solid #1f2c47;
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  width: 0%;
  transition: width 0.5s ease;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

input[type="time"],
input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #24344f;
  background: #0d1628;
  color: var(--text);
  transition: border-color 0.2s ease;
}

input[type="time"]:focus,
input[type="number"]:focus,
input[type="text"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent2);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #2b3a56;
  background: #0b1324;
  font-size: 12px;
  color: #cbd5e1;
}

/* Star rating */
.stars {
  display: inline-flex;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
.stars .star {
  font-size: 24px;
  color: #475569;
  transition: color 0.15s;
}
.stars .star.active {
  color: #fbbf24;
}

footer {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.small {
  font-size: 11px;
  color: #8aa0bf;
}

.flex {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

canvas {
  width: 100%;
  height: 140px;
  background: #0b1324;
  border: 1px solid #24344f;
  border-radius: 12px;
}

.tasksBar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 50;
}

.modal.active {
  display: flex;
}

.modal-card {
  width: min(560px, 92vw);
  background: linear-gradient(180deg, #0d1628, #0b1324);
  border: 1px solid #263247;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #223049;
  border-radius: 10px;
  background: #0c1527;
  transition: all 0.2s ease;
}

.task-item:hover {
  background: #0e1829;
  border-color: #2a3a5a;
}

.task-item.done {
  opacity: 0.7;
  text-decoration: line-through;
}

.task-list {
  display: grid;
  gap: 8px;
  max-height: 50vh;
  overflow: auto;
  margin-top: 8px;
}

.chip {
  border: 1px solid #234;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0b1324;
}

/* Crash Risk UI */
#crashRisk {
  margin-left: 10px;
  color: #fff;
  font-weight: 500;
}

#crashTips {
  margin-top: 8px;
  padding: 8px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 8px;
}

#crashTips ul {
  margin: 4px 0 0 18px;
  padding: 0;
  font-size: 12px;
}

#crashTips li {
  margin-bottom: 2px;
}

/* Responsive Design */
@media (max-width: 640px) {
  body {
    padding: 10px;
  }
  
  .title {
    font-size: 18px;
  }
  
  .grid {
    grid-template-columns: 1fr;
  }
  
  .row {
    gap: 10px;
  }
  
  .card {
    padding: 12px;
  }
  
  header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .flex {
    justify-content: center;
  }
}

/* Loading States */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* Focus States */
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* Timer Blocks */
.block {
  border: 1px solid #263247;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  background: #0e162a;
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.block-buttons {
  display: flex;
  gap: 6px;
}

.block-buttons button {
  padding: 4px 8px;
  border: 1px solid #263247;
  border-radius: 6px;
  background: #1f2937;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.block-buttons button:hover:not(:disabled) {
  background: #374151;
  border-color: #4b5563;
}

.block-buttons button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.timer-display {
  font-family: monospace;
  font-size: 18px;
  font-weight: bold;
  color: var(--accent2);
  text-align: center;
  margin: 8px 0;
  padding: 8px;
  background: #0b1223;
  border-radius: 8px;
  border: 1px solid #1b2740;
}

/* Score Bar */
.score-bar {
  width: 100%;
  height: 8px;
  background: #1f2937;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.dash-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.dash-chart-item canvas {
  width: 100%;
  height: 60px;
  background: #0b1324;
  border: 1px solid #24344f;
  border-radius: 8px;
}
.dash-chart-item {
  background: linear-gradient(180deg, #0d1628, #0b1324);
  border: 1px solid #263247;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.25);
}
.dash-chart-item .muted {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.dash-chart-legend {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}
.legend-green { background: #22c55e; }
.legend-yellow { background: #fbbf24; }
.legend-red { background: #991b1b; }

.score-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.3s ease;
  width: 0%;
}

/* Chart Summary */
.chart-summary {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Task Input */
.task-input {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.task-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #263247;
  border-radius: 8px;
  background: #1f2937;
  color: var(--text);
}

.task-input button {
  padding: 8px 16px;
  border: 1px solid #263247;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.task-input button:hover {
  background: #16a34a;
  border-color: #16a34a;
}

/* Task List */
#taskList {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
}

#taskList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #263247;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #1f2937;
}

#taskList li.completed {
  opacity: 0.6;
  text-decoration: line-through;
}

#taskList li input[type="checkbox"] {
  margin: 0;
}

#taskList li .task-text {
  flex: 1;
}

#taskList li .delete-task {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

#taskList li .delete-task:hover {
  background: #dc2626;
}

/* Pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent2);
  color: white;
  font-size: 12px;
  font-weight: 500;
}

/* Save Status */
#saveStatus {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}
