/* ==========================================================================
   Cashew Web - /app only (/css/app.css). Loaded after site.css; uses only its
   tokens and reuses .btn, .card, .callout, .muted and the header/footer.
   Adds: the state panels, loading, the sign-in card, the shell bar, the game.

   Which panel shows is decided ONLY here, from <body data-state> (design 8.1):
     loading -> #loading   out -> #signin   in, leaving -> #shell   error -> #load-error
   The HTML default is "loading", so without working JS the form never shows.
   ========================================================================== */

/* ============ State panels ============ */
#loading, #signin, #shell, #load-error { display: none; }
body[data-state="loading"] #loading { display: flex; }
body[data-state="out"] #signin { display: block; }
body[data-state="in"] #shell,
body[data-state="leaving"] #shell { display: block; }
body[data-state="error"] #load-error { display: block; }

.app-main { padding-block: clamp(1.6rem, 5vw, 3rem); }
.app-panel { max-width: 30rem; margin-inline: auto; }
.app-panel__title { margin-top: 0; margin-bottom: .4em; font-size: clamp(1.5rem, 4vw, 1.9rem); }
/* These headings only ever receive focus from script (so a screen reader lands on the new
   panel); they are not controls, so they show no focus ring. */
.app-panel__title:focus, #app-title:focus { outline: none; }
.nowrap { white-space: nowrap; }

/* ============ Loading ============ */
.loading {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 40vh;
  text-align: center;
}
.loading__text { margin: 0; font-weight: 800; color: var(--green-900); }
.loading__spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--green-500);
  animation: app-spin .9s linear infinite;
}
@keyframes app-spin { to { transform: rotate(360deg); } }
.loading__slow { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.loading__slow p { margin: 0; color: var(--ink-soft); }

/* ============ Sign-in card ============ */
.signin__providers { display: grid; gap: 10px; margin-top: 1.2rem; }
.signin__provider { width: 100%; }
.signin__icon { width: 20px; height: 20px; }
/* Apple's logo and label stay near-black, in every state; otherwise the same quiet button as Google */
#btn-apple { color: var(--ink); }

.signin__or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 1.2rem 0 1rem;
  color: var(--ink-soft);
  font-weight: 800;
  font-size: .92rem;
}
.signin__or::before, .signin__or::after { content: ""; flex: 1; height: 1.5px; background: var(--line); }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 4px; font-weight: 800; font-size: .95rem; color: var(--green-900); }
.field input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  font: inherit;
  font-size: 1rem; /* 16px: no zoom-on-focus on iOS */
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--muted); /* 3:1+ boundary on paper */
  border-radius: 12px;
}
.field input:disabled { opacity: .6; }
.field__hint { margin: 4px 0 0; font-size: .9rem; color: var(--ink-soft); }

.signin__submit { width: 100%; margin-top: 4px; }
.signin__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 12px;
  margin-top: 8px;
}
.signin__switch { margin: 0; color: var(--ink-soft); font-size: .95rem; }

/* a button that looks like a link (text buttons in 8.3), still a 44px target */
.btn-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 2px;
  background: none;
  border: 0;
  font: inherit;
  font-size: .95rem;
  font-weight: 800;
  color: var(--green-700);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1.5px;
  cursor: pointer;
}
.btn-link:hover:not(:disabled) { color: var(--green-900); }
.btn-link:disabled { opacity: .6; cursor: not-allowed; }

.signin__note:empty, .signin__error:empty { margin: 0; }
.signin__note { margin: 8px 0 0; font-size: .95rem; color: var(--green-700); font-weight: 700; }
.signin__error:not(:empty) {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border-left: 4px solid var(--danger);
  background: var(--coral-100);
  color: var(--ink);
  font-weight: 700;
}
.signin__fine { margin: 1rem 0 0; font-size: .92rem; color: var(--ink-soft); }
.signin__fine + .signin__fine { margin-top: .35rem; }

/* ============ Shell ============ */
#shell { max-width: 36rem; margin-inline: auto; }
.shell__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 1.2rem;
}
.shell__who { margin: 0; color: var(--ink-soft); font-weight: 700; overflow-wrap: anywhere; }
.shell__who strong { color: var(--green-900); }
.verify__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: .6rem; }
.verify__status { margin: 0; font-size: .95rem; font-weight: 700; }
#app-title { margin-bottom: .2em; }

/* ============ Game ============ */
.game { margin-top: 1rem; }
/* below the board (game-ui.js), so a status line that wraps never moves the cells */
.game__status { min-height: 1.65em; margin: 1rem 0 0; font-weight: 800; color: var(--green-900); }
.game__board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 21rem);
}
.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-height: var(--tap);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 1;
  color: var(--green-900);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.cell:hover:not([aria-disabled="true"]) { border-color: var(--gold-400); }
.cell[aria-disabled="true"] { cursor: default; }
.cell--x { color: var(--green-700); }
.cell--o { color: var(--gold-text); }
.cell--win { background: var(--gold-100); border-color: var(--gold-500); border-width: 3px; }
.game__controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-top: 1.2rem; }
.game__tally { margin: 0; font-weight: 700; color: var(--ink-soft); }

/* Firebase's hidden Auth helper frame: its inline style is blocked by the CSP
   (style-src 'self'), so it is placed off-screen here instead (design 4.4).
   The second selector is the same frame when served by the local Auth emulator. */
iframe[src*="/__/auth/iframe"],
iframe[src*="/emulator/auth/iframe"] { position: absolute; top: -100px; width: 1px; height: 1px; border: 0; }

/* ============ Small screens ============ */
@media (max-width: 420px) {
  .game__board { gap: 8px; }
  .shell__bar .btn { padding: 9px 14px; }
}
