body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(160deg, #5fb3ff, #cfefff);
    font-family: 'Segoe UI', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

h1 {
    margin: 15px 0;
    font-weight: 800;
    font-size: 2.5em;
    color: #05445e;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

button {
  touch-action: none;
}

canvas {
  touch-action: none;
}

#intro-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    height: 100vh;
    text-align: center;
    bottom: 20;
}

#intro-screen h1 {
    font-size: 2em;
    margin: 10px 0;
}

#intro-image {
    width: 80%;
    max-width: 250px;
    height: auto;
    margin-top: 20px;
}

#new-game-btn {
    cursor: pointer;
    background: linear-gradient(145deg, #48a385, #4fad99);
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 18px;
    box-shadow: 0 4px 0 #317264, 0 6px 10px rgba(0,0,0,0.2);
    transition: transform 0.08s, box-shadow 0.08s;
}

/* Hide the game container and controls until the game starts */
#game-container, #touch-controls, #action-buttons {
    display: none;
}

#game-container {
    margin: 0;
}

#game-board {
    background: linear-gradient(180deg, #48a385, #4fad99);
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
    display: block;
    margin: 0;
    border: 2px solid #317264;
    outline: none;
    touch-action: none;
}

#touch-controls {
    position: fixed;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 8px;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    transition: opacity 0.3s ease;
}

#touch-controls button:focus {
    outline: none;
}

#touch-controls button {
    cursor: pointer;
    background: linear-gradient(145deg, #f0f0f0, #dcdcdc);
    border: 2px solid #aaa;
    box-shadow: 0 5px 0 #999, 0 8px 10px rgba(0,0,0,0.15);
    font-size: 22px;
    border-radius: 14px;
    transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
    opacity: 0.75;
}

#touch-controls button:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 #999, 0 4px 6px rgba(0,0,0,0.15);
    background: linear-gradient(145deg, #ddd, #bbb);
}

#up-btn { grid-column: 2; grid-row: 1; }
#left-btn { grid-column: 1; grid-row: 2; }
#right-btn { grid-column: 3; grid-row: 2; }
#down-btn { grid-column: 2; grid-row: 3; }

#action-buttons {
    position: fixed;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
    transition: transform 0.6s ease-in-out;
    transform-origin: top right;
    user-select: none;   /* Prevents text selection */
    -webkit-user-select: none; /* For Safari */
    -ms-user-select: none; /* For Internet Explorer/Edge */
}

#action-buttons button:focus {
    outline: none;
}

#action-buttons button {
    cursor: pointer;
    background: linear-gradient(145deg, #ffde59, #ffb347);
    border: 2px solid #cc7a00;
    font-weight: bold;
    box-shadow: 0 5px 0 #cc7a00, 0 8px 12px rgba(0,0,0,0.2);
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 16px;
    transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
    opacity: 0.75;
}

#action-buttons button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #cc7a00, 0 4px 6px rgba(0,0,0,0.2);
    background: linear-gradient(145deg, #ffbf47, #ff9933);
}

.smaller-buttons {
  transform: scale(0.7);
  transition: transform 0.6s ease-in-out;
  transform-origin: top right;
}

#score-box {
    position: fixed;
    top: 15px;
    left: 15px;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 8px 14px;
    border-radius: 8px;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: #05445e;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 10;
}

#message-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.97);
    padding: 25px 35px;
    border-radius: 16px;
    display: none;
    z-index: 20;
    font-size: 20px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    color: #05445e;
    font-weight: 600;
}

#message-modal button {
    margin-top: 15px;
    background: linear-gradient(145deg, #48a385, #4fad99);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #317264, 0 6px 10px rgba(0,0,0,0.2);
    transition: transform 0.08s, box-shadow 0.08s;
}

#message-modal button:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #317264, 0 4px 6px rgba(0,0,0,0.2);
}

#qr-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;

    background: white;
    padding: 16px 12px;       /* less padding for mobile */
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);

    display: none;
    width: 90vw;              /* almost full width on small screens */
    max-width: 320px;         /* limit width on larger screens */
    text-align: center;
    user-select: none;
}

#qr-container.visible {
    display: block;
}

#qr-code {
    width: 80%;               /* 80% of container width */
    max-width: 220px;         /* cap on large screens */
    height: auto;             /* maintain aspect ratio */
    margin: 0 auto 12px auto; /* spacing below QR code */
    display: block;
}

#invoice-text {
    font-size: 11px;
    word-break: break-word;
    max-height: 60px;
    overflow-y: auto;
    background: #f5f5f5;
    padding: 6px;
    border-radius: 6px;
    margin-bottom: 12px;       /* space between text and buttons */
    user-select: text;
}

.qr-buttons {
    display: flex;
    justify-content: space-between;
    gap: 8px;                  /* space between buttons */
}

.qr-buttons button {
    flex: 1;
    padding: 6px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(145deg, #48a385, #4fad99);
    color: white;
    border: none;
    box-shadow: 0 3px 0 #317264, 0 4px 6px rgba(0,0,0,0.15);
    transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}

.qr-buttons button:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #317264, 0 3px 4px rgba(0,0,0,0.15);
    background: linear-gradient(145deg, #317264, #48a385);
}

@media (max-height: 500px) {
    #qr-container {
        top: 40%;
        max-height: 90vh;
        overflow-y: auto;
        padding: 12px 10px;
    }
}

@media (max-width: 400px) {
    #intro-screen h1 {
        font-size: 1.6em;
    }
    #intro-image {
        max-width: 180px;
    }
}

@media (pointer: fine) {
  #touch-controls {
    display: none !important;
  }
}
