* {
    box-sizing: border-box;
}

:root {
    --bg-color: #fffafa;
    --text-color: #3d0a0a;
    --accent-color: #ff3333; /* Bright Red */
    --accent-hover: #cc0000;
    --slot-bg: #fffdfd;
    --slot-border: rgba(255, 51, 51, 0.2);
    --slot-hover: #fff5f5;
    --modal-bg: rgba(255, 255, 255, 0.95);
    --btn-text: #ffffff;
    --btn-shadow: #880000;
    
    --font-sans: 'Noto Sans JP', sans-serif;
    --font-serif: 'Noto Serif JP', 'Yu Mincho', serif;
}

/* Theme: Forest (Green) */
body.theme-forest {
    --bg-color: #f0fdf4;
    --text-color: #064e3b;
    --accent-color: #15803d;
    --accent-hover: #166534;
    --slot-bg: #f7faf7;
    --slot-border: rgba(21, 128, 61, 0.2);
    --slot-hover: #f0fdf4;
    --btn-shadow: #14532d;
}

/* Theme: Ocean (Blue) */
body.theme-ocean {
    --bg-color: #f0f9ff;
    --text-color: #0c4a6e;
    --accent-color: #0369a1;
    --accent-hover: #075985;
    --slot-bg: #f7f9fc;
    --slot-border: rgba(3, 105, 161, 0.2);
    --slot-hover: #e0f2fe;
    --btn-shadow: #0c4a6e;
}

/* Theme: Sakura (Pink) */
body.theme-sakura {
    --bg-color: #fffafb;
    --text-color: #9d174d;
    --accent-color: #ff69b4; /* Hot Pink */
    --accent-hover: #ff1493;
    --slot-bg: #fffcfd;
    --slot-border: rgba(255, 105, 180, 0.3);
    --slot-hover: #fff0f6;
    --btn-shadow: #c71585;
}

/* Theme: Purple */
body.theme-purple {
    --bg-color: #faf5ff;
    --text-color: #4c1d95;
    --accent-color: #8b008b; /* Dark Magenta/Purple */
    --accent-hover: #6a006a;
    --slot-bg: #fcfaff;
    --slot-border: rgba(139, 0, 139, 0.2);
    --slot-hover: #f5ebf5;
    --btn-shadow: #4a004a;
}

/* Theme: Yellow */
body.theme-yellow {
    --bg-color: #fffff8;
    --text-color: #713f12;
    --accent-color: #ffd700; /* Golden Yellow */
    --accent-hover: #e6c200;
    --slot-bg: #ffffff;
    --slot-border: rgba(255, 215, 0, 0.4);
    --slot-hover: #fffff0;
    --btn-shadow: #b39b00;
    --btn-text: #3d3222;
}

/* Theme: Orange */
body.theme-orange {
    --bg-color: #fffcf5;
    --text-color: #7c2903;
    --accent-color: #ffa500; /* Clear Orange */
    --accent-hover: #cc8400;
    --slot-bg: #fffdfa;
    --slot-border: rgba(255, 165, 0, 0.3);
    --slot-hover: #fff4e0;
    --btn-shadow: #996300;
}

/* Theme: Black (Accent mode) */
body.theme-black {
    --bg-color: #ffffff;
    --text-color: #111827;
    --accent-color: #000000;
    --accent-hover: #374151;
    --slot-bg: #ffffff;
    --slot-border: rgba(0, 0, 0, 0.1);
    --slot-hover: #f3f4f6;
    --modal-bg: rgba(255, 255, 255, 0.98);
    --btn-shadow: #4b5563;
}

/* Theme: Gray */
body.theme-gray {
    --bg-color: #fafafa;
    --text-color: #4b5563;
    --accent-color: #9ca3af;
    --accent-hover: #6b7280;
    --slot-bg: #ffffff;
    --slot-border: rgba(156, 163, 175, 0.3);
    --slot-hover: #f9fafb;
    --btn-shadow: #4b5563;
}

/* Theme: Brown */
body.theme-brown {
    --bg-color: #fdfaf7;
    --text-color: #432818;
    --accent-color: #a0522d; /* Sienna/Adjusted Brown */
    --accent-hover: #8b4513; /* SaddleBrown */
    --slot-bg: #ffffff;
    --slot-border: rgba(160, 82, 45, 0.2);
    --slot-hover: #fdf5f0;
    --btn-shadow: #5c2d14;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E"); /* Subtle paper noise */
    color: var(--text-color);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.app-container {
    max-width: 900px;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.controls-container {
    position: sticky;
    bottom: 2rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    margin-top: 2rem;
    width: 100%;
}

.download-btn {
    padding: 0.8rem 1.8rem;
    font-size: 1.1rem;
    font-weight: 900;
    background-color: var(--accent-color);
    color: var(--btn-text, #ffffff);
    border: 2px solid var(--accent-hover);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--btn-shadow, #5e2c0b), 0 8px 15px rgba(0,0,0,0.15);
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    position: relative;
    z-index: 100;
}

.download-btn:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 4px 0 var(--btn-shadow, #5e2c0b), 0 8px 15px rgba(0,0,0,0.2);
}

.download-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--btn-shadow, #5e2c0b), 0 4px 10px rgba(0,0,0,0.2);
}

.hidden {
    display: none !important;
}

.capture-options {
    background-color: rgba(253, 251, 247, 0.9);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--slot-border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    backdrop-filter: blur(4px);
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    user-select: none;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    background-color: #fff;
    border: 2px solid var(--slot-border);
    border-radius: 4px;
    position: relative;
    transition: all 0.2s;
}

.checkbox-container:hover .checkmark {
    border-color: var(--accent-color);
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 5px;
    top: 1px;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

/* Theme Picker Bubble */
.theme-picker {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateY(15px);
    background-color: var(--modal-bg);
    border: 1px solid var(--slot-border);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.8rem;
    backdrop-filter: blur(10px);
}

.theme-picker::before {
    content: "";
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--modal-bg);
}

.theme-option {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.theme-option:hover {
    transform: scale(1.15);
    border-color: rgba(0,0,0,0.3);
}

.theme-option.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 4px var(--accent-color);
}

/* Theme Option Colors */
.theme-option[data-theme="default"] { background-color: #ff3333; }
.theme-option[data-theme="theme-forest"] { background-color: #15803d; }
.theme-option[data-theme="theme-ocean"] { background-color: #0369a1; }
.theme-option[data-theme="theme-yellow"] { background-color: #ffd700; }
.theme-option[data-theme="theme-purple"] { background-color: #8b008b; }
.theme-option[data-theme="theme-sakura"] { background-color: #ff69b4; }
.theme-option[data-theme="theme-orange"] { background-color: #ffa500; }
.theme-option[data-theme="theme-brown"] { background-color: #a0522d; }
.theme-option[data-theme="theme-black"] { background-color: #000000; }
.theme-option[data-theme="theme-gray"] { background-color: #9ca3af; }

/* Hide theme picker during capture */
.is-capturing .theme-picker {
    display: none !important;
}

.capture-area {
    background-color: var(--bg-color);
    padding: 3rem;
    border-radius: 8px;
    border: 1px solid var(--slot-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    position: relative;
    /* Subtle canvas/paper texture */
    background-image: 
        linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 20px 20px;
}

.main-title {
    font-size: 2.2rem;
    color: var(--accent-color);
    margin-bottom: 2rem;
    font-family: var(--font-serif);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.5);
    width: 100%;
}

.editable-title {
    padding: 0.3rem 0.8rem 0.3rem 2.0rem; /* Restore left padding for icon */
    border-radius: 6px;
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s; /* Remove all to fix jitter on resize */
    outline: none;
    cursor: text;
    border: 1px dashed rgba(139, 69, 19, 0.25);
    background-color: rgba(255, 255, 255, 0.25);
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 150px;
    max-width: calc(100% - 6rem);
    white-space: nowrap;
    overflow: hidden;
    line-height: stretch;
}

/* Edit indicator icon on the left */
.editable-title::before {
    content: "✎";
    font-size: 1.4rem;
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    color: var(--accent-color);
    transition: opacity 0.2s;
    pointer-events: none;
}

.editable-title:hover {
    background-color: rgba(139, 69, 19, 0.08);
    border-color: rgba(139, 69, 19, 0.6);
}

.editable-title:hover::before {
    opacity: 0.8;
}

.editable-title:focus {
    background-color: rgba(255, 255, 255, 0.95);
    outline: 2px dashed var(--accent-color);
    outline-offset: 4px;
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(139, 69, 19, 0.1);
}

/* Hide editing artifacts during capture */
.is-capturing .editable-title {
    border: none !important;
    background-color: transparent !important;
    outline: none !important;
    padding: 0.3rem 0.5rem !important;
    box-shadow: none !important;
}

.is-capturing .editable-title::before {
    display: none !important;
}

.meeple-icon {
    width: 2.2rem;
    height: auto;
    flex-shrink: 0;
    /* fill: var(--accent-color);  Moved to .meeple-shape */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer; /* Indicates interactivity */
}

.meeple-shape {
    fill: var(--accent-color);
    transition: fill 0.3s;
}

.meeple-icon:hover {
    transform: rotate(0deg) scale(1.2);
}

.meeple-icon:active {
    transform: scale(0.95);
}

.main-title svg:first-of-type {
    transform: rotate(-10deg);
}

.main-title svg:last-of-type {
    transform: rotate(10deg);
}

.main-title .highlight {
    color: var(--accent-color);
    font-size: 2.8rem;
    font-style: italic;
    padding: 0 0.2rem;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0px;
    width: 100%;
}

.grid-slot {
    background-color: var(--slot-bg);
    border: 2px dashed var(--slot-border);
    border-radius: 6px; /* Like a card corner */
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.02);
    overflow: hidden;
    touch-action: none; /* Prevent scroll/zoom during drag */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* Simulate empty card slots on a player mat */
.grid-slot::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    border: 1px solid rgba(212, 196, 183, 0.5);
    border-radius: 4px;
    pointer-events: none;
}

.grid-slot.is-hovered {
    border-style: solid;
    border-color: var(--accent-color);
    background-color: var(--slot-hover);
    transform: scale(1.02) rotate(1deg);
    box-shadow: 0 8px 16px rgba(62, 50, 34, 0.1);
    z-index: 2;
}

.grid-slot.has-image {
    border: none;
    background-color: transparent;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3); /* Card shadow */
    border-radius: 0;
}

.grid-slot.has-image::before {
    display: none;
}

.grid-slot.has-image.is-hovered {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.4);
    z-index: 10;
}

/* Drag and Drop Feedback */
.grid-slot.dragging {
    opacity: 0.5;
    z-index: 100;
}

.grid-slot.drag-over {
    border: 3px solid var(--accent-color) !important;
    background-color: var(--slot-hover) !important;
    transform: scale(1.05) !important;
    z-index: 100 !important;
}

/* Long press visual feedback */
.touch-lifting {
    transform: scale(1.1) rotate(2deg) !important;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5) !important;
    z-index: 1000 !important;
    animation: touch-pulse 0.4s infinite alternate ease-in-out;
    opacity: 1 !important; /* Force visible for the lifted item */
}

.touch-lifting .slot-image {
    opacity: 1 !important; /* Ensure image is visible while carrying */
}

@keyframes touch-pulse {
    from { transform: scale(1.1) rotate(1deg); }
    to { transform: scale(1.15) rotate(3deg); }
}

.slot-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--icon-color);
    font-family: var(--font-serif);
}

.grid-slot.has-image .slot-content {
    display: none;
}

.add-icon {
    font-size: 2.5rem;
    font-weight: 300;
    line-height: 1;
    margin-bottom: 8px;
    color: var(--slot-border);
}

.grid-slot.is-hovered .add-icon {
    color: var(--accent-color);
}

.slot-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    border-radius: 0;
    z-index: 2;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.2s;
    backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

body.no-scroll {
    overflow: hidden;
}

#full-page-loader {
    z-index: 9999;
    background-color: rgba(0, 0, 0, 0.5);
}

#full-page-loader .loader {
    width: 50px;
    height: 50px;
    border-width: 5px;
}

.is-capturing-no-title .main-title {
    display: none !important;
}

.modal-content {
    background-color: #faf7f2;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 2rem;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(1);
    transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    position: relative;
}



.modal-content.confirm-content {
    max-width: 400px;
    padding: 2.5rem 2rem;
    text-align: center;
}

.confirm-content h3 {
    margin-top: 0;
    color: var(--accent-color);
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.confirm-content p {
    margin-bottom: 2rem;
    line-height: 1.6;
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
}

.confirm-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-primary, .btn-secondary {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-secondary {
    background-color: #eee;
    color: #666;
}

.btn-secondary:hover {
    background-color: #e0e0e0;
}

.search-filters {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 1.5rem;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 30px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.filter-option {
    position: relative;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-color);
    padding: 0.5rem 1.2rem;
    border-radius: 25px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.filter-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.filter-label {
    font-weight: 600;
    opacity: 0.7;
}

.filter-option:has(input[type="radio"]:checked) {
    background: var(--accent-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.filter-option:has(input[type="radio"]:checked) .filter-label {
    color: white;
    opacity: 1;
}

.filter-option:hover:not(:has(input[type="radio"]:checked)) {
    background: rgba(0, 0, 0, 0.08);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.95);
}

.modal-header {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 2rem;
}

.modal-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-color);
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 0.5rem;
}

.close-btn {
    position: absolute;
    right: -1rem;
    top: -1rem;
    background: #faf7f2;
    border: 2px solid var(--accent-color);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    line-height: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.close-btn:hover {
    background-color: var(--accent-color);
    color: #fff;
    transform: scale(1.1);
}

.search-input-wrapper {
    position: relative;
    margin-bottom: 1rem;
}

.search-icon {
    position: absolute;
    left: 1.2rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-color);
}

#game-search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3.5rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    border: 2px solid #d4c4b7;
    background-color: #fff;
    border-radius: 4px; /* Boxy aesthetic */
    outline: none;
    transition: box-shadow 0.2s, border-color 0.2s;
    color: var(--text-color);
}

#game-search-input:focus {
    box-shadow: inset 0 0 0 1px var(--accent-color);
    border-color: var(--accent-color);
}

.search-results {
    list-style: none;
    overflow-y: auto;
    max-height: 350px;
    border-radius: 4px;
    border: 1px solid #d4c4b7;
    background-color: #fff;
    flex-grow: 1;
}

/* Scrollbar styling for a cleaner look */
.search-results::-webkit-scrollbar {
    width: 8px;
}
.search-results::-webkit-scrollbar-track {
    background: #f4efe6; 
}
.search-results::-webkit-scrollbar-thumb {
    background: #d4c4b7; 
    border-radius: 4px;
}
.search-results::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color); 
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 0.2rem 1.2rem;
    border-bottom: 1px solid #f4efe6;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background-color 0.1s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover, .search-result-item.active {
    background-color: #f1ebd9;
}

.search-result-item.more-results {
    border-top: 1px dashed var(--accent-light);
    margin-top: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item.more-results:hover {
    background-color: rgba(0, 0, 0, 0.05); /* Subtle highlight */
}

.search-result-item.more-results .result-name {
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--accent-color) !important;
}

.result-thumb-wrapper {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    background-color: #e2d5c3;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0,0,0,0.1);
}

.result-thumb {
    width: 100%;
    height: 100%;
    object-fit: fill; /* Force fill to square container */
}

.result-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    flex-grow: 1;
}

.result-name {
    font-family: var(--font-serif);
    font-weight: 900; /* Extra Bold for maximum visibility */
    color: var(--text-color);
    transition: color 0.1s;
    line-height: 1.2;
}

.result-subname {
    font-family: var(--font-serif);
    font-weight: 900;
    color: var(--text-color);
    font-size: 0.8rem;
    line-height: 1.2;
    display: block;
}

.search-result-item:hover .result-name,
.search-result-item.active .result-name {
    color: var(--accent-color);
}

.result-year {
    font-size: 0.8rem;
    color: #8a7b6b;
}

.search-result-item:hover .result-year,
.search-result-item.active .result-year {
    color: var(--accent-hover);
}

/* Loaders */
.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem;
    color: var(--text-color);
    font-weight: 600;
    font-family: var(--font-serif);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 100;
}

.loading-indicator.hidden {
    display: none;
}

.loader {
    border: 3px solid rgba(139, 69, 19, 0.2);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

.loader.large {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

.loader.small {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.footer-loader-item {
    display: flex;
    justify-content: center;
    padding: 10px;
    border-bottom: 1px solid #f4efe6;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Overrides for html2canvas to ensure good quality */
.capture-mode {
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 3rem !important;
    background-color: #faf7f2 !important;
    background-image: none !important; /* simplify capture */
}

/* Toast Notification */
.toast-message {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(50px);
    background-color: rgba(50, 50, 50, 0.9);
    color: #fff;
    padding: 0.8rem 1.5rem;
    border-radius: 30px;
    font-family: var(--font-sans);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.3s ease;
    z-index: 2000;
    pointer-events: none;
    white-space: nowrap;
}

.toast-message.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* =========================================
   Responsive Design (Mobile & Tablet)
   ========================================= */

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }
    
    .capture-area {
        padding: 1.5rem;
        border-radius: 0; 
        border: none;
        box-shadow: 0 4px 15px rgba(62, 50, 34, 0.1);
    }

    .main-title {
        font-size: 1.8rem;
    }

    .main-title .highlight {
        font-size: 2.2rem;
    }

    .grid-container {
        gap: 0px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0.5rem;
        padding-bottom: 7rem; /* Increased to avoid overlap with controls */
    }
    
    .controls-container {
        position: fixed !important; /* Force fixed for mobile */
        flex-direction: column;
        gap: 0.8rem;
        padding: 1.2rem 1rem;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        transform: none !important; /* CLEAR BASE TRANSFORM */
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 25px rgba(0,0,0,0.15);
        z-index: 9999;
    }

    body.modal-open .controls-container {
        display: none !important;
    }

    .checkbox-container {
        white-space: nowrap;
        font-size: 0.9rem;
    }

    .download-btn {
        position: static;
        width: 100%;
        justify-content: center;
        margin-top: 0.2rem;
    }

    .capture-area {
        padding: 1rem;
    }

    .main-title {
        font-size: 1.2rem; /* Shrunk for long titles */
        margin-bottom: 1.2rem;
        gap: 0.6rem;
    }

    .editable-title {
        max-width: 250px;
        overflow: visible !important;
        text-overflow: clip;
        white-space: nowrap;
        font-size: 1.1rem;
        padding-left: 2.8rem; /* Adjusted for larger icon */
        outline: none !important; /* Remove mystery focus lines */
        border: 1px dashed rgba(139, 69, 19, 0.25) !important; /* Restore dashed line */
        box-shadow: none !important;
        background-color: transparent !important;
        display: flex !important; /* Better box behavior */
    }

    .editable-title:focus {
        outline: none !important;
        border: 1px dashed var(--accent-color) !important;
        background-color: rgba(255, 255, 255, 0.8) !important;
    }

    .main-title .meeple-icon {
        width: 2rem;
        height: 2rem;
    }

    .grid-container {
        gap: 0px;
    }

    .add-icon {
        font-size: 1.8rem;
    }
    
    .modal-title {
        font-size: 1.2rem;
    }

    .confirm-actions {
        flex-wrap: nowrap; /* Prevent button wrapping */
    }

    .btn-primary, .btn-secondary {
        padding: 0.8rem 1.2rem;
        font-size: 0.9rem;
        flex: 1; /* Equal width buttons */
    }
}

/* Guard for theme picker on small screens */
.theme-picker {
    max-width: 90vw;
}
/* App Footer */
.app-footer {
    margin-top: 3rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
    border-top: 1px solid var(--slot-border);
    padding-top: 1.5rem;
}

.credits-link {
    font-size: 0.85rem;
    color: var(--accent-color);
    text-decoration: underline;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.2s;
    font-weight: 600;
    display: inline-block;
}

.credits-link:hover {
    opacity: 1;
    transform: translateY(-1px);
}

/* Credits Modal Specific */
.credits-content {
    max-width: 400px;
}

.credits-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.credit-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.credit-label {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.3rem;
}

.credit-link, .bgg-credit-link {
    font-size: 0.8rem;
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s, opacity 0.2s, transform 0.2s;
    display: inline-block;
}

.credit-link:hover {
    opacity: 0.7;
    transform: translateY(-1px);
}

.bgg-credit-link {
    display: block;
    width: fit-content;
}

.bgg-credit-link:hover {
    transform: scale(1.02);
}

.bgg-logo-img {
    height: 45px;
    width: auto;
    display: block;
    margin-top: 0.2rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.credits-footer {
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--slot-border);
    text-align: center;
}

.copyright {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-color);
}

/* Hide footer during capture */
.is-capturing .app-footer {
    display: none !important;
}
.share-icon-wrapper {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.share-icon-wrapper svg {
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

.share-modal-content {
    text-align: center;
    padding: 2.5rem 2rem;
}

.share-modal-content h3 {
    margin-top: 0;
    color: var(--accent-color);
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    font-family: var(--font-serif);
}

.share-label {
    display: block;
    font-weight: 900;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.share-url-container {
    display: flex;
    gap: 0;
    margin: 0.5rem 0 2rem;
    background: #fff;
    border: 1px solid #d4c4b7;
    border-radius: 6px;
    padding: 4px;
    overflow: hidden;
}

#share-url-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    color: #666;
    outline: none;
    width: 0;
}

.modal-copy-btn {
    background-color: #ff3b30; /* Bright Red */
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0 1.2rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-copy-btn:active {
    transform: scale(0.95);
    filter: brightness(0.9);
}

.modal-copy-btn:hover {
    filter: brightness(1.1);
}

.confirm-actions.centered {
    justify-content: center;
    margin-top: 0.5rem;
}

.btn-close-large {
    background-color: #ff3b30;
    color: white;
    padding: 0.8rem 3rem;
    font-size: 1.2rem;
    font-weight: 900;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 #b32b22;
    transition: all 0.1s;
}

.btn-close-large:hover {
    filter: brightness(1.1);
}

/* App Footer */
.app-footer {
    margin-top: 3rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
    border-top: 1px solid var(--slot-border);
    padding-top: 1.5rem;
}

.credits-link {
    font-size: 0.85rem;
    color: var(--accent-color);
    text-decoration: underline;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.2s;
    font-weight: 600;
    display: inline-block;
}

.credits-link:hover {
    opacity: 1;
    transform: translateY(-1px);
}

/* Credits Modal Specific */
.credits-content {
    max-width: 400px;
}

.credits-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.credit-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.credit-label {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.3rem;
}

.credit-link, .bgg-credit-link {
    font-size: 0.9rem;
    color: var(--accent-color);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 700;
    transition: all 0.2s;
    display: inline-block;
}

.credit-link:hover, .bgg-credit-link:hover {
    opacity: 0.7;
    transform: translateY(-2px);
    color: var(--accent-hover);
}

.bgg-logo-img {
    height: 45px;
    width: auto;
    display: block;
    margin-top: 0.2rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    transition: transform 0.2s;
}

.bgg-credit-link:hover .bgg-logo-img {
    transform: scale(1.05);
}

.credits-footer {
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--slot-border);
    text-align: center;
}

.copyright {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-color);
    opacity: 0.7;
    margin-bottom: 0.3rem;
}

.app-info {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-version {
    font-size: 0.75rem;
    color: var(--accent-color);
    margin-left: 0.5rem;
    font-weight: 600;
    background-color: rgba(255, 51, 51, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

/* Hide footer during capture */
.is-capturing .app-footer {
    display: none !important;
}
.share-icon-wrapper {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.share-icon-wrapper svg {
    stroke: var(--accent-color);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

.share-modal-content {
    text-align: center;
    padding: 2rem;
}

.share-modal-content .modal-header {
    margin-bottom: 1.5rem;
}

.share-label {
    display: block;
    font-weight: 900;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.share-url-container {
    display: flex;
    flex-direction: column;
    margin: 0.5rem 0 0.5rem;
    background: #fff;
    border: 1px solid #d4c4b7;
    border-radius: 6px;
    padding: 10px;
    overflow: hidden;
}

#share-url-input {
    width: 100%;
    min-height: 40px;
    height: auto;
    border: none;
    background: transparent;
    padding: 0.4rem;
    font-size: 0.95rem;
    color: #444;
    outline: none;
    resize: none;
    font-family: var(--font-sans);
    line-height: 1.5;
    white-space: pre;
    overflow-x: auto;
    overflow-y: hidden;
    /* Hide scrollbar but keep functionality */
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}

#share-url-input::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.btn-copy-large {
    padding: 0.8rem 2rem;
    font-size: 1rem;
    font-weight: 900;
    border-radius: 12px;
    box-shadow: 0 4px 0 var(--btn-shadow);
}

.btn-copy-large:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--btn-shadow);
}

.modal-copy-btn:active {
    transform: scale(0.95);
    filter: brightness(0.9);
}

.modal-copy-btn:hover {
    filter: brightness(1.1);
}

.confirm-actions.centered {
    justify-content: center;
    margin-top: 0.5rem;
}

.btn-close-large {
    background-color: var(--accent-color);
    color: var(--btn-text, #fff);
    padding: 0.8rem 3rem;
    font-size: 1.2rem;
    font-weight: 900;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--btn-shadow);
    transition: all 0.1s;
}

.btn-close-large:hover {
    filter: brightness(1.1);
}

.btn-close-large:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #b32b22;
}

/* Responsive constraints for the title editing icon */
@media (max-width: 600px) {
    .editable-title {
        padding: 0.3rem 0.4rem 0.3rem 1.2rem;
    }
    .editable-title::before {
        font-size: 0.6rem;
        left: 0.3rem;
    }
}

.footer-separator {
    display: inline-block;
    width: 1px;
    height: 12px;
    background-color: var(--slot-border);
    margin: 0 0.375rem; /* Further reduced to 0.375rem as requested */
    vertical-align: middle;
    opacity: 0.5;
}

.modal-content {
    display: flex;
    flex-direction: column;
    max-height: 85vh; /* Limit modal height */
    overflow: hidden; /* Hide outer overflow to allow inner scroll only */
}

.credits-content {
    max-width: 400px;
}

.privacy-modal-content {
    max-width: 630px;
}

.credits-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
    overflow-y: auto; /* Enable scrolling only here */
    padding-right: 0.5rem; /* Add small padding for scrollbar */
}

/* Selected Games BGG Links List */
.selected-links-container {
    margin: 1.5rem auto;
    max-width: 600px;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    border-radius: 16px;
    border: 1px solid var(--slot-border);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: opacity 0.3s, transform 0.3s;
}

.selected-links-container.hidden {
    display: none;
}

.selected-link-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 0; /* Important for text-overflow in grid */
}

.selected-link-item:hover {
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.selected-link-icon {
    color: var(--accent-color);
    flex-shrink: 0;
}

.selected-link {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.selected-link:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

@media (max-width: 600px) {
    .selected-links-container {
        margin: 1rem 0.5rem 3rem 0.5rem;
        font-size: 0.85rem;
        padding: 1rem;
    }
    .app-footer {
        margin-top: 1.5rem;
    }
    .selected-link {
        font-size: 0.9rem;
    }
}
