body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    display: flex;
    justify-content: center;
    /* align-items: center;  Removed to fix mobile scrolling issues with long content */
    min-height: 100vh;
    /* touch-action: none; Removed to allow scrolling on mobile */
    overflow-y: auto; /* Ensure vertical scrolling is enabled */
}

.container {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.game-area {
    width: 100%;
}

.sidebar {
    width: 100%;
}

h1 {
    color: #333;
    margin-bottom: 10px;
}

#level-info {
    font-size: 1.2em;
    margin-bottom: 15px;
    color: #555;
}

#game-board {
    position: relative;
    width: 100%;
    height: 0; /* Will be set by JS */
    background-color: #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin: 0 auto 20px;
    /* touch-action: none; Removed to allow scrolling on background */
}

.puzzle-piece {
    position: absolute;
    background-size: cover;
    border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2), 0 2px 4px rgba(0,0,0,0.2);
    cursor: grab;
    transition: left 0.2s ease-out, top 0.2s ease-out;
    z-index: 10;
    box-sizing: border-box; 
    transform: scale(0.96);
}

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    transition: none;
    transform: scale(1.02);
}

.puzzle-piece.merged {
    border-radius: 0;
    transform: scale(1);
    box-shadow: none;
    z-index: 5;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #45a049;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

#message {
    height: 20px;
    color: #d9534f;
    font-weight: bold;
}

/* PC Layout: Side-by-side */
@media (min-width: 768px) {
    body {
        align-items: center; /* Center vertically on PC */
    }

    .container {
        flex-direction: row;
        max-width: 1200px; /* Increased max-width for side-by-side */
        align-items: flex-start; /* Align top */
        gap: 40px;
    }

    .game-area {
        flex: 2; /* Takes more space */
        min-width: 600px; /* Minimum width for game board on PC */
    }

    .sidebar {
        flex: 1; /* Takes less space */
        text-align: left;
        padding-top: 20px;
    }

    .controls {
        justify-content: flex-start; /* Align buttons to left on PC */
    }
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 200; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    position: relative;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 10px;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.categories-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 15px 0;
    max-height: 300px;
    overflow-y: auto;
    justify-content: space-between;
}

.category-item {
    display: flex;
    align-items: center;
    width: 48%; /* Two columns */
    margin-bottom: 8px;
    background: #f9f9f9;
    padding: 8px;
    border-radius: 5px;
    box-sizing: border-box;
}

.category-item:hover {
    background: #eee;
}

.category-item input {
    margin-right: 10px;
    transform: scale(1.2);
    cursor: pointer;
}

.category-item label {
    cursor: pointer;
    text-transform: capitalize;
    font-size: 14px;
    user-select: none;
    flex: 1;
}

.modal-footer {
    text-align: right;
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

#save-settings-btn {
    background-color: #2196F3;
}

#save-settings-btn:hover {
    background-color: #0b7dda;
}

/* Mobile Layout Optimizations */
@media (max-width: 767px) {
    .container {
        padding-bottom: 80px; /* Ensure space for scrolling to bottom */
    }

    .game-area {
        margin-bottom: 30px;
    }
}

/* ===== 难度选择器 ===== */
.difficulty-section select:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

/* ===== 原图预览区 ===== */
.preview-section {
    background: #fafafa;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #eee;
}

.preview-image {
    transition: transform 0.2s, box-shadow 0.2s;
}

.preview-image:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 预览图全屏放大遮罩层 */
.preview-zoom-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    cursor: zoom-out;
    animation: previewFadeIn 0.2s ease-out;
}

.preview-zoom-overlay img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

@keyframes previewFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== 图片选择器模态框：更大更居中 ===== */
#image-picker-modal {
    display: none;
    position: fixed;
    z-index: 200;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

#image-picker-modal .modal-content {
    background-color: #fefefe;
    margin: 5vh auto;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 1100px;
    max-height: 85vh;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#image-picker-modal .close-image-picker {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

#image-picker-modal .close-image-picker:hover,
#image-picker-modal .close-image-picker:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.image-picker-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
    margin-top: 10px;
}

.picker-category-group {
    margin-bottom: 22px;
}

.picker-category-group h3 {
    margin: 0 0 10px 0;
    color: #333;
    text-transform: capitalize;
    font-size: 16px;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 5px;
}

.picker-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.picker-image-item {
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    aspect-ratio: 3 / 4;
    border: 2px solid transparent;
    transition: transform 0.15s, border-color 0.15s;
    background: #f0f0f0;
    position: relative;
}

.picker-image-item:hover {
    border-color: #4CAF50;
    transform: scale(1.05);
}

.picker-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.picker-image-item.load-error::after {
    content: '加载失败';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b94a48;
    font-size: 12px;
    background: #fff0f0;
}

/* ===== 图片选择器：预览确认层 ===== */
.picker-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 310; /* 高于图片选择器模态框(200)与预览放大层(300) */
    padding: 20px;
    box-sizing: border-box;
    animation: previewFadeIn 0.2s ease-out;
}

.picker-preview-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 100%;
}

.picker-preview-content img {
    max-width: min(90vw, 480px);
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    object-fit: contain;
}

.picker-preview-info {
    color: #fff;
    font-size: 15px;
    text-transform: capitalize;
}

.picker-preview-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.picker-preview-actions button {
    padding: 10px 20px;
    font-size: 15px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #fff;
    transition: background-color 0.2s;
}

#picker-preview-confirm {
    background-color: #4CAF50;
}

#picker-preview-confirm:hover {
    background-color: #45a049;
}

#picker-preview-cancel {
    background-color: #757575;
}

#picker-preview-cancel:hover {
    background-color: #616161;
}

/* ========== 拼图完成庆祝动画 ========== */
.confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9998;
}

.celebrate-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.celebrate-overlay.show {
    opacity: 1;
}

.celebrate-text {
    font-size: clamp(36px, 7vw, 72px);
    font-weight: bold;
    color: #ffeb3b;
    text-shadow:
        0 0 12px rgba(255, 193, 7, 0.9),
        0 0 24px rgba(255, 87, 34, 0.7),
        3px 3px 0 #e91e63;
    animation: celebrateBounce 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    background: linear-gradient(45deg, #ff6b6b, #ffd93d, #6bcf7f, #4d9de0, #e15554);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: celebrateBounce 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               celebrateGradient 3s ease infinite;
}

.celebrate-sub {
    margin-top: 16px;
    font-size: clamp(16px, 2.5vw, 22px);
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    padding: 8px 20px;
    border-radius: 999px;
    animation: celebrateFadeIn 0.8s ease 0.4s both;
}

@keyframes celebrateBounce {
    0%   { transform: scale(0.3) rotate(-15deg); opacity: 0; }
    50%  { transform: scale(1.15) rotate(5deg); opacity: 1; }
    70%  { transform: scale(0.95) rotate(-2deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes celebrateFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes celebrateGradient {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.celebrate-overlay.hide {
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* ========== 英文单词学习卡片 ========== */
.word-card-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.78);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 16px;
    box-sizing: border-box;
    animation: wordCardFade 0.25s ease-out;
}
.word-card-overlay.show {
    display: flex;
}
@keyframes wordCardFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.word-card {
    position: relative;
    width: 100%;
    max-width: 460px;
    background: #fff;
    border-radius: 18px;
    padding: 28px 26px 22px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    text-align: center;
    animation: wordCardPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes wordCardPop {
    0%   { transform: scale(0.7) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}
.word-card-close {
    position: absolute;
    top: 10px;
    right: 14px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 0;
    font-size: 24px;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
}
.word-card-close:hover {
    background: #f1f5f9;
    color: #ef4444;
}
.word-card-eyebrow {
    display: inline-block;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 11px;
    padding: 3px 12px;
    border-radius: 999px;
    letter-spacing: 1px;
    margin-bottom: 12px;
}
.word-card-en {
    font-size: clamp(34px, 8vw, 48px);
    font-weight: 700;
    color: #1e293b;
    line-height: 1.1;
    margin: 6px 0 4px;
    word-break: break-word;
}
.word-card-pron {
    font-size: 15px;
    color: #64748b;
    font-style: italic;
    margin-bottom: 14px;
    min-height: 22px;
}
.word-card-cn {
    font-size: 18px;
    color: #0f172a;
    font-weight: 600;
    background: #fef3c7;
    border-radius: 10px;
    padding: 10px 12px;
    margin: 0 0 14px;
}
.word-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 14px;
}
.word-card-btn {
    background: #f1f5f9;
    color: #334155;
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}
.word-card-btn:hover {
    background: #e2e8f0;
}
.word-card-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.word-card-btn-primary {
    background: linear-gradient(90deg, #4f46e5, #7c3aed);
    color: #fff;
}
.word-card-btn-primary:hover {
    background: linear-gradient(90deg, #4338ca, #6d28d9);
}
.word-card-example-label {
    text-align: left;
    color: #64748b;
    font-size: 12px;
    letter-spacing: 1px;
    margin: 8px 0 4px;
}
.word-card-example {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 14px;
    text-align: left;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 180px;
    overflow-y: auto;
    font-family: inherit;
    font-size: 14px;
    color: #1e293b;
    line-height: 1.6;
    margin: 0 0 12px;
}
.word-card-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
    padding-top: 10px;
}
.word-card-link {
    background: transparent;
    border: 0;
    color: #4f46e5;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
}
.word-card-link:hover {
    background: #eef2ff;
}

@media (max-width: 480px) {
    .word-card {
        padding: 22px 18px 16px;
    }
    .word-card-en {
        font-size: 32px;
    }
}

/* ===== 单词图片提示（图选器缩略图上的英文单词标签） ===== */
.picker-image-item {
    position: relative;
}
.picker-image-word {
    position: absolute;
    left: 6px;
    bottom: 6px;
    max-width: calc(100% - 12px);
    padding: 3px 8px;
    background: rgba(13, 148, 136, 0.92);   /* 主品牌色:青绿 #0d9488 */
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    text-align: center;
    pointer-events: none;       /* 不阻挡点击 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== 单词卡片里的"拼图对应的单词"提示 ===== */
.word-card-bound {
    display: inline-block;
    margin: 4px 0 6px;
    padding: 4px 10px;
    background: #ecfdf5;
    color: #0d9488;
    border: 1px solid #99f6e4;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}
.word-card-bound b {
    color: #0f766e;
    font-weight: 700;
}

/* ===== 拼图右栏单词学习面板 ===== */
.word-panel {
    margin: 0 0 18px 0;
    padding: 12px;
    background: linear-gradient(135deg, #ecfdf5 0%, #f0fdfa 100%);
    border: 1px solid #99f6e4;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.08);
}
.word-panel-eyebrow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: #0f766e;
    font-size: 13px;
    font-weight: 600;
}
.word-panel-mini {
    background: #fff;
    border: 1px solid #99f6e4;
    color: #0d9488;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.word-panel-mini:hover {
    background: #0d9488;
    color: #fff;
}
.word-panel-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.word-panel-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.word-panel-overlay-tag {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(13, 148, 136, 0.92);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    pointer-events: none;
}
.word-panel-body {
    margin-top: 10px;
}
.word-panel-en-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.word-panel-en {
    font-size: 26px;
    font-weight: 700;
    color: #134e4a;
    line-height: 1.2;
    flex: 1;
    word-break: break-word;
}
.word-panel-speak {
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid #99f6e4;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}
.word-panel-speak:hover {
    background: #0d9488;
    transform: scale(1.05);
}
.word-panel-speak:active {
    transform: scale(0.95);
}
.word-panel-pron {
    font-size: 14px;
    color: #0f766e;
    font-family: 'Lucida Sans Unicode', 'Arial Unicode MS', serif;
    margin-bottom: 4px;
    min-height: 18px;
}
.word-panel-cn {
    font-size: 17px;
    color: #134e4a;
    font-weight: 500;
    margin-bottom: 6px;
}
.word-panel-example {
    font-size: 12px;
    color: #64748b;
    line-height: 1.5;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed #cbd5e1;
    max-height: 80px;
    overflow-y: auto;
    white-space: pre-wrap;
}
.word-panel-source {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 6px;
    text-align: right;
}

/* 移动端:单词面板放在拼图下方,更紧凑 */
@media (max-width: 767px) {
    .word-panel {
        margin-top: 16px;
    }
    .word-panel-en {
        font-size: 22px;
    }
}

/* ===== 音节切分显示（参考 howmanysyllables.com） ===== */
/* 单词卡片（拼图完成弹窗）里的音节切分：*/
.word-card-syllables {
    font-size: 22px;
    color: #6366f1;
    letter-spacing: 1px;
    margin: 4px 0 8px;
    min-height: 26px;
    line-height: 1.2;
    font-weight: 500;
}
.word-card-syllable {
    display: inline-block;
    padding: 1px 4px;
    border-radius: 4px;
    transition: background 0.15s, transform 0.15s;
}
.word-card-syllable:hover {
    background: #eef2ff;
    transform: translateY(-1px);
}
.word-card-syllable-sep {
    color: #94a3b8;
    margin: 0 2px;
    font-weight: 300;
}

/* 单词面板（拼图右栏）里的音节切分：*/
.word-panel-syllables {
    font-size: 18px;
    color: #0d9488;
    letter-spacing: 0.5px;
    margin: 2px 0 4px;
    min-height: 22px;
    line-height: 1.2;
    font-weight: 500;
}
.word-panel-syllable {
    display: inline-block;
    padding: 1px 3px;
    border-radius: 3px;
    transition: background 0.15s;
}
.word-panel-syllable:hover {
    background: #ccfbf1;
}
.word-panel-syllable-sep {
    color: #94a3b8;
    margin: 0 2px;
    font-weight: 300;
}

@media (max-width: 480px) {
    .word-card-syllables { font-size: 18px; }
    .word-panel-syllables { font-size: 15px; }
}
