/* ==========================================================================
   Base: reset, tokens, layout skeleton, utilities.
   Mobile-first. The whole shell is designed for a 360–430px viewport first and
   only then widened. No colour values here — only tokens from themes.css.
   ========================================================================== */

/* --- non-colour design tokens ------------------------------------------- */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-xs: 6px;
  --radius-sm: 9px;
  --radius-md: 13px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 999px;

  --app-bar-height: 54px;
  --tabbar-height: 58px;
  --content-max: 1440px;

  /* Comfortable one-handed touch target. */
  --tap-target: 44px;

  --duration-fast: 120ms;
  --duration: 200ms;
  --duration-slow: 320ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --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 {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Never allow sideways scrolling on a phone. */
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

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

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* A visible, high-contrast focus ring everywhere, but not on mouse clicks. */
:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* --- app shell ----------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.app[hidden] {
  display: none;
}

.app-bar {
  order: 0;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: calc(var(--app-bar-height) + var(--safe-top));
  padding: var(--safe-top) var(--space-2) 0 var(--space-2);
  background: color-mix(in srgb, var(--color-bg-nav) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--color-border-subtle);
}

.app-bar__title {
  flex: 1;
  min-width: 0;
  padding-left: var(--space-1);
}

.app-bar__title h1 {
  font-size: 19px;
  font-weight: 620;
}

.app-bar__subtitle {
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.app-bar__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.app-bar__back {
  flex: none;
}

.search-bar {
  order: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-3);
  background: var(--color-bg);
}

.search-bar[hidden] {
  display: none;
}

.selection-bar {
  order: 2;
  position: sticky;
  top: calc(var(--app-bar-height) + var(--safe-top));
  z-index: 29;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-raised);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.selection-bar[hidden] {
  display: none;
}

.selection-bar__count {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.selection-bar__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.views {
  order: 4;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-4));
}

.view[hidden] {
  display: none;
}

/* --- bottom navigation --------------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 32;
  order: 3;
  display: flex;
  align-items: stretch;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--color-bg-nav) 92%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--color-border-subtle);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-target);
  color: var(--color-text-faint);
  transition: color var(--duration-fast) var(--ease);
}

.tab__icon {
  display: flex;
}

.tab__label {
  font-size: 10.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
}

.tab.is-active {
  color: var(--color-text);
}

.tab.is-active .tab__icon {
  color: var(--color-accent);
}

.tab:active {
  transform: scale(0.96);
}

.fab {
  position: fixed;
  right: calc(var(--space-4) + var(--safe-right));
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-3));
  z-index: 31;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 52px;
  padding: 0 var(--space-5) 0 var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-primary-bg);
  color: var(--color-primary-text);
  font-size: 14.5px;
  font-weight: 620;
  box-shadow: var(--shadow-md);
  transition: transform var(--duration-fast) var(--ease), box-shadow var(--duration) var(--ease);
}

.fab__icon {
  display: flex;
}

.fab__label {
  white-space: nowrap;
}

/* While photos are selected the selection bar owns the screen, so the floating
   action button steps aside instead of covering the grid. */
html.is-selecting .fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.fab:active {
  transform: scale(0.96);
}

/* --- boot splash --------------------------------------------------------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.boot[hidden] {
  display: none;
}

/* --- desktop / tablet ---------------------------------------------------- */

@media (min-width: 860px) {
  :root {
    --app-bar-height: 60px;
  }

  /* The bottom tab bar becomes a horizontal navigation row beneath the app
     bar, so the wide layout uses the extra width instead of stretching four
     icons across a 1440px strip. */
  .tabbar {
    position: static;
    order: 3;
    height: auto;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-1);
    border-top: 0;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg-nav);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .tab {
    flex: none;
    flex-direction: row;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: 14px;
  }

  .tab__label {
    font-size: 13.5px;
    font-weight: 560;
  }

  .tab.is-active {
    background: var(--color-surface-raised);
    box-shadow: inset 0 0 0 1px var(--color-border);
  }

  .views {
    padding-bottom: var(--space-8);
  }

  .fab {
    bottom: calc(var(--space-6) + var(--safe-bottom));
  }
}

@media (min-width: 1100px) {
  .boot {
    background: var(--color-bg);
  }
}

/* --- utilities ----------------------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.is-hidden {
  display: none !important;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -60px;
  z-index: 70;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  transition: top var(--duration) var(--ease);
}

.skip-link:focus {
  top: var(--space-3);
}

.text-muted {
  color: var(--color-text-muted);
}

.text-small {
  font-size: 12.5px;
}

.text-danger {
  color: var(--color-danger);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: -0.01em;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.divider {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--color-border-subtle);
}

.noscript {
  max-width: 32rem;
  margin: 20vh auto;
  padding: var(--space-6);
  text-align: center;
}

/* Lock background scrolling while a modal is open. */
html.has-open-dialog,
html.has-open-dialog body {
  overflow: hidden;
}

/* Respect reduced-motion preferences across the whole app. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
