:root {
    color-scheme: light;
    --paper: #f1efe9;
    --paper-deep: #d7d2c7;
    --ink: #2f3331;
    --muted: #6c716b;
    --moss: #59635d;
    --moss-dark: #3b413d;
    --vermilion: #7e6a55;
    --gold: #a99674;
    --stone: #aaa69d;
    --fresh: #cecac0;
    --shadow: rgba(25, 31, 28, 0.18);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    background:
        radial-gradient(circle at 18% 8%, rgba(169, 150, 116, 0.16), transparent 28%),
        linear-gradient(160deg, #efede7 0%, #dedbd2 58%, #aaa79c 100%);
    color: var(--ink);
    font-family:
        "Hiragino Sans", "Yu Gothic", "YuGothic", "Noto Sans JP", system-ui, sans-serif;
    letter-spacing: 0;
}

button {
    border: 0;
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#app {
    position: relative;
    width: min(100vw, 520px);
    min-height: 100dvh;
    margin: 0 auto;
    overflow: visible;
    background:
        linear-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.4) 1px, transparent 1px),
        var(--paper);
    background-size: 24px 24px;
    box-shadow: 0 0 42px rgba(23, 33, 29, 0.24);
}

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

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

#title-screen {
    flex-direction: column;
    justify-content: space-between;
    padding: max(22px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
}

.title-visual {
    position: relative;
    min-height: 44dvh;
    border-bottom: 2px solid rgba(36, 48, 45, 0.18);
}

.stone-wall {
    position: absolute;
    left: 2%;
    right: 2%;
    bottom: 0;
    height: 34%;
    transform: skewX(-9deg);
    background:
        linear-gradient(35deg, rgba(255, 255, 255, 0.32), transparent 36%),
        repeating-linear-gradient(8deg, transparent 0 28px, rgba(80, 64, 45, 0.28) 29px 31px),
        repeating-linear-gradient(96deg, transparent 0 42px, rgba(80, 64, 45, 0.22) 43px 45px),
        #aaa69d;
    box-shadow: 0 -10px 0 rgba(89, 99, 93, 0.16) inset;
    clip-path: polygon(14% 0, 100% 0, 92% 100%, 0 100%);
}

.wall-b {
    left: 10%;
    right: 14%;
    bottom: 26%;
    height: 22%;
    opacity: 0.9;
}

.tower-block {
    position: absolute;
    right: 20%;
    bottom: 48%;
    width: 74px;
    height: 70px;
    background: linear-gradient(#fbfbf3 0 58%, #222 58% 68%, #f5f0df 68%);
    border: 3px solid #2b332e;
    box-shadow: 10px 10px 0 rgba(36, 48, 45, 0.12);
}

.tower-block::before {
    position: absolute;
    left: -10px;
    right: -10px;
    top: -18px;
    height: 22px;
    content: "";
    background: #252d2a;
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.crane-line {
    position: absolute;
    width: 3px;
    height: 40%;
    transform-origin: bottom;
    background: var(--vermilion);
}

.crane-left {
    left: 20%;
    bottom: 28%;
    transform: rotate(-34deg);
}

.crane-right {
    right: 18%;
    bottom: 36%;
    transform: rotate(28deg);
    background: #737d80;
}

.title-copy {
    padding: 18px 0 4px;
}

.eyebrow,
.hud-label,
.modal-kicker,
#mission-kicker {
    margin: 0;
    color: var(--moss);
    font-size: 0.78rem;
    font-weight: 800;
}

h1,
h2,
p {
    margin: 0;
}

.title-copy h1 {
    margin-top: 8px;
    font-size: clamp(2.4rem, 14vw, 4.4rem);
    line-height: 0.95;
    font-weight: 900;
}

.lead {
    margin-top: 16px;
    color: #3d4a45;
    font-size: 1rem;
    line-height: 1.75;
}

.start-panel,
.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 22px;
}

.primary-button,
.secondary-button,
.tool-button,
.small-button {
    min-height: 46px;
    border-radius: 8px;
    font-weight: 800;
}

.primary-button {
    background: var(--moss-dark);
    color: #fffdf6;
    box-shadow: 0 8px 0 rgba(33, 66, 53, 0.22);
}

.secondary-button {
    border: 2px solid rgba(36, 48, 45, 0.18);
    background: rgba(255, 255, 255, 0.54);
    color: var(--ink);
}

.compact {
    width: 100%;
    margin-top: 20px;
}

.copyright {
    margin-top: 18px;
    color: var(--muted);
    font-size: 0.78rem;
}

#game-screen {
    position: relative;
    flex-direction: column;
    min-height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
    overflow: visible;
}

.game-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 8px;
    align-items: center;
}

.game-header > div {
    min-width: 0;
    padding: 7px 8px;
    border: 1px solid rgba(36, 48, 45, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.6);
}

.game-header strong {
    display: block;
    margin-top: 1px;
    font-size: 1.05rem;
}

.small-button {
    min-width: 58px;
    min-height: 42px;
    padding: 0 10px;
    background: #e4dfd4;
    color: var(--ink);
}

.small-button.accent {
    background: var(--vermilion);
    color: #fbfaf6;
}

#mission-panel {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    min-height: 66px;
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(36, 48, 45, 0.12);
    border-radius: 8px;
    background: rgba(255, 252, 244, 0.84);
}

#mission-title {
    margin-top: 3px;
    font-size: 1.02rem;
    line-height: 1.25;
}

#game-canvas {
    width: 100%;
    flex: 0 0 clamp(820px, 150dvh, 1080px);
    min-height: 820px;
    margin-top: 8px;
    border: 1px solid rgba(36, 48, 45, 0.14);
    border-radius: 8px;
    background: #eeece6;
    touch-action: none;
}

.tool-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

.tool-button {
    background: var(--ink);
    color: #fffaf0;
}

.tool-button:disabled {
    cursor: default;
    background: #c7c1b3;
    color: rgba(36, 48, 45, 0.52);
}

.modal {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(36, 48, 45, 0.42);
}

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

.modal-content,
.result-card {
    width: min(100%, 430px);
    border-radius: 8px;
    padding: 22px;
    background: #fffaf0;
    box-shadow: 0 22px 50px rgba(25, 31, 28, 0.26);
}

.modal-content h2,
.result-card h1 {
    margin-top: 6px;
    font-size: 1.55rem;
    line-height: 1.22;
}

.modal-content p:not(.modal-kicker),
.result-card p:not(.eyebrow) {
    margin-top: 12px;
    color: #3c4842;
    line-height: 1.65;
}

#result-screen {
    align-items: center;
    justify-content: center;
    padding: 22px;
}

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

.result-stats div {
    padding: 12px 6px;
    border-radius: 8px;
    background: #dfdbd0;
    text-align: center;
}

.result-stats dt {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
}

.result-stats dd {
    margin: 4px 0 0;
    font-size: 1.05rem;
    font-weight: 900;
}

@media (max-width: 380px) {
    .game-header {
        grid-template-columns: 1fr 1fr 1fr;
    }

    #pause-button {
        grid-column: 1 / -1;
        min-height: 36px;
    }

    #mission-panel {
        min-height: 58px;
        padding: 8px;
    }

    #mission-title {
        font-size: 0.92rem;
    }
}
