/* Shove — flat, calm, rounded. Colors are defined once here as variables. */

@font-face {
  font-family: "Tajawal";
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/tajawal-arabic-500-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "Tajawal";
  font-weight: 800;
  font-display: swap;
  src: url("/fonts/tajawal-arabic-800-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: "Tajawal";
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/tajawal-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Tajawal";
  font-weight: 800;
  font-display: swap;
  src: url("/fonts/tajawal-latin-800-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}

:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #23263a;
  --muted: #8a8fa3;
  --line: #e6e1d6;
  --primary: #ff7a59;
  --primary-press: #e9643f;
  --dark: #3a3d56;
  --good: #3caea3;
  --danger: #e0525a;
  --wa: #25d366;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(35, 38, 58, 0.06), 0 8px 24px rgba(35, 38, 58, 0.06);
  --font: "Tajawal", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; /* no pull-to-refresh */
}

body { min-height: 100dvh; }

#app {
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; user-select: none; -webkit-user-select: none; }

h1, h2 { margin: 0; font-weight: 800; }
h2 { font-size: 1.05rem; }

/* ---------- Top bar ---------- */
.topbar { display: flex; justify-content: flex-end; gap: 8px; min-height: 40px; }
.icon-chip { min-width: 40px; font-size: 1rem; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  min-height: 48px;
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--line);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--primary-press); }
.btn.primary:active { box-shadow: 0 1px 0 var(--primary-press); }
.btn.dark { background: var(--dark); color: #fff; box-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.good { background: var(--good); color: #fff; box-shadow: 0 3px 0 #2e8f86; }
.btn.wa { background: var(--wa); color: #fff; box-shadow: none; }
.btn.big { min-height: 58px; font-size: 1.15rem; border-radius: 16px; }

/* ---------- Screens ---------- */
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; }

/* Home */
.home {
  width: 100%;
  max-width: 380px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  padding-bottom: 24px;
}
.hero { width: 100%; height: 120px; }
.logo {
  font-size: clamp(3.2rem, 16vw, 4.4rem);
  letter-spacing: -0.03em;
  line-height: 0.9;
  color: var(--ink);
}
.tagline { margin: 0 0 10px; color: var(--muted); font-size: 1.05rem; line-height: 1.5; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 10px; }
.join-row .btn { flex: 0 0 auto; min-width: 96px; }
.code-input, .text-input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 10px 14px;
  font-size: 1rem;
  outline: none;
}
.code-input {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-weight: 800;
  font-size: 1.25rem;
}
/* No letter-spacing on the placeholder: it would pull Arabic letters apart. */
.code-input::placeholder { letter-spacing: 0; font-weight: 500; font-size: 1rem; }
.code-input:focus, .text-input:focus { border-color: var(--primary); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 0.95rem; }

/* Lobby */
.lobby {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.label { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.room-code { font-size: 2.1rem; font-weight: 800; letter-spacing: 0.12em; line-height: 1; }
.share-panel { display: flex; flex-direction: column; gap: 8px; }
.share-buttons { display: flex; gap: 10px; }
.share-link {
  background: var(--card);
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.9rem;
  text-align: center;
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}
.room-code { cursor: pointer; }
.share-buttons .btn { flex: 1; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.players { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 12px;
  min-height: 52px;
}
.player.me { background: #fbf4ee; }
.player.empty { color: var(--muted); }
.player.empty .avatar-sm { opacity: 0.35; }
.player.offline { opacity: 0.45; }
.avatar-sm { width: 40px; height: 40px; flex: 0 0 auto; }
.player .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.player .tag { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.badge {
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 4px 10px;
  background: #f0ede6;
  color: var(--muted);
  white-space: nowrap;
}
.badge.ready { background: #e2f4f1; color: #2a8c83; }
.crown { font-size: 1rem; }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 12px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 44px; height: 26px; border-radius: 999px; background: var(--line);
  position: relative; flex: 0 0 auto; transition: background 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: inset-inline-start 0.15s;
}
.toggle input:checked + .switch { background: var(--good); }
.toggle input:checked + .switch::after { inset-inline-start: 21px; }
.toggle input:focus-visible + .switch { outline: 2px solid var(--primary); outline-offset: 2px; }
.toggle.disabled { opacity: 0.55; cursor: default; }

.profile { display: flex; gap: 14px; align-items: flex-start; }
.avatar-lg { width: 84px; height: 84px; flex: 0 0 auto; }
.profile-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.profile-fields .text-input { width: 100%; margin-bottom: 6px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-width: 280px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.06);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }

.lobby-actions { display: flex; gap: 10px; align-items: stretch; }
.lobby-actions .btn.big { flex: 1; }
.lobby-actions .btn.ghost { flex: 0 0 auto; }

/* Status + toast */
.status, .toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  z-index: 10;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.status { top: calc(env(safe-area-inset-top) + 10px); background: var(--danger); }
.toast { bottom: calc(env(safe-area-inset-bottom) + 20px); }

@media (min-height: 700px) {
  .hero { height: 150px; }
}

/* ---------- Game screen ---------- */
.game-screen {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: #e4eaf0;
  touch-action: none; /* no scrolling, zooming or pull-to-refresh while playing */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
.game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.game-banner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(35, 38, 58, 0.85);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
}

.desktop-hint {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  pointer-events: none;
}
/* Touch screens: no keyboard hint. */
@media (pointer: coarse) {
  .desktop-hint { display: none; }
}

/* ---------- Match: HUD, countdown, feed, emoji, result cards ---------- */
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.hud-round { font-weight: 800; font-size: 0.95rem; color: var(--ink); }
.hud-scores { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.score-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 3px 6px 3px 4px;
}
.score-chip.me { box-shadow: 0 0 0 2px var(--primary); }
.score-chip.out { opacity: 0.45; }
.chip-dot { width: 14px; height: 14px; border-radius: 50%; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: #d6d1c6; }
.pip.on { background: var(--ink); }

.game-banner { top: calc(env(safe-area-inset-top) + 64px); }

.feed {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 104px);
  inset-inline-start: calc(env(safe-area-inset-left) + 12px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  max-width: 60%;
}
.feed-line {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.85rem;
  animation: feed-in 0.25s ease-out, feed-out 0.5s ease-in 2.8s forwards;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes feed-in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes feed-out { to { opacity: 0; } }

.countdown {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 800;
  color: var(--ink);
  pointer-events: none;
  text-shadow: 0 4px 0 rgba(255, 255, 255, 0.8);
}
.countdown.tick { animation: count-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
.countdown.go { color: var(--primary); }
@keyframes count-pop { from { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } }

.emoji-bar {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 10px);
  top: 50%;
  transform: translateY(-62%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
}
.emoji-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.85);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0;
  touch-action: manipulation;
  transition: transform 0.08s, opacity 0.2s;
}
.emoji-btn:active { transform: scale(0.88); }
.emoji-bar.cooling .emoji-btn { opacity: 0.4; }
@media (orientation: landscape) and (max-height: 500px) {
  .emoji-bar { top: 12px; transform: none; flex-direction: row; right: calc(env(safe-area-inset-right) + 12px); }
  .emoji-btn { width: 38px; height: 38px; font-size: 1.15rem; }
  .feed { top: calc(env(safe-area-inset-top) + 60px); }
  .game-banner { top: calc(env(safe-area-inset-top) + 56px); }
}

.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(228, 234, 240, 0.55);
  pointer-events: none;
}
#matchCard { pointer-events: auto; background: rgba(228, 234, 240, 0.8); }
.result-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px 22px 16px;
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: card-pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes card-pop { from { transform: scale(0.8); opacity: 0; } }
.result-card h2 { font-size: 1.45rem; line-height: 1.3; }
.result-line { margin: 0; color: var(--muted); }
.trophy { font-size: 3rem; line-height: 1; }
.small { font-size: 0.85rem; margin: 0; }
.standings { list-style: none; margin: 4px 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; text-align: start; }
.standings li { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 10px; }
.standings li.me { background: #fbf4ee; }
.standings li.top { font-weight: 800; }
.standings .st-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .pips { display: flex; gap: 4px; }
.standings .pip { width: 10px; height: 10px; }

/* Eye / hat pickers */
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; max-width: 300px; margin-bottom: 4px; }
.opt-btn {
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: #f4f1ea;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.opt-btn[aria-pressed="true"] { background: #fff; box-shadow: 0 0 0 2px var(--ink); }
.opt-canvas { width: 100%; height: 100%; display: block; }

/* ---------- How to play ---------- */
.howto {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(35, 38, 58, 0.35);
}
.howto-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px 20px 18px;
  width: min(380px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
  animation: card-pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.howto-card h2 { font-size: 1.5rem; }
.howto-steps { display: flex; flex-direction: column; gap: 12px; }
.howto-step { display: flex; align-items: center; gap: 14px; text-align: start; }
.howto-step p { margin: 0; line-height: 1.5; }
.howto-icon { width: 64px; height: 64px; flex: 0 0 auto; }
/* Short landscape screens: the three steps side by side */
@media (orientation: landscape) and (max-height: 500px) {
  .howto-card { width: min(640px, 100%); padding: 14px 18px; gap: 10px; }
  .howto-steps { flex-direction: row; }
  .howto-step { flex-direction: column; text-align: center; flex: 1; gap: 6px; }
  .howto-step p { font-size: 0.9rem; }
  .howto-icon { width: 52px; height: 52px; }
}

/* Portrait phones: emoji row under the score HUD, so nothing covers the platform.
   (The renderer keeps the platform between this row and the push button.) */
@media (orientation: portrait) {
  .emoji-bar {
    top: calc(env(safe-area-inset-top) + 84px);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    flex-direction: row;
  }
  .emoji-btn { width: 38px; height: 38px; font-size: 1.15rem; }
  .game-banner { top: calc(env(safe-area-inset-top) + 130px); }
  .feed { top: calc(env(safe-area-inset-top) + 172px); }
}

/* Narrow phones: compact score chips so all 6 fit on one row */
@media (max-width: 380px), (orientation: landscape) and (max-height: 500px) {
  .hud-scores { gap: 4px; flex-wrap: nowrap; }
  .score-chip { padding: 2px 4px 2px 3px; gap: 2px; }
  .chip-dot { width: 12px; height: 12px; }
  .hud .pip { width: 6px; height: 6px; }
}

/* Short landscape phones: emojis stacked on the right edge, above the push button */
@media (orientation: landscape) and (max-height: 500px) {
  .emoji-bar {
    top: calc(env(safe-area-inset-top) + 8px);
    right: calc(env(safe-area-inset-right) + 12px);
    left: auto;
    transform: none;
    flex-direction: column;
    gap: 4px;
  }
  .emoji-btn { width: 34px; height: 34px; font-size: 1.05rem; }
}

/* Share-result button on the match card */
.btn.share-result { background: #FFC93C; color: var(--ink); box-shadow: 0 3px 0 #E0A92A; }
.btn.share-result:active { box-shadow: 0 1px 0 #E0A92A; }
.btn.share-result:disabled { opacity: 0.7; }

/* Readable on top of the busy city background */
.hud-round { background: rgba(255, 255, 255, 0.88); padding: 2px 12px; border-radius: 999px; }
.desktop-hint { left: 50%; right: auto; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px);
  background: rgba(255, 255, 255, 0.85); color: var(--ink); padding: 4px 12px; border-radius: 999px; }
.game-screen { background: #8FA3C8; }

/* Touch controls: the whole screen (under the HUD, emoji bar and cards) */
.touch-zone { position: absolute; inset: 0; touch-action: none; }
.game-overlay { pointer-events: none; }

/* Weak-connection warning + optional diagnostics (?debug) */
.net-warn {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: #E0525A;
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}
.debug-info {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 50px);
  left: 8px;
  background: rgba(35, 38, 58, 0.75);
  color: #fff;
  font: 12px/1.3 ui-monospace, monospace;
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
  direction: ltr;
}
