* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    background: #071019;
    color: #f7fbfc;
    font-family:
        "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

button {
    font: inherit;
}

#app {
    position: relative;
    width: 100%;
    max-width: 520px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    overflow: hidden;
    background: #0c2334;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
}

.screen.is-visible {
    display: block;
}

#title-screen,
#result-screen {
    overflow-y: auto;
}

#title-screen {
    background:
        linear-gradient(180deg, rgba(6, 20, 31, 0.08), rgba(6, 20, 31, 0.76)),
        radial-gradient(circle at 20% 12%, rgba(108, 220, 203, 0.42), transparent 30%),
        linear-gradient(160deg, #0d5c71 0%, #174564 42%, #0c1e2d 100%);
}

.title-ocean {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.title-ocean::before,
.title-ocean::after {
    position: absolute;
    left: -12%;
    right: -12%;
    height: 140px;
    content: "";
    background: repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.22) 0 2px, transparent 2px 22px);
    opacity: 0.28;
    transform: rotate(-5deg);
}

.title-ocean::before {
    top: 16%;
}

.title-ocean::after {
    bottom: 12%;
    opacity: 0.18;
    transform: rotate(7deg);
}

.ring {
    position: absolute;
    display: block;
    border: 2px solid rgba(243, 255, 252, 0.72);
    border-radius: 50%;
    transform: rotate(18deg);
}

.ring::after {
    position: absolute;
    inset: 16%;
    content: "";
    border: 2px solid rgba(172, 238, 226, 0.58);
    border-radius: 50%;
}

.ring-a {
    right: -28px;
    top: 88px;
    width: 150px;
    height: 110px;
}

.ring-b {
    left: -38px;
    bottom: 92px;
    width: 178px;
    height: 128px;
}

.ring-c {
    right: 54px;
    bottom: 40px;
    width: 86px;
    height: 64px;
    opacity: 0.78;
}

.title-content,
.result-content {
    position: relative;
    display: flex;
    width: min(100% - 36px, 420px);
    min-height: 100%;
    margin: 0 auto;
    padding: 30px 0 22px;
    flex-direction: column;
    justify-content: center;
}

.eyebrow {
    margin: 0 0 10px;
    color: #b9f2e7;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
}

h1 {
    margin: 0;
    color: #ffffff;
    font-size: 38px;
    line-height: 1.08;
    letter-spacing: 0;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.36);
}

.lead {
    margin: 16px 0 18px;
    color: #ecf8f6;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.7;
}

.rules {
    display: grid;
    gap: 8px;
    margin: 0 0 22px;
}

.rules p {
    margin: 0;
    padding: 10px 12px;
    border-left: 4px solid #f6d76b;
    background: rgba(4, 22, 35, 0.62);
    color: #f5fbf8;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.45;
}

.primary-button {
    width: 100%;
    min-height: 52px;
    padding: 12px 18px;
    border: 0;
    border-radius: 8px;
    background: #f6d76b;
    color: #122033;
    font-size: 18px;
    font-weight: 900;
    box-shadow: 0 8px 0 #a36d23;
    cursor: pointer;
}

.primary-button:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #a36d23;
}

.primary-button:disabled {
    background: #9aa9a3;
    color: #2f3a3c;
    box-shadow: none;
    cursor: wait;
    transform: none;
}

.primary-button.compact {
    min-height: 46px;
    font-size: 16px;
}

.secondary-button {
    width: 100%;
    min-height: 48px;
    padding: 11px 18px;
    border: 2px solid rgba(248, 251, 245, 0.72);
    border-radius: 8px;
    background: rgba(3, 18, 29, 0.38);
    color: #f8fbf5;
    font-size: 16px;
    font-weight: 900;
    cursor: pointer;
}

.secondary-button:active {
    transform: translateY(2px);
}

.copyright {
    margin: 24px 0 0;
    color: rgba(255, 255, 255, 0.66);
    font-size: 12px;
    text-align: center;
}

#game-screen {
    background: #0b2435;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#hud {
    position: absolute;
    top: env(safe-area-inset-top, 0);
    left: 10px;
    right: 10px;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    pointer-events: none;
}

.hud-cell {
    min-width: 0;
    padding: 7px 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(2, 15, 26, 0.74);
    backdrop-filter: blur(7px);
}

.hud-label {
    display: block;
    margin-bottom: 1px;
    color: #a7d8e2;
    font-size: 10px;
    font-weight: 800;
}

.hud-cell strong {
    display: block;
    color: #ffffff;
    font-size: 18px;
    line-height: 1;
}

#mission-panel {
    position: absolute;
    left: 12px;
    right: 70px;
    bottom: calc(112px + env(safe-area-inset-bottom, 0));
    z-index: 6;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(7, 17, 25, 0.74);
    pointer-events: none;
}

#mission-title {
    color: #f6d76b;
    font-size: 14px;
    font-weight: 900;
}

#mission-detail {
    margin-top: 2px;
    color: #f4fbff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
}

#stick-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: env(safe-area-inset-bottom, 0);
    z-index: 7;
    height: 102px;
    pointer-events: none;
}

#stick-base {
    position: absolute;
    left: 50%;
    bottom: 16px;
    width: 74px;
    height: 74px;
    border: 2px solid rgba(255, 255, 255, 0.34);
    border-radius: 50%;
    background:
        linear-gradient(90deg, transparent 47%, rgba(255, 255, 255, 0.28) 47% 53%, transparent 53%),
        linear-gradient(0deg, transparent 47%, rgba(255, 255, 255, 0.28) 47% 53%, transparent 53%),
        rgba(4, 18, 30, 0.44);
    transform: translateX(-50%);
}

#stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #f6d76b;
    box-shadow: 0 0 0 5px rgba(246, 215, 107, 0.16);
    transform: translate(-50%, -50%);
}

.icon-button {
    position: absolute;
    right: 12px;
    bottom: calc(122px + env(safe-area-inset-bottom, 0));
    z-index: 8;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    background: rgba(2, 15, 26, 0.72);
    color: #ffffff;
    font-size: 16px;
    font-weight: 900;
    cursor: pointer;
}

.modal {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(3, 8, 12, 0.72);
}

.modal.is-visible {
    display: flex;
}

.modal-content {
    width: min(100%, 390px);
    padding: 22px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: #f8fbf5;
    color: #172431;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
}

#knowledge-kind,
.modal-subtitle {
    margin: 0 0 8px;
    color: #13797a;
    font-size: 13px;
    font-weight: 900;
}

.modal-content h2 {
    margin: 0 0 12px;
    color: #13243b;
    font-size: 24px;
    line-height: 1.2;
    letter-spacing: 0;
}

.modal-content p {
    color: #223142;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.65;
}

#result-screen {
    background:
        linear-gradient(180deg, rgba(5, 15, 24, 0.1), rgba(5, 15, 24, 0.86)),
        linear-gradient(155deg, #135f7a 0%, #243650 52%, #111827 100%);
}

.result-content {
    text-align: left;
}

#result-title {
    font-size: 34px;
}

#result-message {
    margin: 16px 0 20px;
    color: #edf9f8;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.7;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 0 0 22px;
}

.result-stats div {
    padding: 10px 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: rgba(3, 18, 29, 0.64);
}

.result-stats dt {
    margin-bottom: 5px;
    color: #a7d8e2;
    font-size: 11px;
    font-weight: 900;
}

.result-stats dd {
    margin: 0;
    color: #ffffff;
    font-size: 18px;
    font-weight: 900;
    line-height: 1.1;
}

.result-actions {
    display: grid;
    gap: 12px;
}

@media (max-height: 670px) {
    .title-content,
    .result-content {
        justify-content: flex-start;
        padding-top: 22px;
    }

    h1 {
        font-size: 32px;
    }

    .lead {
        margin: 12px 0;
        font-size: 14px;
    }

    .rules {
        gap: 6px;
        margin-bottom: 16px;
    }

    .rules p {
        padding: 8px 10px;
        font-size: 12px;
    }
}

@media (min-width: 700px) {
    #app {
        border-left: 1px solid rgba(255, 255, 255, 0.12);
        border-right: 1px solid rgba(255, 255, 255, 0.12);
    }
}
