/* ─────────────────────────────────────────────────────────────────────────
   Error states — toasts, view-level error panels, offline banner.
   See error-states.js for what each shape is for.
   ───────────────────────────────────────────────────────────────────────── */

/* ── Toast stack ────────────────────────────────────────────────────────
   Above the bottom navigation and clear of the iOS home indicator. The host
   never intercepts clicks; only the toasts themselves do, so a stale message
   can never block the UI underneath it. */
.fpl-error-host {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 2600;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}

.fpl-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 12px;
  background: #201826;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.45;
  /* Starts just below its resting place and fades in. */
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.23, 1, 0.32, 1);
}

.fpl-toast.is-in { opacity: 1; transform: translateY(0); }
.fpl-toast.is-leaving { opacity: 0; transform: translateY(6px); }

/* A coloured left edge rather than a fully tinted card: the message stays
   legible, and the tone is still readable at a glance. */
.fpl-toast--error { border-left: 3px solid var(--pl-red, #ff2d55); }
.fpl-toast--warning { border-left: 3px solid var(--pl-yellow, #ffd60a); }
.fpl-toast--success { border-left: 3px solid var(--pl-green, #00ff87); }
.fpl-toast--info { border-left: 3px solid var(--pl-cyan, #00d1ff); }

.fpl-toast-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 900;
  color: #12080f;
}

.fpl-toast--error .fpl-toast-icon { background: var(--pl-red, #ff2d55); color: #fff; }
.fpl-toast--warning .fpl-toast-icon { background: var(--pl-yellow, #ffd60a); }
.fpl-toast--success .fpl-toast-icon { background: var(--pl-green, #00ff87); }
.fpl-toast--info .fpl-toast-icon { background: var(--pl-cyan, #00d1ff); }

.fpl-toast-body { flex: 1 1 auto; min-width: 0; }
.fpl-toast-title { display: block; font-weight: 800; margin-bottom: 1px; }
/* Long API messages must wrap rather than widen the toast off-screen. */
.fpl-toast-text { overflow-wrap: anywhere; }

.fpl-toast-action,
.fpl-toast-close {
  flex: 0 0 auto;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  font: inherit;
}

.fpl-toast-action {
  align-self: center;
  padding: 5px 10px;
  border-radius: 999px;
  border-color: rgba(255, 255, 255, 0.28);
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.fpl-toast-action:hover { border-color: currentColor; }

.fpl-toast-close {
  font-size: 1.15rem;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.6;
}

.fpl-toast-close:hover { opacity: 1; }

/* ── View-level error panel ─────────────────────────────────────────── */

.fpl-error-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 40px 22px;
  max-width: 460px;
  margin: 0 auto;
}

.fpl-error-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--pl-red, #ff2d55);
  background: rgba(255, 45, 85, 0.12);
  border: 1px solid rgba(255, 45, 85, 0.4);
  margin-bottom: 2px;
}

.fpl-error-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary, #fff);
}

.fpl-error-msg {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.6;
  color: var(--text-secondary, #c0a8c8);
}

.fpl-error-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted, #8b7a93);
}

.fpl-error-retry {
  margin-top: 10px;
  padding: 10px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.85rem;
  color: #06130c;
  background: var(--pl-green, #00ff87);
  border: 1px solid transparent;
  transition: filter 0.18s ease;
}

.fpl-error-retry:hover { filter: brightness(1.08); }
.fpl-error-retry:disabled { opacity: 0.6; cursor: default; }

/* ── Offline banner ─────────────────────────────────────────────────── */

.fpl-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2700;
  padding: calc(7px + env(safe-area-inset-top, 0px)) 14px 7px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #12080f;
  background: var(--pl-yellow, #ffd60a);
  transform: translateY(-100%);
  transition: transform 0.28s cubic-bezier(0.23, 1, 0.32, 1);
}

.fpl-offline-banner.is-in { transform: translateY(0); }

/* ── Light mode ─────────────────────────────────────────────────────── */

:root.light-mode .fpl-toast {
  background: #fff;
  color: var(--text-primary, #0d0a14);
  border-color: rgba(24, 24, 27, 0.12);
  box-shadow: 0 12px 34px rgba(24, 24, 27, 0.14);
}

:root.light-mode .fpl-toast-action { border-color: rgba(24, 24, 27, 0.24); }

/* ── Motion and contrast preferences ────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .fpl-toast,
  .fpl-offline-banner,
  .fpl-error-retry {
    transition: none;
  }
  /* With no transition there is no transitionend, so dismiss() falls back to
     its timeout — the toast disappears rather than sliding out. */
  .fpl-toast { opacity: 1; transform: none; }
}

@media (prefers-contrast: more) {
  .fpl-toast { border-width: 2px; }
  .fpl-error-mark { border-width: 2px; }
}

@media (max-width: 480px) {
  .fpl-error-host { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .fpl-error-panel { padding: 30px 16px; }
}
