/*
 * Title and loading screens.
 *
 * Wide: a two-column paper page (hero/actions left, card fan right).
 * Portrait: one column with the fan between the wordmark and the buttons.
 * All colours come from theme.css; no baked background image is needed.
 */

.title-screen,
.loading-screen {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

.title-screen {
  z-index: 70;
  isolation: isolate;
}

.loading-screen {
  z-index: 100;
  display: grid;
  place-items: center;
}

.title-bg,
.loading-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.title-bg {
  background: var(--bg);
}

.title-bg::before,
.loading-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--pattern);
}

.title-bg::after {
  content: "";
  position: absolute;
  left: -18vw;
  bottom: -32vw;
  width: 72vw;
  height: 72vw;
  border: 1px solid var(--line);
  border-radius: 50%;
  opacity: 0.55;
}

/* ---------------------------------------------------------------- loading */

.loading-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 2.4vh, 18px);
  width: min(420px, calc(100vw - 48px));
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  text-align: center;
}

.loading-brand {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2.4vw, 18px);
}

.loading-seal {
  display: grid;
  place-items: center;
  width: clamp(40px, 10vw, 54px);
  height: clamp(40px, 10vw, 54px);
  border-radius: 6px;
  background: var(--accent-fill);
  box-shadow:
    inset 0 0 0 2px var(--accent-fill),
    inset 0 0 0 3px rgba(255, 255, 255, 0.72);
  color: #fffdf8;
  font-family: var(--font-seal);
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 900;
  line-height: 1;
  transform: rotate(-4deg);
}

.loading-wordmark {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 5vw, 2.9rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.01em;
}

.loading-label {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.38em;
  padding-left: 0.38em;
  text-transform: uppercase;
}

.loading-track {
  width: min(250px, 70vw);
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.loading-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.12s linear;
}

.loading-pct {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.16em;
}

/* ------------------------------------------------------------------ title */

.title-top {
  position: absolute;
  z-index: 4;
  top: max(12px, calc(var(--safe-top) + 8px));
  right: max(12px, calc(var(--safe-right) + 8px));
}

.title-content {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  grid-template-rows: auto auto;
  grid-template-areas:
    "hero fan"
    "actions fan";
  align-content: center;
  column-gap: clamp(28px, 6vw, 88px);
  row-gap: clamp(16px, 3vh, 28px);
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: calc(max(22px, var(--safe-top)) + 48px) clamp(24px, 7vw, 104px)
    max(22px, var(--safe-bottom));
}

.title-hero {
  grid-area: hero;
  display: flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 28px);
  min-width: 0;
}

.title-seal {
  flex: none;
  display: grid;
  place-items: center;
  padding: 0.55em 0.3em;
  border-radius: 6px;
  background: var(--accent-fill);
  box-shadow:
    inset 0 0 0 2px var(--accent-fill),
    inset 0 0 0 3px rgba(255, 255, 255, 0.72);
  color: #fffdf8;
  font-family: var(--font-seal);
  font-size: clamp(17px, 2vw, 24px);
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: 0.02em;
  text-align: center;
  transform: rotate(-3deg);
  writing-mode: vertical-rl;
}

.title-heading {
  min-width: 0;
}

.title-wordmark {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 6.4vw, 5rem);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: -0.025em;
}

.title-wordmark span {
  display: block;
}

.title-subtitle {
  margin: clamp(10px, 1.8vh, 18px) 0 0;
  padding-top: 8px;
  border-top: 1.5px solid var(--text);
  color: var(--muted);
  font-size: clamp(10px, 1.2vw, 12px);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.title-actions {
  grid-area: actions;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.6vh, 14px);
  width: min(340px, 100%);
  margin-top: clamp(6px, 2vh, 20px);
}

.title-btn {
  width: 100%;
  min-height: clamp(42px, 6vh, 52px);
  border-radius: var(--radius-control);
  font-size: clamp(14px, 1.3vw, 16px);
}

.title-fan {
  --fan-card: clamp(96px, 15vw, 210px);
  grid-area: fan;
  position: relative;
  align-self: center;
  justify-self: center;
  width: 100%;
  min-height: calc(var(--fan-card) * 1.55);
}

.title-fan::before {
  content: "";
  position: absolute;
  inset: 4% 6%;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    color-mix(in srgb, var(--accent) 9%, transparent),
    transparent 72%
  );
}

.title-fan .title-fan-card {
  --cw: var(--fan-card);
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: 50% 120%;
}

.title-fan-card .card-face {
  box-shadow:
    inset 0 0 0 1px var(--card-bd),
    0 16px 30px rgba(27, 26, 23, 0.16);
}

.title-fan-card:nth-child(1) {
  z-index: 1;
  left: calc(50% - var(--fan-card) * 0.42);
  transform: translate(-50%, -50%) rotate(-10deg);
}

.title-fan-card:nth-child(2) {
  z-index: 3;
  transform: translate(-50%, -54%);
}

.title-fan-card:nth-child(3) {
  z-index: 2;
  left: calc(50% + var(--fan-card) * 0.42);
  transform: translate(-50%, -50%) rotate(10deg);
}

/* ------------------------------------------------------- responsive title */

@media (orientation: portrait), (max-width: 720px) {
  .title-content {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "hero"
      "fan"
      "actions";
    align-content: center;
    row-gap: clamp(14px, 2.6vh, 26px);
    padding: calc(max(18px, var(--safe-top)) + 46px) clamp(20px, 7vw, 54px)
      max(20px, var(--safe-bottom));
  }

  .title-wordmark {
    font-size: clamp(2.5rem, 11vw, 3.6rem);
  }

  .title-actions {
    width: 100%;
    margin-top: 0;
  }

  .title-fan {
    --fan-card: clamp(80px, 24vw, 132px);
    min-height: calc(var(--fan-card) * 1.5);
  }

  .title-fan-card:nth-child(1) {
    left: calc(50% - var(--fan-card) * 0.36);
  }

  .title-fan-card:nth-child(3) {
    left: calc(50% + var(--fan-card) * 0.36);
  }
}

@media (orientation: portrait) and (max-height: 680px) {
  .title-fan {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .title-content {
    row-gap: 8px;
    padding-top: calc(max(10px, var(--safe-top)) + 38px);
    padding-bottom: max(10px, var(--safe-bottom));
  }

  .title-wordmark {
    font-size: clamp(2.1rem, 6vw, 3rem);
  }

  .title-subtitle {
    margin-top: 7px;
    padding-top: 5px;
    font-size: 9px;
  }

  .title-actions {
    gap: 7px;
    margin-top: 2px;
  }

  .title-btn {
    min-height: 34px;
    font-size: 13px;
  }

  .title-fan {
    --fan-card: clamp(64px, 19vh, 108px);
  }
}

/* ------------------------------------------------------- shared app toast */

.toast.app-toast {
  z-index: 95;
}

/* ----------------------------------------------------------------- motion */

.title-screen.is-visible .title-hero,
.title-screen.is-visible .title-fan,
.title-screen.is-visible .title-actions {
  animation: title-rise 0.45s var(--ease-out) both;
}

.title-screen.is-visible .title-fan {
  animation-delay: 0.06s;
}

.title-screen.is-visible .title-actions {
  animation-delay: 0.12s;
}

@keyframes title-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-screen.is-visible .title-hero,
  .title-screen.is-visible .title-fan,
  .title-screen.is-visible .title-actions {
    animation: none;
  }

  .loading-fill,
  .toast,
  .toast.app-toast {
    transition: none;
  }
}
