/* ===================================================================
   BASE RESET + iOS-FRIENDLY GLOBALS - Frosted Glass Edition
   =================================================================== */

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

/* Viewport helpers for iOS URL-bar dynamics */
:root {
  --vh: 1dvh;   /* dynamic viewport height */
  --svh: 1svh;  /* small viewport height */
  --lvh: 1lvh;  /* large viewport height */
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* Vertical-only app */
  overflow-x: hidden;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  touch-action: pan-y;               /* allow vertical pans; block horizontal */
  -webkit-text-size-adjust: 100%;    /* avoid iOS font auto-zoom */
}

/* Assist full-height pages that shouldn't jump when URL bar collapses */
[data-screen],
#homeRoot,
#moduleRoot {
  min-height: calc(100 * var(--vh));
  min-height: 100svh; /* fallback chain for older Safari */
}

/* Momentum scrolling where we allow scrolling */
.as-scroll-y {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Overlays/sheets scroll independently; body is locked via JS when open */
.as-overlay,
.as-sheet,
#mediaPicker {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Utility to respect safe areas (use on headers/footers/sheets) */
.safe-inset {
  padding-top:    var(--safe-top);
  padding-right:  var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left:   var(--safe-left);
}

/* ===================================================================
   TYPOGRAPHY & ELEMENT BASICS
   =================================================================== */

button, input, select, textarea {
  font-family: inherit;
  font-size: var(--text-md);
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--blue);
  text-decoration: none;
  transition: color var(--t-fast);
}

a:hover { 
  text-decoration: underline;
}

/* Typography */
body {
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-normal);
  font-size: var(--text-md);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--ink);
  margin: 0 0 0.5em;
  letter-spacing: var(--tracking-tight);
}

h1 { font-size: var(--text-4xl); font-weight: var(--weight-heavy); }
h2 { font-size: var(--text-3xl); font-weight: var(--weight-bold); }
h3 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h4 { font-size: var(--text-xl);  font-weight: var(--weight-semibold); }
h5 { font-size: var(--text-lg);  font-weight: var(--weight-semibold); }
h6 { font-size: var(--text-md);  font-weight: var(--weight-semibold); }

p {
  margin: 0 0 1em;
  color: var(--ink-dim);
  line-height: var(--leading-relaxed);
}

/* ===================================================================
   CONTROLS (Buttons / Inputs) - Frosted Glass Style
   =================================================================== */

/* Base button styling */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  transition: all var(--t-fast) var(--ease-out);
  touch-action: manipulation; /* avoid 300ms delay / dbl-tap zoom quirks */
  font-weight: var(--weight-medium);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  
  /* Frosted glass base */
  background: var(--glass-light);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border: 1px solid var(--stroke);
  color: var(--ink);
  
  padding: var(--pad-sm) var(--pad-lg);
  
  box-shadow: var(--shadow-sm),
              var(--inset-highlight);
}

button:hover:not([disabled]) {
  background: var(--glass-medium);
  border-color: var(--stroke-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md),
              var(--inset-highlight);
}

button:active:not([disabled]) {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: saturate(0.5);
}

/* Primary button - Blue accent */
button.primary,
button[type="submit"],
.as-btn--primary {
  background: var(--blue);
  color: #ffffff;
  border-color: rgba(10, 132, 255, 0.4);
  font-weight: var(--weight-semibold);
  box-shadow: var(--shadow-blue),
              var(--inset-highlight);
}

button.primary:hover:not([disabled]),
button[type="submit"]:hover:not([disabled]),
.as-btn--primary:hover:not([disabled]) {
  background: color-mix(in srgb, var(--blue) 90%, #fff);
  box-shadow: 0 8px 32px rgba(10, 132, 255, 0.4),
              var(--inset-highlight);
}

/* Secondary/ghost button - Transparent */
button.secondary,
.as-btn--ghost,
.as-btn--secondary {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-color: var(--stroke-2);
  box-shadow: none;
}

button.secondary:hover:not([disabled]),
.as-btn--ghost:hover:not([disabled]),
.as-btn--secondary:hover:not([disabled]) {
  background: var(--glass-subtle);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border-color: var(--stroke);
}

/* Danger button - Red */
button.danger,
.as-btn--danger {
  background: var(--red);
  color: #ffffff;
  border-color: rgba(255, 59, 48, 0.4);
  box-shadow: var(--shadow-red),
              var(--inset-highlight);
}

button.danger:hover:not([disabled]),
.as-btn--danger:hover:not([disabled]) {
  background: color-mix(in srgb, var(--red) 90%, #fff);
  box-shadow: 0 8px 32px rgba(255, 59, 48, 0.4),
              var(--inset-highlight);
}

/* Success button - Green */
button.success,
.as-btn--success {
  background: var(--green);
  color: #ffffff;
  border-color: rgba(52, 199, 89, 0.4);
  box-shadow: var(--shadow-green),
              var(--inset-highlight);
}

button.success:hover:not([disabled]),
.as-btn--success:hover:not([disabled]) {
  background: color-mix(in srgb, var(--green) 90%, #fff);
}

/* Input fields - Frosted glass style */
input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="time"],
textarea,
select {
  /* Frosted glass input */
  background: var(--glass-light);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  color: var(--ink);
  padding: var(--pad-sm) var(--pad-md);
  
  box-shadow: var(--inset-shadow);
  
  transition: all var(--t-fast) var(--ease-out);
  
  font-size: var(--text-md);
  line-height: var(--leading-normal);
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--glass-medium);
  box-shadow: 0 0 0 3px var(--blue-light),
              var(--inset-shadow);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--glass-subtle);
}

/* Textarea specific */
textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

/* Select specific */
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23eef3ff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--pad-md) center;
  padding-right: calc(var(--pad-md) * 2 + 12px);
}

/* Checkbox and radio */
input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  margin: 0;
  
  /* Custom appearance */
  appearance: none;
  -webkit-appearance: none;
  
  background: var(--glass-light);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  
  transition: all var(--t-fast);
  
  position: relative;
  flex-shrink: 0;
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background: var(--blue);
  border-color: var(--blue);
}

input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 14px;
  font-weight: var(--weight-bold);
}

input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  inset: 4px;
  background: #ffffff;
  border-radius: 50%;
}

/* ===================================================================
   SURFACES / CARDS / HEADERS - Frosted Glass
   =================================================================== */

/* Base card/surface styling */
article,
section,
.as-card,
.ms-card,
.cs-card {
  border-radius: var(--radius-lg);
  
  /* Frosted glass surface */
  background: var(--glass-light);
  backdrop-filter: var(--blur-medium);
  -webkit-backdrop-filter: var(--blur-medium);
  
  border: 1px solid var(--stroke);
  
  box-shadow: var(--shadow-glass);
  
  transition: all var(--t-fast) var(--ease-out);
  
  overflow: hidden;
}

/* Card hover effect */
article:hover,
.as-card:hover,
.ms-card:hover,
.cs-card:hover {
  background: var(--glass-medium);
  border-color: var(--stroke-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg),
              var(--inset-highlight);
}

/* Elevated surfaces */
.elevated,
.elev-1 {
  background: var(--elev-1);
  box-shadow: var(--shadow-md);
}

.elev-2 {
  background: var(--elev-2);
  box-shadow: var(--shadow-lg);
}

.elev-3 {
  background: var(--elev-3);
  box-shadow: var(--shadow-xl);
}

/* Frosted headers */
.ms__hdr,
.cs__hdr,
.as-header,
header {
  backdrop-filter: var(--blur-medium);
  -webkit-backdrop-filter: var(--blur-medium);
  background: var(--glass-medium);
  border-bottom: 1px solid var(--stroke);
  box-shadow: var(--shadow-sm);
}

/* Title styles */
.ms__title,
.cs__title,
.as-title {
  font-weight: var(--weight-heavy);
  letter-spacing: var(--tracking-tight);
  font-size: var(--text-3xl);
  margin: 0;
  color: var(--ink);
}

/* ===================================================================
   ROUTE FADE (paired with boot.js class toggles)
   =================================================================== */

#moduleRoot {
  opacity: 1;
  transform: none;
  transition: opacity var(--t-medium) var(--ease-out),
              transform var(--t-medium) var(--ease-out);
}

@media (prefers-reduced-motion: no-preference) {
  body.loading #moduleRoot {
    opacity: 0;
    transform: translateY(12px);
  }
  
  body.loaded #moduleRoot {
    opacity: 1;
    transform: none;
  }
}

/* ===================================================================
   LINKS / UTILITIES / TOASTS
   =================================================================== */

[hidden] {
  display: none !important;
}

/* Code blocks */
code,
pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

code {
  background: var(--glass-subtle);
  padding: 2px 6px;
  color: var(--ink-dim);
  border: 1px solid var(--stroke-subtle);
}

pre {
  background: var(--glass-light);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border: 1px solid var(--stroke);
  padding: var(--pad-lg);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
}

pre code {
  background: none;
  border: none;
  padding: 0;
}

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--stroke);
  margin: var(--space-xl) 0;
}

/* Toast notification - Frosted glass */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%);
  
  /* Frosted glass toast */
  background: var(--glass-strong);
  backdrop-filter: var(--blur-medium);
  -webkit-backdrop-filter: var(--blur-medium);
  
  color: var(--ink);
  padding: var(--pad-md) var(--pad-xl);
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke-strong);
  
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  
  box-shadow: var(--shadow-xl);
  
  z-index: var(--z-toast);
  
  max-width: calc(100vw - 48px);
  
  animation: toastSlideUp var(--t-medium) var(--ease-out);
}

@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 24px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Success toast */
.toast.success {
  background: var(--green);
  color: #ffffff;
  border-color: rgba(52, 199, 89, 0.4);
}

/* Error toast */
.toast.error {
  background: var(--red);
  color: #ffffff;
  border-color: rgba(255, 59, 48, 0.4);
}

/* Info toast */
.toast.info {
  background: var(--blue);
  color: #ffffff;
  border-color: rgba(10, 132, 255, 0.4);
}

/* Warning toast */
.toast.warning {
  background: var(--orange);
  color: #ffffff;
  border-color: rgba(255, 149, 0, 0.4);
}

/* ===================================================================
   SCROLLBARS - Frosted style
   =================================================================== */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--glass-subtle);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
  background: var(--glass-medium);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border-radius: var(--radius-sm);
  border: 2px solid var(--stroke-subtle);
  transition: background var(--t-fast);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--glass-strong);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--glass-medium) var(--glass-subtle);
}

/* ===================================================================
   BADGES / PILLS
   =================================================================== */

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  
  padding: var(--pad-xs) var(--pad-md);
  border-radius: var(--radius-pill);
  
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  
  background: var(--glass-light);
  backdrop-filter: var(--blur-light);
  -webkit-backdrop-filter: var(--blur-light);
  border: 1px solid var(--stroke);
  
  color: var(--ink);
}

.badge.primary { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }
.badge.success { background: var(--green-light); color: var(--green); border-color: var(--green); }
.badge.danger  { background: var(--red-light); color: var(--red); border-color: var(--red); }
.badge.warning { background: var(--orange-light); color: var(--orange); border-color: var(--orange); }

/* ===================================================================
   RESPONSIVE / MOTION
   =================================================================== */

@media (max-width: 720px) {
  /* Reduce font sizes on mobile */
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  h4 { font-size: var(--text-lg); }
  
  .ms__title, .cs__title {
    font-size: var(--text-2xl);
  }
  
  /* Adjust button padding */
  button {
    padding: var(--pad-sm) var(--pad-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===================================================================
   LIGHT MODE OVERRIDES
   =================================================================== */

:root[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231a1a1c' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

/* Light mode scrollbar */
:root[data-theme="light"] ::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.04);
}

:root[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.05);
}

:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
} 