:root {
    --bg: #f7f2e8;
    --bg-accent: #f9d9c3;
    --panel-bg: #fff8f1;
    --card-bg: #ffffff;
    --border-color: #d7c7b8;
    --text-color: #2f2b26;
    --muted-color: #6b6156;
    --accent: #ff7a59;
    --accent-dark: #e65f3d;
    --shadow: 0 8px 24px rgba(47, 43, 38, 0.12);
    --grid-size: calc(min(70vmin, 46vh, 520px) * 1.3);
}




































*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Fredoka", "Trebuchet MS", sans-serif;
    color: var(--text-color);
    background: radial-gradient(circle at top, #fff2e8 0%, var(--bg) 60%, #f3e6da 100%);
    overflow: hidden;
}









.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    padding-bottom: 2.1rem;
}

.app-header {
    text-align: center;
}

/* Hero image (responsive, lightweight) */
.hero {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.25rem 0 0.5rem 0;
}

.hero-img {
    width: auto;
    height: clamp(56px, 12vh, 140px);
    max-width: 92%;
    object-fit: contain;
    display: block;
    border-radius: 10px;
    box-shadow: var(--shadow);
    background: transparent;
    pointer-events: none;
}

/* Hide hero on single-game (when a game/tab is opened) to keep focus on the game */
.single-game .hero {
    display: none !important;
}

.app-footer {
    display: flex;
    justify-content: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0.2rem;
    z-index: 5;
    pointer-events: none;
    padding: 0 0.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-decoration: none;
    color: var(--muted-color);
    font-size: 0.72rem;
    pointer-events: auto;
}

.app-footer .back-link+.back-link::before {
    content: "|";
    color: var(--muted-color);
    margin: 0 0.2rem 0 0.05rem;
}

.back-link:hover {
    color: var(--accent-dark);
}





















.intro {
    margin: 0;
    font-size: clamp(0.9rem, 2.6vw, 1.1rem);
    color: var(--muted-color);
}

.tabs {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tab-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
}

.tab-links li {
    margin: 0;
}

.tab-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    border-radius: 999px;
    border: 2px solid transparent;
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow);
    font-size: 0.95rem;
}

.tab-links a span {
    white-space: nowrap;
}

.tab-links .active a {
    border-color: var(--accent);
    background: #ffffff;
    color: var(--accent-dark);
}

.tab-links a:hover {
    border-color: var(--accent-dark);
}

.tab-content {
    flex: 1;
    min-height: 0;
}

.tab {
    display: none;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    gap: 0.6rem;
    animation: fadeUp 0.25s ease;
}

.tab.active {
    display: flex;
}

.tab-description {
    margin: 0;
    text-align: center;
    color: var(--muted-color);
    font-size: clamp(0.85rem, 2.2vw, 0.98rem);
}

.instruction-bar {
    width: 100%;
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 14px;
    padding: 0.4rem 0.6rem;
    box-shadow: var(--shadow);
}

.game-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
}

/* Spacing for Sounds of Letters UI: category, words display, and grid */
#words-container {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    /* reduced to 75% of previous gap */
    /* small vertical spacing between controls, display and grid */
    width: 100%;
}

#words-container .controls,
#words-container #display,
#words-container .grid-slot {
    width: 100%;
}

/* also reduce internal grid gap for the words screen */
#words-container .grid {
    gap: 0.45rem;
}

/* Apply the same smaller vertical spacing for the Hear the Numbers screen */
#numbers-container {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    width: 100%;
}

#numbers-container .controls,
#numbers-container #selected-number,
#numbers-container .grid-slot {
    width: 100%;
}

#numbers-container .grid {
    gap: 0.45rem;
}

.panel {
    background: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 0.6rem 0.8rem;
    box-shadow: var(--shadow);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
}

.compact-controls {
    gap: 0.4rem;
}

.compact-controls .field {
    min-width: 72px;
}

.compact-controls button {
    padding: 0.5rem 0.8rem;
}

.numbers-controls {
    flex-wrap: nowrap;
    gap: 0.35rem;
}

.numbers-controls .field {
    flex: 1 1 80px;
    min-width: 70px;
}

.numbers-controls input,
.numbers-controls select {
    padding: 0.35rem 0.5rem;
    min-height: 40px;
    font-size: 0.95rem;
}

.numbers-controls button {
    padding: 0.4rem 0.6rem;
    min-height: 40px;
    font-size: 0.9rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 90px;
}

label {
    font-size: 0.85rem;
    color: var(--muted-color);
}

input[type="number"],
input[type="text"],
select {
    padding: 0.45rem 0.6rem;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    font-size: 1rem;
    background: #ffffff;
    min-height: 44px;
}




















button {
    border: none;
    border-radius: 12px;
    padding: 0.6rem 1rem;
    font-size: 1rem;
    cursor: pointer;
    background: var(--accent);
    color: #ffffff;
    box-shadow: var(--shadow);
    transition: transform 0.08s ease, background-color 0.2s ease;
    touch-action: manipulation;
    min-height: 44px;
}

button:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

button.secondary {
    background: #5a6b7a;
}

button.secondary:hover {
    background: #415060;
}

.status-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.puzzle-status {
    margin-bottom: 0.5rem;
}

.numbers-status {
    flex-wrap: nowrap;
    gap: 0.5rem;
}

/* small gap below the status row so grid doesn't touch it */
.numbers-status.panel {
    margin-bottom: 0.6rem;
}

.numbers-status .status-line {
    white-space: nowrap;
}

.numbers-status button {
    padding: 0.4rem 0.6rem;
    min-width: 44px;
}

.numbers-status.panel {
    padding: 0.35rem 0.55rem;
}

.status-line {
    min-height: 1.5rem;
    font-size: 1.2rem;
    text-align: center;
    color: var(--text-color);
}

.status-line.panel {
    margin-top: 0.4rem;
    margin-bottom: 0.4rem;
}

.message-container {
    text-align: center;
    min-height: 1.5rem;
}

.message-container button+button {
    margin-left: 0.5rem;
}

.message {
    margin-top: 0.4rem;
    padding: 0.35rem 0.6rem;
    border-radius: 10px;
    display: inline-block;
    background: #fff0e8;
    border: 2px solid var(--accent);
}

.message.error {
    border-color: #c0392b;
    color: #c0392b;
}

.hearts-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 1.35rem;
    letter-spacing: 0.05rem;
}

.grid-slot {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid {
    width: var(--grid-size);
    max-width: 100%;
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    touch-action: none;
    user-select: none;
}

.card {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.4rem, 5vw, 2.4rem);
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 18px;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.2s ease;
    box-shadow: var(--shadow);
    touch-action: none;
}

.card:hover {
    transform: translateY(-2px);
    background-color: #fff3ea;
}

.card.clicked,
.card.purple {
    background-color: var(--accent);
    color: #ffffff;
    border-color: var(--accent-dark);
}

.selected-number {
    font-size: clamp(1.4rem, 4.2vw, 2rem);
    font-weight: 700;
    text-align: center;
    min-height: 1.8rem;
}









.selected-number.panel {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    justify-content: center;
}

.word-input {
    min-width: 180px;
}

.caps-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.caps-toggle input {
    width: 22px;
    height: 22px;
}

.letters-row,
.assembly-row {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
}

.letters-row {
    /* keep a small bottom spacing but reduced so layout fits on small screens */
    margin-bottom: 0.15rem;
}

.assembly-row {
    /* small gap below placeholders so selectable letters don't touch */
    margin-top: 0.2rem;
    margin-bottom: 0.35rem;
}

.assembly-cell,
.puzzle-piece {
    width: clamp(48px, 10vmin, 84px);
    height: clamp(56px, 11vmin, 92px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 3.5vw, 2rem);
    border-radius: 14px;
}

.assembly-cell {
    border: 2px dashed var(--border-color);
    background: #ffffff;
}

.puzzle-piece {
    border: 2px solid var(--text-color);
    font-weight: 600;
    cursor: pointer;
    background: #fff0e0;
}

.puzzle-piece.shake,
.card.shake {
    animation: shake 0.4s;
}

.letters-row.is-disabled .puzzle-piece {
    pointer-events: none;
    opacity: 0.5;
}

.abbreviation {
    color: var(--accent-dark);
}

.is-hidden {
    display: none !important;
}

/* Single-game focused view: hide the tab links/menu and let the game take full space */
body.single-game .tab-links {
    display: none;
}

/* When not in single-game, hide the tab contents (we show only menu) */
body:not(.single-game) .tab-content {
    display: none;
}

.back-to-menu {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    margin: 0.4rem 0.6rem;
}

/* Show the intro/header only on the initial menu; hide it in single-game view */
body.single-game .app-header {
    display: none;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

@keyframes fadeUp {
    from {
        opacity: 0.4;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


@media (max-height: 700px) {
    :root {
        --grid-size: calc(min(76vmin, 24vh, 360px) * 1.3);
    }

    .panel {
        padding: 0.35rem 0.5rem;
    }

    label {
        font-size: 0.78rem;
    }

    .instruction-bar {
        padding: 0.3rem 0.5rem;
    }

    .tab-description {
        font-size: 0.82rem;
    }
}

@media (max-width: 600px) {
    :root {
        --grid-size: calc(min(76vmin, 24vh, 280px) * 1.3);
    }

    .app {
        padding: 0.5rem;
    }

    .tab-links a {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .controls {
        gap: 0.35rem;
    }

    .field {
        min-width: 64px;
    }

    input[type="number"],
    input[type="text"],
    select,
    button {
        font-size: 0.95rem;
    }

    .compact-controls {
        gap: 0.25rem;
    }

    .compact-controls.panel {
        padding: 0.25rem 0.35rem;
    }

    .compact-controls .field {
        flex: 1 1 96px;
    }

    .compact-controls button {
        flex: 1 1 110px;
        min-height: 36px;
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
    }

    .numbers-controls {
        flex-wrap: wrap;
    }

    .numbers-status {
        gap: 0.25rem;
    }

    .numbers-status .status-line {
        font-size: 0.9rem;
    }

    .numbers-status button {
        min-width: 34px;
        padding: 0.2rem 0.3rem;
    }

    .numbers-status.panel {
        padding: 0.25rem 0.35rem;
    }

    .hearts-container {
        font-size: 1.1rem;
    }

    .app-footer {
        bottom: 0.2rem;
        gap: 0.4rem;
    }

    .back-link {
        font-size: 0.75rem;
    }

    .panel {
        padding: 0.45rem;
    }

    .tab-description {
        font-size: 0.85rem;
    }
}