* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}


  body {
    margin: 0;
    height: 100vh;
    font-family:
      -apple-system,
      BlinkMacSystemFont,
      "Hiragino Sans",
      "Yu Gothic",
      "Meiryo",
      sans-serif;
    background: #f2f2f2;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .container {
    max-width: 1196px;
    width: 100%;
    height: 540px;
    background: linear-gradient(160deg, #fff9f0 0%, #f0f9ff 100%);
    border: 2px solid #333;
    box-shadow: 0 8px 40px rgba(80,120,200,0.18), 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
  }

  /* ===== HEADER ===== */
  .game-header {
    background: linear-gradient(90deg, #ff7043 0%, #ffb74d 40%, #ffd54f 70%, #81c784 100%);
    padding: 0 24px;
    height: 50px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
  }

  #header-title {
    grid-column: 2;
    justify-self: center;
    font-size: 22px;
    font-weight: 900;
    color: #fff;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.18);
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  #header-title span.star { font-size: 20px; }

  #sound-btn {
    grid-column: 3;
    justify-self: end;
    position: relative;
    background: rgba(255,255,255,0.35);
    border: 3px solid rgba(255,255,255,0.7);
    border-radius: 50px;
    padding: 6px 18px;
    font-size: 18px;
    cursor: pointer;
    color: #fff;
    font-weight: 900;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 6px;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.15);
  }

  #sound-btn.sound-off::after {
    content: '×';
    position: absolute;
    left: 16px;
    top: 3px;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #ff5252;
    border: 2px solid #fff;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    text-shadow: none;
    box-shadow: 0 2px 0 rgba(183,28,28,0.35);
    pointer-events: none;
  }

  #sound-btn:hover { background: rgba(255,255,255,0.5); transform: scale(1.05); }
  #sound-btn:active { transform: scale(0.97); }

  /* ===== SCREENS ===== */
  .screen { display: none; flex: 1; overflow: hidden; }
  .screen.active { display: flex; }

  /* ===== START SCREEN ===== */
  #start-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
  }

  .start-hero {
    font-size: 52px;
    line-height: 1;
    filter: drop-shadow(2px 4px 0 rgba(0,0,0,0.12));
    animation: bounce-hero 2s ease-in-out infinite;
  }

  @keyframes bounce-hero {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
  }

  .start-title {
    font-size: 30px;
    font-weight: 900;
    color: #e65100;
    text-shadow: 2px 2px 0 rgba(255,200,0,0.5);
    text-align: center;
    line-height: 1.3;
  }

  .start-sub {
    font-size: 22px;
    color: #5d6b7a;
    text-align: center;
    line-height: 1.6;
    max-width: 460px;
  }

  .level-select {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .level-btn {
    border: none;
    border-radius: 20px;
    padding: 14px 28px;
    font-size: 24px;
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 5px 0 rgba(0,0,0,0.18);
    color: #fff;
    font-family: inherit;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 130px;
  }

  .level-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 0 rgba(0,0,0,0.18); }
  .level-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(0,0,0,0.18); }

  .level-btn small { font-size: 17px; font-weight: 700; opacity: 0.9; }

  .btn-easy { background: linear-gradient(160deg, #66bb6a, #43a047); }
  .btn-normal { background: linear-gradient(160deg, #42a5f5, #1976d2); }
  .btn-hard { background: linear-gradient(160deg, #ef5350, #c62828); }

  /* ===== GAME SCREEN ===== */
  #game-screen {
    flex-direction: column;
    padding: 10px 16px 12px;
    gap: 8px;
  }

  #game-hud {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
  }

  #quit-btn {
    order: 3;
    margin-left: auto;
    background: linear-gradient(160deg, #ff7043, #e64a19);
    border: none;
    border-radius: 50px;
    padding: 7px 18px;
    font-size: 14px;
    font-weight: 900;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
    box-shadow: 0 4px 0 #bf360c;
    transition: transform 0.12s, box-shadow 0.12s;
  }

  #quit-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #bf360c; }
  #quit-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #bf360c; }

  .hud-stat {
    background: rgba(255,255,255,0.7);
    border-radius: 50px;
    padding: 5px 16px;
    font-size: 14px;
    font-weight: 900;
    color: #4a5568;
    border: 2px solid rgba(200,200,220,0.4);
  }

  .hud-stat span { color: #e65100; font-size: 18px; }

  #level-label {
    order: -1;
    background: linear-gradient(90deg, #ffd54f, #ffb74d);
    border-radius: 50px;
    padding: 5px 16px;
    font-size: 13px;
    font-weight: 900;
    color: #5d4037;
    border: 2px solid #ffa726;
  }

  /* ===== CARD GRID ===== */
  #card-grid {
    flex: 1;
    display: grid;
    gap: 8px;
    align-content: center;
    justify-content: center;
    overflow: hidden;
  }

  /* Card */
  .card {
    perspective: 600px;
    cursor: pointer;
  }

  .card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.45s cubic-bezier(0.4,0,0.2,1);
  }

  .card.flipped .card-inner { transform: rotateY(180deg); }
  .card.matched .card-inner { transform: rotateY(180deg); }

  .card-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    font-weight: 900;
  }

  .card-back {
    transform: rotateY(0deg);
    z-index: 2;
    background:
      radial-gradient(circle at 16% 18%, #ffb3c7 0 9%, transparent 10%),
      radial-gradient(circle at 84% 18%, #ffd76d 0 9%, transparent 10%),
      radial-gradient(circle at 16% 82%, #8fe6d1 0 9%, transparent 10%),
      radial-gradient(circle at 84% 82%, #9fd5ff 0 9%, transparent 10%),
      linear-gradient(135deg, #fff2b8 0%, #bff1ff 100%);
    border: 3px solid #ffffff;
    box-shadow: 0 4px 12px rgba(33,150,183,0.2), inset 0 2px 0 rgba(255,255,255,0.65);
    overflow: hidden;
  }

  .card-back::before {
    content: '';
    pointer-events: none;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    position: absolute;
    inset: 8px;
    border: 3px solid rgba(255,255,255,0.88);
    border-radius: 9px;
    box-shadow: inset 0 0 0 2px rgba(255,183,77,0.28);
  }

  .card-back::after {
    content: '♥   ♦\A\A♣   ♠';
    pointer-events: none;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    z-index: 0;
    position: absolute;
    inset: 15px;
    white-space: pre;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,122,122,0.58);
    font-size: 14px;
    line-height: 1.45;
    letter-spacing: 8px;
    text-align: center;
  }

  .card-back-icon {
    color: #ff7f7f;
    font-size: 28px;
    text-shadow: 0 2px 0 rgba(255,255,255,0.95);
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.12));
    z-index: 1;
  }

  .card.flipped .card-back,
  .card.matched .card-back {
    z-index: 1;
  }

  .card.flipped .card-front,
  .card.matched .card-front {
    z-index: 2;
  }

  .card-front {
    background: #fff;
    border: 3px solid #e0e7ef;
    box-shadow: 0 4px 14px rgba(0,0,0,0.1);
    transform: rotateY(180deg);
    z-index: 1;
    flex-direction: column;
    padding: 6px;
    text-align: center;
  }

  .card-front .card-emoji { font-size: 30px; line-height: 1; }
  .card-front .card-word {
    font-size: 16px;
    color: #1a237e;
    letter-spacing: 0.5px;
    font-weight: 900;
    line-height: 1;
  }
  .card-front .card-mean {
    font-size: 13px;
    color: #d32f2f;
    font-weight: 900;
    line-height: 1.2;
    letter-spacing: 0.5px;
  }

  .card.matched .card-front {
    background: linear-gradient(135deg, #fff9c4, #f1f8e9);
    border-color: #a5d6a7;
    animation: match-pop 0.5s ease;
  }

  @keyframes match-pop {
    0% { transform: rotateY(180deg) scale(1); }
    40% { transform: rotateY(180deg) scale(1.12); box-shadow: 0 0 0 6px rgba(129,199,132,0.5); }
    100% { transform: rotateY(180deg) scale(1); }
  }

  .card:not(.flipped):not(.matched):hover .card-inner {
    transform: translateY(-3px);
  }

  .card:not(.flipped):not(.matched) .card-back {
    box-shadow: 0 4px 12px rgba(0,150,136,0.24), inset 0 2px 0 rgba(255,255,255,0.55);
  }

  .card:not(.flipped):not(.matched):hover .card-back {
    box-shadow: 0 8px 20px rgba(255,112,67,0.34), inset 0 2px 0 rgba(255,255,255,0.65);
  }

  /* ===== CLEAR SCREEN ===== */
  #clear-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 24px;
  }

  .clear-confetti {
    font-size: 48px;
    animation: spin-bounce 1.5s ease-in-out infinite;
  }

  @keyframes spin-bounce {
    0% { transform: rotate(-10deg) scale(1); }
    25% { transform: rotate(10deg) scale(1.1); }
    50% { transform: rotate(-5deg) scale(1); }
    75% { transform: rotate(8deg) scale(1.08); }
    100% { transform: rotate(-10deg) scale(1); }
  }

  .clear-title {
    font-size: 34px;
    font-weight: 900;
    color: #e65100;
    text-shadow: 2px 2px 0 rgba(255,200,0,0.6);
    text-align: center;
  }

  .clear-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .clear-stat-box {
    background: rgba(255,255,255,0.8);
    border-radius: 16px;
    padding: 12px 22px;
    font-size: 16px;
    font-weight: 900;
    color: #4a5568;
    border: 3px solid #e0e7ef;
    text-align: center;
  }

  .clear-stat-box span {
    display: block;
    font-size: 28px;
    color: #ff7043;
  }

  .clear-stars {
    font-size: 38px;
    letter-spacing: 8px;
    animation: star-glow 1.2s ease-in-out infinite alternate;
  }

  @keyframes star-glow {
    from { filter: drop-shadow(0 0 4px gold); }
    to { filter: drop-shadow(0 0 12px orange); }
  }

  .clear-btns { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

  .clear-btn {
    border: none;
    border-radius: 50px;
    padding: 13px 30px;
    font-size: 16px;
    font-weight: 900;
    cursor: pointer;
    font-family: inherit;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.15);
    transition: transform 0.12s, box-shadow 0.12s;
    color: #fff;
  }

  .clear-btn:hover { transform: translateY(-2px); }
  .clear-btn:active { transform: translateY(1px); }

  .btn-retry {
    background: linear-gradient(160deg, #42a5f5, #1976d2);
    box-shadow: 0 5px 0 #0d47a1;
  }
  .btn-retry:hover { box-shadow: 0 7px 0 #0d47a1; }

  .btn-home {
    background: linear-gradient(160deg, #66bb6a, #388e3c);
    box-shadow: 0 5px 0 #1b5e20;
  }
  .btn-home:hover { box-shadow: 0 7px 0 #1b5e20; }

  /* Floating bubbles background decoration */
  .bubble {
    position: absolute;
    border-radius: 50%;
    opacity: 0.08;
    pointer-events: none;
    animation: float-bubble linear infinite;
  }

  @keyframes float-bubble {
    0% { transform: translateY(0) scale(1); opacity: 0.06; }
    50% { opacity: 0.1; }
    100% { transform: translateY(-600px) scale(1.3); opacity: 0; }
  }
.game-main { position:relative; flex:1; overflow:hidden; display:flex; }
.game-main .screen { width:100%; }


