.game-themiddle * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-family: 'Baloo 2', system-ui, sans-serif;
}

html:has(.game-themiddle) {
    height: auto;
    min-height: 100%;
}

html:has(.game-themiddle), body:has(.game-themiddle) {
    color: #1a1a1a;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

body:has(.game-themiddle) {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    min-height: 100dvh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    background: transparent !important;
    overscroll-behavior: none;
}

.game-themiddle .content {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    max-width: 1403px;
    min-height: 700px;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    background: transparent;
    box-sizing: border-box;
    line-height: normal;
}

.game-themiddle .game-shell {
    width: 100%;
    max-width: 440px;
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    line-height: normal;
}

.game-themiddle .container {
    width: 100%;
    max-width: 440px;
    height: auto;
    min-height: 700px;
    display: flex;
    flex-direction: column;
    padding: 20px;
    padding-top: 24px;
    touch-action: manipulation;
    margin: 0 auto;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    html:has(.game-themiddle), body:has(.game-themiddle) {
        height: auto !important;
        max-height: none !important;
        min-height: 100dvh !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
    .game-themiddle .content {
        min-height: auto !important;
    }
    .game-themiddle .game-shell, .game-themiddle .container {
        min-height: 0 !important;
        height: auto !important;
    }
}

/* Back / help row */
.game-themiddle .help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    color: #1a1a1a;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s ease;
}
.game-themiddle .help-btn:hover {
    color: #801980;
    opacity: 1;
}
.game-themiddle .help-btn svg {
    width: 30px;
    height: 30px;
    display: block;
}

.game-themiddle .playing-area {
    max-height: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: visible;
    margin-bottom: 40px;
}

.game-themiddle .playing-area.has-guesses {
    justify-content: flex-start;
}

.game-themiddle .guesses-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    touch-action: pan-y;
}

.game-themiddle #beforeGuesses, .game-themiddle #afterGuesses {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}


.game-themiddle .input-wrapper {
    width: 100%;
    perspective: 1000px;
    padding: 8px 0;
    touch-action: manipulation;
    transform-origin: center center;
}

.game-themiddle .input-card {
    width: 100%;
    height: 56px;
    position: relative;
    transform-style: preserve-3d;
    transform-origin: center center;
    transition: transform 0.6s ease;
}

.game-themiddle .input-card.flipped {
    transform: rotateX(180deg);
}

.game-themiddle .input-front, .game-themiddle .input-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    background: var(--pd-colour-background, #fff);
    border: 2px solid #b8b8b4;
    box-sizing: border-box;
}

/* Mobile-only stand-in caret (autofocus isn't allowed); hides when real caret shows */
.game-themiddle .fake-caret {
    display: none;
    pointer-events: none;
}

@media (max-width: 768px) {
    .game-themiddle .fake-caret {
        display: block;
        position: absolute;
        left: 50%;
        top: 50%;
        width: 2px;
        height: 24px;
        margin-top: -12px;
        margin-left: -1px;
        background: #1a1a1a;
        border-radius: 1px;
        animation:themiddle-fakeCaretBlink 1s steps(1, end) infinite;
    }

    .game-themiddle .guess-input:focus ~ .fake-caret, .game-themiddle .guess-input:not(:placeholder-shown) ~ .fake-caret, .game-themiddle .input-card.flipped .fake-caret {
        display: none;
    }
}

@keyframes themiddle-fakeCaretBlink {
    0%, 49.999% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.game-themiddle .input-back {
    transform: rotateX(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    font-size: 20px;
    font-weight: 700;
    text-transform: capitalize;
    color: #fff;
    background: #2e9e5b;
    border-color: #2e9e5b;
}

.game-themiddle .guess-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #1a1a1a;
    font-family: 'Baloo 2', system-ui, sans-serif;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    padding: 0 18px;
    text-transform: capitalize;
    letter-spacing: -0.01em;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    caret-color: #1a1a1a;
}

.game-themiddle .guess-input::placeholder {
    color: #a8a49c;
    text-align: center;
    text-transform: none;
    letter-spacing: 0;
    font-family: var(--pd-font-ui);
    font-size: 16px;
    font-weight: 700;
    transition: color 0.2s ease;
}

.game-themiddle .guess-input.error::placeholder {
    color: #ff6b6b;
}

.game-themiddle .guess-input:read-only {
    opacity: 1;
    caret-color: #1a1a1a;
    cursor: text;
}

.game-themiddle .guess-div {
    width: 100%;
    min-height: 58px;
    padding: 12px 18px;
    box-sizing: border-box;
    background: #e7e2d6;
    border: 1.5px solid #d2caba;
    border-radius: 14px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    font-family: 'Baloo 2', system-ui, sans-serif;
    color: #1a1a1a;
    line-height: 1.15;
}
.game-themiddle .guess-div.is-bound .guess-word {
    color: #3d3832;
}
.game-themiddle .guess-word {
    display: block;
    min-width: 0;
    font-family: 'Baloo 2', system-ui, sans-serif;
    font-size: 20px;
    font-weight: 700;
    text-transform: capitalize;
    text-align: center;
    letter-spacing: -0.01em;
}

@keyframes themiddle-slideUpFromInput {
    0% {
        opacity: 0;
        transform: translateY(64px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes themiddle-slideDownFromInput {
    0% {
        opacity: 0;
        transform: translateY(-64px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.game-themiddle .guess-div.slide-up {
    animation:themiddle-slideUpFromInput 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.game-themiddle .guess-div.slide-down {
    animation:themiddle-slideDownFromInput 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes themiddle-wiggle {
    0%, 100% { transform: rotate(0deg); }
    10% { transform: rotate(-0.8deg) scale(1.005); }
    20% { transform: rotate(0.8deg) scale(1.008); }
    30% { transform: rotate(-0.8deg) scale(1.005); }
    40% { transform: rotate(0.8deg) scale(1.008); }
    50% { transform: rotate(-0.5deg) scale(1.005); }
    60% { transform: rotate(0.5deg) scale(1.005); }
    70% { transform: rotate(-0.3deg) scale(1.003); }
    80% { transform: rotate(0.3deg) scale(1.003); }
    90% { transform: rotate(0deg) scale(1); }
}

.game-themiddle .input-wrapper.wiggle {
    animation:themiddle-wiggle 1.4s ease;
}

@keyframes themiddle-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-1px); }
    20%, 40%, 60%, 80% { transform: translateX(1px); }
}

.game-themiddle .input-wrapper.shake {
    animation:themiddle-shake 0.6s ease;
}

.game-themiddle .footer {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    touch-action: manipulation;
}

.game-themiddle .footer p {
    font-size: 22px;
    font-weight: 600;
    color: #1a1a1a;
}

.game-themiddle .footer .show-results {
    cursor: pointer;
    background: none;
    border: 3px solid #1a1a1a;
    color: #1a1a1a;
    font-size: 19px;
    font-weight: 600;
    padding: 12px 32px;
    border-radius: 50px;
    transition: opacity 0.2s ease;
}

.game-themiddle .footer .show-results:hover {
    opacity: 0.7;
}

/* Modal */
.game-themiddle .modal-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s linear 0.25s;
}

.game-themiddle .modal-overlay.active {
    opacity: 1;
    visibility: visible;
    background: transparent;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s linear 0s;
}

.game-themiddle .modal,
.game-themiddle .modal * {
    font-family: var(--pd-font-ui);
}

.game-themiddle .modal {
    position: relative;
    background: var(--pd-colour-background, #fff);
    border: 2px solid #2B2B2B;
    border-radius: 12px;
    box-shadow: none;
    padding: 28px 16px 22px;
    max-width: 400px;
    width: 100%;
    max-height: min(58dvh, calc(100dvh - 96px));
    overflow: hidden;
    overscroll-behavior: none;
    text-align: center;
    box-sizing: border-box;
    transform: scale(0.95) translateY(20px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
body:has(.game-themiddle):has(.modal-overlay.active) {
    overflow: hidden !important;
    overscroll-behavior: none;
}

.game-themiddle .modal-overlay.active .modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.game-themiddle .modal h2 {
    font-family: var(--pd-font-ui);
    font-size: 24px;
    font-weight: 800;
    line-height: 28px;
    margin-top: 0;
    margin-bottom: 12px;
    color: #1a1a1a;
    padding: 0 28px;
    text-align: center;
}

.game-themiddle .modal-close {
    position: absolute;
    top: 25px;
    right: 12px;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 0;
    display: grid;
    place-items: center;
    float: none;
    background: none;
    border: none;
    color: #2B2B2B;
    font-size: 32px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
    text-align: center;
    border-radius: 8px;
    z-index: 10;
}
.game-themiddle .modal-close:hover {
    background: rgba(0, 0, 0, .06);
}
.game-themiddle .modal-bottom-close {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 12px 24px;
    border: 2px solid #2B2B2B;
    border-radius: 999px;
    background: #2B2B2B;
    color: #fff;
    font-family: var(--pd-font-ui);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.game-themiddle .modal-bottom-close:hover {
    background: #3D3D3D;
    border-color: #3D3D3D;
}
.game-themiddle {
    --ink: #1a1a1a;
    --muted: #b8b8b4;
    --card: #ffffff;
    --green: #2e9e5b;
    --green-dark: #278a4f;
    --blue: #4169f1;
    --blue-dark: #2f50d8;
}

.game-themiddle.is-done .footer {
    display: none !important;
}
.game-themiddle.is-done .container {
    min-height: 0 !important;
    height: auto !important;
    padding-bottom: 8px;
    flex: none;
}
.game-themiddle.is-done .playing-area {
    max-height: none;
    overflow: visible;
    margin-bottom: 12px;
}

/* Done: grow with results and scroll the document — never the play-area. */
html:has(.game-themiddle.is-done),
body:has(.game-themiddle.is-done) {
    height: auto !important;
    max-height: none !important;
    min-height: 100dvh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    touch-action: manipulation !important;
    overscroll-behavior-y: auto !important;
}
.game-themiddle.is-done .content,
.game-themiddle.is-done .game-shell,
.game-themiddle.is-done .pd-play-area,
.game-themiddle.is-done .playing-area,
.game-themiddle.is-done .container {
    flex: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
}

/* Hide pause only — keep help (?) and archive (calendar) on completion */
body:has(.game-themiddle.is-done) #pd-chrome-tools #pauseBtnTop { visibility: hidden; }
.game-themiddle.is-paused #playingArea { visibility: hidden; }

/* Under-board completion — staged reveal like Sunflowers */
.game-themiddle #completeScreen.pd-complete-panel {
    margin-top: 36px;
    opacity: 1;
    transform: none;
    transition: none;
}
.game-themiddle #completeScreen.pd-complete-panel:not(.is-shown) {
    visibility: hidden;
    pointer-events: none;
}
.game-themiddle #completeScreen.pd-complete-panel.is-shown {
    visibility: visible;
    pointer-events: auto;
}
.game-themiddle #completeScreen.pd-complete-panel.is-instant .tm-c-stage {
    transition: none;
}
.game-themiddle .tm-c-stage {
    opacity: 0;
    transform: translateY(22px);
    transition: opacity 0.45s cubic-bezier(.22,1,.36,1), transform 0.45s cubic-bezier(.22,1,.36,1);
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.game-themiddle .tm-c-stage.is-in {
    opacity: 1;
    transform: none;
}
.game-themiddle .tm-c-score-block {
    width: 100%;
}

/* Site-wide dark theme */
html[data-theme="dark"] body:has(.game-themiddle),
html[data-theme="dark"] .game-themiddle {
  color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .content {
  background: transparent;
}
html[data-theme="dark"] .game-themiddle .help-btn {
  color: var(--pd-colour-heading, #f5f4ed);
}
html[data-theme="dark"] .game-themiddle .input-front,
html[data-theme="dark"] .game-themiddle .input-back {
  border-color: #4a4a44;
}
html[data-theme="dark"] .game-themiddle .guess-input {
  color: var(--pd-colour-text, #f0efe8);
  caret-color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .guess-input::placeholder {
  color: #6b6b66;
}
html[data-theme="dark"] .game-themiddle .fake-caret {
  background: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .guess-div {
  background: #2a2a26;
  border-color: #4a4a44;
  color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .guess-div.is-bound .guess-word {
  color: #d8d2c8;
}
html[data-theme="dark"] .game-themiddle .footer-text,
html[data-theme="dark"] .game-themiddle .show-results {
  color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .show-results {
  border-color: var(--pd-colour-border-strong, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .modal,
html[data-theme="dark"] .game-themiddle .confirm-modal {
  background: var(--pd-colour-surface, #1c1c19);
  color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .modal-x,
html[data-theme="dark"] .game-themiddle .modal-close {
  color: var(--pd-colour-text, #f0efe8);
}
html[data-theme="dark"] .game-themiddle .btn-secondary,
html[data-theme="dark"] .game-themiddle button.secondary {
  background: #2a2a26;
  color: var(--pd-colour-text, #f0efe8);
  border-color: #4a4a44;
}
