/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --primary-dark: #1d4ed8;
    --bg-body: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --tile-bg: #ffffff;
    --tile-border: #e2e8f0;
    --tile-depth: #cbd5e1;
    --tile-radius: 8px;
    --tile-size: clamp(40px, 13.6vw, 56px);
    --grid-gap: clamp(4px, 1.3vw, 8px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(10px, 2.5vw, 24px) clamp(6px, 1.5vw, 16px);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Container for the whole game */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 440px;
    gap: clamp(12px, 3.5vw, 20px);
}

/* Header & Category Badge */
header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.app-title {
    font-size: clamp(1.75rem, 7.5vw, 2.25rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    text-align: center;
    color: var(--text-main);
    line-height: 1.1;
}

.date-subheader {
    font-size: clamp(0.78rem, 3.2vw, 0.9rem);
    font-weight: 500;
    color: var(--text-muted);
}

.category-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 4px 14px;
    border-radius: 9999px;
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    font-size: clamp(0.72rem, 2.8vw, 0.82rem);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border: 1px solid #bfdbfe;
    margin-top: 2px;
    transition: all 0.15s ease;
    cursor: pointer;
    user-select: none;
}

.category-badge:hover {
    background-color: #dbeafe;
    border-color: #93c5fd;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
}

.category-badge:active {
    transform: translateY(1px);
}

.category-badge .typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: var(--primary);
    margin-left: 2px;
    border-radius: 1px;
    animation: cursorBlink 0.65s step-end infinite;
    vertical-align: baseline;
    transition: opacity 0.3s ease;
}

.category-badge .typing-cursor.fade-out {
    opacity: 0;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Main Layout */
main {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Guess Row: 5-col Guess Display + 1-col Submit Button */
.guess-area {
    display: grid;
    grid-template-columns: calc(5 * var(--tile-size) + 4 * var(--grid-gap)) var(--tile-size);
    grid-auto-rows: var(--tile-size);
    gap: var(--grid-gap);
    width: calc(6 * var(--tile-size) + 5 * var(--grid-gap));
    margin-bottom: 32px;
}

.guess-line {
    width: 100%;
    height: 100%;
    min-height: var(--tile-size);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    letter-spacing: 0.08em;
    font-size: clamp(1.4rem, 6.2vw, 2rem);
    font-weight: 800;
    color: var(--text-main);
    background: transparent;
    border: none;
    border-bottom: 3px solid var(--tile-depth);
    border-radius: 0;
    padding: 0 4px 4px 4px;
    box-sizing: border-box;
    position: relative;
    overflow-x: hidden;
    overflow-y: hidden;
    user-select: none;
    cursor: default;
    line-height: 1;
    white-space: nowrap;
}

/* 5x5 Board slot containers */
.board-slot {
    width: var(--tile-size);
    height: var(--tile-size);
    aspect-ratio: 1 / 1;
    border-radius: var(--tile-radius);
    background-color: rgba(226, 232, 240, 0.45);
    border: 1.5px dashed rgba(203, 213, 225, 0.85);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
}

.board-slot .tile {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
}

.board-slot.empty .tile {
    display: none;
}

/* Main Play Area (5-col Board + 1-col Toolbar) */
.play-area {
    display: grid;
    grid-template-columns: calc(5 * var(--tile-size) + 4 * var(--grid-gap)) var(--tile-size);
    gap: var(--grid-gap);
    width: calc(6 * var(--tile-size) + 5 * var(--grid-gap));
    align-items: start;
}

.board-column {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(5, var(--tile-size));
    grid-auto-rows: var(--tile-size);
    gap: var(--grid-gap);
}

.stats-grid-container {
    display: grid;
    grid-template-columns: repeat(5, var(--tile-size));
    grid-auto-rows: var(--tile-size);
    gap: var(--grid-gap);
    margin-top: 32px;
}

.actions-container {
    display: grid;
    grid-template-columns: repeat(1, var(--tile-size));
    grid-auto-rows: var(--tile-size);
    gap: var(--grid-gap);
    flex: 0 0 auto;
    width: var(--tile-size);
}

/* Tile Component & Tactile Physics */
.tile {
    aspect-ratio: 1 / 1;
    background-color: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-bottom: 3px solid var(--tile-depth);
    border-radius: var(--tile-radius);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: clamp(1.2rem, 5.2vw, 1.65rem);
    color: var(--text-main);
    user-select: none;
    touch-action: manipulation;
    transition: transform 0.08s ease, border-color 0.12s ease, background-color 0.12s ease;
}

.tile:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.tile:active {
    transform: translateY(2px);
    border-bottom-width: 1px;
}

.tile:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Stats Tiles */
.tile.stat-tile {
    aspect-ratio: auto;
    width: 100%;
    height: 100%;
    flex-direction: column;
    gap: 1px;
    cursor: default;
    background-color: #ffffff;
}

.tile.stat-tile.double-width {
    grid-column: span 2;
}

.tile.stat-tile .stat-value {
    font-size: clamp(0.95rem, 4vw, 1.2rem);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
    white-space: nowrap;
}

.tile.stat-tile .stat-label {
    font-size: clamp(0.55rem, 2.3vw, 0.68rem);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.tile.stat-tile.clickable {
    cursor: pointer;
}

.tile.stat-tile.clickable .stat-value {
    color: var(--primary);
}

.tile.stat-tile.clickable:hover {
    background-color: var(--primary-light);
    border-color: #bfdbfe;
}

.tile.stat-tile.clickable:active {
    transform: translateY(2px);
    border-bottom-width: 1px;
}

/* Action Buttons & Icons */
.tile.btn-action {
    background-color: #ffffff;
}

/* Primary Submit Action Button */
.tile.btn-submit {
    width: 100%;
    height: 100%;
    background-color: var(--primary);
    border-color: #1d4ed8;
    border-bottom: 3px solid #1e40af;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.tile.btn-submit img {
    filter: brightness(0) invert(1);
    width: 52%;
    height: 52%;
}

.tile.btn-submit:hover {
    background-color: #1d4ed8;
    border-color: #1e40af;
}

.tile.btn-submit:active {
    background-color: #1e40af;
    transform: translateY(2px);
    border-bottom-width: 1px;
}

.tile img {
    width: 52%;
    height: 52%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}

.tile.gap {
    background: transparent;
    border: none;
    box-shadow: none;
    cursor: default;
    pointer-events: none;
}

/* Badge overlay */
.tile-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
}

.tile-wrapper .tile {
    width: 100%;
    height: 100%;
}

.tile-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--primary);
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 800;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    border: 1.5px solid #ffffff;
    z-index: 10;
    pointer-events: none;
}

/* Game Container relative positioning */
.game-container {
    position: relative;
}

/* Conceal category badge & play area until game starts */
.game-unstarted #category-badge,
.game-unstarted #game-main {
    opacity: 0;
    filter: blur(8px);
    pointer-events: none;
    user-select: none;
}

#category-badge,
#game-main {
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), filter 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Start / Instructions Sheet Overlay */
.start-overlay {
    position: absolute;
    top: 66px;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 50;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: translateY(-8px) scale(0.98);
}

.start-card {
    background-color: #ffffff;
    width: 100%;
    max-width: calc(6 * var(--tile-size) + 5 * var(--grid-gap));
    border-radius: 16px;
    padding: clamp(18px, 4.5vw, 24px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--tile-border);
    border-bottom: 3px solid var(--tile-depth);
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 3.5vw, 20px);
}

.start-card-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

.start-pill {
    display: inline-flex;
    padding: 3px 12px;
    border-radius: 9999px;
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border: 1px solid #bfdbfe;
}

.start-title {
    font-size: clamp(1.3rem, 5.5vw, 1.6rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-main);
}

.start-subtitle {
    font-size: clamp(0.78rem, 3vw, 0.86rem);
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.35;
    max-width: 280px;
}

.start-rules-list {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 2vw, 12px);
}

.rule-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background-color: #f8fafc;
    border: 1px solid var(--tile-border);
    border-radius: 10px;
    padding: 10px 12px;
}

.rule-number-box {
    aspect-ratio: 1 / 1;
    width: 36px;
    height: 36px;
    background-color: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-bottom: 3px solid var(--tile-depth);
    border-radius: var(--tile-radius);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
    user-select: none;
}

.rule-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rule-content h3 {
    font-size: clamp(0.85rem, 3.2vw, 0.92rem);
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.rule-content p {
    font-size: clamp(0.76rem, 2.9vw, 0.82rem);
    line-height: 1.35;
    color: var(--text-muted);
}

.rule-content p strong {
    color: var(--text-main);
    font-weight: 800;
}

/* Big Tactile Start Button */
.btn-start {
    width: 100%;
    height: 52px;
    background-color: var(--primary);
    color: #ffffff;
    border: 1px solid #1d4ed8;
    border-bottom: 4px solid #1e40af;
    border-radius: 12px;
    font-size: clamp(1rem, 4vw, 1.15rem);
    font-weight: 800;
    letter-spacing: 0.06em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    transition: transform 0.08s ease, background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
    user-select: none;
    touch-action: manipulation;
    margin-top: 4px;
}

.btn-start:hover {
    background-color: #1d4ed8;
    border-color: #1e40af;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.btn-start:active {
    background-color: #1e40af;
    transform: translateY(3px);
    border-bottom-width: 1px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.btn-start:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Modern Frosted Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 16px;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: #ffffff;
    width: 100%;
    max-width: 320px;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--tile-border);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.show .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--tile-border);
    padding-bottom: 10px;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-main);
}

.modal-close-btn {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.modal-close-btn:hover {
    color: var(--text-main);
    background-color: #f1f5f9;
}

.guessed-words-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}

.guessed-words-list::-webkit-scrollbar {
    width: 5px;
}
.guessed-words-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}
.guessed-words-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.guessed-word-tag {
    background-color: #ffffff;
    border: 1px solid var(--tile-border);
    border-bottom: 2px solid var(--tile-depth);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Smooth Staggered Board Tile Entrance */
.tile.tile-deal {
    animation: tileFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes tileFadeIn {
    0% {
        opacity: 0;
        transform: translateY(8px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hint Highlighted Tile (Blue Outlines) */
.tile.tile-hint {
    background-color: var(--tile-bg);
    border-color: var(--primary);
    border-bottom: 3px solid var(--primary-dark);
    color: var(--text-main);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.5), 0 2px 6px rgba(37, 99, 235, 0.15);
    animation: hintPulse 1.8s ease-in-out infinite;
}

.tile.tile-hint:hover {
    background-color: var(--primary-light);
    border-color: var(--primary);
    border-bottom-color: var(--primary-dark);
}

.tile.tile-hint:active {
    transform: translateY(2px);
    border-bottom-width: 1px;
}

@keyframes hintPulse {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4), 0 2px 6px rgba(37, 99, 235, 0.1);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 3.5px rgba(37, 99, 235, 0.75), 0 3px 8px rgba(37, 99, 235, 0.25);
        transform: scale(1.03);
    }
}

/* Shake Animation for Invalid / Duplicate Submissions */
.shake {
    animation: shakeAnim 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shakeAnim {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Floating Toast Notifications */
.toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    background-color: var(--text-main);
    color: #ffffff;
    padding: 10px 18px;
    border-radius: 9999px;
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.15);
    animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.toast.toast-exit {
    animation: toastOut 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastIn {
    0% {
        opacity: 0;
        transform: translateY(-12px) scale(0.92);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastOut {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-8px) scale(0.92);
    }
}

/* Simple & Clean Victory Modal Styling */
.win-card.simple-win-card {
    position: relative;
    width: 100%;
    max-width: calc(6 * var(--tile-size) + 5 * var(--grid-gap));
    border-radius: 18px;
    padding: clamp(20px, 5vw, 28px) clamp(16px, 4vw, 24px);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.simple-win-card .win-title {
    font-size: clamp(1.5rem, 6.5vw, 1.9rem);
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.03em;
}

.simple-win-card .win-share-box {
    width: 100%;
    background-color: #f8fafc;
    border: 1px solid var(--tile-border);
    border-bottom: 2px solid var(--tile-depth);
    border-radius: 12px;
    padding: 16px 14px;
    font-size: clamp(0.85rem, 3.4vw, 0.98rem);
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 0.01em;
    user-select: all;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    line-height: 1.4;
}

.simple-win-card .win-share-box .share-line {
    width: 100%;
    text-align: center;
    word-break: break-word;
}

.simple-win-card .win-share-box:hover {
    background-color: var(--primary-light);
    border-color: #bfdbfe;
    color: var(--primary-dark);
}

.simple-win-card .win-share-box:active {
    transform: translateY(1px);
}

.simple-win-card .btn-share {
    width: 100%;
    margin-top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.simple-win-card .btn-share .btn-icon {
    flex-shrink: 0;
}


