/* ============================================================
   Habitergy — Apple HIG-inspired design system
   Font: SF Pro via system stack, 17pt body, generous spacing
   ============================================================ */

:root {
  /* Colors — inspired by iOS system palette */
  --color-bg: #F2F2F7;
  --color-surface: #FFFFFF;
  --color-primary: #007AFF;
  --color-primary-active: #0056CC;
  --color-text: #1C1C1E;
  --color-text-secondary: #8E8E93;
  --color-text-tertiary: #AEAEB2;
  --color-separator: rgba(60, 60, 67, 0.12);
  --color-fill: rgba(120, 120, 128, 0.08);
  --color-input-bg: rgba(120, 120, 128, 0.08);
  --color-input-border: rgba(60, 60, 67, 0.18);
  --color-danger: #FF3B30;

  /* Typography — iOS default = 17pt body */
  /* Modern system typography stack */
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-large-title: 600 34px/41px var(--font-family);
  --font-title1: 600 28px/34px var(--font-family);
  --font-title2: 600 22px/28px var(--font-family);
  --font-title3: 600 20px/25px var(--font-family);
  --font-headline: 600 17px/22px var(--font-family);
  --font-body: 400 17px/22px var(--font-family);
  --font-callout: 400 16px/21px var(--font-family);
  --font-subhead: 400 15px/20px var(--font-family);
  --font-footnote: 400 13px/18px var(--font-family);
  --font-caption1: 400 12px/16px var(--font-family);
  --font-caption2: 400 11px/13px var(--font-family);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radii — iOS uses 10-13px for cards */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---- Reset ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100%;
  font: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  /* Modern typographic rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ---- Layout containers ---- */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
}

.page-center {
  justify-content: center;
  align-items: center;
}

/* ---- Typography helpers ---- */
.large-title { font: var(--font-large-title); letter-spacing: 0.37px; }
.title1      { font: var(--font-title1); letter-spacing: 0.36px; }
.title2      { font: var(--font-title2); letter-spacing: 0.35px; }
.title3      { font: var(--font-title3); letter-spacing: 0.38px; }
.headline    { font: var(--font-headline); letter-spacing: -0.41px; }
.body-text   { font: var(--font-body); letter-spacing: -0.41px; }
.callout     { font: var(--font-callout); letter-spacing: -0.32px; }
.subhead     { font: var(--font-subhead); letter-spacing: -0.24px; }
.footnote    { font: var(--font-footnote); letter-spacing: -0.08px; }
.caption1    { font: var(--font-caption1); }
.caption2    { font: var(--font-caption2); }

.text-secondary { color: var(--color-text-secondary); }
.text-tertiary  { color: var(--color-text-tertiary); }
.text-center    { text-align: center; }

/* ---- Card / Surface ---- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  width: 100%;
}

/* ---- Form elements ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  width: 100%;
}

.form-label {
  font: var(--font-subhead);
  color: var(--color-text-secondary);
  padding-left: 2px;
}

.form-input {
  font: var(--font-body);
  color: var(--color-text);
  background: var(--color-input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.form-input::placeholder {
  color: var(--color-text-tertiary);
}

.form-input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.15);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font: var(--font-headline);
  letter-spacing: -0.41px;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 24px;
  min-height: 50px; /* Apple recommends 44pt minimum */
  width: 100%;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.85;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-active);
}

.btn-secondary {
  background: var(--color-fill);
  color: var(--color-primary);
}

.btn-text {
  background: transparent;
  color: var(--color-primary);
  padding: 12px;
  min-height: 44px;
}

/* ---- Spacing utilities ---- */
.mt-xs  { margin-top: var(--space-xs); }
.mt-sm  { margin-top: var(--space-sm); }
.mt-md  { margin-top: var(--space-md); }
.mt-lg  { margin-top: var(--space-lg); }
.mt-xl  { margin-top: var(--space-xl); }
.mt-2xl { margin-top: var(--space-2xl); }
.mb-xs  { margin-bottom: var(--space-xs); }
.mb-sm  { margin-bottom: var(--space-sm); }
.mb-md  { margin-bottom: var(--space-md); }
.mb-lg  { margin-bottom: var(--space-lg); }
.gap-sm  { gap: var(--space-sm); }
.gap-md  { gap: var(--space-md); }
.gap-lg  { gap: var(--space-lg); }

.w-full { width: 100%; }

/* ---- Animations ---- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeInUp 0.5s ease-out both;
}

.animate-in-delay-1 { animation-delay: 0.08s; }
.animate-in-delay-2 { animation-delay: 0.16s; }
.animate-in-delay-3 { animation-delay: 0.24s; }
.animate-in-delay-4 { animation-delay: 0.32s; }

/* ---- iOS-like standalone status bar spacing ---- */
@media all and (display-mode: standalone) {
  body {
    padding-top: max(var(--safe-top), 20px);
  }
}

/* Prevent rubber-band on standalone PWA */
@supports (-webkit-touch-callout: none) {
  html, body { overflow: hidden; }
  .page { overflow-y: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- PWA Install Bottom Sheet ---- */
.pwa-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 9998;
  transition: background 0.35s ease;
}

.pwa-overlay-visible {
  background: rgba(0, 0, 0, 0.3);
}

.pwa-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 12px var(--space-lg) calc(var(--space-lg) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  max-width: 480px;
  margin: 0 auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
}

.pwa-sheet-visible {
  transform: translateY(0);
}

.pwa-sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 2.5px;
  background: var(--color-text-tertiary);
  opacity: 0.4;
  margin: 0 auto 20px;
}

.pwa-sheet-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.pwa-sheet-icon {
  width: 56px;
  height: 56px;
  border-radius: 13px;
  background: linear-gradient(135deg, #007AFF, #5856D6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.pwa-sheet-title {
  font: var(--font-headline);
  letter-spacing: -0.41px;
  color: var(--color-text);
}

.pwa-sheet-subtitle {
  font: var(--font-subhead);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.pwa-sheet-steps {
  background: var(--color-fill);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.pwa-sheet-steps-title {
  font: var(--font-subhead);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

.pwa-sheet-steps ol {
  list-style: none;
  counter-reset: steps;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: 0;
}

.pwa-sheet-steps li {
  counter-increment: steps;
  font: var(--font-body);
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.pwa-sheet-steps li::before {
  content: counter(steps);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font: var(--font-caption1);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-share-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  color: var(--color-primary);
}

.pwa-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.glass-card { background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border: 1px solid rgba(255, 255, 255, 0.6); border-radius: var(--radius-lg); padding: var(--space-lg) var(--space-lg) var(--space-xl) var(--space-lg); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); width: 100%; max-width: 400px; margin: 0 auto; box-sizing: border-box; }

/* ---- Login Specific Styles ---- */
.login-body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

.login-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  width: 100%;
  background: url('assets/images/welcome_image.webp?v=20260330.13') center/cover no-repeat;
  padding: 0 24px 8vh 24px;
  box-sizing: border-box;
}

.glass-card-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-title {
  margin-top: 0;
  margin-bottom: 8px;
  color: #111;
  font-weight: 600;
}

.login-subtitle {
  color: #333;
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

input.glass-input {
  background: rgba(255, 255, 255, 0.7);
  border: none;
  font-size: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  transition: transform 0.3s, background 0.2s ease, box-shadow 0.2s ease;
}

input.glass-input:focus {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.2);
}

.login-btn {
  border-radius: 16px;
  font-weight: 600;
}

/* ---- Hidden utility ---- */
.hidden {
  display: none !important;
}

/* ---- Email display chip ---- */
.email-display {
  font: var(--font-subhead);
  color: var(--color-text-secondary);
  background: var(--color-fill);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
  word-break: break-all;
}

/* ---- Feedback message ---- */
.login-feedback {
  font: var(--font-subhead);
  text-align: center;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

.login-feedback-error {
  color: var(--color-danger);
  background: rgba(255, 59, 48, 0.1);
}

.login-feedback-success {
  color: #34C759;
  background: rgba(52, 199, 89, 0.1);
}

/* ---- Notice subtitle for register ---- */
.login-notice {
  color: var(--color-danger);
  font-weight: 500;
}

/* ---- Back button ---- */
.login-back-btn {
  font-weight: 400;
  margin-top: -4px;
}

/* ---- Step Navigation ---- */
.relative-step {
  position: relative;
}

.header-back-btn {
  position: absolute;
  top: 0;
  left: -8px;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  z-index: 10;
}

.header-back-btn:active {
  opacity: 0.5;
}

.header-back-btn svg {
  width: 24px;
  height: 24px;
}

.caption {
  font-size: 13px;
  color: rgba(0,0,0,0.6);
  font-weight: 400;
}

/* ---- App Main Layout ---- */
.app-body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  font-family: var(--font-family);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  padding-bottom: 72px; /* Space for bottom nav */
}

.app-view {
  min-height: 100%;
  display: none;
  animation: fade-in 0.3s ease-out;
}

.app-view.active-view {
  display: block;
}

.app-header {
  padding: var(--space-xl) var(--space-lg) var(--space-sm);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 20;
}

.view-body {
  padding: 0 var(--space-lg) var(--space-xl) var(--space-lg);
}

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

/* ---- Bottom Navigation Bar (Liquid Glass – clear variant) ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 72px;
  background: rgba(40, 40, 45, 0.45);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.45);
  transition: color 0.25s ease;
  height: 100%;
  padding-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active {
  color: rgba(255, 255, 255, 0.95);
}

.nav-icon {
  width: 26px;
  height: 26px;
  margin-bottom: 3px;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}


/* ---- TikTok/IG Feed (Home View) ---- */
.feed-container {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.feed-slide {
  position: relative;
  width: 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  flex-shrink: 0;
  overflow: hidden;
}

.feed-slide-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 0;
}

/* Gradient overlay at bottom for readability */
.feed-slide-bg::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, transparent 100%);
  z-index: 1;
}

.feed-slide-content {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  z-index: 2;
  padding: 0 24px;
}

.feed-device-name {
  font-size: 38px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

/* Dots indicator */
.feed-dots {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 0 24px;
  pointer-events: none;
}

.feed-dot {
  flex: 1;
  max-width: 60px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
  transition: background 0.3s ease;
}

.feed-dot.active {
  background: rgba(255, 255, 255, 0.9);
}

/* Empty + Loading */
.feed-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.feed-empty-text {
  color: #999;
  font-size: 16px;
  font-weight: 500;
}

/* When Home is active, its feed takes all available space */
#view-home.active-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#view-home .feed-container {
  flex: 1;
}

