:root {
  --bg: #09090b;
  --bg-elev: #131316;
  --bg-elev-hi: #1c1c21;
  --border: #26262c;
  --border-hi: #34343b;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #6b6b75;
  --accent: #8b9eff;
  --accent-2: #b18bff;
  --accent-glow: rgba(139, 158, 255, 0.18);
  --present: #4ade80;
  --absent: #f87171;
  --warn: #fbbf24;
  --scheduled: #60a5fa;
  --scheduled-fill: rgba(96, 165, 250, 0.78);
  --attended: #4ade80;
  --attended-fill: rgba(74, 222, 128, 0.78);
  --missed: #f87171;
  --missed-fill: rgba(248, 113, 113, 0.78);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 18px rgba(0, 0, 0, 0.22);
}

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

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 40% at 50% -10%, rgba(139, 158, 255, 0.07), transparent 60%),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(177, 139, 255, 0.04), transparent 60%),
    var(--bg);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    max(28px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(60px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 4px;
}
.header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--border-hi);
}

/* Toggle-button: Plus by default, Check when active */
#selectModeBtn .icon-check { display: none; }
#selectModeBtn.active .icon-plus { display: none; }
#selectModeBtn.active .icon-check { display: block; }

.icon-btn.active {
  background: var(--scheduled);
  border-color: var(--scheduled);
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.28), 0 4px 14px rgba(96, 165, 250, 0.4);
  transform: scale(1.05);
}
.icon-btn.active:hover {
  background: var(--scheduled);
  filter: brightness(1.08);
  color: #ffffff;
}

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

/* While in select-mode: subtle blue tint on calendar to reinforce mode */
body.select-mode .calendar.card {
  border-color: rgba(96, 165, 250, 0.45);
  box-shadow: var(--shadow), 0 0 0 1px rgba(96, 165, 250, 0.18);
}
body.select-mode .calendar-cell:not(.empty):not(.scheduled):not(.attended):not(.missed):hover {
  background: rgba(96, 165, 250, 0.12);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* Hero */
.hero {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px;
}
.hero-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.label {
  font-size: 13px;
  color: var(--text-muted);
}
.threshold-pill {
  font-size: 12px;
  color: var(--text);
  background: var(--bg-elev-hi);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.hero-percent {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-feature-settings: "tnum";
}
.hero-percent #percentValue {
  font-size: 42px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(180deg, #ffffff 0%, #d4d4d8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-percent .unit {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 500;
}

.progress {
  position: relative;
  padding-top: 10px;
}
.progress-track {
  height: 8px;
  background: var(--bg-elev-hi);
  border-radius: 999px;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width 0.4s ease, background 0.25s ease;
}
.progress-fill.warn {
  background: linear-gradient(90deg, var(--warn), #f97316);
}
.progress-fill.danger {
  background: linear-gradient(90deg, var(--absent), #dc2626);
}
.progress-fill.good {
  background: linear-gradient(90deg, var(--present), #22c55e);
}
.progress-threshold {
  position: absolute;
  top: 6px;
  bottom: -4px;
  width: 2px;
  background: rgba(250, 250, 250, 0.45);
  pointer-events: none;
}
.progress-threshold::after {
  content: attr(data-label);
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-dim);
  font-feature-settings: "tnum";
}

.hero-status {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.hero-status.good {
  color: var(--present);
}
.hero-status.warn {
  color: var(--warn);
}
.hero-status.bad {
  color: var(--absent);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  padding: 12px 14px;
}
.stat-value {
  font-size: 22px;
  font-weight: 600;
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Calendar */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.calendar-header h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.nav-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.nav-btn:hover {
  background: var(--bg-elev-hi);
  color: var(--text);
  border-color: var(--border-hi);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.calendar-weekdays {
  margin-bottom: 8px;
}
.calendar-weekdays span {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 0;
}

.calendar-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 400;
  font-feature-settings: "tnum";
  position: relative;
  isolation: isolate;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: manipulation;
  outline: none;
  overflow: hidden;
}
.calendar-cell * {
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}
.calendar-cell:focus { outline: none; }
.calendar-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.calendar-cell:active:not(.empty) {
  transform: scale(0.94);
  transition: transform 0.08s ease;
}
.calendar-cell.empty {
  visibility: hidden;
  pointer-events: none;
}
.calendar-cell.today {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.calendar-cell.weekend:not(.empty) {
  color: var(--text-dim);
  cursor: default;
}
body.select-mode .calendar-cell.weekend:not(.empty) {
  opacity: 0.55;
}
body.select-mode .calendar-cell.weekend:not(.empty):hover {
  background: transparent;
}
.calendar-cell.scheduled {
  background: var(--scheduled-fill);
  color: #ffffff;
  font-weight: 500;
}
.calendar-cell.attended {
  background: var(--attended-fill);
  color: #052e16;
  font-weight: 600;
}
.calendar-cell.missed {
  background: var(--missed-fill);
  color: #ffffff;
  font-weight: 500;
}

/* Pulse: brief scale-up after status change for visual confirmation */
.calendar-cell.pulse {
  animation: cellPulse 0.32s cubic-bezier(0.34, 1.45, 0.64, 1);
}
@keyframes cellPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* Long-press progress fill (scaleY from bottom) */
.calendar-cell.pressing::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--attended-fill);
  border-radius: inherit;
  transform: scaleY(0);
  transform-origin: bottom;
  animation: pressFill 0.4s linear forwards;
  pointer-events: none;
  z-index: -1;
}
.calendar-cell.pressing.press-undo::before {
  background: var(--missed-fill);
}
@keyframes pressFill {
  to { transform: scaleY(1); }
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
}
.dot.scheduled {
  background: var(--scheduled);
}
.dot.attended {
  background: var(--attended);
}
.dot.missed {
  background: var(--missed);
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.5;
}

.footer {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
}

/* Dialog */
.dialog {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0;
  max-width: 520px;
  width: 92%;
  border-radius: var(--radius);
  margin: auto;
  max-height: calc(100dvh - 32px);
}
.dialog[open] {
  inset: 0;
}
.dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
}
.dialog-content {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.info-content {
  gap: 14px;
}
.info-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.info-section p {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0;
}
.info-section p strong { color: var(--text); font-weight: 600; }
.info-section p em { color: var(--text); font-style: normal; font-weight: 500; }
.info-section + .info-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.info-legend, .info-arrows {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.info-legend li, .info-arrows li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.info-legend li strong { color: var(--text); font-weight: 600; }
.info-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  flex-shrink: 0;
}
.info-dot.scheduled { background: var(--scheduled-fill); }
.info-dot.attended { background: var(--attended-fill); }
.info-dot.missed { background: var(--missed-fill); }

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field > label {
  font-size: 13px;
  color: var(--text-muted);
}
input[type="number"],
input[type="url"],
input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
  outline: none;
  transition: border 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-suffix {
  position: relative;
  display: flex;
  align-items: center;
}
.input-suffix input {
  padding-right: 32px;
}
.input-suffix span {
  position: absolute;
  right: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.btn-primary,
.btn-secondary,
.btn-danger {
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--text);
  color: var(--bg);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.08);
}
.btn-secondary {
  background: var(--bg-elev-hi);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--border-hi);
  background: #23232a;
}
.btn-danger {
  background: transparent;
  color: var(--absent);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.08);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .app {
    padding:
      max(22px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(50px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
  }
  .hero-percent #percentValue {
    font-size: 44px;
  }
  .stats {
    gap: 8px;
  }
  .stat {
    padding: 10px 12px;
  }
  .stat-value {
    font-size: 20px;
  }
}
