:root {
  color-scheme: light;
  --primary: #6750a4;
  --surface: #fdf8ff;
  --surface-container: #f1ebf6;
  --on-surface: #1d1b20;
  --on-surface-variant: #49454f;
  --outline-variant: #cac4d0;
  --error: #b3261e;
  --error-container: #f9dedc;
  --on-error-container: #410e0b;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.28), 0 1px 3px 1px rgba(0, 0, 0, 0.12);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.3), 0 6px 14px 2px rgba(0, 0, 0, 0.16);
  --radius: 10px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --primary: #d0bcff;
  --surface: #121016;
  --surface-container: #211f26;
  --on-surface: #e6e0e9;
  --on-surface-variant: #cac4d0;
  --outline-variant: #49454f;
  --error: #f2b8b5;
  --error-container: #4a1f1c;
  --on-error-container: #f9dedc;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--on-surface);
  font-family: Roboto, system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* --- Marque --------------------------------------------------------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand span {
  color: var(--on-surface);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--on-surface-variant);
  width: 42px;
  height: 42px;
  border-radius: 999px;
  cursor: pointer;
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
}

/* --- Mosaïque ------------------------------------------------------- */

main {
  flex: 1;
  width: 100%;
  /* 7 colonnes : 7 × 104 px + 6 × 10 px de gouttière + 2 × 14 px de padding. */
  max-width: 816px;
  margin: 0 auto;
  padding: 18px 14px 32px;
}

.mosaic {
  display: grid;
  gap: var(--gap, 10px);
  justify-content: center;
  grid-auto-flow: dense;
}

.tile {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  grid-column: span var(--span-c, 1);
  grid-row: span var(--span-r, 1);
  text-decoration: none;
  color: var(--tile-fg, var(--on-surface));
  background: var(--tile-bg, var(--surface-container));
  box-shadow: var(--shadow-1);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  -webkit-tap-highlight-color: transparent;
  container-type: size;
}

.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 100% at 12% 8%, rgba(255, 255, 255, 0.3), transparent 62%);
  pointer-events: none;
}

a.tile:hover,
a.tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  outline: none;
}

.tile__icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Material Symbols Outlined';
  font-weight: 300;
  font-size: calc(var(--cell, 110px) * 0.4);
  line-height: 1;
  opacity: 0.95;
  pointer-events: none;
}

.tile__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.4;
  -webkit-mask-image: radial-gradient(130% 110% at 70% 15%, #000 25%, transparent 80%);
  mask-image: radial-gradient(130% 110% at 70% 15%, #000 25%, transparent 80%);
}

.tile__url {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 6%;
  font-size: calc(var(--cell, 110px) * 0.2);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.005em;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

@supports (font-size: 1cqw) {
  .tile__url {
    /* Proportionnel à la largeur de la tuile : une URL courte occupe au
       moins ~50 %, une URL longue remplit la largeur (ellipse), sans
       empiéter sur les paddings. */
    font-size: 17cqw;
  }
}

.tile__meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 28px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.86) 0%,
    rgba(0, 0, 0, 0.62) 55%,
    transparent 100%
  );
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.tile__meta strong,
.tile__meta em {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

.tile__meta strong {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.tile__meta em {
  font-style: normal;
  font-size: 0.82rem;
  opacity: 0.9;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile:hover .tile__url,
.tile:focus-visible .tile__url,
.tile.is-open .tile__url {
  opacity: 0;
}

.tile:hover .tile__meta,
.tile:focus-visible .tile__meta,
.tile.is-open .tile__meta {
  opacity: 1;
  transform: none;
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

/* Tuiles avec texte : au survol, l'icône s'efface pour laisser lire le titre. */
.tile--site .tile__icon,
.tile--portal .tile__icon {
  transition: opacity 0.22s ease, transform 0.28s ease;
}

.tile--site:hover .tile__icon,
.tile--site:focus-visible .tile__icon,
.tile--site.is-open .tile__icon,
.tile--portal:hover .tile__icon,
.tile--portal:focus-visible .tile__icon,
.tile--portal.is-open .tile__icon {
  opacity: 0.3;
  transform: translate(-50%, -68%) scale(0.82);
}

/* --- Réseaux sociaux ------------------------------------------------ */

.tile--social {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg, var(--surface-container));
  border-radius: 16px;
}

.tile--social::before {
  display: none;
}

.tile__logo {
  width: calc(var(--cell, 110px) * 0.42);
  height: calc(var(--cell, 110px) * 0.42);
  fill: var(--brand, var(--on-surface));
}

/* --- Tuiles décoratives --------------------------------------------- */

.tile--decor {
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.tile--decor .tile__icon {
  position: static;
  transform: none;
  font-size: calc(var(--cell, 110px) * 0.34);
  opacity: 0.5;
}

/* Tuile décorative cliquable : surprise, URL masquée. */
.tile--link {
  cursor: pointer;
  box-shadow: var(--shadow-1);
}

.tile--decor.tile--link .tile__icon {
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.tile--decor.tile--link:hover .tile__icon,
.tile--decor.tile--link:focus-visible .tile__icon {
  transform: scale(1.18) rotate(-6deg);
  opacity: 0.8;
}

.tile--decor.tile--link::after {
  content: '';
  position: absolute;
  inset: -25%;
  background: linear-gradient(
    115deg,
    transparent 42%,
    rgba(255, 255, 255, 0.5) 50%,
    transparent 58%
  );
  transform: translateX(-130%);
  transition: transform 0.7s ease;
  pointer-events: none;
}

.tile--decor.tile--link:hover::after,
.tile--decor.tile--link:focus-visible::after {
  transform: translateX(130%);
}

/* --- Portail / erreur ----------------------------------------------- */

.tile--portal .tile__icon {
  font-size: calc(var(--cell, 110px) * 0.46);
}

.mosaic.is-blurred .tile:not(.tile--error) {
  filter: blur(6px);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
}

.tile--error {
  background: var(--error-container);
  color: var(--on-error-container);
  cursor: pointer;
}

.tile--error::before {
  display: none;
}

.tile--error .tile__icon {
  color: var(--error);
  position: static;
  transform: none;
  font-size: calc(var(--cell, 110px) * 0.34);
  display: block;
  margin: 0 auto 6px;
}

.tile--error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
}

.tile--error .error__label {
  font-size: 0.82rem;
  font-weight: 700;
}

.tile--error .error__path {
  font-size: 0.7rem;
  opacity: 0.85;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Modale d'erreur ------------------------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: var(--surface-container);
  color: var(--on-surface);
  border-radius: 22px;
  padding: 24px;
  width: min(520px, 100%);
  max-height: 88vh;
  overflow: auto;
  box-shadow: var(--shadow-2);
}

.modal .material-symbols-outlined {
  font-size: 40px;
  color: var(--error);
}

.modal h2 {
  margin: 8px 0;
  font-size: 1.25rem;
}

.modal p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--on-surface-variant);
}

.modal code {
  background: color-mix(in srgb, var(--error) 16%, transparent);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 0.85em;
}

.modal form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.modal input {
  flex: 1 1 200px;
  min-width: 0;
  border: 1px solid var(--outline-variant);
  background: transparent;
  color: var(--on-surface);
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
}

.modal button[type='submit'] {
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.suggestions a {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--on-surface);
  text-decoration: none;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.85rem;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
}

.modal__actions button {
  border: none;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}

.modal__actions button:hover {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

/* --- Pied de page --------------------------------------------------- */

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 16px 40px;
  color: var(--on-surface-variant);
  font-size: 0.82rem;
}

.footer .brand {
  font-size: 0.95rem;
}

.footer__links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.footer a {
  color: var(--on-surface-variant);
  text-decoration: none;
}

.footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }
}
