:root {
    --glow: #ff9f1c;
    --orange: #ff9f1c;
    --wood: #6b3f1d;
    --wood-dark: #4a2a10;
    --grass: #3fa34d;
    --grass-dark: #2c7e3a;
    --dirt: #6e4222;
    --dirt-dark: #3c2210;
    --cream: #f6efdc;
    --pixel-font: 'Press Start 2P', 'Courier New', monospace;
    /* Board width: limited by screen width and by height so the controls stay on screen */
    --board: min(420px, calc(100vw - 110px), max(240px, calc((100vh - 340px) * 1.1)));
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 10px 12px 40px;
    font-family: var(--pixel-font);
    color: #fff;
    background:
        radial-gradient(circle at 50% 0%, #7a3e12 0%, transparent 62%),
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 60px),
        #2b1608;
    background-attachment: fixed;
}

.home {
    display: inline-block;
    margin-bottom: 8px;
    font-size: 10px;
    color: var(--orange);
    text-decoration: none;
    text-shadow: 0 0 8px var(--orange);
}

.home:hover,
.home:focus-visible {
    color: #fff;
}

/* ---------- Cabinet (wooden planks) ---------- */
.cabinet {
    position: relative;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

.cabinet::after {
    content: '';
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: -16px;
    height: 24px;
    background: radial-gradient(ellipse at center, var(--glow) 0%, transparent 70%);
    opacity: 0.45;
    filter: blur(8px);
}

.body {
    position: relative;
    z-index: 1;
    padding: 10px 16px 0;
    border: 4px solid #1c0e04;
    border-radius: 18px 18px 4px 4px;
    box-shadow: 0 0 0 3px var(--glow), 0 10px 30px rgba(0, 0, 0, 0.6);
    background:
        repeating-linear-gradient(90deg, transparent 0 46px, rgba(0, 0, 0, 0.35) 46px 48px),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 3px, transparent 3px 7px),
        linear-gradient(90deg, #5e3719, #7a4a24 50%, #5e3719);
}

.marquee {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 14px;
    background: #000;
    border-radius: 6px;
    border: 3px solid var(--glow);
    box-shadow: 0 0 16px var(--glow), inset 0 0 12px rgba(255, 255, 255, 0.12);
}

.mq-title {
    font-size: clamp(11px, 3.4vw, 18px);
    letter-spacing: 2px;
    text-shadow: 0 0 6px var(--orange), 0 0 18px var(--orange);
}

.mq-icon {
    width: 40px;
    height: 30px;
    overflow: hidden;
    display: block;
}

.mq-icon svg {
    width: 100%;
    display: block;
    transform: translateY(-4px);
}

/* ---------- Screen ---------- */
.bezel {
    margin-top: 10px;
    padding: 8px 10px 10px;
    background: #1b0f06;
    border-radius: 10px;
    border: 3px solid var(--wood-dark);
    box-shadow: inset 0 0 14px #000;
}

.hud {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px 4px;
    background: linear-gradient(#8a5428, #6b3f1d);
    border: 2px solid var(--wood-dark);
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.hud-item .label {
    font-size: 7px;
    color: #f3d9a8;
}

.hud-item .value {
    font-size: 13px;
    color: #ffe9a8;
    text-shadow: 0 0 6px var(--orange);
}

.hud-item .value.low {
    color: #ff6b5a;
    text-shadow: 0 0 6px #ff3b2a;
}

/* ---------- Picket fence around the lawn ---------- */
.fence {
    --b: 20px;
    position: relative;
    width: fit-content;
    margin: 0 auto;
    padding: var(--b);
}

.fence-edge {
    position: absolute;
}

.fence-edge.top, .fence-edge.bottom {
    left: var(--b);
    right: var(--b);
    height: var(--b);
    background-size: 18px var(--b);
    background-repeat: repeat-x;
}

.fence-edge.left, .fence-edge.right {
    top: var(--b);
    bottom: var(--b);
    width: var(--b);
    background-size: var(--b) 18px;
    background-repeat: repeat-y;
}

.fence-edge.top { top: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2218%22 height=%2222%22 viewBox=%220 0 18 22%22%3E%3Crect x=%222%22 y=%227%22 width=%2214%22 height=%2215%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22/%3E%0A%3Cpolygon points=%222,7 9,0.8 16,7%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22 stroke-linejoin=%22round%22/%3E%0A%3Crect x=%222%22 y=%2212%22 width=%2214%22 height=%222.5%22 fill=%22%23cdbb8f%22 opacity=%22.6%22/%3E%3C/svg%3E"); }
.fence-edge.bottom { bottom: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2218%22 height=%2222%22 viewBox=%220 0 18 22%22%3E%3Cg transform=%22rotate(180 9 11)%22%3E%3Crect x=%222%22 y=%227%22 width=%2214%22 height=%2215%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22/%3E%0A%3Cpolygon points=%222,7 9,0.8 16,7%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22 stroke-linejoin=%22round%22/%3E%0A%3Crect x=%222%22 y=%2212%22 width=%2214%22 height=%222.5%22 fill=%22%23cdbb8f%22 opacity=%22.6%22/%3E%3C/g%3E%3C/svg%3E"); }
.fence-edge.left { left: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2222%22 height=%2218%22 viewBox=%220 0 22 18%22%3E%3Cg transform=%22translate(0,18) rotate(-90)%22%3E%3Crect x=%222%22 y=%227%22 width=%2214%22 height=%2215%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22/%3E%0A%3Cpolygon points=%222,7 9,0.8 16,7%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22 stroke-linejoin=%22round%22/%3E%0A%3Crect x=%222%22 y=%2212%22 width=%2214%22 height=%222.5%22 fill=%22%23cdbb8f%22 opacity=%22.6%22/%3E%3C/g%3E%3C/svg%3E"); }
.fence-edge.right { right: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2222%22 height=%2218%22 viewBox=%220 0 22 18%22%3E%3Cg transform=%22translate(22,0) rotate(90)%22%3E%3Crect x=%222%22 y=%227%22 width=%2214%22 height=%2215%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22/%3E%0A%3Cpolygon points=%222,7 9,0.8 16,7%22 fill=%22%23f6efdc%22 stroke=%22%23a8946a%22 stroke-width=%221.5%22 stroke-linejoin=%22round%22/%3E%0A%3Crect x=%222%22 y=%2212%22 width=%2214%22 height=%222.5%22 fill=%22%23cdbb8f%22 opacity=%22.6%22/%3E%3C/g%3E%3C/svg%3E"); }

.post {
    position: absolute;
    width: var(--b);
    height: var(--b);
    background: linear-gradient(135deg, #e8dcc0, #b9a77a);
    border: 2px solid #8c7a50;
    border-radius: 3px;
}

.post.tl { top: 0; left: 0; }
.post.tr { top: 0; right: 0; }
.post.br { bottom: 0; right: 0; }
.post.bl { bottom: 0; left: 0; }

/* ---------- Lawn + board ---------- */
.lawn {
    position: relative;
    width: fit-content;
    padding: 12px;
    overflow: hidden;
    background:
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.06) 0 3px, transparent 4px) 0 0 / 26px 26px,
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 22px, transparent 22px 44px),
        linear-gradient(#4fba5c, #3fa34d);
    box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35);
}

.lawn.flash::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 5;
    background: rgba(255, 60, 40, 0.5);
    animation: flash 0.35s ease-out forwards;
    pointer-events: none;
}

@keyframes flash {
    to { opacity: 0; }
}

.board {
    width: var(--board);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 8px;
}

.board.shake {
    animation: shake 0.3s;
}

@keyframes shake {
    20% { transform: translate(-5px, 2px); }
    40% { transform: translate(5px, -2px); }
    60% { transform: translate(-4px, 1px); }
    80% { transform: translate(3px, -1px); }
}

/* ---------- A hole ---------- */
.hole {
    position: relative;
    aspect-ratio: 1 / 0.9;
    padding: 0;
    background: none;
    border: 0;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.hole:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    border-radius: 12px;
}

/* dirt mound with a dark pit in it */
.mound {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 42%;
    border-radius: 50%;
    background: radial-gradient(ellipse at 50% 40%, var(--dirt) 0 55%, var(--dirt-dark) 100%);
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.pit {
    position: absolute;
    left: 12%;
    right: 12%;
    bottom: 8%;
    height: 26%;
    border-radius: 50%;
    background: radial-gradient(ellipse at 50% 30%, #1a0d04 0 60%, #3a2210 100%);
}

/* the critter rises inside this window; the front lip hides its feet */
.window {
    position: absolute;
    left: 10%;
    right: 10%;
    top: 0;
    bottom: 24%;
    overflow: hidden;
    pointer-events: none;
}

.critter {
    position: absolute;
    left: 6%;
    right: 6%;
    bottom: 0;
    aspect-ratio: 1;
    transform: translateY(105%);
    transition: transform 0.11s ease-out;
}

.critter svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.hole.up .critter {
    transform: translateY(0);
}

.lip {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 42%;
    border-radius: 50%;
    background: radial-gradient(ellipse at 50% 30%, #84502a 0 40%, var(--dirt) 75%, var(--dirt-dark) 100%);
    clip-path: inset(46% 0 0 0);
    pointer-events: none;
}

.key {
    position: absolute;
    right: 6%;
    bottom: 3%;
    z-index: 4;
    padding: 3px 5px;
    font-size: 8px;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 3px;
    pointer-events: none;
}

.xeyes {
    display: none;
}

.hole.hit .eyes {
    display: none;
}

.hole.hit .xeyes {
    display: inline;
}

.hole.hit .critter {
    filter: brightness(1.25) saturate(1.3);
}

.hole.boom .critter {
    animation: boom 0.3s ease-out;
}

@keyframes boom {
    0% { transform: translateY(0) scale(1); filter: brightness(3); }
    100% { transform: translateY(0) scale(1.6); filter: brightness(3) opacity(0); }
}

/* mallet swings down on the hole that was hit */
.mallet {
    position: absolute;
    left: 38%;
    top: -14%;
    z-index: 5;
    width: 64%;
    opacity: 0;
    transform-origin: 85% 90%;
    pointer-events: none;
}

.hole.swing .mallet {
    animation: swing 0.28s ease-out;
}

@keyframes swing {
    0% { opacity: 1; transform: rotate(-65deg); }
    45% { opacity: 1; transform: rotate(12deg); }
    100% { opacity: 0; transform: rotate(12deg); }
}

.pop-text {
    position: absolute;
    left: 50%;
    top: 10%;
    z-index: 6;
    font-size: clamp(11px, 3vw, 16px);
    color: #fff3b0;
    text-shadow: 0 2px 0 #7a3e12, 0 0 8px var(--orange);
    white-space: nowrap;
    pointer-events: none;
    animation: float-up 0.8s ease-out forwards;
}

.pop-text.bad {
    color: #ff8a7a;
    text-shadow: 0 2px 0 #5a0d05, 0 0 8px #ff3b2a;
}

.pop-text.miss {
    color: #e9e9e9;
    text-shadow: 0 2px 0 #333;
}

@keyframes float-up {
    from { transform: translate(-50%, 0); opacity: 1; }
    to { transform: translate(-50%, -34px); opacity: 0; }
}

/* ---------- Overlay (start / game over) ---------- */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    text-align: center;
    background: rgba(24, 12, 4, 0.88);
    overflow-y: auto;
}

.overlay[hidden] {
    display: none;
}

.overlay h2 {
    margin: 0;
    font-size: clamp(13px, 3.6vw, 22px);
    font-weight: 400;
    color: var(--orange);
    text-shadow: 0 0 10px var(--orange);
}

.overlay-text {
    margin: 0;
    max-width: 340px;
    font-family: 'Courier New', monospace;
    font-size: clamp(11px, 2.8vw, 14px);
    line-height: 1.5;
    color: #f6e6c8;
}

.overlay-text .score {
    display: block;
    margin: 6px 0;
    font-family: var(--pixel-font);
    font-size: clamp(16px, 4.4vw, 26px);
    color: #ffe9a8;
    text-shadow: 0 0 10px var(--orange);
}

.overlay-text .record {
    display: block;
    font-family: var(--pixel-font);
    font-size: 10px;
    color: #7dff8f;
    animation: blink 0.7s steps(1) infinite;
}

.start-btn {
    padding: 12px 22px;
    font-family: var(--pixel-font);
    font-size: 12px;
    color: #2b1608;
    background: linear-gradient(#ffc24d, var(--orange));
    border: 3px solid #7a3e12;
    border-radius: 8px;
    box-shadow: 0 5px 0 #7a3e12, 0 0 14px rgba(255, 159, 28, 0.6);
    cursor: pointer;
    touch-action: manipulation;
}

.start-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #7a3e12;
}

.start-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

.overlay-hint {
    font-size: 7px;
    color: #c9a97a;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ---------- Control area ---------- */
.panel {
    margin: 10px -16px 0;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 12px;
    background: linear-gradient(#4a2a10, #3a1f0a);
    border-top: 4px solid #8a5428;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.4);
}

.legend {
    display: flex;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.legend li {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    color: #ffe9a8;
}

.legend b.bad {
    color: #ff8a7a;
}

.legend-icon {
    display: block;
    width: 34px;
    height: 30px;
    overflow: hidden;
    border-radius: 6px;
    background: var(--grass-dark);
    border: 2px solid var(--wood-dark);
}

.legend-icon svg {
    display: block;
    width: 100%;
    transform: translateY(2px);
}

.how {
    display: flex;
    align-items: center;
    gap: 10px;
}

.how-keys {
    padding: 6px 8px;
    font-size: 9px;
    line-height: 1.7;
    letter-spacing: 3px;
    text-align: center;
    color: #ffe9a8;
    background: #1b0f06;
    border: 2px solid #8a5428;
    border-radius: 4px;
}

.how-text {
    font-size: 7px;
    line-height: 1.8;
    color: #c9a97a;
}

/* Touch screens: no keyboard, so hide the key hints */
@media (pointer: coarse) {
    .key,
    .how-keys {
        display: none;
    }
}

/* ---------- Coin door + base ---------- */
.coin-door {
    margin: 0 -16px;
    padding: 12px 16px 14px;
    text-align: center;
    background: linear-gradient(#1b0f06, #0f0803);
    border-top: 3px solid #000;
}

.coin-slot {
    display: inline-block;
    width: 54px;
    padding: 8px 8px 10px;
    background: #3a2a1a;
    border: 3px solid #7a5a3a;
    border-radius: 6px;
}

.coin-slot::before {
    content: '';
    display: block;
    width: 6px;
    height: 22px;
    margin: 0 auto 6px;
    background: #000;
    border-radius: 2px;
    box-shadow: 0 0 0 2px #ffcc66;
}

.coin-slot span {
    display: block;
    font-size: 6px;
    color: #ffcc66;
}

.insert {
    margin-top: 10px;
    font-size: 9px;
    color: #ffe14d;
    text-shadow: 0 0 6px #ffe14d;
    animation: blink 1.2s steps(1) infinite;
}

.base {
    height: 18px;
    margin: 0 -16px;
    border-radius: 0 0 4px 4px;
    background:
        radial-gradient(circle at 10px 0, var(--grass) 0 7px, transparent 8px) 0 0 / 20px 12px repeat-x,
        linear-gradient(#2c7e3a 0 6px, #3c2210 6px);
}

@media (max-width: 480px) {
    .fence { --b: 16px; }
    .hud-item .value { font-size: 11px; }
    .panel { flex-wrap: wrap; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
    .hole.swing .mallet {
        opacity: 1;
        transform: rotate(12deg);
    }
}
