<script lang="ts">
  // Non-dismissable maintenance cover. Shown while the edge is in a planned deploy window
  // (maintenance.svelte.ts, raised from a caddy 503 carrying X-Scrabble-Maintenance). It has
  // no close affordance — an in-session user cannot dismiss it — but the store's poll lifts
  // it automatically the moment the gateway answers again; the "retry" button just forces an
  // immediate re-check. Mirrors the static caddy maintenance page (deploy/caddy/maintenance.html)
  // so a fresh load and an in-session user see the same thing.
  import { maintenance, retryNow } from '../lib/maintenance.svelte';
  import { t } from '../lib/i18n/index.svelte';
</script>

{#if maintenance.active}
  <div class="scrim" role="alertdialog" aria-modal="true" aria-labelledby="maint-title" aria-describedby="maint-body">
    <div class="card">
      <div class="tile" aria-hidden="true">Э</div>
      <h1 id="maint-title">{t('maintenance.title')}</h1>
      <p id="maint-body">{t('maintenance.body')}</p>
      <button type="button" onclick={retryNow}>{t('maintenance.retry')}</button>
    </div>
  </div>
{/if}

<style>
  .scrim {
    position: fixed;
    inset: 0;
    /* Above the game (z 60) and toasts (z 50) — a planned window covers everything the user
       could otherwise interact with; below the dev DebugPanel (z 10000). */
    z-index: 100;
    background: rgba(0, 0, 0, 0.55);
    display: grid;
    place-items: center;
    padding: 24px;
    box-sizing: border-box;
  }
  .card {
    max-width: 22rem;
    text-align: center;
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem 1.5rem;
  }
  /* Mirrors a placed board tile (as Splash.svelte / the caddy page do). */
  .tile {
    display: inline-grid;
    place-items: center;
    width: 3.5rem;
    height: 3.5rem;
    font-size: 2rem;
    font-weight: 700;
    border-radius: 4px;
    background: var(--tile-bg);
    color: var(--tile-text);
    box-shadow:
      inset 0 -2px 0 var(--tile-edge),
      2px 0 3px -1px rgba(0, 0, 0, 0.4);
    margin-bottom: 1.25rem;
  }
  h1 {
    font-size: 1.25rem;
    margin: 0 0 0.5rem;
  }
  p {
    margin: 0 0 1.5rem;
    color: var(--text-muted);
    line-height: 1.5;
  }
  button {
    font: inherit;
    padding: 0.55rem 1.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }
  button:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
</style>
