:root {
      --felt: #1a5c2a;
      --felt-dark: #145222;
      --card-white: #ffffff;
      --card-back: #1a3a4a;
      --red: #d32f2f;
      --black: #1a1a2e;
      --accent: #e94560;
      --gold: #ffd700;
      --cyan: #00e5ff;
      --text: #fff;
      --text-muted: #b0b0b0;
      --joker-common: #9e9e9e;
      --joker-rare: #2196f3;
      --joker-epic: #ffd700;
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: var(--felt);
      color: var(--text);
      height: 100vh;
      height: 100dvh;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      touch-action: manipulation;
      -webkit-tap-highlight-color: transparent;
      user-select: none;
    }

    /* Header stats row (below shared game-header) */
    .game-header {
      background: rgba(0,0,0,0.3);
    }
    .header-stats {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 1.5rem;
      padding: 0.2rem 0.75rem 0.4rem;
      font-size: 0.8rem;
    }
    .stat-group {
      display: flex;
      align-items: center;
      gap: 0.3rem;
    }
    .stat-label {
      color: var(--text-muted);
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.03em;
    }
    .score-display {
      font-size: 1.1rem;
      font-weight: 800;
      color: var(--gold);
    }
    .timer-display {
      font-size: 1rem;
      font-weight: 700;
      color: var(--text);
    }

    /* Active Jokers Bar */
    .jokers-bar {
      display: flex;
      justify-content: center;
      gap: 0.5rem;
      padding: 0.3rem 1rem;
      background: rgba(0,0,0,0.2);
      min-height: 36px;
      flex-wrap: wrap;
    }
    .joker-badge {
      display: flex;
      align-items: center;
      gap: 0.3rem;
      padding: 0.2rem 0.5rem;
      border-radius: 6px;
      font-size: 0.7rem;
      font-weight: 600;
      border: 1px solid;
      cursor: pointer;
      transition: transform 0.15s;
    }
    .joker-badge:hover { transform: scale(1.1); }
    .joker-badge.common { border-color: var(--joker-common); color: var(--joker-common); }
    .joker-badge.rare { border-color: var(--joker-rare); color: var(--joker-rare); }
    .joker-badge.epic { border-color: var(--joker-epic); color: var(--joker-epic); }
    .joker-badge.cursed { border-color: #ef4444; color: #ef4444; background: rgba(239,68,68,0.1); }
    .joker-badge .joker-glow {
      animation: jokerGlow 0.5s ease-out;
    }
    @keyframes jokerGlow {
      0% { filter: brightness(2); transform: scale(1.3); }
      100% { filter: brightness(1); transform: scale(1); }
    }

    /* Game Area */
    .game-area {
      max-width: 700px;
      width: 100%;
      margin: 0 auto;
      padding: 0.5rem;
      position: relative;
      flex: 1;
      overflow-y: auto;
      scrollbar-width: none;
      -ms-overflow-style: none;
    }
    .game-area::-webkit-scrollbar { display: none; }

    /* Top row: stock, waste, gap, foundations */
    .top-row {
      display: grid;
      grid-template-columns: repeat(7, 1fr);
      gap: 4px;
      margin-bottom: 8px;
    }
    .top-row .slot {
      aspect-ratio: 2.5/3.5;
      border-radius: 6px;
    }

    /* Tableau */
    .tableau {
      display: grid;
      grid-template-columns: repeat(7, 1fr);
      gap: 4px;
      align-items: start;
    }
    .tableau-column {
      position: relative;
      min-height: 100px;
    }

    /* Cards */
    .card {
      width: 100%;
      aspect-ratio: 2.5/3.5;
      border-radius: 6px;
      position: absolute;
      cursor: pointer;
      transition: box-shadow 0.15s, transform 0.1s;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      font-weight: 700;
      overflow: hidden;
    }
    .card.face-up {
      background: var(--card-white);
      border: 1px solid #ddd;
    }
    .card.face-down {
      background: var(--card-back);
      border: 1px solid #2a5a6a;
      cursor: default;
    }
    .card.face-down::after {
      content: '';
      position: absolute;
      inset: 3px;
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 4px;
    }
    .card.selected {
      box-shadow: 0 0 0 3px var(--cyan), 0 4px 16px rgba(0,229,255,0.4);
      transform: translateY(-4px);
      z-index: 99 !important;
    }
    .card.valid-target {
      box-shadow: 0 0 0 2px rgba(74,222,128,0.6);
    }
    .card .rank-suit {
      padding: 2px 4px;
      font-size: clamp(0.6rem, 2.5vw, 0.85rem);
      line-height: 1.1;
    }
    .card .rank-suit.bottom {
      align-self: flex-end;
      transform: rotate(180deg);
    }
    .card .center-suit {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: clamp(1rem, 5vw, 1.8rem);
      opacity: 0.3;
    }
    .card.red { color: var(--red); }
    .card.black { color: var(--black); }

    /* Slot placeholders */
    .slot-placeholder {
      width: 100%;
      aspect-ratio: 2.5/3.5;
      border: 2px dashed rgba(255,255,255,0.2);
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.2rem;
      opacity: 0.5;
      cursor: pointer;
    }
    .slot-placeholder.foundation {
      border-color: rgba(255,215,0,0.3);
    }
    .slot-placeholder.foundation .suit-ghost {
      font-size: clamp(1rem, 4vw, 1.5rem);
      opacity: 0.4;
    }

    /* Stock pile */
    .stock-pile {
      position: relative;
      cursor: pointer;
    }
    .stock-pile .card {
      position: absolute;
      top: 0;
      left: 0;
    }
    .stock-empty {
      width: 100%;
      aspect-ratio: 2.5/3.5;
      border: 2px dashed rgba(255,255,255,0.2);
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }
    .stock-empty::after {
      content: '↻';
      font-size: 1.5rem;
      color: rgba(255,255,255,0.4);
    }

    /* Waste pile */
    .waste-pile {
      position: relative;
    }

    /* Foundation progress */
    .foundation-slot {
      position: relative;
    }
    .foundation-progress {
      position: absolute;
      bottom: -2px;
      left: 10%;
      width: 80%;
      height: 3px;
      background: rgba(0,0,0,0.3);
      border-radius: 2px;
      overflow: hidden;
    }
    .foundation-progress-fill {
      height: 100%;
      background: var(--gold);
      transition: width 0.3s ease;
    }

    /* Joker Shop Overlay */
    .shop-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.85);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 200;
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.3s, visibility 0.3s;
    }
    .shop-overlay.show {
      opacity: 1;
      visibility: visible;
    }
    .shop-title {
      font-size: 1.5rem;
      font-weight: 800;
      margin-bottom: 0.5rem;
      color: var(--gold);
    }
    .shop-subtitle {
      font-size: 0.9rem;
      color: var(--text-muted);
      margin-bottom: 1.5rem;
    }
    .shop-cards {
      display: flex;
      gap: 1rem;
      margin-bottom: 1.5rem;
      flex-wrap: wrap;
      justify-content: center;
    }
    .shop-card {
      width: 160px;
      background: #1a1a2e;
      border-radius: 12px;
      padding: 1.2rem 1rem;
      text-align: center;
      cursor: pointer;
      transition: transform 0.2s, box-shadow 0.2s;
      border: 2px solid;
    }
    .shop-card:hover {
      transform: translateY(-6px);
      box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    }
    .shop-card.common { border-color: var(--joker-common); }
    .shop-card.rare { border-color: var(--joker-rare); }
    .shop-card.epic { border-color: var(--joker-epic); animation: epicShimmer 2s infinite; }
    @keyframes epicShimmer {
      0%,100% { box-shadow: 0 0 10px rgba(255,215,0,0.2); }
      50% { box-shadow: 0 0 20px rgba(255,215,0,0.5); }
    }
    .shop-card-icon { font-size: 2rem; margin-bottom: 0.5rem; }
    .shop-card-name {
      font-weight: 700;
      font-size: 0.95rem;
      margin-bottom: 0.3rem;
    }
    .shop-card-desc {
      font-size: 0.75rem;
      color: var(--text-muted);
      line-height: 1.3;
    }
    .shop-card-rarity {
      font-size: 0.65rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-top: 0.5rem;
    }
    .shop-card.common .shop-card-rarity { color: var(--joker-common); }
    .shop-card.rare .shop-card-rarity { color: var(--joker-rare); }
    .shop-card.epic .shop-card-rarity { color: var(--joker-epic); }
    .shop-skip {
      background: none;
      border: 1px solid rgba(255,255,255,0.2);
      color: var(--text-muted);
      padding: 0.5rem 1.5rem;
      border-radius: 8px;
      cursor: pointer;
      font-size: 0.85rem;
    }
    .shop-skip:hover { border-color: var(--text); color: var(--text); }

    /* Game Over Modal */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.85);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 300;
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.3s, visibility 0.3s;
    }
    .modal-overlay.show { opacity: 1; visibility: visible; }
    .modal {
      background: #16213e;
      border-radius: 16px;
      padding: 2rem;
      width: 90%;
      max-width: 400px;
      text-align: center;
      transform: scale(0.9);
      transition: transform 0.3s;
    }
    .modal-overlay.show .modal { transform: scale(1); }
    .modal h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
    .modal .final-score {
      font-size: 2.5rem;
      font-weight: 900;
      color: var(--gold);
      margin: 0.5rem 0;
    }
    .modal .stats-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0.75rem;
      margin: 1rem 0;
      text-align: center;
    }
    .modal .stat-item {
      background: rgba(0,0,0,0.3);
      padding: 0.6rem;
      border-radius: 8px;
    }
    .modal .stat-value {
      font-size: 1.2rem;
      font-weight: 700;
      color: var(--cyan);
    }
    .modal .stat-label {
      font-size: 0.7rem;
      color: var(--text-muted);
    }
    .modal .jokers-used {
      display: flex;
      justify-content: center;
      gap: 0.4rem;
      margin: 0.75rem 0;
      flex-wrap: wrap;
    }
    .modal-btn {
      background: var(--accent);
      color: white;
      border: none;
      padding: 0.75rem 2rem;
      border-radius: 10px;
      font-size: 1rem;
      font-weight: 700;
      cursor: pointer;
      margin: 0.3rem;
      transition: transform 0.2s;
    }
    .modal-btn:hover { transform: scale(1.05); }
    .modal-btn.secondary {
      background: transparent;
      border: 1px solid var(--text-muted);
      color: var(--text-muted);
    }
    .new-best { color: var(--gold); font-weight: 700; margin-top: 0.5rem; }

    /* Achievement Toast */
    .achievement-toast {
      position: fixed; top: 20px; right: -320px;
      background: linear-gradient(135deg, #b59f3b, #8b7a2e);
      padding: 1rem 1.5rem; border-radius: 12px;
      display: flex; align-items: center; gap: 1rem;
      z-index: 2000; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
      transition: right 0.35s ease; max-width: 300px;
    }
    .achievement-toast.show { right: 20px; }
    .achievement-icon { font-size: 2rem; }
    .achievement-info { color: #fff; }
    .achievement-name { font-weight: 700; font-size: 1rem; }
    .achievement-desc { font-size: 0.8rem; opacity: 0.9; }

    /* Confetti */
    .confetti-container {
      position: fixed; inset: 0;
      pointer-events: none; z-index: 1500; overflow: hidden;
    }
    .confetti {
      position: absolute; width: 10px; height: 10px; top: -10px;
      animation: confettiFall 3s ease-out forwards;
    }
    @keyframes confettiFall {
      0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
      100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
    }

    /* Score Pop */
    .score-pop {
      position: fixed; pointer-events: none; z-index: 1400;
      font-size: 1.2rem; font-weight: 900; color: var(--gold);
      text-shadow: 0 2px 8px rgba(0,0,0,0.6);
      animation: scorePop 1.2s ease-out forwards;
    }
    @keyframes scorePop {
      0%   { transform: translateY(0); opacity: 1; }
      100% { transform: translateY(-60px); opacity: 0; }
    }

    /* Hint glow */
    @keyframes hintPulse {
      0%,100% { box-shadow: 0 0 0 2px rgba(74,222,128,0.3); }
      50% { box-shadow: 0 0 0 4px rgba(74,222,128,0.6); }
    }
    .card.hint-target {
      animation: hintPulse 1.5s ease infinite;
    }

    /* How to Play Modal */
    .help-overlay {
      position: fixed; inset: 0;
      background: rgba(0,0,0,0.88);
      display: flex; align-items: center; justify-content: center;
      z-index: 400; opacity: 0; visibility: hidden;
      transition: opacity 0.3s, visibility 0.3s;
    }
    .help-overlay.show { opacity: 1; visibility: visible; }
    .help-modal {
      background: #16213e;
      border-radius: 16px;
      padding: 1.5rem 1.8rem;
      width: 92%; max-width: 480px;
      max-height: 85vh; overflow-y: auto;
      transform: scale(0.9);
      transition: transform 0.3s;
    }
    .help-overlay.show .help-modal { transform: scale(1); }
    .help-modal h2 { font-size: 1.3rem; margin-bottom: 1rem; text-align: center; }
    .help-section { margin-bottom: 1rem; }
    .help-section h3 {
      font-size: 0.9rem; color: var(--gold);
      margin-bottom: 0.4rem;
      display: flex; align-items: center; gap: 0.4rem;
    }
    .help-section p, .help-section li {
      font-size: 0.82rem; color: var(--text-muted);
      line-height: 1.5;
    }
    .help-section ul {
      list-style: none; padding: 0;
    }
    .help-section li::before {
      content: '• '; color: var(--cyan);
    }
    .help-section li { margin-bottom: 0.25rem; }
    .help-divider {
      border: none; border-top: 1px solid rgba(255,255,255,0.1);
      margin: 0.8rem 0;
    }
    .help-close-btn {
      display: block; margin: 1rem auto 0;
      background: var(--accent); color: white; border: none;
      padding: 0.65rem 2rem; border-radius: 10px;
      font-size: 0.95rem; font-weight: 700; cursor: pointer;
    }
    .help-close-btn:hover { transform: scale(1.05); }

    .daily-badge {
      display: inline-block;
      background: linear-gradient(135deg, #ffd700, #ff8c00);
      color: #000;
      padding: 0.15rem 0.5rem;
      border-radius: 8px;
      font-size: 0.65rem;
      font-weight: 700;
      letter-spacing: 0.03em;
    }

    .btn-daily {
      background: linear-gradient(135deg, #ffd700, #ff8c00) !important;
      color: #000 !important;
    }

    .escalation-warning {
      text-align: center;
      color: #ef4444;
      font-size: 0.75rem;
      font-weight: 600;
      padding: 0.3rem;
      animation: flashWarn 0.5s ease 2;
    }

    @keyframes flashWarn {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.3; }
    }

    /* Reduced motion */
    @media (prefers-reduced-motion: reduce) {
      *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
      }
    }

    /* Responsive */
    @media (max-width: 500px) {
      .game-area { padding: 2px; }
      .top-row, .tableau { gap: 2px; }
      .shop-card { width: 130px; padding: 0.8rem; }
      .shop-cards { gap: 0.5rem; }
    }
    @media (min-width: 700px) {
      .card .rank-suit { font-size: 0.9rem; }
    }
