/*
 * Base styles: reset, M3 type scale and the adaptive app shell.
 *
 * Window size classes (M3):
 *   compact  < 600px  → bottom navigation bar
 *   medium  >= 600px  → navigation rail on the left
 *   expanded >= 840px → navigation rail, wider margins
 */

/* ---------- Reset ---------- */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-family: var(--md-font-plain);
  font-size: 16px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ol, ul {
  margin: 0;
}

ul[role="list"] {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
}

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

button {
  cursor: pointer;
}

a,
button,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--md-secondary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Type scale ---------- */

.display-small   { font-size: 36px; line-height: 44px; font-weight: 400; }
.headline-medium { font-size: 28px; line-height: 36px; font-weight: 400; }
.headline-small  { font-size: 24px; line-height: 32px; font-weight: 400; }
.title-large     { font-size: 22px; line-height: 28px; font-weight: 400; }
.title-medium    { font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: 0.15px; }
.title-small     { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }
.body-large      { font-size: 16px; line-height: 24px; letter-spacing: 0.5px; }
.body-medium     { font-size: 14px; line-height: 20px; letter-spacing: 0.25px; }
.body-small      { font-size: 12px; line-height: 16px; letter-spacing: 0.4px; }
.label-large     { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }
.label-medium    { font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0.5px; }

.on-surface-variant {
  color: var(--md-on-surface-variant);
}

/* ---------- Icons ---------- */

.icon {
  flex: none;
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.icon--small {
  width: 18px;
  height: 18px;
}

/* ---------- Skip link ---------- */

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 16px;
  border-radius: var(--md-shape-full);
  background: var(--md-inverse-surface);
  color: var(--md-inverse-on-surface);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

/* ---------- App shell ---------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-bar-height) + env(safe-area-inset-bottom));
}

.page {
  flex: 1;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 8px 16px 32px;
}

/* Tool pages leave room for the floating action button. */
.page--with-fab {
  padding-bottom: 104px;
}

.page__intro {
  max-width: 680px;
  margin-bottom: 24px;
  color: var(--md-on-surface-variant);
}

.section {
  margin-top: 32px;
}

.section__title {
  margin-bottom: 16px;
}

/* ---------- Top app bar (small) ---------- */

.top-app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--top-app-bar-height);
  padding: 0 4px 0 16px;
  background: var(--md-surface);
  transition: background-color var(--md-duration-medium) var(--md-easing-standard);
}

/* Set by top-app-bar.js once content scrolls underneath. */
.top-app-bar--scrolled {
  background: var(--md-surface-container);
}

.top-app-bar__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Navigation: bottom bar (compact) / rail (medium+) ---------- */

.navigation {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  height: calc(var(--nav-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--md-surface-container);
}

.navigation__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  color: var(--md-on-surface-variant);
  text-decoration: none;
}

.navigation__item:focus-visible {
  outline: none;
}

.navigation__indicator {
  display: grid;
  place-items: center;
  width: 64px;
  height: 32px;
  border-radius: var(--md-shape-full);
  transition: background-color var(--md-duration-short) var(--md-easing-standard);
}

.navigation__item:focus-visible .navigation__indicator {
  outline: 3px solid var(--md-secondary);
  outline-offset: 2px;
}

.navigation__label {
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.navigation__item[aria-current="page"] {
  color: var(--md-on-surface);
}

.navigation__item[aria-current="page"] .navigation__indicator {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

.navigation__item[aria-current="page"] .navigation__label {
  font-weight: 700;
}

/* The indicator shows the item's hover state layer. */
.navigation__item:hover .navigation__indicator::after {
  opacity: var(--md-state-hover);
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant);
}

/* ---------- Medium and expanded windows ---------- */

@media (min-width: 600px) {
  .app {
    margin-left: var(--nav-rail-width);
    padding-bottom: 0;
  }

  .page {
    padding: 8px 24px 40px;
  }

  .page--with-fab {
    padding-bottom: 112px;
  }

  .top-app-bar {
    padding: 0 12px 0 24px;
  }

  .navigation {
    top: 0;
    right: auto;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    width: var(--nav-rail-width);
    height: auto;
    padding: 88px 0 0;
    background: var(--md-surface);
  }

  .navigation__item {
    flex: none;
  }

  .navigation__indicator {
    width: 56px;
  }
}

@media (min-width: 840px) {
  .page {
    padding-right: 24px;
    padding-left: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
