:root {
  --bg: #0b1220;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #334155;
  --primary: #22c55e;
  --danger-bg: #3f1d24;
  --danger-text: #fca5a5;
  --hm-cell-w: 11px;
  --hm-cell-h: 10px;
  --hm-gap-x: 4px;
  --hm-gap-y: 3px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  width: min(960px, calc(100% - 2rem));
  margin: 2rem auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 1rem;
  height: calc(100vh - 4rem);
}

.app-header h1 {
  margin: 0;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.header-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.panel,
.habit-card {
  background: var(--card);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.habit-card {
  min-width: 0;
}

.habit-form {
  display: grid;
  grid-template-columns: 40% auto auto auto;
  gap: 0.75rem;
  align-items: end;
}

.habit-form label {
  display: grid;
  gap: 0;
  min-width: 0;
}

.name-field {
  min-width: 288px;
}

.target-field {
  min-width: 0;
}

.target-color-group {
  display: inline-flex;
  align-items: end;
  gap: 0.35rem;
}

.icon-field {
  position: relative;
}

.target-slider-wrap {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f172a;
  padding: 0 0.55rem;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.08) inset,
    0 -2px 0 rgba(0, 0, 0, 0.28) inset;
}

.target-slider-wrap input[type="range"] {
  width: 118px;
  min-height: auto;
  box-shadow: none;
  border: none;
  padding: 0;
}

.target-display {
  min-width: 48px;
  text-align: center;
  color: var(--text);
  font-weight: 700;
  font-size: 0.92rem;
}

input {
  background: #0f172a;
  color: var(--text);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.72rem;
  font-size: 0.95rem;
  min-height: 44px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.08) inset,
    0 -2px 0 rgba(0, 0, 0, 0.28) inset;
}

select {
  background: #0f172a;
  color: var(--text);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.72rem;
  font-size: 0.95rem;
  min-height: 44px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.08) inset,
    0 -2px 0 rgba(0, 0, 0, 0.28) inset;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.habit-form button,
.inc-btn {
  background: var(--primary);
  color: #052e16;
}

#add-habit-btn {
  width: 110px;
  justify-self: end;
  transition: background-color 220ms ease, color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
  background: #22c55e;
  color: #052e16;
}

.habit-list {
  display: grid;
  gap: 0.85rem;
}

.list-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.list-panel .habit-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.35rem;
}

.habit-head,
.habit-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.habit-head-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.year-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.year-nav-btn {
  min-height: 30px;
  width: 28px;
  padding: 0;
  background: #0f172a;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 0.75rem;
}

.year-nav-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.year-label {
  min-width: 54px;
  text-align: center;
  font-size: 0.8rem;
  color: #cbd5e1;
}

.habit-head h3,
.habit-progress-row p {
  margin: 0;
}

.habit-icon-btn {
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  background: #0f172a;
  color: var(--text);
  border: 1px solid #64748b;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.1) inset,
    0 -2px 0 rgba(0, 0, 0, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.35);
}

.inc-btn {
  width: 110px;
  min-height: 44px;
  padding: 0.35rem 0.2rem 0.35rem 0.45rem;
  background: #0f172a;
  color: var(--text);
  border: 1px solid #64748b;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.1) inset,
    0 -2px 0 rgba(0, 0, 0, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.35);
  transition: transform 120ms ease, box-shadow 220ms ease;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.inc-btn:active {
  transform: scale(0.95);
}

.water-tank {
  position: relative;
  display: block;
  width: calc(100% - 8px);
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(15, 23, 42, 0.85);
}

.battery-cap {
  width: 6px;
  height: 12px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.25);
}

.water-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  transition: width 220ms ease, background-color 220ms ease;
}

.charge-wave {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: repeating-linear-gradient(
    -60deg,
    rgba(255, 255, 255, 0.18) 0 8px,
    rgba(255, 255, 255, 0.05) 8px 16px
  );
  transform: translateX(-22px);
}

.water-tank.charging .charge-wave {
  opacity: 1;
  animation: chargeFlow 1.1s linear infinite;
}

.water-tank.full .charge-wave {
  opacity: 0;
}

.water-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #e5e7eb;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

@keyframes chargeFlow {
  from { transform: translateX(-24px); }
  to { transform: translateX(24px); }
}

.heatmap {
  margin-top: 0.85rem;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  padding-bottom: 0.3rem;
  display: flex;
  justify-content: center;
}

.gh-heatmap {
  width: max-content;
  min-width: 0;
}

.heat-cell {
  width: var(--hm-cell-w);
  height: var(--hm-cell-h);
  border-radius: 2px;
}

.heat-out {
  opacity: 0.3;
}

.gh-months {
  margin-left: 26px;
  margin-bottom: 4px;
  display: grid;
  grid-template-columns: repeat(var(--weeks), var(--hm-cell-w));
  column-gap: var(--hm-gap-x);
  color: var(--muted);
  font-size: 0.72rem;
}

.gh-month {
  white-space: nowrap;
}

.gh-body {
  display: flex;
  gap: 8px;
}

.gh-weekdays {
  width: 24px;
  height: calc(var(--hm-cell-h) * 7 + var(--hm-gap-y) * 6);
  display: grid;
  grid-template-rows: repeat(7, var(--hm-cell-h));
  row-gap: var(--hm-gap-y);
  color: var(--muted);
  font-size: 0.65rem;
}

.gh-weekdays span {
  line-height: var(--hm-cell-h);
}

.gh-grid {
  display: grid;
  grid-template-columns: repeat(var(--weeks), var(--hm-cell-w));
  grid-template-rows: repeat(7, var(--hm-cell-h));
  grid-auto-flow: column;
  column-gap: var(--hm-gap-x);
  row-gap: var(--hm-gap-y);
}

.gh-legend {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.gh-legend .heat-cell {
  width: 12px;
  height: 12px;
}

.level-0 { background: #e5e7eb; }
.level-1 { background: #86efac; }
.level-2 { background: #4ade80; }
.level-3 { background: #16a34a; }

.empty {
  margin: 0;
  color: var(--muted);
}

.color-picker-wrap {
  display: flex;
}

#habit-color {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.color-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 44px;
  gap: 0;
  background: #0f172a;
  color: var(--text);
  border: 1px solid #64748b;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.1) inset,
    0 -2px 0 rgba(0, 0, 0, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.35);
  padding: 0.6rem 0.7rem;
  transition: background-color 220ms ease, color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.color-icon {
  font-size: 1.05rem;
}

.icon-trigger {
  width: 52px;
  height: 44px;
  padding: 0;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  background: #0f172a;
  color: var(--text);
  border: 1px solid #64748b;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.1) inset,
    0 -2px 0 rgba(0, 0, 0, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.35);
  transition: background-color 220ms ease, color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

#add-habit-btn {
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.2) inset,
    0 -2px 0 rgba(0, 0, 0, 0.28) inset,
    0 6px 12px rgba(0, 0, 0, 0.35);
}

.icon-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: 260px;
  padding: 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f172a;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.icon-choice {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.05rem;
  background: #1f2937;
  color: #e5e7eb;
  border: 1px solid #374151;
}

.icon-choice:hover {
  background: #334155;
}

.hidden {
  display: none;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.55);
}

.confirm-modal.hidden {
  display: none;
}

.confirm-card {
  width: min(360px, calc(100% - 2rem));
  background: #111827;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.confirm-card p {
  margin: 0;
  color: #d1d5db;
}

.confirm-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.confirm-actions button {
  min-width: 70px;
}

#confirm-ok {
  background: #93c5fd;
  color: #0b1220;
}

#confirm-cancel {
  background: #0f172a;
  color: #e5e7eb;
  border: 1px solid #334155;
}

@media (max-width: 860px) {
  .habit-form {
    grid-template-columns: 1fr 1fr;
  }

  .name-field {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .target-color-group {
    grid-column: 1 / -1;
  }
}
