/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #000000;
  --bg2:       #0a0a0a;
  --bg3:       #111111;
  --bg4:       #1a1a1a;
  --border:    #222222;
  --text:      #ffffff;
  --text2:     #888888;
  --text3:     #444444;
  --accent:    #ffffff;
  --radius:    14px;
  --radius-sm: 8px;
  --nav-h:     64px;
  --font:      'Space Mono', monospace;
  --font-sans: 'DM Sans', sans-serif;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== SPLASH SCREEN ===== */
#splash {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
#splash.hide {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}
.splash-icon {
  font-size: 64px;
  margin-bottom: 20px;
  animation: pulse-icon 2s ease infinite;
}
.splash-title {
  font-family: var(--font);
  font-size: 28px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #fff;
}
.splash-sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text2);
  letter-spacing: 1px;
}
.splash-bar {
  margin-top: 40px;
  width: 120px;
  height: 2px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.splash-bar-fill {
  height: 100%;
  width: 0;
  background: #fff;
  animation: load-bar 1.8s ease forwards;
}
@keyframes load-bar { to { width: 100%; } }
@keyframes pulse-icon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ===== APP SHELL ===== */
#app {
  display: none;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}
#app.visible { display: flex; }

/* ===== TOP BAR ===== */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.topbar-title {
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.topbar-date {
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font);
}
#btn-add-habit {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
#btn-add-habit:active { transform: scale(0.9); }

/* ===== VIEWS ===== */
#views {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + 16px);
  display: none;
}
.view.active { display: block; }

/* ===== HABITS VIEW ===== */
.habits-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s;
  cursor: pointer;
}
.habit-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-color, #fff);
}
.habit-card:active { transform: scale(0.98); }

.habit-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg4);
  border-radius: var(--radius-sm);
  position: relative;
}
.habit-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  background: var(--card-color, #fff);
  opacity: 0.08;
}

.habit-info { flex: 1; min-width: 0; }
.habit-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit-stats {
  font-size: 12px;
  color: var(--text2);
  margin-top: 3px;
  font-family: var(--font);
}

.habit-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.btn-hit {
  padding: 8px 16px;
  border-radius: 20px;
  border: none;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  background: var(--card-color, #fff);
  color: #000;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  letter-spacing: 0.5px;
}
.btn-hit:active { transform: scale(0.92); opacity: 0.8; }

.btn-del-habit {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s;
}
.btn-del-habit:hover { color: #ff4444; }

.btn-edit-habit {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s;
}
.btn-edit-habit:hover { color: #fff; }

/* Hit animation */
.hit-ripple {
  position: absolute;
  inset: 0;
  background: var(--card-color, #fff);
  opacity: 0;
  border-radius: var(--radius);
  pointer-events: none;
  animation: hit-flash 0.35s ease forwards;
}
@keyframes hit-flash {
  0%   { opacity: 0.25; transform: scale(0.95); }
  100% { opacity: 0; transform: scale(1.02); }
}

.today-count {
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--card-color, #fff);
  min-width: 28px;
  text-align: right;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* ===== LOGS VIEW ===== */
.logs-list { display: flex; flex-direction: column; gap: 0; }

.log-date-group { margin-bottom: 20px; }
.log-date-header {
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text2);
  text-transform: uppercase;
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.log-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--bg3);
  transition: background 0.1s;
}
.log-item:active { background: var(--bg3); }
.log-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.log-name { font-size: 14px; flex: 1; }
.log-time { font-family: var(--font); font-size: 11px; color: var(--text2); }
.log-icon { font-size: 16px; }
.btn-del-log {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.15s;
}
.btn-del-log:hover { color: #ff4444; }

/* ===== STATS VIEW ===== */
.stats-section { margin-bottom: 28px; }
.stats-section h3 {
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text2);
  text-transform: uppercase;
  margin-bottom: 14px;
}
.chart-wrap {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.habit-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}
.filter-chip.active {
  background: var(--chip-color, #fff);
  border-color: var(--chip-color, #fff);
  color: #000;
}

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 10px;
  font-family: var(--font);
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: color 0.15s;
  padding: 8px 0 10px;
}
.nav-btn svg { transition: transform 0.15s; }
.nav-btn.active { color: var(--text); }
.nav-btn.active svg { transform: translateY(-1px); }

/* ===== MODAL ===== */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  display: none;
  align-items: flex-end;
  backdrop-filter: blur(4px);
}
#modal-overlay.open { display: flex; }
#modal {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  padding: 24px 20px 32px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.22,.68,0,1.2);
}
#modal-overlay.open #modal { transform: translateY(0); }

.modal-title {
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 20px;
}
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: #555; }

.emoji-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.emoji-opt {
  font-size: 22px;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.emoji-opt.selected {
  border-color: #fff;
  background: var(--bg);
}

.color-preview {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: #fff;
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font);
  letter-spacing: 1px;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 8px;
}
.btn-primary:active { opacity: 0.8; }
.btn-cancel {
  width: 100%;
  padding: 12px;
  background: none;
  color: var(--text2);
  border: none;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
  font-family: var(--font-sans);
}

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #fff;
  color: #000;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 5000;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== INSTALL BANNER ===== */
#install-banner {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#install-banner.show { display: flex; }
.install-text { flex: 1; font-size: 13px; }
.install-text strong { display: block; font-size: 14px; }
.install-text span { color: var(--text2); font-size: 12px; }
#btn-install {
  padding: 8px 16px;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  flex-shrink: 0;
}
#btn-install-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

/* ===== UTILS ===== */
.section-title {
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text2);
  text-transform: uppercase;
  margin-bottom: 14px;
  padding-top: 4px;
}
