:root {
    --ink: #17212f;
    --muted: #5f6d7c;
    --paper: #fffaf0;
    --panel: #fffdf7;
    --line: rgba(23, 33, 47, 0.16);
    --shadow: 0 26px 70px rgba(7, 18, 24, 0.34);
    --grass: #68b464;
    --grass-dark: #347a48;
    --barn: #c74235;
    --barn-dark: #8f2924;
    --wood: #8d5a2d;
    --gold: #f2bd45;
    --sky: #9bd2ee;
    --wolf: #626b74;
    --wolf-dark: #3f4750;
    --wolf-soft: #8d97a2;
    --danger: #c73535;
    --good: #247a4d;
    --heart: #ef4a5f;
    --heart-empty: rgba(255, 255, 255, 0.22);
}

* {
    box-sizing: border-box;
}

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

html {
    background: #16201c;
}

body {
    align-items: center;
    background:
        linear-gradient(180deg, #203a47 0%, #14241c 100%);
    color: var(--ink);
    display: flex;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    padding: 12px;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

.game-shell {
    background: #26302a;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    height: min(760px, calc(100vh - 24px));
    height: min(760px, calc(100dvh - 24px));
    max-width: 1220px;
    min-height: 620px;
    overflow: hidden;
    position: relative;
    width: min(1220px, calc(100vw - 24px));
}

.play-section {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.hud-bar {
    align-items: center;
    background: rgba(17, 27, 29, 0.94);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    min-height: 84px;
    padding: 14px 18px;
    position: relative;
    z-index: 7;
}

.brand-lockup {
    min-width: 360px;
}

.badge {
    background: var(--gold);
    border-radius: 999px;
    color: #3b2813;
    display: inline-flex;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    padding: 7px 10px;
    white-space: nowrap;
}

.badge.dark {
    background: #243a45;
    color: #d7edf6;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 31px;
    letter-spacing: 0;
    line-height: 1.05;
}

.title-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
}

.heart-track {
    align-items: center;
    display: flex;
    gap: 4px;
}

.heart {
    color: var(--heart-empty);
    display: inline-block;
    font-size: 28px;
    height: 30px;
    line-height: 1;
    position: relative;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
    width: 30px;
}

.heart::before,
.heart-fill::before {
    content: "♥";
    left: 0;
    position: absolute;
    top: 0;
}

.heart-fill {
    color: var(--heart);
    height: 100%;
    left: 0;
    overflow: hidden;
    position: absolute;
    top: 0;
    width: var(--fill, 100%);
}

.stat-strip {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(4, minmax(70px, 1fr));
    min-width: min(420px, 46%);
}

.stat {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 54px;
    min-width: 0;
    padding: 8px 10px;
}

.stat span {
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
    font-weight: 800;
}

.stat strong {
    color: #fff;
    font-size: 24px;
    line-height: 1;
}

.rank-stat strong {
    font-size: 21px;
}

.field {
    background: var(--sky);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.sky,
.hills,
.pasture,
.path,
.farm,
.fence,
.wolf-layer,
.arrow-layer,
.fx-layer {
    position: absolute;
}

.sky {
    background: linear-gradient(180deg, #9bd2ee 0%, #d5ecf2 100%);
    inset: 0 0 46% 0;
}

.sun {
    background: #f5c95a;
    border-radius: 50%;
    box-shadow: 0 0 0 8px rgba(245, 201, 90, 0.18);
    height: 64px;
    left: 62%;
    position: absolute;
    top: 42px;
    width: 64px;
}

.cloud {
    background: #fff;
    border-radius: 999px;
    box-shadow:
        34px 2px 0 8px #fff,
        68px 10px 0 2px #fff,
        18px -12px 0 10px #fff;
    height: 26px;
    opacity: 0.85;
    position: absolute;
    width: 76px;
}

.cloud-a {
    left: 20%;
    top: 68px;
}

.cloud-b {
    left: 76%;
    top: 118px;
    transform: scale(0.78);
}

.hills {
    bottom: 40%;
    height: 150px;
    width: 70%;
}

.hill-a {
    background: #5fa66a;
    border-radius: 50% 50% 0 0;
    left: -12%;
}

.hill-b {
    background: #4e935a;
    border-radius: 50% 50% 0 0;
    right: -22%;
    transform: scaleY(0.82);
}

.pasture {
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px),
        linear-gradient(180deg, #7bc36a 0%, #4e9f57 100%);
    background-size: 78px 78px, 78px 78px, auto;
    inset: 48% 0 0 0;
}

.path {
    background:
        linear-gradient(90deg, rgba(107, 67, 34, 0.18) 1px, transparent 1px),
        linear-gradient(180deg, #d2a263 0%, #b57842 100%);
    bottom: -16%;
    height: 44%;
    left: 13%;
    transform: skewX(-16deg);
    width: 74%;
}

.farm {
    --farm-scale: 1;
    bottom: 78px;
    height: 210px;
    left: 38px;
    transform: scale(var(--farm-scale));
    transform-origin: left bottom;
    width: 210px;
    z-index: 4;
}

.farm.shake {
    animation: farmShake 0.38s ease;
}

.silo {
    background: linear-gradient(90deg, #d8e2e8 0%, #f6fbff 48%, #ccd5da 100%);
    border: 4px solid rgba(88, 99, 105, 0.34);
    border-radius: 34px 34px 6px 6px;
    bottom: 18px;
    height: 145px;
    left: 4px;
    position: absolute;
    width: 58px;
}

.silo::before {
    background: #a94439;
    border-radius: 40px 40px 0 0;
    content: "";
    height: 35px;
    left: -4px;
    position: absolute;
    top: -20px;
    width: 58px;
}

.barn {
    background: linear-gradient(180deg, #d34e40 0%, var(--barn) 100%);
    border: 4px solid var(--barn-dark);
    border-radius: 7px;
    bottom: 10px;
    height: 126px;
    left: 50px;
    position: absolute;
    width: 142px;
}

.roof {
    background: #793026;
    clip-path: polygon(50% 0, 100% 52%, 90% 66%, 10% 66%, 0 52%);
    height: 82px;
    left: -18px;
    position: absolute;
    top: -58px;
    width: 178px;
}

.door {
    background:
        linear-gradient(45deg, transparent 47%, rgba(255, 255, 255, 0.35) 48%, rgba(255, 255, 255, 0.35) 52%, transparent 53%),
        linear-gradient(-45deg, transparent 47%, rgba(255, 255, 255, 0.35) 48%, rgba(255, 255, 255, 0.35) 52%, transparent 53%),
        #7b3f25;
    border: 3px solid rgba(255, 255, 255, 0.55);
    bottom: 0;
    height: 68px;
    left: 35px;
    position: absolute;
    width: 66px;
}

.window {
    background: #ffe59a;
    border: 3px solid rgba(255, 255, 255, 0.75);
    border-radius: 4px;
    height: 28px;
    position: absolute;
    right: 16px;
    top: 22px;
    width: 32px;
}

.farm-label {
    background: #fff4c7;
    border: 2px solid #7b3f25;
    border-radius: 5px;
    bottom: 84px;
    color: #6d2b22;
    font-size: 12px;
    font-weight: 900;
    left: 83px;
    letter-spacing: 0;
    padding: 3px 7px;
    position: absolute;
}

.archer {
    bottom: 94px;
    height: 124px;
    left: 220px;
    position: absolute;
    width: 86px;
    z-index: 5;
}

.archer-hair {
    background: #4b2c20;
    border-radius: 26px 26px 14px 14px;
    height: 34px;
    left: 20px;
    position: absolute;
    top: 5px;
    transform: rotate(-7deg);
    width: 42px;
    z-index: 2;
}

.archer-head {
    background: linear-gradient(180deg, #f6d0a1 0%, #eeb982 100%);
    border: 3px solid #5b3821;
    border-radius: 50%;
    height: 39px;
    left: 23px;
    position: absolute;
    top: 14px;
    width: 39px;
    z-index: 3;
}

.archer-face {
    background:
        radial-gradient(circle at 10px 8px, #222 0 2px, transparent 3px),
        radial-gradient(circle at 24px 8px, #222 0 2px, transparent 3px),
        linear-gradient(180deg, transparent 0 19px, rgba(118, 66, 34, 0.55) 20px 22px, transparent 23px);
    height: 28px;
    left: 28px;
    position: absolute;
    top: 26px;
    width: 32px;
    z-index: 4;
}

.archer-body {
    background: linear-gradient(180deg, #2f875f 0%, #1f6148 100%);
    border: 3px solid #17402d;
    border-radius: 20px 20px 9px 9px;
    height: 60px;
    left: 20px;
    position: absolute;
    top: 50px;
    width: 46px;
    z-index: 2;
}

.archer-body::before,
.archer-body::after {
    background: #243b34;
    border-radius: 8px;
    bottom: -21px;
    content: "";
    height: 27px;
    position: absolute;
    width: 10px;
}

.archer-body::before {
    left: 8px;
    transform: rotate(6deg);
}

.archer-body::after {
    right: 8px;
    transform: rotate(-6deg);
}

.archer-arm {
    background: #eeb982;
    border: 3px solid #5b3821;
    border-radius: 14px;
    height: 15px;
    left: 51px;
    position: absolute;
    top: 66px;
    transform: rotate(12deg);
    width: 34px;
    z-index: 4;
}

.quiver {
    background: #6a4028;
    border: 3px solid #3c2418;
    border-radius: 9px 9px 7px 7px;
    height: 48px;
    left: 4px;
    position: absolute;
    top: 56px;
    transform: rotate(-16deg);
    width: 19px;
    z-index: 1;
}

.quiver::before,
.quiver::after {
    background: #e8d6a2;
    content: "";
    height: 31px;
    position: absolute;
    top: -23px;
    width: 3px;
}

.quiver::before {
    left: 5px;
    transform: rotate(-9deg);
}

.quiver::after {
    right: 4px;
    transform: rotate(12deg);
}

.bow {
    border: 4px solid #7b431f;
    border-left: 0;
    border-radius: 0 48px 48px 0;
    height: 86px;
    left: 63px;
    position: absolute;
    top: 28px;
    width: 26px;
    z-index: 3;
}

.bow::before {
    background: rgba(255, 255, 255, 0.78);
    content: "";
    height: 82px;
    left: 0;
    position: absolute;
    top: -2px;
    width: 2px;
}

.fence {
    background:
        repeating-linear-gradient(90deg, var(--wood) 0 9px, transparent 9px 50px),
        linear-gradient(0deg, transparent 0 18px, var(--wood) 18px 27px, transparent 27px 47px, var(--wood) 47px 56px, transparent 56px);
    height: 64px;
    left: 0;
    right: 0;
}

.fence-back {
    bottom: 226px;
    opacity: 0.82;
    z-index: 2;
}

.fence-front {
    bottom: 42px;
    z-index: 6;
}

.wolf-layer,
.arrow-layer,
.fx-layer {
    inset: 0;
    pointer-events: none;
    z-index: 8;
}

.wolf {
    background: transparent;
    border: 0;
    cursor: crosshair;
    height: 96px;
    margin: 0;
    padding: 0;
    pointer-events: auto;
    position: absolute;
    transform: translate(-50%, -50%) scale(var(--wolf-scale, 1));
    transform-origin: center bottom;
    width: 136px;
}

.wolf:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 5px;
}

.wolf-body {
    background: linear-gradient(180deg, var(--wolf-soft) 0%, var(--wolf) 100%);
    border: 3px solid var(--wolf-dark);
    border-radius: 48px 42px 30px 34px;
    bottom: 23px;
    box-shadow: inset 0 -7px 0 rgba(58, 66, 75, 0.18);
    height: 47px;
    left: 39px;
    position: absolute;
    width: 77px;
}

.wolf-head {
    background: linear-gradient(180deg, #9aa4ae 0%, #717b86 100%);
    border: 3px solid var(--wolf-dark);
    border-radius: 42px 36px 30px 38px;
    height: 45px;
    left: 9px;
    position: absolute;
    top: 19px;
    width: 52px;
}

.wolf-head::before,
.wolf-head::after {
    background: #737d88;
    border: 3px solid var(--wolf-dark);
    content: "";
    height: 18px;
    position: absolute;
    top: -14px;
    width: 15px;
}

.wolf-head::before {
    border-radius: 12px 0 12px 0;
    left: 9px;
    transform: rotate(-8deg);
}

.wolf-head::after {
    border-radius: 0 12px 0 12px;
    right: 4px;
    transform: rotate(18deg);
}

.wolf-eye {
    background: #1d2630;
    border-radius: 50%;
    box-shadow: 14px 1px 0 #1d2630;
    height: 5px;
    left: 16px;
    position: absolute;
    top: 15px;
    width: 5px;
}

.wolf-snout {
    background:
        radial-gradient(circle at 4px 7px, #1f252b 0 4px, transparent 5px),
        #d6d0c8;
    border: 3px solid var(--wolf-dark);
    border-radius: 18px 8px 12px 18px;
    bottom: 5px;
    height: 18px;
    left: -15px;
    position: absolute;
    width: 29px;
}

.wolf-tail {
    background: linear-gradient(180deg, #7f8994 0%, #56616b 100%);
    border: 3px solid var(--wolf-dark);
    border-radius: 10px 34px 34px 12px;
    height: 24px;
    position: absolute;
    right: 0;
    top: 34px;
    transform: rotate(18deg);
    width: 45px;
}

.wolf-leg {
    background: #4e5761;
    border-radius: 10px 10px 5px 5px;
    bottom: 0;
    height: 27px;
    position: absolute;
    width: 11px;
}

.leg-a {
    animation: walkA 0.48s infinite ease-in-out;
    left: 53px;
}

.leg-b {
    animation: walkB 0.48s infinite ease-in-out;
    left: 77px;
}

.leg-c {
    animation: walkB 0.48s infinite ease-in-out;
    left: 101px;
}

.wolf.hit {
    filter: brightness(1.5);
}

.arrow {
    height: 8px;
    pointer-events: none;
    position: absolute;
    transform-origin: 0 50%;
    transition: left 0.34s linear, top 0.34s linear;
    width: 74px;
    z-index: 12;
}

.arrow::before {
    background: #6b4425;
    content: "";
    height: 4px;
    left: 0;
    position: absolute;
    top: 2px;
    width: 64px;
}

.arrow::after {
    border-bottom: 7px solid transparent;
    border-left: 14px solid #303841;
    border-top: 7px solid transparent;
    content: "";
    left: 58px;
    position: absolute;
    top: -3px;
}

.burst {
    color: #fff9dd;
    font-size: 18px;
    font-weight: 900;
    pointer-events: none;
    position: absolute;
    text-shadow: 0 2px 5px rgba(45, 30, 15, 0.5);
    transform: translate(-50%, -50%);
    z-index: 20;
}

.rank-toast {
    background: rgba(25, 46, 37, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    color: #fff7d7;
    font-size: 16px;
    font-weight: 900;
    left: 50%;
    padding: 11px 15px;
    pointer-events: none;
    position: absolute;
    top: 18px;
    transform: translateX(-50%);
    z-index: 24;
}

.control-panel {
    background: var(--paper);
    border-left: 1px solid var(--line);
    display: grid;
    gap: 14px;
    grid-template-rows: auto auto 1fr;
    min-width: 0;
    padding: 16px;
}

.problem-panel,
.keypad-panel,
.action-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(58, 41, 23, 0.1);
    padding: 14px;
}

.panel-heading {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.panel-meta {
    align-items: center;
    display: inline-flex;
    gap: 6px;
    min-width: 0;
}

#level-label,
#mode-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

#mode-label {
    background: rgba(36, 58, 69, 0.1);
    border-radius: 999px;
    color: #284957;
    padding: 5px 8px;
    white-space: nowrap;
}

.problem {
    align-items: center;
    background: #1d2a30;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #fff;
    display: flex;
    font-size: 46px;
    font-weight: 900;
    justify-content: center;
    letter-spacing: 0;
    line-height: 1;
    margin-top: 14px;
    min-height: 104px;
    padding: 12px;
}

.answer-row {
    display: grid;
    gap: 9px;
    grid-template-columns: minmax(0, 1fr) 58px;
    margin-top: 12px;
}

#answer-input {
    background: #fff;
    border: 2px solid rgba(23, 33, 47, 0.2);
    border-radius: 8px;
    color: var(--ink);
    font-size: 34px;
    font-weight: 900;
    height: 58px;
    letter-spacing: 0;
    line-height: 1;
    padding: 0 16px;
    text-align: center;
    width: 100%;
}

#answer-input:focus {
    border-color: #2673ad;
    outline: 3px solid rgba(38, 115, 173, 0.18);
}

.input-hint {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    margin-top: 8px;
}

body.keyboard-input.manual-mode .keypad-panel {
    display: none;
}

.check-btn,
.secondary-btn,
.volley-btn,
.keypad button {
    align-items: center;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 900;
    justify-content: center;
    min-height: 48px;
    transition: filter 0.16s ease, transform 0.16s ease, background-color 0.16s ease;
    user-select: none;
}

.check-btn {
    background: var(--good);
    color: #fff;
}

.check-btn svg {
    fill: none;
    height: 30px;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
    width: 30px;
}

.check-btn:hover,
.secondary-btn:hover,
.volley-btn:hover,
.keypad button:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.feedback {
    align-items: center;
    background: #f3ead9;
    border: 1px solid rgba(23, 33, 47, 0.12);
    border-radius: 8px;
    color: #514432;
    display: flex;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.35;
    margin-top: 12px;
    min-height: 48px;
    padding: 9px 11px;
}

.feedback.good {
    background: #dbf2df;
    color: #175c38;
}

.feedback.bad {
    background: #ffe2df;
    color: #8d2620;
}

.feedback.warn {
    background: #fff1c9;
    color: #755018;
}

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

.keypad button {
    background: #fff;
    border: 1px solid rgba(23, 33, 47, 0.14);
    color: var(--ink);
    font-size: 21px;
    min-height: 52px;
}

.action-panel {
    align-content: start;
    display: grid;
    gap: 10px;
}

.volley-btn {
    background: linear-gradient(180deg, #f0a735 0%, #db6b24 100%);
    border: 1px solid rgba(112, 61, 24, 0.35);
    box-shadow: 0 12px 22px rgba(154, 78, 27, 0.22);
    color: #fff;
    flex-direction: column;
    font-size: 21px;
    gap: 4px;
    min-height: 72px;
}

.volley-btn small {
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
}

.volley-btn:disabled {
    background: #c9c0b0;
    border-color: #bcb2a1;
    box-shadow: none;
    color: rgba(255, 255, 255, 0.78);
    cursor: not-allowed;
    transform: none;
}

.secondary-btn {
    background: #263942;
    color: #fff;
}

.danger-btn {
    background: #8f2924;
}

.secondary-btn:disabled,
.check-btn:disabled {
    background: #b9b0a0;
    color: rgba(255, 255, 255, 0.78);
    cursor: not-allowed;
    transform: none;
}

.start-overlay {
    align-items: center;
    background:
        linear-gradient(90deg, rgba(17, 27, 29, 0.9) 0%, rgba(17, 27, 29, 0.72) 52%, rgba(17, 27, 29, 0.38) 100%);
    display: flex;
    inset: 0;
    justify-content: flex-start;
    padding: clamp(22px, 7vw, 72px);
    position: absolute;
    z-index: 26;
}

.start-overlay.hidden {
    display: none;
}

.start-box {
    color: #fff;
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(280px, 390px) minmax(260px, 320px);
    max-width: 760px;
    min-width: 0;
    width: min(760px, 100%);
}

.start-box h2 {
    color: #fff;
    font-size: clamp(36px, 6vw, 58px);
    letter-spacing: 0;
    line-height: 1.02;
}

.start-main {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.setup-card {
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    min-width: 0;
    padding: 14px 16px;
}

.setup-card > span,
.player-card > span {
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    font-weight: 900;
}

.player-card input {
    background: rgba(255, 255, 255, 0.95);
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    font-size: 20px;
    font-weight: 900;
    min-height: 48px;
    padding: 0 13px;
    width: 100%;
}

.player-card input:focus {
    outline: 3px solid rgba(242, 189, 69, 0.36);
}

.start-btn {
    background: linear-gradient(180deg, #f0a735 0%, #db6b24 100%);
    border: 1px solid rgba(112, 61, 24, 0.35);
    border-radius: 8px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
    color: #fff;
    cursor: pointer;
    font-size: 24px;
    font-weight: 900;
    min-height: 68px;
    width: 100%;
}

.start-btn:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.leaderboard-card {
    align-self: stretch;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    color: var(--ink);
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 0;
    overflow: hidden;
    padding: 16px;
}

.leaderboard-heading {
    align-items: baseline;
    display: flex;
    gap: 8px;
    justify-content: space-between;
    margin-bottom: 12px;
}

.leaderboard-heading span {
    font-size: 24px;
    font-weight: 900;
}

.leaderboard-heading small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.leaderboard-list,
.modal-leaderboard {
    display: grid;
    gap: 7px;
    list-style: none;
    margin: 0;
    min-height: 0;
    overflow: auto;
    padding: 0;
}

.leaderboard-row,
.empty-rank {
    align-items: center;
    background: rgba(38, 57, 66, 0.08);
    border: 1px solid rgba(38, 57, 66, 0.1);
    border-radius: 8px;
    display: flex;
    font-size: 14px;
    font-weight: 900;
    justify-content: space-between;
    min-height: 36px;
    padding: 7px 9px;
}

.leaderboard-row span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-row strong {
    color: #8f2924;
    margin-left: 10px;
}

.empty-rank {
    color: var(--muted);
    justify-content: center;
}

.game-modal {
    align-items: center;
    background: rgba(13, 20, 22, 0.62);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 20px;
    position: absolute;
    z-index: 30;
}

.game-modal.hidden {
    display: none;
}

.modal-box {
    background: #fffaf0;
    border: 1px solid rgba(23, 33, 47, 0.16);
    border-radius: 8px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
    max-height: calc(100dvh - 40px);
    max-width: 360px;
    overflow: auto;
    padding: 24px;
    text-align: center;
    width: min(360px, 100%);
}

.modal-box h2 {
    color: #8f2924;
    font-size: 28px;
    letter-spacing: 0;
    line-height: 1.16;
}

.modal-box p {
    color: var(--muted);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.45;
    margin: 10px 0 18px;
}

.modal-rank {
    background: #dbf2df;
    border: 1px solid rgba(36, 122, 77, 0.2);
    border-radius: 8px;
    color: #175c38;
    font-size: 15px;
    font-weight: 900;
    margin: 0 0 14px;
    padding: 10px 12px;
}

.modal-leaderboard {
    margin-bottom: 16px;
    text-align: left;
}

.modal-leaderboard .leaderboard-row,
.modal-leaderboard .empty-rank {
    background: #f4ead8;
}

@keyframes walkA {
    0%,
    100% {
        transform: rotate(13deg);
    }
    50% {
        transform: rotate(-16deg);
    }
}

@keyframes walkB {
    0%,
    100% {
        transform: rotate(-14deg);
    }
    50% {
        transform: rotate(14deg);
    }
}

@keyframes farmShake {
    0%,
    100% {
        transform: translateX(0) scale(var(--farm-scale));
    }
    25% {
        transform: translateX(-8px) scale(var(--farm-scale));
    }
    50% {
        transform: translateX(7px) scale(var(--farm-scale));
    }
    75% {
        transform: translateX(-4px) scale(var(--farm-scale));
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}

@media (max-width: 980px) {
    body {
        align-items: stretch;
        overflow: auto;
    }

    .game-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(440px, 58vh) auto;
        height: auto;
        min-height: calc(100vh - 24px);
        min-height: calc(100dvh - 24px);
        overflow: visible;
    }

    .control-panel {
        border-left: 0;
        border-top: 1px solid var(--line);
        grid-template-columns: minmax(0, 1fr) 230px 180px;
        grid-template-rows: auto;
    }

    body.keyboard-input.manual-mode .control-panel {
        grid-template-columns: minmax(0, 1fr) 190px;
    }

    .problem {
        font-size: 40px;
        min-height: 86px;
    }

    .keypad button {
        min-height: 45px;
    }
}

@media (max-width: 720px) {
    body {
        padding: 0;
    }

    .game-shell {
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
        width: 100vw;
    }

    .hud-bar {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
        min-height: 0;
        padding: 12px;
    }

    h1 {
        font-size: 25px;
        margin-top: 6px;
    }

    .stat-strip {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        min-width: 0;
        width: 100%;
    }

    .brand-lockup {
        min-width: 0;
    }

    .stat {
        min-height: 48px;
        padding: 7px;
    }

    .stat strong {
        font-size: 20px;
    }

    .farm {
        left: 4px;
        --farm-scale: 0.74;
    }

    .archer {
        left: 138px;
        transform: scale(0.82);
        transform-origin: left bottom;
    }

    .control-panel {
        gap: 10px;
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .problem-panel,
    .keypad-panel,
    .action-panel {
        padding: 10px;
    }

    .problem {
        font-size: 36px;
        min-height: 78px;
    }

    .action-panel {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .volley-btn {
        font-size: 16px;
        min-height: 56px;
    }

    .start-overlay {
        align-items: flex-start;
        padding: 84px 14px 24px;
    }

    .start-box {
        grid-template-columns: 1fr;
        max-width: none;
        min-width: 0;
        width: 100%;
    }

    .start-box h2 {
        font-size: 34px;
    }

    .leaderboard-card {
        max-height: 260px;
    }
}

@media (max-width: 430px) {
    .stat-strip {
        gap: 6px;
    }

    .stat span {
        font-size: 11px;
    }

    .stat strong {
        font-size: 18px;
    }

    .stat {
        padding-left: 5px;
        padding-right: 5px;
    }

    .problem {
        font-size: 32px;
    }

    #answer-input {
        font-size: 30px;
    }

    .keypad button {
        min-height: 46px;
    }
}
