@font-face {
    font-family: "Yusei Magic";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/yusei-magic.ttf") format("truetype");
}

@font-face {
    font-family: "M PLUS Rounded 1c";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/rounded-regular.ttf") format("truetype");
}

@font-face {
    font-family: "M PLUS Rounded 1c";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("fonts/rounded-bold.ttf") format("truetype");
}

:root {
    --bg: #fff7ec;
    --bg-alt: #ffe6c7;
    --text: #1f2a38;
    --accent: #0e9f6e;
    --accent-strong: #0a7f58;
    --warning: #ef4444;
    --card: rgba(255, 255, 255, 0.72);
    --line: rgba(31, 42, 56, 0.16);
    --shadow: 0 14px 35px rgba(15, 23, 42, 0.18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100svh;
    padding-bottom: env(safe-area-inset-bottom);
    color: var(--text);
    font-family: "M PLUS Rounded 1c", sans-serif;
    background: radial-gradient(circle at 12% 8%, #fff3df 0%, var(--bg) 45%, var(--bg-alt) 100%);
    overflow-x: hidden;
}

.bg-shape {
    position: fixed;
    z-index: -1;
    border-radius: 50%;
    filter: blur(6px);
}

.bg-shape-a {
    width: 420px;
    height: 420px;
    top: -140px;
    right: -90px;
    background: rgba(14, 159, 110, 0.2);
}

.bg-shape-b {
    width: 320px;
    height: 320px;
    bottom: -120px;
    left: -80px;
    background: rgba(247, 181, 56, 0.25);
}

.hud {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 16px;
    align-items: center;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(8px);
}

.hud-title {
    font-family: "Yusei Magic", sans-serif;
    font-size: 1.3rem;
}

.hud-meta,
.hud-scores {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-weight: 700;
    overflow-wrap: anywhere;
    min-width: 0;
}

.screen-wrap {
    width: min(1100px, 92vw);
    margin: 22px auto 32px;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.screen {
    display: none;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card);
    box-shadow: var(--shadow);
    animation: reveal 260ms ease;
}

.screen.active {
    display: block;
}

h1,
h2,
h3 {
    margin-top: 0;
    font-family: "Yusei Magic", sans-serif;
    overflow-wrap: anywhere;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
    gap: 16px;
    margin: 18px 0;
}

.card {
    padding: 18px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--line);
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    max-width: 960px;
    margin-inline: auto;
    border-radius: 12px;
    border: 0;
    box-shadow: 0 0 0 2px rgba(31, 42, 56, 0.3);
    background: #fff;
    touch-action: manipulation;
}

.message {
    font-weight: 700;
    margin: 12px 0;
    overflow-wrap: anywhere;
}

.btn {
    border: 0;
    border-radius: 999px;
    padding: 10px 18px;
    min-height: 48px;
    max-width: 100%;
    font-size: 1rem;
    touch-action: manipulation;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: transform 140ms ease, filter 140ms ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
}

.btn-ghost {
    color: var(--text);
    background: transparent;
    border: 1px solid var(--line);
}

.actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 700;
}

input,
select {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
    font-size: 16px;
    min-height: 48px;
    min-width: 0;
    width: 100%;
    background: #fff;
}

.player-inputs {
    display: grid;
    gap: 8px;
    margin: 14px 0;
}

.result-list {
    list-style: none;
    padding: 0;
    margin: 12px 0;
    display: grid;
    gap: 8px;
}

.result-list li {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    font-weight: 700;
    overflow-wrap: anywhere;
}

[hidden] {
    display: none !important;
}

.offline-status {
    min-height: 1.5em;
    margin: 14px 0 0;
    font-size: 0.8rem;
    color: #486052;
}

:focus-visible {
    outline: 3px solid var(--accent-strong);
    outline-offset: 4px;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 700px) {
    .hud {
        grid-template-columns: 1fr;
    }

    .screen {
        padding: 16px;
    }

    .screen-wrap {
        width: 96%;
        margin-top: 12px;
    }

    .hud {
        gap: 4px;
    }

    .hud-meta,
    .hud-scores {
        font-size: 0.85rem;
        gap: 8px;
    }

    .actions > .btn {
        flex: 1 1 auto;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    .hud {
        position: relative;
        grid-template-columns: auto 1fr;
        padding-block: 6px;
        gap: 2px 16px;
    }

    .hud-title {
        font-size: 1rem;
    }

    .hud-scores {
        grid-column: 1 / -1;
    }

    .screen-wrap {
        margin-block: 8px;
    }

    .screen {
        padding: 8px 12px;
    }

    #arcade-screen h2,
    #versus-screen h2 {
        display: none;
    }

    canvas {
        width: min(100%, calc((100svh - 190px) * 16 / 9));
    }

    .message {
        margin: 4px 0 8px;
    }

    .actions {
        margin-top: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .screen {
        animation: none;
    }

    .btn {
        transition: none;
    }
}