
    :root {
      --cell-size: 100px;
      --cell-font: 2.5rem;
      --gap: 8px;
      --title-size: 4rem;
      --subtitle-size: 1.2rem;
      --status-size: 1.2rem;
    }
    @media (min-width: 900px) {
      :root {
        --cell-size: 140px;
        --cell-font: 3.6rem;
        --gap: 12px;
        --title-size: 5.5rem;
        --subtitle-size: 1.6rem;
        --status-size: 1.6rem;
      }
    }
    @media (min-width: 1400px) {
      :root {
        --cell-size: 180px;
        --cell-font: 4.6rem;
        --gap: 16px;
        --title-size: 7rem;
        --subtitle-size: 2rem;
        --status-size: 2rem;
      }
    }
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      margin: 0;
      background: #f0f4f8;
      user-select: none;
      -webkit-user-select: none;
      -webkit-tap-highlight-color: transparent;
      -webkit-touch-callout: none;
    }
    h1 {
      color: #1e293b;
    }
    #status {
      font-size: var(--status-size);
      margin-bottom: 16px;
      color: #475569;
      min-height: 1.5em;
    }
    #board {
      display: grid;
      grid-template-columns: repeat(3, var(--cell-size));
      grid-template-rows: repeat(3, var(--cell-size));
      gap: var(--gap);
    }
    .cell {
      width: var(--cell-size);
      height: var(--cell-size);
      font-size: var(--cell-font);
      font-weight: bold;
      border: none;
      border-radius: 8px;
      background: #ffffff;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
      cursor: pointer;
      color: #1e293b;
      transition: background 0.15s, transform 0.1s;
    }
    .cell.placed {
      animation: cell-pop 0.25s ease;
    }
    @keyframes cell-pop {
      from { transform: scale(0.4); opacity: 0; }
      to { transform: scale(1); opacity: 1; }
    }
    .cell:hover:not(:disabled) {
      background: #e2e8f0;
    }
    .cell:active:not(:disabled) {
      transform: scale(0.95);
    }
    .cell.preview:hover::after {
      content: var(--preview, '');
      opacity: 0.25;
    }
    .cell.win {
      background: #dcfce7;
      box-shadow: 0 0 0 3px #22c55e, 0 2px 6px rgba(0, 0, 0, 0.1);
      color: #16a34a;
      animation: win-pop 0.5s ease-in-out infinite alternate;
    }
    .cell.win.x {
      color: var(--color-x, #2563eb);
    }
    .cell.win.o {
      color: var(--color-o, #dc2626);
    }
    @keyframes win-pop {
      from { transform: scale(1); }
      to { transform: scale(1.12); }
    }
    .cell.dim {
      opacity: 0.3;
    }
    .cell.x {
      color: var(--color-x, #2563eb);
    }
    .cell.o {
      color: var(--color-o, #dc2626);
    }
    .cell:disabled {
      cursor: default;
    }
    #reset {
      margin-top: 20px;
      padding: 10px 24px;
      font-size: 1rem;
      border: none;
      border-radius: 8px;
      background: #1e293b;
      color: #ffffff;
      cursor: pointer;
    }
    #reset:hover {
      background: #334155;
    }
    #game {
      opacity: 0;
      transform: translateY(20px);
      transition: opacity 0.4s ease, transform 0.4s ease;
      pointer-events: none;
    }
    #game.show {
      opacity: 1;
      transform: translateY(0);
      pointer-events: auto;
    }
    #title-screen {
      position: fixed;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: linear-gradient(135deg, #1e293b, #0f172a);
      z-index: 10;
      opacity: 1;
      transition: opacity 0.4s ease;
    }
    #title-screen.hide {
      opacity: 0;
      pointer-events: none;
    }
    #title-screen h1 {
      font-size: var(--title-size);
      color: #ffffff;
      margin: 0 0 8px;
    }
    #title-screen p {
      color: #94a3b8;
      margin: 0 0 40px;
      font-size: var(--subtitle-size);
    }
    #start {
      padding: 14px 40px;
      font-size: 1.2rem;
      border: none;
      border-radius: 8px;
      background: #2563eb;
      color: #ffffff;
      cursor: pointer;
      transition: background 0.15s;
    }
    #start:hover {
      background: #1d4ed8;
    }
    @media (min-width: 900px) {
      #start, #leaderboard-btn, #options-btn, #about-btn {
        font-size: 1.6rem;
        padding: 16px 48px;
      }
      #reset {
        font-size: 1.4rem;
        padding: 14px 32px;
      }
    }
    #leaderboard-btn, #options-btn, #about-btn {
      margin-top: 16px;
      padding: 10px 24px;
      font-size: 1rem;
      border: 2px solid #475569;
      border-radius: 8px;
      background: transparent;
      color: #cbd5e1;
      cursor: pointer;
      transition: background 0.15s, color 0.15s;
    }
    #leaderboard-btn:hover, #options-btn:hover, #about-btn:hover {
      background: #475569;
      color: #ffffff;
    }
    #leaderboard {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(15, 23, 42, 0.8);
      z-index: 30;
    }
    #leaderboard.show {
      display: flex;
    }
    .leaderboard-box {
      background: #ffffff;
      padding: 32px 40px 36px;
      border-radius: 20px;
      text-align: center;
      width: min(780px, 90vw);
      max-height: 90vh;
      overflow-y: auto;
    }
    .leaderboard-box h2 {
      margin: 0 0 28px;
      color: #1e293b;
      font-size: 2rem;
    }
    .stats {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 20px;
      margin-bottom: 32px;
    }
    .stat-card {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      padding: 32px 12px;
      border-radius: 16px;
      background: #f8fafc;
    }
    .stat-icon {
      font-size: 2.2rem;
      line-height: 1;
    }
    .stat-value {
      font-size: 4rem;
      font-weight: 700;
      line-height: 1;
      color: #1e293b;
    }
    .stat-label {
      font-size: 0.95rem;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: #64748b;
    }
    @media (max-width: 600px) {
      .leaderboard-box {
        padding: 24px 18px 28px;
      }
      .stats {
        grid-template-columns: 1fr;
        gap: 14px;
      }
      .stat-card {
        flex-direction: row;
        justify-content: space-between;
        padding: 18px 24px;
      }
      .stat-value {
        font-size: 2.6rem;
      }
      .stat-icon {
        font-size: 1.8rem;
      }
      .stat-label {
        font-size: 0.85rem;
      }
    }
    .stat-card.x {
      background: linear-gradient(135deg, #eff6ff, #dbeafe);
      border-top: 4px solid var(--color-x, #2563eb);
    }
    .stat-card.x .stat-icon {
      color: var(--color-x, #2563eb);
    }
    .stat-card.o {
      background: linear-gradient(135deg, #fef2f2, #fee2e2);
      border-top: 4px solid var(--color-o, #dc2626);
    }
    .stat-card.o .stat-icon {
      color: var(--color-o, #dc2626);
    }
    .stat-card.draw {
      background: linear-gradient(135deg, #f8fafc, #e2e8f0);
      border-top: 4px solid #94a3b8;
    }
    .stat-card.draw .stat-icon {
      color: #64748b;
    }
    #leaderboard-close {
      padding: 10px 24px;
      font-size: 1rem;
      border: none;
      border-radius: 8px;
      background: #1e293b;
      color: #ffffff;
      cursor: pointer;
    }
    #leaderboard-close:hover {
      background: #334155;
    }
    #about {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(15, 23, 42, 0.8);
      z-index: 30;
    }
    #about.show {
      display: flex;
    }
    .about-box {
      background: #ffffff;
      padding: 32px 48px;
      border-radius: 16px;
      text-align: left;
      max-width: 460px;
      max-height: 80vh;
      overflow-y: auto;
    }
    .about-box h2 {
      margin: 0 0 8px;
      color: #1e293b;
      text-align: center;
    }
    .about-box .version {
      text-align: center;
      color: #2563eb;
      margin: 0 0 16px;
      font-size: 1.1rem;
    }
    .about-box ul {
      margin: 0 0 24px;
      padding-left: 20px;
      color: #334155;
      line-height: 1.7;
    }
    #about-close {
      display: block;
      margin: 0 auto;
      padding: 10px 24px;
      font-size: 1rem;
      border: none;
      border-radius: 8px;
      background: #1e293b;
      color: #ffffff;
      cursor: pointer;
    }
    #about-close:hover {
      background: #334155;
    }
    #options {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(15, 23, 42, 0.8);
      z-index: 30;
    }
    #options.show {
      display: flex;
    }
    .options-box {
      background: #ffffff;
      padding: 28px 32px;
      border-radius: 16px;
      width: 460px;
      max-width: 92vw;
      max-height: 85vh;
      overflow-y: auto;
    }
    .options-box h2 {
      margin: 0 0 20px;
      color: #1e293b;
      text-align: center;
    }
    .option-group {
      margin-bottom: 22px;
    }
    .option-group > label {
      display: block;
      font-weight: 600;
      color: #334155;
      margin-bottom: 10px;
    }
    .theme-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
    }
    .theme-option {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
      padding: 10px 6px;
      border: 2px solid #e2e8f0;
      border-radius: 10px;
      background: #f8fafc;
      cursor: pointer;
      transition: border-color 0.15s, background 0.15s;
    }
    .theme-option:hover {
      border-color: #94a3b8;
    }
    .theme-option.active {
      border-color: #2563eb;
      background: #eff6ff;
    }
    .theme-preview {
      display: flex;
      gap: 10px;
      font-size: 1.6rem;
      line-height: 1;
    }
    .tp-x {
      color: var(--color-x, #2563eb);
    }
    .tp-o {
      color: var(--color-o, #dc2626);
    }
    .theme-label {
      font-size: 0.85rem;
      color: #475569;
      text-align: center;
    }
    .color-row {
      display: flex;
      gap: 24px;
    }
    .color-picker {
      display: flex;
      align-items: center;
      gap: 8px;
      cursor: pointer;
    }
    .color-label {
      font-weight: 600;
      color: #334155;
    }
    .color-picker input[type="color"] {
      width: 48px;
      height: 36px;
      border: none;
      border-radius: 8px;
      background: transparent;
      cursor: pointer;
      padding: 0;
    }
    .toggle {
      position: relative;
      display: inline-block;
      width: 52px;
      height: 28px;
      cursor: pointer;
    }
    .toggle input {
      opacity: 0;
      width: 0;
      height: 0;
    }
    .toggle-slider {
      position: absolute;
      inset: 0;
      background: #cbd5e1;
      border-radius: 28px;
      transition: background 0.2s;
    }
    .toggle-slider::before {
      content: "";
      position: absolute;
      width: 22px;
      height: 22px;
      left: 3px;
      top: 3px;
      background: #ffffff;
      border-radius: 50%;
      transition: transform 0.2s;
    }
    .toggle input:checked + .toggle-slider {
      background: #2563eb;
    }
    .toggle input:checked + .toggle-slider::before {
      transform: translateX(24px);
    }
    #reset-stats {
      padding: 8px 18px;
      font-size: 0.95rem;
      border: none;
      border-radius: 8px;
      background: #fee2e2;
      color: #b91c1c;
      cursor: pointer;
    }
    #reset-stats:hover {
      background: #fecaca;
    }
    #options-close {
      display: block;
      margin: 8px auto 0;
      padding: 10px 24px;
      font-size: 1rem;
      border: none;
      border-radius: 8px;
      background: #1e293b;
      color: #ffffff;
      cursor: pointer;
    }
    #options-close:hover {
      background: #334155;
    }
    #game-over {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(15, 23, 42, 0.7);
      z-index: 20;
    }
    #game-over.show {
      display: flex;
    }
    .game-over-box {
      background: #ffffff;
      padding: 40px 60px;
      border-radius: 16px;
      text-align: center;
      box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
      transform: scale(0.5);
      opacity: 0;
      animation: pop-in 0.4s ease-out forwards;
    }
    .game-over-box h2 {
      margin: 0 0 8px;
      font-size: 2.2rem;
    }
    .game-over-box h2.x {
      color: #2563eb;
    }
    .game-over-box h2.o {
      color: #dc2626;
    }
    .game-over-box p {
      margin: 0;
      color: #64748b;
      font-size: 1.1rem;
    }
    .game-over-actions {
      display: flex;
      gap: 12px;
      justify-content: center;
      margin-top: 24px;
    }
    .game-over-actions button {
      padding: 10px 24px;
      font-size: 1rem;
      border: none;
      border-radius: 8px;
      cursor: pointer;
    }
    #play-again {
      background: #2563eb;
      color: #ffffff;
    }
    #play-again:hover {
      background: #1d4ed8;
    }
    #to-menu {
      background: #e2e8f0;
      color: #1e293b;
    }
    #to-menu:hover {
      background: #cbd5e1;
    }
    @keyframes pop-in {
      from { transform: scale(0.5); opacity: 0; }
      to { transform: scale(1); opacity: 1; }
    }
    .confetti {
      position: fixed;
      top: -20px;
      width: 10px;
      height: 16px;
      border-radius: 2px;
      opacity: 0.9;
      pointer-events: none;
      z-index: 25;
      animation: confetti-fall linear forwards;
    }
    @keyframes confetti-fall {
      to {
        transform: translateY(115vh) rotate(720deg);
      }
    }
  