:root {
  --bg:        #08090d;
  --bg2:       #0d0f16;
  --bg3:       #131720;
  --border:    #1e2230;
  --border2:   #2a3040;
  --yellow:    #e8f542;
  --yellow2:   #b8c220;
  --text:      #c8d0e0;
  --text-dim:  #4a5060;
  --text-mid:  #7a8090;
  --red:       #e54242;
  --green:     #42e57a;
  --blue:      #4278e5;
  --orange:    #e58020;

  --card-red:    #dc2626;
  --card-green:  #16a34a;
  --card-blue:   #2563eb;
  --card-yellow: #ca8a04;

  --font-display: 'Syne', sans-serif;
  --font-mono:    'Space Mono', monospace;
  --radius:    8px;
  --radius-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  overflow-x: hidden;
}

/* ---- Screens ---- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---- Brand ---- */
.brand { display: flex; align-items: baseline; gap: 4px; }
.brand-ivski {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 400;
  color: rgba(255,255,255,0.85);
  letter-spacing: -1px;
}
.brand-uno {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 800;
  color: var(--yellow);
  letter-spacing: -1px;
}

/* ---- Inputs ---- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label {
  font-size: 10px; letter-spacing: 2px; color: var(--text-mid); text-transform: uppercase;
}
.hint-label { font-size: 9px; color: var(--text-dim); letter-spacing: 1px; margin-left: 6px; }
input[type="text"], input[type="password"], input[type="email"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  font-family: var(--font-mono);
  font-size: 13px;
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
input:focus { border-color: var(--yellow); }
input::placeholder { color: var(--text-dim); }

/* Honeypot — visually hidden */
.hp-field {
  position: absolute; left: -9999px; top: -9999px;
  width: 1px; height: 1px; overflow: hidden;
  opacity: 0; pointer-events: none;
}

/* Password strength */
.pw-strength {
  height: 3px; border-radius: 2px; background: var(--border);
  margin-top: 4px; transition: all 0.3s; overflow: hidden;
}
.pw-strength::after {
  content: ''; display: block; height: 100%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.pw-strength.weak::after   { width: 33%; background: var(--red); }
.pw-strength.medium::after { width: 66%; background: var(--orange); }
.pw-strength.strong::after { width: 100%; background: var(--green); }

/* ---- Buttons ---- */
.btn-primary {
  display: block; width: 100%; padding: 13px;
  background: var(--yellow); color: #08090d;
  border: none; border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  letter-spacing: 3px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 6px;
}
.btn-primary:hover  { background: var(--yellow2); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: var(--border2); color: var(--text-dim); cursor: not-allowed; }

.btn-sm {
  padding: 7px 14px;
  background: transparent; border: 1px solid var(--border2);
  color: var(--text-mid); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 1px;
  cursor: pointer; transition: all 0.15s;
}
.btn-sm:hover { border-color: var(--yellow); color: var(--yellow); }
.btn-dim { color: var(--text-dim); }
.btn-back {
  background: none; border: none; color: var(--text-dim);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 1px;
  cursor: pointer; padding: 4px 0; margin-bottom: 16px; transition: color 0.15s;
}
.btn-back:hover { color: var(--yellow); }
.btn-guest {
  background: transparent; border: 1px solid var(--border2);
  color: var(--text-mid); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 2px;
  padding: 10px 24px; cursor: pointer; transition: all 0.2s;
  margin-top: 12px;
}
.btn-guest:hover { border-color: var(--text-mid); color: var(--text); }

/* ---- Error ---- */
.error-msg {
  color: var(--red); font-size: 12px; text-align: center;
  min-height: 20px; margin-top: 10px; line-height: 1.5;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-brand { flex: 0 0 auto; }
.topbar-brand .brand-ivski { font-size: 18px; }
.topbar-brand .brand-uno   { font-size: 18px; }
.topbar-user { display: flex; align-items: center; gap: 8px; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.avatar-dot {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #08090d;
  flex-shrink: 0;
}

/* ---- Overlay ---- */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,9,13,0.85);
  display: flex; align-items: center; justify-content: center;
}
.overlay-card {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); padding: 28px 32px;
  min-width: 340px; max-width: 500px; width: 90%;
}
.overlay-card h2 {
  font-family: var(--font-display); font-size: 20px;
  color: var(--yellow); margin-bottom: 16px; letter-spacing: 2px;
}

/* ---- Leaderboard ---- */
.lb-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.lb-table th {
  font-size: 10px; letter-spacing: 2px; color: var(--text-dim);
  padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left;
}
.lb-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 12px; }
.lb-table tr:first-child td { color: var(--yellow); }
.lb-table tr:hover td { background: var(--bg3); }

/* ---- Divider ---- */
.divider {
  text-align: center; font-size: 10px; letter-spacing: 2px;
  color: var(--text-dim); margin: 16px 0;
  position: relative;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%;
  width: 30%; height: 1px; background: var(--border);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(8,9,13,0.88);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); padding: 28px 32px;
  min-width: 280px; max-width: 380px; width: 90%;
  text-align: center;
}
.modal-title {
  font-size: 11px; letter-spacing: 3px; color: var(--text-mid);
  margin-bottom: 18px; text-transform: uppercase;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--yellow); }

/* ---- Animations ---- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes popIn  { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
@keyframes shake  {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-6px); }
  40%,80% { transform: translateX(6px); }
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.4); }
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(232,245,66,0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(232,245,66,0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   MOBILE / TOUCH OPTIMIZATIONS
   ============================================================ */

/* Prevent text selection on tap */
* { -webkit-tap-highlight-color: transparent; }

/* Smooth scrolling */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

/* Touch-friendly tap targets */
button, .card, .mode-card, .room-item, .size-btn, .tab-btn {
  touch-action: manipulation;
}

/* ---- Mobile base (≤480px) ---- */
@media (max-width: 480px) {
  :root { font-size: 12px; }

  /* Auth */
  .auth-wrap { padding: 24px 16px 0; }
  .auth-card { padding: 20px 16px 16px; border-radius: 10px; }
  .auth-wrap .brand-ivski,
  .auth-wrap .brand-uno { font-size: 28px; }
  .auth-wrap .brand { margin-bottom: 20px; }

  /* Inputs larger for touch */
  input[type="text"],
  input[type="password"],
  input[type="email"] { padding: 13px 12px; font-size: 16px; }

  .btn-primary { padding: 15px; font-size: 13px; }
  .btn-guest   { padding: 13px 20px; font-size: 12px; }

  /* Lobby */
  .lobby-wrap { padding: 16px 12px; }
  .mode-cards { grid-template-columns: 1fr; max-width: 100%; gap: 10px; }
  .mode-card  { padding: 20px 16px; }
  .mode-icon  { font-size: 28px; }
  .mode-name  { font-size: 14px; }
  .cj-grid    { grid-template-columns: 1fr; gap: 12px; }
  .cj-card    { padding: 16px; }
  .size-btns  { gap: 6px; }
  .size-btn   { padding: 10px 4px; font-size: 12px; }

  /* Topbar compact */
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar-brand .brand-ivski,
  .topbar-brand .brand-uno { font-size: 15px; }
  #topbar-username { font-size: 11px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn-sm { padding: 6px 10px; font-size: 9px; }

  /* Waiting room */
  .waiting-card { padding: 24px 16px; }
  .rcd-code { font-size: 26px; letter-spacing: 6px; }
  .wp-dot   { width: 38px; height: 38px; font-size: 12px; }

  /* Footer compact */
  .uno-footer { font-size: 9px; padding: 12px 16px; }
}

/* ---- Game screen mobile ---- */
@media (max-width: 600px) {
  /* Full viewport game */
  #screen-game {
    height: 100dvh;
    overflow: hidden;
  }

  /* Opponents area — horizontal scroll if many */
  .opponents-area {
    padding: 8px 10px 6px;
    gap: 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
    min-height: 90px;
    scrollbar-width: none;
  }
  .opponents-area::-webkit-scrollbar { display: none; }

  .opponent-seat { min-width: 70px; }
  .opp-name      { font-size: 9px; }
  .opp-dot       { width: 20px; height: 20px; font-size: 8px; }
  .opp-cards .card { margin-right: -20px !important; }

  /* Game table compact */
  .game-table  { padding: 8px; gap: 16px; flex: 1; }
  .table-felt  { gap: 16px; padding: 12px 14px; }
  .game-log    { display: none; }

  /* Deck/discard smaller */
  .card        { width: 52px; height: 78px; }
  .card-face   { border-width: 2px; }
  .card-corner { font-size: 10px; }
  .card-center { font-size: 22px; }
  .card-center.special { font-size: 15px; }
  .card-center.wild-symbol { font-size: 16px; }
  .wild-quarters { width: 28px; height: 28px; }
  .card.mini   { width: 32px; height: 46px; }

  /* Deck stack smaller */
  .deck-pile, .card-stack { width: 52px; height: 78px; }

  /* Direction indicator */
  .direction-ind { font-size: 18px; }

  /* Player area */
  .player-area  { padding: 6px 10px 10px; }
  .player-info-bar { gap: 6px; margin-bottom: 4px; }
  .pib-name     { font-size: 11px; }
  .turn-ind     { font-size: 9px; padding: 3px 7px; }

  /* Hand — bigger cards, horizontal scroll */
  .player-hand {
    padding: 4px 0 6px;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .player-hand::-webkit-scrollbar { display: none; }
  .player-hand .card { margin-right: -14px; flex-shrink: 0; }
  .player-hand .card:last-child { margin-right: 8px; }

  /* Bigger touch target for cards in hand */
  .player-hand .card { width: 58px; height: 86px; }

  /* Action bar — scrollable row */
  .action-bar {
    padding: 6px 10px;
    gap: 6px;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .action-bar::-webkit-scrollbar { display: none; }
  .action-bar-main {
    display: flex; gap: 6px; flex-wrap: nowrap; flex-shrink: 0;
  }
  .action-btn {
    padding: 8px 12px; font-size: 10px;
    white-space: nowrap; flex-shrink: 0;
  }
  #btn-leave-game { flex-shrink: 0; }

  /* Draw stack banner */
  .draw-stack-banner { padding: 3px 10px; }
  .draw-stack-banner span:first-child { font-size: 13px; }
  .ds-label { font-size: 8px; }

  /* Modals full width */
  .modal-card { padding: 20px 16px; min-width: unset; width: 90%; }
  .gameover-emoji { font-size: 50px; }
  .gameover-card h2 { font-size: 20px; }

  /* Color picker */
  .color-choices { grid-template-columns: 1fr 1fr; gap: 8px; }
  .color-choice  { padding: 16px 8px; font-size: 14px; }

  /* Callout button */
  .callout-btn { padding: 5px 8px; font-size: 9px; }

  /* Watermark smaller */
  .game-watermark { font-size: 10px; top: 6px; right: 8px; }
}

/* ---- Landscape mobile ---- */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .opponents-area { min-height: 70px; padding: 4px 10px; }
  .game-table     { padding: 4px; flex: 1; }
  .table-felt     { gap: 10px; padding: 8px 12px; }
  .player-area    { padding: 4px 10px 6px; }
  .player-info-bar { margin-bottom: 2px; }

  .card           { width: 44px; height: 66px; }
  .deck-pile, .card-stack { width: 44px; height: 66px; }
  .card-center    { font-size: 18px; }
  .card-center.special { font-size: 13px; }
  .card-corner    { font-size: 9px; }

  .action-btn     { padding: 6px 10px; font-size: 10px; }
  .player-hand    { padding: 2px 0 4px; }
}
