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

:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-dim: #484f58;
  --accent: #58a6ff;
  --green-0: #161b22;
  --green-1: #0e4429;
  --green-2: #006d32;
  --green-3: #26a641;
  --green-4: #39d353;
  --cell-size: 11px;
  --cell-gap: 3px;
  --cell-radius: 2px;
}

html {
  font-size: 14px;
}

body {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Cascadia Code", monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
  flex: 1;
  width: 100%;
}

/* Header */
header {
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.prompt {
  color: var(--green-4);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* Form */
#form {
  margin-bottom: 2rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.input-group {
  flex: 1;
  min-width: 160px;
}

.input-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.icon {
  width: 14px;
  height: 14px;
}

.input-group input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.input-group input::placeholder {
  color: var(--text-dim);
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

#submit-btn {
  padding: 0.55rem 1.25rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
  white-space: nowrap;
}

#submit-btn:hover {
  opacity: 0.9;
}

#submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Error banner */
.error-banner {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: #f85149;
}

/* Demo hint */
.demo-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 1.5rem 0;
}

.demo-hint a {
  color: var(--text-muted);
}

.demo-hint a:hover {
  color: var(--text);
}

/* Results */
.hidden {
  display: none !important;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.stats .total {
  color: var(--text);
  font-weight: 600;
}

.stats .source {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stats .source a {
  color: var(--text-muted);
  text-decoration: none;
}

.stats .source a:hover {
  color: var(--text);
  text-decoration: underline;
}

.stats .gh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-4);
  display: inline-block;
}

.stats .gl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e24329;
  display: inline-block;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: color 0.15s, border-color 0.15s;
}

.action-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Year navigation */
.year-nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.year-btn {
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: inherit;
  transition: all 0.15s;
}

.year-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.year-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

/* Graph */
#graph-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  overflow: hidden;
}

#graph-wrap {
  width: 100%;
}

.month-labels {
  display: flex;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  padding-left: 32px;
  gap: 0;
}

.month-labels span {
  flex: none;
}

.graph-body {
  display: flex;
  gap: 4px;
}

.day-labels {
  display: flex;
  flex-direction: column;
  font-size: 0.65rem;
  color: var(--text-muted);
  width: 28px;
  flex-shrink: 0;
}

.day-labels span {
  height: var(--cell-size);
  margin-bottom: var(--cell-gap);
  display: flex;
  align-items: center;
  line-height: 1;
}

.graph-grid {
  display: flex;
  gap: var(--cell-gap);
}

.week-col {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
}

.day-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--cell-radius);
  background: var(--green-0);
  outline: 1px solid rgba(27, 31, 35, 0.06);
  position: relative;
  cursor: pointer;
}

.day-cell[data-level="1"] { background: var(--green-1); }
.day-cell[data-level="2"] { background: var(--green-2); }
.day-cell[data-level="3"] { background: var(--green-3); }
.day-cell[data-level="4"] { background: var(--green-4); }

.day-cell:hover {
  outline: 1px solid var(--text-muted);
}

/* Shimmer loading state */
#graph-container.loading .day-cell {
  animation: shimmer 1.5s ease-in-out infinite;
  background: var(--green-0) !important;
}

#graph-container.loading .day-cell:nth-child(1) { animation-delay: 0s; }
#graph-container.loading .day-cell:nth-child(2) { animation-delay: 0.05s; }
#graph-container.loading .day-cell:nth-child(3) { animation-delay: 0.1s; }
#graph-container.loading .day-cell:nth-child(4) { animation-delay: 0.15s; }
#graph-container.loading .day-cell:nth-child(5) { animation-delay: 0.2s; }
#graph-container.loading .day-cell:nth-child(6) { animation-delay: 0.25s; }
#graph-container.loading .day-cell:nth-child(7) { animation-delay: 0.3s; }

@keyframes shimmer {
  0%, 100% { background: var(--green-0); }
  50% { background: #1e2a35; }
}

#graph-container.loading .month-labels,
#graph-container.loading .stats {
  opacity: 0.4;
}

/* Year label in all-years view */
.year-graph-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.35rem;
}

.year-graph-label:first-child {
  margin-top: 0;
}

/* Tooltip */
.tooltip {
  position: fixed;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font-size: 0.7rem;
  color: var(--text);
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tooltip .tip-date {
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

/* Streak stats */
.streak-stats {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.streak-card {
  flex: 1;
  min-width: 100px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  text-align: center;
}

.streak-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.streak-unit {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 1px;
}

.streak-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  text-transform: lowercase;
}

/* Legend */
.legend {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 0.6rem;
  justify-content: flex-end;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend span {
  margin: 0 3px;
}

.legend-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--cell-radius);
  background: var(--green-0);
}

.legend-cell[data-level="1"] { background: var(--green-1); }
.legend-cell[data-level="2"] { background: var(--green-2); }
.legend-cell[data-level="3"] { background: var(--green-3); }
.legend-cell[data-level="4"] { background: var(--green-4); }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 200;
  animation: fadeInUp 0.2s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

/* Embed mode */
body.embed-mode {
  min-height: auto;
}

body.embed-mode header,
body.embed-mode #form,
body.embed-mode #demo-hint,
body.embed-mode footer,
body.embed-mode .actions,
body.embed-mode .year-nav {
  display: none !important;
}

body.embed-mode .container {
  padding: 0.75rem;
}

body.embed-mode .results-header {
  margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 2rem 1rem 1.5rem;
  }

  .input-row {
    flex-direction: column;
  }

  .input-group {
    min-width: 100%;
  }

  #submit-btn {
    width: 100%;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats {
    flex-direction: column;
    gap: 0.25rem;
  }

  #graph-container {
    padding: 0.75rem;
  }

  .day-labels {
    display: none;
  }

  .month-labels {
    padding-left: 0 !important;
    font-size: 0.55rem;
  }

  .year-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .year-nav::-webkit-scrollbar {
    display: none;
  }

  .year-btn {
    flex-shrink: 0;
  }

  .graph-body {
    gap: 0;
  }

  .streak-stats {
    gap: 0.35rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .streak-card {
    min-width: 0;
    padding: 0.5rem 0.4rem;
    overflow: hidden;
  }

  .streak-label {
    font-size: 0.6rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .streak-value {
    font-size: 0.95rem;
  }
}
