* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

body {
    background: linear-gradient(180deg, #b3e5ff 0%, #ffd6f5 100%);
    font-family: 'Comic Sans MS', 'Segoe UI', sans-serif;
    color: #4a1d6e;
    user-select: none;
    -webkit-user-select: none;
}

.game-wrap {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: linear-gradient(180deg, #b3e5ff 0%, #ffd6f5 100%);
}

#game {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #b3e5ff 0%, #ffd6f5 100%);
    touch-action: none;
}

.hud {
    position: absolute;
    top: max(16px, env(safe-area-inset-top, 16px));
    left: 20px;
    font-size: clamp(28px, 8vw, 40px);
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 0 #4a1d6e, -1px -1px 0 #4a1d6e, 1px -1px 0 #4a1d6e, -1px 1px 0 #4a1d6e;
    pointer-events: none;
    z-index: 5;
}

.pause-btn {
    position: absolute;
    top: max(14px, env(safe-area-inset-top, 14px));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.85);
    background: linear-gradient(135deg, #ff7eb9 0%, #c977ff 60%, #8b5cf6 100%);
    color: #fff;
    font-size: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 6;
    box-shadow: 0 4px 0 rgba(74, 29, 110, 0.6),
                0 8px 16px rgba(74, 29, 110, 0.35),
                inset 0 2px 4px rgba(255, 255, 255, 0.5),
                inset 0 -3px 6px rgba(0, 0, 0, 0.18);
    padding: 0;
    margin: 0;
    font-family: inherit;
    transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
    overflow: hidden;
}

.pause-btn::before,
.pause-btn::after {
    content: '';
    width: 6px;
    height: 22px;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(74, 29, 110, 0.5);
    margin: 0 3px;
}

.pause-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 0 rgba(74, 29, 110, 0.6),
                0 10px 18px rgba(74, 29, 110, 0.4),
                inset 0 2px 4px rgba(255, 255, 255, 0.5),
                inset 0 -3px 6px rgba(0, 0, 0, 0.18);
}

.pause-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(74, 29, 110, 0.6),
                0 3px 6px rgba(74, 29, 110, 0.3),
                inset 0 2px 4px rgba(255, 255, 255, 0.5),
                inset 0 -3px 6px rgba(0, 0, 0, 0.18);
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(74, 29, 110, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-align: center;
    padding: max(24px, env(safe-area-inset-top, 24px)) 20px max(24px, env(safe-area-inset-bottom, 24px));
    overflow-y: auto;
    z-index: 10;
}

.overlay h1 {
    font-size: clamp(36px, 10vw, 56px);
    margin-bottom: 12px;
    text-shadow: 3px 3px 0 #ff5fb0;
    line-height: 1.05;
}

.overlay .tagline {
    font-size: clamp(16px, 4.5vw, 22px);
    margin-bottom: 8px;
    opacity: 0.9;
}

.overlay .hint {
    font-size: clamp(13px, 3.8vw, 16px);
    margin-bottom: 14px;
    opacity: 0.85;
}

.overlay .highscore {
    font-size: clamp(15px, 4vw, 20px);
    margin-bottom: 8px;
}

.overlay .score-line {
    font-size: clamp(20px, 6vw, 28px);
    margin-bottom: 8px;
    color: #ffe770;
}

kbd {
    background: #fff;
    color: #4a1d6e;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
}

button {
    margin-top: 14px;
    padding: 14px 32px;
    font-size: clamp(16px, 5vw, 20px);
    font-weight: bold;
    border: none;
    border-radius: 32px;
    background: linear-gradient(135deg, #ff7eb9 0%, #ff5fb0 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 0 #c43d8a, 0 8px 16px rgba(0, 0, 0, 0.2);
    font-family: inherit;
    min-width: 160px;
    min-height: 48px;
    transition: transform 0.05s, box-shadow 0.05s;
}

button:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #c43d8a, 0 2px 4px rgba(0, 0, 0, 0.2);
}

.legend {
    margin-top: 18px;
    display: flex;
    gap: 18px;
    font-size: clamp(12px, 3.5vw, 16px);
    flex-wrap: wrap;
    justify-content: center;
}

.legend > div {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dia {
    display: inline-block;
    width: 12px;
    height: 12px;
    transform: rotate(45deg);
    box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2);
}

.dia.blue { background: #4fc3ff; }
.dia.pink { background: #ff7eb9; }
.dia.gold { background: #ffd24a; }

.hidden {
    display: none !important;
}

.scoreboard {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    padding: 10px 14px;
    margin: 6px 0 8px;
    width: min(360px, 90vw);
    max-height: 38vh;
    overflow-y: auto;
}

.scoreboard h2 {
    font-size: clamp(14px, 4vw, 18px);
    margin-bottom: 6px;
    text-shadow: 1px 1px 0 #4a1d6e;
}

.scoreboard ol {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: rank;
}

.scoreboard li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: clamp(13px, 3.6vw, 15px);
    padding: 3px 4px;
    counter-increment: rank;
}

.scoreboard li::before {
    content: counter(rank) ".";
    width: 22px;
    color: #ffd24a;
    font-weight: bold;
    text-align: right;
}

.scoreboard li .name {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scoreboard li .pts {
    font-weight: bold;
    color: #ffd24a;
}

.scoreboard li.empty {
    justify-content: center;
    opacity: 0.6;
    font-style: italic;
}

.scoreboard li.empty::before {
    content: '';
    width: 0;
}

#namePrompt h1 {
    color: #ffe770;
    text-shadow: 3px 3px 0 #ff5fb0;
}

#nameInput {
    margin-top: 14px;
    padding: 12px 18px;
    font-size: clamp(16px, 5vw, 20px);
    border: 3px solid #ff7eb9;
    border-radius: 12px;
    background: #fff;
    color: #4a1d6e;
    font-family: inherit;
    text-align: center;
    width: min(280px, 80vw);
    outline: none;
}

#nameInput:focus {
    border-color: #ffd24a;
    box-shadow: 0 0 0 4px rgba(255, 210, 74, 0.3);
}

.link-btn {
    margin-top: 8px;
    padding: 8px 18px;
    font-size: clamp(12px, 3.5vw, 14px);
    background: transparent;
    color: #fff;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 18px;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 0;
    min-height: 40px;
}

.link-btn:hover,
.link-btn:active {
    background: rgba(255, 255, 255, 0.15);
    transform: none;
    box-shadow: none;
}

.about-line {
    font-size: clamp(16px, 5vw, 22px);
    margin: 8px 0;
}

.about-line strong {
    color: #ffd24a;
}

.link-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.setting-group {
    margin: 14px 0;
    width: min(360px, 90vw);
}

.setting-label {
    font-size: clamp(14px, 4vw, 18px);
    margin-bottom: 8px;
    opacity: 0.9;
}

.setting-note {
    font-size: clamp(11px, 3vw, 13px);
    opacity: 0.7;
    margin-top: 6px;
    font-style: italic;
}

.diff-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.diff-btn,
.toggle-btn {
    margin: 0;
    padding: 10px 18px;
    font-size: clamp(14px, 4vw, 16px);
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    box-shadow: none;
    min-width: 80px;
    min-height: 42px;
    font-family: inherit;
    transition: all 0.12s;
}

.diff-btn.active {
    background: linear-gradient(135deg, #ff7eb9 0%, #ff5fb0 100%);
    border-color: #fff;
    box-shadow: 0 3px 0 #c43d8a, 0 6px 12px rgba(0, 0, 0, 0.2);
}

.diff-btn:hover,
.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: none;
    box-shadow: none;
}

.diff-btn.active:hover {
    background: linear-gradient(135deg, #ff7eb9 0%, #ff5fb0 100%);
}

.diff-btn:active,
.toggle-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

.toggle-btn[data-on="true"] {
    background: linear-gradient(135deg, #66cc88 0%, #4caf6e 100%);
    border-color: #fff;
    box-shadow: 0 3px 0 #2e7c4f, 0 6px 12px rgba(0, 0, 0, 0.2);
}

.toggle-btn[data-on="false"] {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.45);
}

.unicorn-fact {
    font-size: clamp(13px, 3.6vw, 16px);
    margin: 10px 0 14px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.14);
    border-left: 3px solid #ffd24a;
    border-radius: 8px;
    width: min(360px, 90vw);
    font-style: italic;
    color: #ffe770;
}

#gameover .scoreboard {
    margin: 8px 0 12px;
}

#gameover .scoreboard h2 {
    font-size: clamp(13px, 3.8vw, 16px);
}

#gameover .scoreboard li {
    font-size: clamp(12px, 3.4vw, 14px);
    padding: 2px 4px;
}

@media (min-width: 600px) and (orientation: landscape) {
    .game-wrap {
        position: relative;
        width: min(500px, 100vw);
        height: min(900px, 100vh);
        margin: 0 auto;
        border-radius: 18px;
        box-shadow: 0 20px 60px rgba(74, 29, 110, 0.35);
    }

    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #ffd1f5 0%, #c5b3ff 50%, #a0e7ff 100%);
    }
}
