/* Piruit — shared styles */

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

:root {
  --bg: #13131f;
  --surface: #1c1c2e;
  --text: #dcdcff;
  --muted: #8888aa;
  --accent: #7c6cf7;
  --success: #00b894;
  --danger: #d63031;
  --warn: #fdcb6e;
  --kid-bg: #fff8e7;
  --kid-surface: #fff;
  --kid-text: #2d3436;
  --radius: 5px;
  --gap: 14px;
  --grid-margin: -12px;
  --cell-border: rgba(255, 255, 255, .15);
  --cal-cell-bg: rgba(255, 255, 255, .05);
}

body.light {
  --bg: #f5f0f5;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #8888aa;
  --accent: #6c5ce7;
  --success: #00b894;
  --danger: #d63031;
  --warn: #fdcb6e;
  --cell-border: rgba(0, 0, 0, .12);
  --cal-cell-bg: rgba(0, 0, 0, .04);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  max-width: 680px;
  margin: 0 auto;
}

body.kid { background: var(--kid-bg); color: var(--kid-text); }
.kid .surface { background: var(--kid-surface); box-shadow: 0 2px 8px #0001; }

header {
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  flex-shrink: 0;
}

.surface {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.full-width {
  margin-left: var(--grid-margin);
  margin-right: var(--grid-margin);
  width: auto;
}

main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 680px;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid rgba(255, 255, 255, .06);
  padding: 8px 0 env(safe-area-inset-bottom, 8px);
  z-index: 10;
}

.kid nav { background: var(--kid-surface); border-color: #eee; }

nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 12px;
  cursor: pointer;
  border-radius: 8px;
  transition: color .2s, background .2s;
  min-height: 48px;
}

nav button.active, nav button:hover { color: var(--accent); }
.kid nav button.active, .kid nav button:hover { color: #e17055; }

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .2s;
}

button:hover { opacity: .85; }
button.outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
button.small { padding: 6px 14px; font-size: 12px; }
button.danger { background: var(--danger); }

input, select {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
}

.kid input, .kid select { background: #fff; border-color: #ddd; color: var(--kid-text); }
input:focus { outline: 2px solid var(--accent); }

.xp-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
}

.xp-bar .level { color: var(--accent); }
.kid .xp-bar .level { color: #e17055; font-size: 24px; }

.month-grid {
  background: var(--surface);
  border-radius: var(--radius);
}

.month-grid h4 {
  font-size: 15px;
  margin-bottom: 6px;
  color: var(--muted);
}

.month-grid .weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  max-width: 320px;
  margin: 0 auto 2px;
}

.month-grid .weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

.month-grid .days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  max-width: 320px;
  margin: 0 auto;
}

.month-grid .day {
  aspect-ratio: 1;
  width: 100%;
  border-radius: 4px;
  background: var(--cal-cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: var(--muted);
}

.kid .month-grid .day { background: #eee; }

.month-grid .day.l1 { background: var(--accent); opacity: .3; }
.month-grid .day.l2 { background: var(--accent); opacity: .6; }
.month-grid .day.l3 { background: var(--accent); opacity: .85; }
.month-grid .day.l4 { background: var(--accent); }
.month-grid .day.today { border: 1.5px solid var(--accent); opacity: 1; }

.kid .month-grid .day.l1 { background: #fab1a0; }
.kid .month-grid .day.l2 { background: #e17055; }
.kid .month-grid .day.l3 { background: #d63031; }
.kid .month-grid .day.l4 { background: #b71540; }

@keyframes slideDown {
  from { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin: 0; }
  to { opacity: 1; max-height: 100px; padding-top: 6px; padding-bottom: 6px; margin: 2px 0; }
}

.day-detail {
  background: rgba(255, 255, 255, .03);
  border-radius: 4px;
  padding: 6px 10px;
  margin: 2px 0;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  box-sizing: border-box;
  animation: slideDown .2s ease-out;
  overflow: hidden;
}

.day-detail span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
}

.calendar-year {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.calendar-year button { padding: 4px 10px; font-size: 12px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kid .modal { background: var(--kid-surface); }
.modal h2 { font-size: 18px; }

.confetti {
  font-size: 48px;
  text-align: center;
  animation: pop .5s ease-out;
}

@keyframes pop {
  0% { transform: scale(0); }
  80% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; }

.flex { display: flex; }
.gap { gap: 8px; }
.col { flex-direction: column; }
.between { justify-content: space-between; }
.center { align-items: center; }

.muted { color: var(--muted); font-size: 13px; }
.mt { margin-top: 8px; }
.mb { margin-bottom: 8px; }
.text-center { text-align: center; }
.hidden { display: none !important; }

.grid-cell-btn.syncing { animation: pulse .8s ease-in-out infinite; }
#view { transition: opacity .15s ease; }
.modal .flex.gap { flex-wrap: wrap; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.grid-view {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  overflow: hidden;
  margin-left: var(--grid-margin);
  margin-right: var(--grid-margin);
  width: auto;
  border-radius: var(--radius);
  padding-top: 4px;
  padding-right: 4px;
  padding-bottom: 4px;
  max-width: 480px;
}

.grid-header {
  display: grid;
  grid-template-columns: 1fr repeat(5, 40px);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.grid-view.collapsed .grid-header,
.grid-view.collapsed .grid-row {
  grid-template-columns: 56px repeat(5, minmax(48px, 1fr));
  column-gap: 8px;
}

.grid-view.collapsed { gap: 8px; padding: 12px 4px; }
.collapsed .grid-row { border-bottom: none; }
.collapsed .grid-cell { padding: 0; }
.grid-view.collapsed .grid-header-cell:first-child { justify-content: center; padding-left: 0; }
.collapsed .grid-header-cell { padding: 8px 2px; }
.collapsed .grid-header-date { font-size: 10px; opacity: .85; margin-top: 2px; }

.grid-header-cell {
  padding: 10px 4px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.grid-header-cell.today { color: var(--accent); }
.grid-header-date {
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
  margin-top: 1px;
  opacity: .7;
}

.grid-row {
  display: grid;
  grid-template-columns: 1fr repeat(5, 40px);
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  min-width: 0;
}

.grid-row:last-child { border-bottom: none; }

.grid-label {
  padding: 6px 8px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: normal;
  line-height: 1.3;
  min-width: 0;
}

.habit-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-freq { font-size: 10px; color: var(--muted); font-weight: 400; line-height: 1; }

.habit-icon-today {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.collapsed .habit-icon-today { font-size: 22px; }

.habit-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  white-space: nowrap;
  max-width: 300px;
  opacity: 1;
  transition: max-width .45s ease, opacity .25s ease;
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 0;
  cursor: pointer;
}

.grid-cell-btn {
  width: min(100%, 34px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--cell-border);
  background: transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, width .45s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: transparent;
  -webkit-tap-highlight-color: transparent;
}

.grid-view.collapsed .grid-cell .grid-cell-btn { width: min(100%, 48px); font-size: 15px; }
.grid-cell-btn.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid-cell-btn.done::after { content: "✓"; font-weight: 600; }
.grid-cell-btn.today { border-color: var(--accent); border-width: 2.5px; }
.grid-cell-btn:active { transform: scale(0.92); }

.collapsed .habit-info { max-width: 0; opacity: 0; margin: 0; padding: 0; }
.collapsed .grid-label { justify-content: center; gap: 0; padding: 6px 0; width: 56px; }

.toggle-tracker {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 6px;
  flex-shrink: 0;
}

body.light .toggle-tracker { background: rgba(0, 0, 0, .04); border-color: rgba(0, 0, 0, .1); }
.toggle-tracker:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .15); }

.tracker-icon {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  display: block;
  transition: transform .45s ease;
}

.collapsed .tracker-icon { transform: rotate(180deg); }

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.menu-overlay.open { opacity: 1; pointer-events: auto; }

.side-menu {
  position: fixed;
  top: 0;
  right: 0;
  width: 260px;
  height: 100%;
  background: var(--surface);
  z-index: 51;
  transform: translateX(100%);
  transition: transform .2s;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-menu.open { transform: translateX(0); }

.side-menu .user-name {
  font-size: 16px;
  font-weight: 600;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.side-menu a {
  color: var(--text);
  cursor: pointer;
  padding: 8px 0;
  font-size: 14px;
  display: block;
}

.side-menu .logout { margin-top: auto; color: var(--danger); }
.side-menu .version { font-size: 11px; color: var(--muted); text-align: center; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.card-row { display: flex; align-items: center; gap: 10px; }

.habit-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.habit-btn {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  line-height: 1;
}

.habit-btn.outline { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.habit-btn.danger { background: var(--danger); color: #fff; }
.habit-btn.warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }

.habit-stats { font-size: 11px; color: var(--muted); margin-top: 4px; }
.habit-card.archived { opacity: .55; }

.archived-badge {
  display: inline-block;
  font-size: 10px;
  background: rgba(127, 127, 127, .18);
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  vertical-align: middle;
}

.del-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: rgba(214, 48, 49, .12);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 8px;
  font-size: 13px;
}

.del-confirm span { flex: 1; min-width: 140px; color: var(--danger); font-weight: 500; }

.empty-state {
  text-align: center;
  padding: 20px 12px;
  color: var(--muted);
  font-size: 14px;
}

.color-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; margin-bottom: 4px; }

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .15s, border-color .15s;
}

.color-swatch.selected { border-color: var(--text); transform: scale(1.1); }
.input-note { font-size: 11px; color: var(--muted); margin-top: 2px; }

.btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}

/* Offline indicator */
#offline-badge {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--warn);
  color: #000;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 4px;
  z-index: 1000;
  transform: translateY(-100%);
  transition: transform .2s;
}

#offline-badge.visible { transform: translateY(0); }

/* Toast notifications */
#toast-container {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: auto;
  animation: toastIn .2s ease-out;
}

.toast.error { border-left: 4px solid var(--danger); }
.toast.success { border-left: 4px solid var(--success); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
