* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #151823;
  --panel: #1f2333;
  --panel-2: #282d42;
  --text: #eef0f6;
  --muted: #9aa1b5;
  --red: #e0344a;
  --green: #1ea44c;
  --purple: #7a3fa8;
  --accent: #4f7cff;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.screen {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); }
.btn-google { background: #fff; color: #1a1a1a; }
.btn-small { padding: 6px 12px; font-size: 13px; }

/* ---------- login ---------- */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box { text-align: center; padding: 24px; }
.logo { font-size: 52px; letter-spacing: 1px; font-weight: 800; }
.l-red { color: var(--red); }
.l-green { color: var(--green); }
.l-purple { color: var(--purple); }
.tagline { color: var(--muted); margin: 8px 0 40px; }
#screen-login .btn { display: flex; width: 240px; margin: 0 auto; }
#screen-login .btn-solo { margin-top: 14px; }
.solo-lobby { width: 100%; margin-bottom: 14px; background: var(--panel); }

/* ---------- lobby ---------- */
#screen-lobby { padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.me { display: flex; align-items: center; gap: 8px; }
.me img { width: 30px; height: 30px; border-radius: 50%; }
.me span { font-size: 14px; color: var(--muted); max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 16px; }
.player-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
}
.player-list li:active { background: var(--panel-2); }
.player-list img { width: 42px; height: 42px; border-radius: 50%; }
.player-list .p-name { flex: 1; font-weight: 600; }
.player-list .p-status { font-size: 12px; color: var(--muted); }
.player-list li.busy { opacity: 0.5; pointer-events: none; }
.empty { text-align: center; color: var(--muted); margin-top: 30vh; line-height: 1.6; }

/* ---------- game ---------- */
#screen-game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
}
.score { display: flex; align-items: center; gap: 8px; min-width: 0; }
.score img { width: 32px; height: 32px; border-radius: 50%; }
.score .s-name { font-size: 13px; color: var(--muted); max-width: 22vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score .s-count { font-size: 22px; font-weight: 800; }
.score.flash .s-count { animation: pop 0.5s; }
.deck-count { text-align: center; line-height: 1.1; }
.deck-count span { font-size: 18px; font-weight: 700; }
.deck-count small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.deck-count.urgent span { color: var(--red); }
.score.hidden-solo { visibility: hidden; }

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  align-content: start;
  overflow-y: auto;
}
.card {
  background: #fdfdf8;
  border-radius: 10px;
  aspect-ratio: 8 / 5;
  width: 96%;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease;
  border: 2.5px solid transparent;
  user-select: none;
  -webkit-user-select: none;
}
.card svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.card.selected {
  transform: scale(0.82);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.35);
}
.card.bad { animation: shake 0.35s; border-color: var(--red); }
.card.claimed {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 164, 76, 0.45);
  animation: claimed-pop 0.4s ease;
}
@keyframes claimed-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.card.claimed.no-anim { animation: none; }
.card.dealt { animation: deal-in 0.45s ease; }
@keyframes deal-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.card.facedown {
  background: linear-gradient(135deg, #ff5f6d, #ffc371, #ffe66d, #4ecdc4, #556bff, #b06ab3);
  background-size: 300% 300%;
  animation: rainbow-drift 5s ease-in-out infinite;
  border: 2.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 14px rgba(176, 106, 179, 0.5);
}
@keyframes rainbow-drift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.6); color: var(--green); }
  100% { transform: scale(1); }
}

/* portrait: pull the whole board in 15% so tall boards fit above the fold */
@media (orientation: portrait) {
  .board { width: 85%; margin: 0 auto; }
}

/* phone rotated sideways: header becomes a left sidebar so the full screen
   height belongs to the cards; same card order, columns of 3 growing rightward */
@media (orientation: landscape) and (max-height: 520px) {
  #screen-game {
    flex-direction: row;
    padding-left: 0;
    padding-right: 0; /* use every horizontal pixel; cards may tuck under the corner */
  }
  .game-header {
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    width: 62px;
    flex-shrink: 0;
    padding: 8px 4px;
    padding-left: calc(4px + env(safe-area-inset-left));
  }
  .score { flex-direction: column; gap: 1px; text-align: center; }
  .score img { width: 26px; height: 26px; }
  .score .s-name { font-size: 11px; max-width: 56px; }
  .score .s-count { font-size: 18px; }
  .deck-count span { font-size: 15px; }
  .board {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-template-rows: repeat(3, 1fr);
    /* --rowh is measured from the board's real height by sizeBoard() in app.js */
    grid-auto-columns: calc(var(--rowh, 100px) * 1.6);
    justify-content: start;
    overflow-x: auto;
    overflow-y: hidden;
    padding-right: 4px;
  }
  .card {
    width: 100%;
    aspect-ratio: 8 / 5;
  }
}

/* wider screens: just cap the board width, phones come first */
@media (min-width: 700px) and (min-height: 521px) {
  .board { max-width: 640px; margin: 0 auto; width: 100%; }
  #screen-lobby { max-width: 560px; margin: 0 auto; }
}

/* ---------- modals & toasts ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.modal-box {
  background: var(--panel);
  border-radius: 18px;
  padding: 28px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
}
.modal-box img { width: 64px; height: 64px; border-radius: 50%; margin-bottom: 12px; }
.modal-box p { margin-bottom: 8px; line-height: 1.4; }
.modal-box h2 { margin-bottom: 10px; }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.btn:disabled { opacity: 0.4; pointer-events: none; }

/* ---------- mystery-card guess grid ---------- */
.guess-box { max-width: 440px; }
.guess-hint { color: var(--muted); font-size: 13px; }
.guess-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 12px;
}
.guess-cell {
  background: #fdfdf8;
  border-radius: 10px;
  aspect-ratio: 3 / 4;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.guess-cell svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.guess-cell.selected {
  border-color: var(--accent);
  transform: scale(0.93);
  box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.35);
}
#go-hidden .card { width: 110px; margin: 10px auto; cursor: default; }
#go-hidden .go-hint { color: var(--muted); font-size: 13px; }
.go-rainbow-line { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.go-rainbow-good { color: var(--green); }
.go-rainbow-neutral { color: var(--muted); }

.go-card-wrap { position: relative; width: 110px; margin: 10px auto; }
.go-card-wrap .card { margin: 0; }
.go-card-x {
  position: absolute;
  inset: -6px;
  pointer-events: none;
}
.go-card-x::before, .go-card-x::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 135%;
  height: 7px;
  background: #ff3d7f;
  border-radius: 4px;
  box-shadow: 0 0 6px rgba(255, 61, 127, 0.6);
}
.go-card-x::before { transform: translate(-50%, -50%) rotate(45deg); }
.go-card-x::after { transform: translate(-50%, -50%) rotate(-45deg); }

.go-turtle {
  width: 90px;
  display: block;
  margin: 12px auto 0;
  animation: turtle-dance 1.1s ease-in-out infinite;
}
@keyframes turtle-dance {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  25% { transform: translateY(-10px) rotate(6deg); }
  50% { transform: translateY(0) rotate(-8deg); }
  75% { transform: translateY(-7px) rotate(8deg); }
}

.countdown {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
}
.countdown span {
  font-size: 150px;
  font-weight: 800;
  color: var(--accent);
  animation: count-pulse 1s ease-in-out infinite;
}
@keyframes count-pulse {
  0% { transform: scale(0.7); opacity: 0.4; }
  30% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.go-bad { color: var(--muted); font-size: 13px; }

.go-time-toggle { margin-top: 14px; }
.go-time-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.go-time-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.go-time-panel.open { max-height: 60px; }

.toast, .game-toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
