/* Arcade overlay. Panel colours all come from the theme variables on body, so every
   theme works. The canvases keep their own pastel palette. */

#arcade { position: fixed; inset: 0; z-index: 45; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; padding: 16px; color: var(--text); background: rgba(43, 30, 39, .45); background: color-mix(in srgb, var(--line) 45%, transparent); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: arcFade .16s ease-out; }
#arcade[hidden], #arcade [hidden] { display: none !important; }
:where(#arcade, #arcadeInvites) button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
@keyframes arcFade { from { opacity: 0; } }
@keyframes arcPop { from { opacity: 0; transform: translateY(8px) scale(.97); } }

/* Emoji bursts and toasts normally sit under z-index 45. Lift them while the arcade is open
   so goals and wins are seen. Both layers ignore the pointer. */
body.arcade-open #fx { z-index: 47; }
body.arcade-open #toasts { z-index: 48; }

.arc-card { width: min(100%, 520px); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; background: var(--panel); border: 1.5px solid var(--line); border-radius: 26px; box-shadow: 5px 5px 0 var(--line); animation: arcPop .18s ease-out; }
.arc-card.play { height: min(100%, 880px); }
.arc-card.wide { width: min(100%, 940px); height: min(100%, 700px); }

.arc-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 8px 20px; }
.arc-head h2 { margin: 0; font: italic 600 26px/1.1 "Fraunces", serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arc-x { flex: none; width: 42px; height: 42px; display: grid; place-items: center; background: var(--panel); border: 1.5px solid var(--line); border-radius: 13px; box-shadow: 2px 2px 0 var(--line); transition: transform .08s, box-shadow .08s; }
.arc-x:hover { background: var(--hover); }
.arc-x:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.arc-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.arc-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 4px 16px 16px; overflow-y: auto; scrollbar-width: none; }
.arc-body::-webkit-scrollbar { display: none; }

/* ---------- lobby ---------- */
.arc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 2px 5px 5px 2px; }
.arc-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px 14px 12px; text-align: left; background: var(--panel); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: 3px 3px 0 var(--line); transition: transform .1s, box-shadow .1s, background .1s; }
.arc-tile:hover { background: var(--hover); transform: translate(-1px, -1px) rotate(-1.2deg); box-shadow: 4px 4px 0 var(--line); }
.arc-tile:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.arc-tile i { font-style: normal; font-size: 34px; line-height: 1.15; }
.arc-tile b { font: italic 600 18px/1.15 "Fraunces", serif; }
.arc-tile span { font-size: 12.5px; color: var(--mute); }

/* ---------- game screen ---------- */
.arc-hud { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.arc-chip { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; justify-self: start; padding: 4px 12px 4px 4px; background: var(--soft); border: 1.5px solid var(--line); border-radius: 999px; }
.arc-chip.b { flex-direction: row-reverse; justify-self: end; padding: 4px 4px 4px 12px; }
.arc-av { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 1.5px solid var(--line); border-radius: 50%; color: #fff; font-weight: 700; font-size: 14px; line-height: 1; }
.arc-name { min-width: 0; font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arc-score { flex: none; font: italic 700 22px/1 "Fraunces", serif; font-variant-numeric: tabular-nums; }
.arc-clock { min-width: 48px; padding: 6px 12px; text-align: center; background: var(--text); color: var(--panel); border-radius: 999px; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.arc-clock:empty { visibility: hidden; }

.arc-stage { position: relative; flex: 1 1 0; min-height: 0; }
.arc-canvas { position: absolute; inset: 0; margin: auto; display: block; background: #fff; border-radius: 18px; box-shadow: 0 0 0 1.5px var(--line), 3px 3px 0 1.5px var(--line); touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

.arc-flash { position: absolute; left: 50%; top: 42%; z-index: 1; padding: 8px 20px; background: var(--panel); color: var(--text); border: 1.5px solid var(--line); border-radius: 999px; box-shadow: 3px 3px 0 var(--line); font: italic 600 26px/1.2 "Fraunces", serif; white-space: nowrap; pointer-events: none; opacity: 0; transform: translate(-50%, -50%); }
.arc-flash.go { animation: arcFlash 1s ease-out forwards; }
@keyframes arcFlash {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6) rotate(-4deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(1deg); }
  24%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -66%) scale(.96); }
}

/* waiting, result and goodbye cards sit over the canvas */
.arc-layer { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 12px; border-radius: 18px; background: var(--panel); background: color-mix(in srgb, var(--panel) 82%, transparent); }
.arc-box { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; padding: 22px 22px 18px; text-align: center; background: var(--panel); border: 1.5px solid var(--line); border-radius: 22px; box-shadow: 4px 4px 0 var(--line); animation: arcPop .18s ease-out; }
.arc-box i { font-style: normal; font-size: 44px; line-height: 1; }
.arc-box h3 { margin: 0; font: italic 600 26px/1.1 "Fraunces", serif; overflow-wrap: anywhere; }
.arc-box p { margin: 0; font: italic 700 30px/1 "Fraunces", serif; font-variant-numeric: tabular-nums; color: var(--accent); }
.arc-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.arc-btn { display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 16px; font: 700 14px/1 "DM Sans", system-ui, sans-serif; color: var(--text); white-space: nowrap; cursor: pointer; background: var(--panel); border: 1.5px solid var(--line); border-radius: 14px; box-shadow: 2px 2px 0 var(--line); transition: transform .08s, box-shadow .08s; }
.arc-btn:hover { background: var(--hover); }
.arc-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.arc-btn.primary { background: var(--accent); color: var(--on-accent); }
.arc-btn.primary:hover { filter: brightness(1.05); }
.arc-btn:disabled { opacity: .5; cursor: default; }

/* ---------- on-screen controls ---------- */
.arc-pad { flex: none; display: none; align-items: center; justify-content: space-between; gap: 10px; }
.arc-pad.dive { display: flex; min-height: 56px; }
.arc-pad.keys { display: flex; justify-content: center; min-height: 20px; }
.arc-keys { display: none; gap: 10px; }
.arc-tip { font-size: 12.5px; font-weight: 700; color: var(--mute); }
.arc-key { min-width: 68px; height: 64px; padding: 0 14px; display: grid; place-items: center; font-weight: 700; font-size: 22px; background: var(--panel); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: 3px 3px 0 var(--line); touch-action: none; -webkit-user-select: none; user-select: none; transition: transform .06s, box-shadow .06s; }
.arc-key.word { font-size: 15px; }
.arc-key.wide { flex: 1; min-width: 0; height: 54px; font-size: 15px; }
.arc-key.wide:hover { background: var(--hover); }
.arc-key.on, .arc-key:active, .arc-key.wide:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); background: var(--accent); color: var(--on-accent); }
/* touch screens get the head soccer buttons, everyone else gets the key hint */
@media (any-pointer: coarse) {
  .arc-pad.keys { justify-content: space-between; }
  .arc-keys { display: flex; }
  .arc-tip { display: none; }
}

/* ---------- invite cards (shown over the board, arcade open or not) ---------- */
#arcadeInvites { position: fixed; z-index: 46; top: calc(max(12px, env(safe-area-inset-top)) + 56px); left: 12px; right: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.arc-invite { pointer-events: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; max-width: 100%; padding: 8px 10px 8px 14px; color: var(--text); background: var(--panel); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: 3px 3px 0 var(--line); animation: arcDrop .22s ease-out, arcInviteOut .3s ease-in 40s forwards; }
.arc-invite i { font-style: normal; font-size: 22px; line-height: 1; }
.arc-invite b { font: italic 600 16px/1.2 "Fraunces", serif; }
.arc-invite .arc-btn { height: 36px; padding: 0 14px; font-size: 13px; }
@keyframes arcDrop { from { opacity: 0; transform: translateY(-10px) scale(.96); } }
@keyframes arcInviteOut { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- phones and short windows ---------- */
@media (max-width: 720px) {
  #arcade { padding: 0; }
  .arc-card, .arc-card.play, .arc-card.wide { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; box-shadow: none; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  .arc-body { padding: 4px 12px 12px; }
  .arc-head { padding: 10px 10px 6px 16px; }
}
@media (max-height: 520px) {
  #arcade { padding: 0; }
  .arc-card.play, .arc-card.wide { height: 100%; border-radius: 0; }
  .arc-head { padding: 4px 8px 2px 14px; }
  .arc-head h2 { font-size: 19px; }
  .arc-x { width: 34px; height: 34px; }
  .arc-body { gap: 6px; padding: 2px 10px 8px; }
  .arc-key { height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  #arcade, .arc-card, .arc-box { animation: none; }
}
