:root {
    --bg-color: #f1f8e9;
    --tile-bg: #ffffff;
    --accent-color: #2b4570;
    --group-color-1: #FF5555;
    --group-color-2: #55FF55;
    --group-color-3: #5555FF;
    --group-color-4: #FFFF55;
    --group-color-5: #FF55FF;
    --group-color-6: #55FFFF;
    --group-color-7: #FFAA00;
    --group-color-8: #AA55FF;
    --group-color-9: #00FF99;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    --master-stroke: #2c3e50;
}

.hidden {
    display: none !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    overflow: hidden;
}

#gallery-viewport {
    width: 100vw;
    height: 100vh;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 세로 중앙 정렬 추가 */
}

#gallery-container {
    display: grid;
    grid-template-columns: repeat(7, 140px);
    /* 7열 유지 */
    grid-auto-rows: 140px;
    gap: 15px;
    /* 간격을 약간 넓혀 여유 공간 확보 */
    padding: 40px;
    width: fit-content;
    transform-origin: center;
    /* 중앙 기준 확대/축소 */
}

/* Master Square Styling */
.master-block {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    border: 3px solid var(--accent-color);
    border-radius: 12px;
    background: white;
    overflow: hidden;
}

.master-square {
    width: 100%;
    height: 100%;
}

.master-square canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    /* 연필 대용으로 정밀한 십자 포인터 사용 */
}

#floating-clear {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}


/* Floating Master Share Buttons */
.floating-share-btn,
.appendix-share-btn-outer {
    position: absolute;
    top: 34px;
    /* below Clear (5+24+5) */
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(230, 126, 34, 0.4);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: all 0.2s;
}

.floating-share-btn:hover,
.appendix-share-btn-outer:hover {
    background: rgba(230, 126, 34, 0.8);
    transform: scale(1.1);
}

/* Grid Tiles */
.mini-grid {
    background: var(--tile-bg);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.mini-grid:hover {
    transform: scale(1.03);
    z-index: 10;
}

.grid-label {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 9px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 5;
}

.mini-tile {
    width: 100%;
    height: 100%;
}

/* Move & Save Button Overlay */
.mini-grid,
.shape-item {
    position: relative;
}

.save-move-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #2b4570;
    color: white;
    border: 1.5px solid white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 15;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transform: translateY(-5px);
}

.mini-grid:hover .save-move-btn,
.shape-item:hover .save-move-btn {
    opacity: 1;
    transform: translateY(0);
}

.save-move-btn:hover {
    background: #3498db;
    transform: scale(1.1);
}


/* Print Space Panel */
.print-space-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 350px;
    max-height: 80vh;
    background: white;
    border: 3px solid #2b4570;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #333;
}

#triangle-print-space,
#hexagon-print-space {
    right: 20px;
    bottom: 20px;
}

.print-space-header {
    background: #2b4570;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.print-space-header h3 {
    font-size: 1rem;
    margin: 0;
}

.print-btn {
    background: #2ecc71;
    color: white;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    margin-right: 10px;
}

.print-btn:hover {
    background: #27ae60;
}

.close-print-space {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
}

.print-space-items {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    background: #f9f9f9;
}

.print-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 5px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.print-item canvas {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #eee;
}

.print-item .item-tag {
    font-size: 10px;
    margin-top: 5px;
    font-weight: bold;
    color: #666;
}

.remove-print-item {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

@media print {
    @page {
        margin: 10mm;
        size: A4;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
    }

    body * {
        visibility: hidden;
    }

    #gallery-viewport,
    .mode-overlay {
        background: white !important;
        position: static !important;
        height: auto !important;
        overflow: visible !important;
    }

    .print-space-panel {
        display: none !important;
        visibility: hidden !important;
    }

    .print-space-panel.printing-active {
        visibility: visible;
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-height: none;
        border: none !important;
        box-shadow: none !important;
        background: white !important;
        display: block !important;
        z-index: 9999 !important;
    }

    .print-space-panel.printing-active * {
        visibility: visible;
    }

    .print-space-header {
        background: transparent !important;
        color: #333 !important;
        padding: 0 0 20px 0 !important;
        border-bottom: 2px solid #333 !important;
        margin-bottom: 20px !important;
    }

    .print-space-header h3 {
        font-size: 1.5rem !important;
        font-weight: bold;
    }

    .close-print-space,
    .print-btn,
    .remove-print-item {
        display: none !important;
    }

    .print-space-items {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
        background: white !important;
        padding: 0 !important;
    }

    .print-item {
        border: 1px solid #ccc !important;
        border-radius: 4px !important;
        padding: 10px !important;
        page-break-inside: avoid;
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        background: white !important;
    }

    .print-item canvas {
        width: 100% !important;
        height: auto !important;
        display: block !important;
        border: 1px solid #eee !important;
    }

    .print-item .item-tag {
        margin-top: 10px !important;
        font-size: 12px !important;
        color: #333 !important;
        text-align: center;
        border-top: 1px dashed #eee;
        padding-top: 5px;
    }
}

/* Compact Pattern Detail Panel (Inside Learn Selector) */
.learn-selector-area {
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
    padding-right: 10px;
    margin-top: -60px;
    /* 추가로 10px 더 올림 (총 60px) */
}

/* 스크롤바 커스텀 */
.learn-selector-area::-webkit-scrollbar {
    width: 6px;
}

.learn-selector-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.selector-columns {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

#pattern-detail-panel {
    position: absolute;
    /* 버튼판 위에 띄우기 */
    top: 30px;
    right: 50px;
    z-index: 3000;
    background: white;
    color: #333;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 2px solid #3498db;
    width: 450px;
    max-height: 80vh;
    overflow-y: auto;
}

#pattern-detail-panel.detail-hidden {
    display: none;
}

#detail-content img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: fill;
    /* 상자 비율에 상관없이 꽉 채움 */
    border-radius: 4px;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

#detail-title {
    font-weight: bold;
    font-size: 0.9rem;
    color: #2b4570;
}

#close-detail {
    background: #fdfdfd;
    border: 1px solid #ddd;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
}

#close-detail:hover {
    background: #e74c3c;
    color: white;
    border-color: #e74c3c;
}

#detail-content {
    font-size: 0.85rem;
}

#detail-content img {
    margin-bottom: 8px;
}

.detail-text {
    line-height: 1.4;
    color: #555;
    font-size: 0.8rem;
}

.mini-tile canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.grid-tile-canvas {
    width: 100%;
    height: 100%;
}

#side-menu {
    position: fixed;
    right: 0;
    top: 0;
    width: 260px;
    /* Narrower width */
    height: 100%;
    background: white;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1);
    transform: translateX(0);
    transition: transform 0.3s ease;
    z-index: 1000;
}

#side-menu.hidden {
    transform: translateX(100%);
}

.menu-content {
    padding: 20px;
    /* Reduced padding */
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* Tighter gap */
}

.menu-header {
    display: flex;
    justify-content: flex-end;
    /* Lang and close at top right */
    align-items: center;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.header-actions {
    display: flex;
    gap: 10px;
}

#lang-select {
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 0.8rem;
    cursor: pointer;
}

#close-menu {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
}

.menu-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-section h3 {
    font-size: 0.9rem;
    color: var(--accent-color);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 700;
    border-bottom: 1.5px solid #f0f0f0;
    padding-bottom: 4px;
    margin-bottom: 5px;
}

.modes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    /* 모든 행의 높이를 동일하게 맞춤 */
    gap: 8px;
}

.mode-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-card.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.mode-icon {
    font-size: 1.2rem;
}

.mode-card span {
    font-size: 0.7rem;
    font-weight: bold;
}

.control-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

.control-group label {
    font-size: 0.75rem;
    color: #666;
    font-weight: bold;
}

.control-group input[type="range"] {
    width: 100%;
}

.control-group input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 2px;
}

.view-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.menu-btn {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: all 0.2s;
}

.menu-btn:hover {
    background: #f8f9fa;
    border-color: #bbb;
}

.menu-btn.mini {
    padding: 6px;
    font-size: 0.75rem;
    color: #555;
}

.menu-btn.primary {
    background: var(--accent-color);
    color: white;
    border: none;
    margin-top: 5px;
}

.menu-btn.primary.small {
    padding: 10px;
    font-size: 0.85rem;
}

.menu-btn:active {
    transform: scale(0.98);
}

#menu-toggle {
    position: fixed;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

#menu-toggle:hover {
    transform: scale(1.1);
}

#gallery-guide-btn {
    position: fixed;
    top: 15px;
    right: 65px;
    width: 40px;
    height: 40px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#gallery-guide-btn:hover {
    transform: scale(1.1);
    background: #2980b9;
}

/* Learn Mode Overlay */
.mode-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #2c3e50;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    padding: 30px;
    color: white;
}

.mode-overlay.hidden {
    display: none;
}

.learn-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.learn-content {
    flex: 1;
    display: grid;
    grid-template-columns: 200px 380px 1fr;
    gap: 15px;
    align-items: center;
    overflow: hidden;
    min-width: 900px;
    /* Force horizontal layout for mobile pan/zoom */
}

.learn-master-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: -80px;
}

.learn-preview-area {
    margin-top: -40px;
}

.learn-canvas-container {
    width: 180px;
    height: 180px;
    background: white;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.learn-canvas-container canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.preview-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 360px;
    height: 360px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.preview-tile {
    border: 1.5px solid #2ecc71;
    background: rgba(255, 255, 255, 0.05);
}

.preview-tile canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Learn Mode Header Buttons */
.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.explain-guide-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.explain-guide-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Button Group Styling */
.btn-group {
    display: flex;
    gap: 4px;
    width: 100%;
}

.rule-btn {
    flex: 1;
    /* 가로 가득 채우기 */
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11.5px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid rgba(52, 152, 219, 0.3);
    color: #3498db;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.info-btn:hover {
    background: #3498db;
    color: white;
    transform: scale(1.1);
}

/* Modal System Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(200, 220, 240, 0.55);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    pointer-events: none;
}

.modal-card {
    background: #f0f6ff;
    color: #2c3e50;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    position: relative;
    padding: 40px;
    box-shadow: 0 15px 40px rgba(100, 140, 200, 0.25);
    border: 1px solid rgba(100, 150, 220, 0.25);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@keyframes modalPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: #95a5a6;
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #e74c3c;
}

.modal-content {
    color: #2c3e50;
    overflow-y: auto;
    padding-right: 15px;
}

.modal-content h2 {
    color: #2b6cb0;
    margin-bottom: 20px;
    font-size: 2rem;
    border-bottom: 2px solid rgba(52, 152, 219, 0.3);
    padding-bottom: 10px;
}

.modal-section {
    margin-bottom: 25px;
    background: rgba(52, 120, 220, 0.07);
    padding: 20px;
    border-radius: 12px;
}

.modal-section h3 {
    color: #2b6cb0;
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.modal-formula {
    background: #1a252f;
    padding: 15px;
    border-radius: 8px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1rem;
    color: #2ecc71;
    border-left: 4px solid #2ecc71;
    margin: 10px 0;
}

.modal-text {
    line-height: 1.7;
    font-size: 1.05rem;
    color: #34495e;
}

.modal-tags {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-tag {
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
}

/* Falling Game (Game 2) */
#falling-game-board {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: calc(100vh - 120px);
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: none;
    border-radius: 0 0 15px 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.falling-square {
    position: absolute;
    width: 120px;
    height: 120px;
    cursor: pointer;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 3px solid transparent;
}

.falling-square:hover {
    border-color: #3498db;
}

.falling-square canvas {
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: block;
}

/* Control Buttons */
.start-btn {
    padding: 5px 18px;
    background: #27ae60;
    border: none;
    border-radius: 15px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.pause-btn {
    padding: 5px 15px;
    background: #f39c12;
    border: none;
    border-radius: 15px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.stop-btn {
    padding: 5px 15px;
    background: #e74c3c;
    border: none;
    border-radius: 15px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.start-btn:hover,
.pause-btn:hover,
.stop-btn:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
}

.falling-guide {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 0.95rem;
    font-weight: 500;
    margin: 0 30px;
    padding: 2px 15px;
}

.guide-text {
    color: #f1c40f;
}

.draw-tip {
    font-size: 0.85rem;
    color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
    padding: 2px 12px;
    border-radius: 10px;
    border: 1px solid rgba(46, 204, 113, 0.2);
}

#falling-score-display {
    font-size: 1.3rem;
    font-weight: 800;
    color: #3498db;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 20px;
    border-radius: 25px;
    letter-spacing: 1px;
}

/* Game Setup Overlay */
.game-setup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
}

.game-setup-overlay h2 {
    color: #fff;
    margin-bottom: 20px;
    font-size: 2rem;
}

.draw-notice {
    color: #f1c40f;
    background: rgba(241, 196, 15, 0.15);
    padding: 15px 25px;
    border-radius: 10px;
    margin-bottom: 30px;
    font-size: 1.1rem;
    max-width: 80%;
    line-height: 1.5;
}

.level-btns {
    display: flex;
    gap: 15px;
    margin-bottom: 40px;
}

.level-btn {
    padding: 12px 25px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 30px;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.level-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.level-btn.active {
    background: #3498db;
    border-color: #3498db;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.5);
}

.start-game-btn {
    padding: 15px 50px;
    background: var(--button-bg, #27ae60);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.start-game-btn:hover {
    background: #2ecc71;
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

/* Scrollbar Styling for Modal */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.modal-content::-webkit-scrollbar-thumb {
    background: rgba(52, 152, 219, 0.4);
    border-radius: 3px;
}

.selector-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2열 배치 */
    gap: 4px;
    /* 버튼 사이 간격 */
    margin-bottom: 12px;
}

.group-header {
    grid-column: 1 / -1;
    /* 두 칸 모두 차지 */
    font-weight: bold;
    color: #3498db;
    margin-bottom: 4px;
    font-size: 0.85rem;
}

.rule-btn {
    display: block;
    width: 100%;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11.5px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rule-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.rule-btn.active {
    background: #3498db;
    border-color: #3498db;
}

.learn-pattern-id {
    position: absolute;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: #ecf0f1;
    color: #2c3e50;
    padding: 5px 20px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 18px;
    white-space: nowrap;
    visibility: hidden;
}

/* Chat Styles */
#chat-panel {
    position: fixed;
    top: 75px;
    /* 상단 버튼 아래에 위치하도록 변경 */
    left: 20px;
    width: 320px;
    height: 400px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
}

#chat-panel.chat-hidden {
    display: none;
}

.chat-header {
    padding: 15px;
    background: var(--accent-color);
    color: white;
    display: flex;
    justify-content: space-between;
}

#chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
}

#chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 15px;
}

#chat-toggle {
    position: fixed;
    top: 20px;
    /* 상단으로 이동 */
    left: 20px;
    width: 45px;
    height: 45px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

#chat-toggle:hover {
    transform: scale(1.1);
}

/* Modal Diagram Decoration */
.modal-diagram {
    width: 100%;
    margin-bottom: 25px;
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    border: 3px solid #3498db;
}

.modal-diagram svg {
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.1));
}

/* Guide Modal Specific Layout */
.guide-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.symbol-grid-wrapper {
    position: relative;
    background: white;
    padding: 10px;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.guide-bg-image {
    width: 100%;
    height: auto;
    display: block;
}

.guide-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.pattern-types-img {
    background: white;
    padding: 15px;
    border-radius: 8px;
    height: 250px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
}

.highlight-red {
    color: #e74c3c;
    font-weight: 500;
}

.highlight-purple {
    color: #9b59b6;
    font-weight: 500;
}

.small-desc {
    font-size: 0.9rem;
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 6px;
    margin: 10px 0;
    line-height: 1.5;
}

/* Quiz Mode Styles */
#quiz-mode-overlay {
    z-index: 3000;
}

.quiz-content {
    flex: 1;
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    /* 에셔 영역을 좁게 수정 */
    gap: 20px;
    padding: 10px 0;
    overflow: hidden;
    height: calc(100vh - 120px);
}

.quiz-label {
    font-size: 1.1rem;
    color: #ecf0f1;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
}

.quiz-guide-tip {
    font-size: 0.8rem;
    color: #f1c40f;
    font-weight: 400;
    opacity: 0.8;
}

.quiz-question-area {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    height: 100%;
}

.quiz-image-container {
    background: white;
    border-radius: 12px;
    height: 320px;
    /* 에셔 그림 영역 높이 축소 */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    position: relative;
}

#quiz-question-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.quiz-image-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.quiz-hint-box {
    background: rgba(52, 152, 219, 0.15);
    border-left: 5px solid #3498db;
    padding: 12px;
    border-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.quiz-choice-area {
    background: rgba(0, 0, 0, 0.2) !important;
    padding: 20px !important;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-top: 0 !important;
}

#quiz-options-container {
    flex: 1;
    overflow: hidden;
    /* 스크롤바 제거 */
    padding: 10px 0;
}

.quiz-feedback {
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    font-weight: bold;
    font-size: 1.1rem;
    margin-top: 10px;
}

.quiz-feedback.correct {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
    border: 1px solid #2ecc71;
}

.quiz-feedback.wrong {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
    border: 1px solid #e74c3c;
}

.quiz-status {
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 20px;
    border-radius: 20px;
}

@keyframes quizSlideIn {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }

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

/* 9 Group Quiz Grid */
.quiz-grid-9 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    /* 간격 축소 */
    padding: 5px;
    height: 100%;
}

.quiz-group-card {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 5px;
    /* 패딩을 최소화하여 공간 확보 */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
    height: 100%;
    /* 부모 높이에 맞춤 */
}

.quiz-group-card:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-5px);
    border-color: #3498db;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.group-img-wrapper {
    width: 100%;
    flex: 1;
    /* 가용 공간 모두 사용 */
    background: white;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    /* 여백 제거 */
}

.group-img-wrapper img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

.group-info {
    display: flex;
    flex-direction: row;
    /* 가로로 배치하여 높이 절약 */
    justify-content: center;
    align-items: baseline;
    gap: 5px;
    width: 100%;
    padding: 2px 0;
}

.group-name {
    font-size: 0.95rem;
    font-weight: 500;
    /* 보통 두께 */
    color: #f1c40f;
    text-transform: uppercase;
    /* 대문자로 변경 */
}

.group-symbol {
    display: none;
    /* 심볼은 이름과 중복되므로 숨김 처리 */
}

.escher-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #2c3e50;
    text-align: center;
    font-weight: bold;
}

/* Appendix Gallery Styles */
#triangle-gallery-overlay,
#hexagon-gallery-overlay {
    background-color: var(--bg-color);
    /* Matches Square Bg */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: auto;
    z-index: 10;
}

#triangle-gallery-overlay .learn-header,
#hexagon-gallery-overlay .learn-header {
    display: none !important;
    /* Hide exit button and header */
}

#triangle-gallery-overlay .appendix-content {
    grid-template-columns: repeat(4, 140px);
}

.appendix-content {
    display: grid;
    grid-template-columns: repeat(7, 140px);
    grid-auto-rows: 140px;
    gap: 15px;
    padding: 40px;
    width: fit-content;
    overflow: visible;
    transform-origin: center;
    background: transparent;
}

.appendix-master-area {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    border: 3px solid var(--accent-color);
    border-radius: 12px;
    background: white;
    overflow: hidden;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.master-shape-wrapper {
    width: 100%;
    height: 100%;
}

.appendix-canvas-container {
    width: 100%;
    height: 100%;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
}

/* Geometric Clip Paths REMOVED to allow full grid display */
.appendix-canvas-container.triangle-container {
    background: white;
}

.appendix-canvas-container.hexagon-container {
    background: white;
}

.appendix-canvas-container canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.shape-label-tag {
    display: none;
    /* Hidden to match Square grid */
}

.appendix-clear-btn-outer {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    color: black;
    border: none;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    z-index: 20;
    transition: transform 0.2s;
}

.appendix-clear-btn-outer:hover {
    transform: scale(1.1);
}


.shape-grid {
    display: contents;
    /* Let shape-items jump to parent grid */
}

.shape-item {
    background: var(--tile-bg);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: none;
    padding: 0;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
    cursor: pointer;
}

.shape-item:hover {
    transform: scale(1.03);
    z-index: 10;
}

.shape-preview-box {
    width: 100%;
    height: 100%;
    background: transparent;
    border-radius: 0;
}

.shape-preview-box canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.shape-id-tag {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 9px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.2);
    /* Remove original styles */
    text-align: right;
    background: none;
}

/* Force horizontal layout for Zoom/Pan on mobile */
.quiz-content {
    min-width: 1024px;
}

#falling-game-board {
    min-width: 800px;
    /* Preserve game board width */
}

/* Original Share (Community Gallery) Styling */
.share-gallery-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}



.share-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--share-card-min, 220px), 1fr));
    gap: 25px;
    padding-bottom: 50px;
}

.share-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    color: #333;
    transition: transform 0.3s;
    position: relative;
    /* For type tag */
}

.share-card-type-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(43, 69, 112, 0.85);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 5;
    backdrop-filter: blur(4px);
}

.share-card:hover {
    transform: translateY(-5px);
}

.share-card-img {
    width: 100%;
    aspect-ratio: 1;
    background: #f0f0f0;
    display: block;
    object-fit: contain;
    border-bottom: 2px solid #eee;
}

.share-card-img.master-thumb {
    background: #f8f9fa;
    padding: 10px;
    box-sizing: border-box;
    background-image:
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.share-card-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.share-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.share-card-name {
    font-weight: bold;
    font-size: 1.05rem;
    color: #2c3e50;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.share-card-time {
    font-size: 0.75rem;
    color: #999;
}

.share-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #f0f0f0;
    padding-top: 8px;
}

.load-shared-btn {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.load-shared-btn:hover {
    background: #2980b9;
    transform: scale(1.05);
}

.heart-container {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.heart-container:hover {
    transform: scale(1.1);
}

.heart-icon {
    font-size: 1.2rem;
    color: #ccc;
    transition: color 0.2s;
}

.heart-container.liked .heart-icon {
    color: #e74c3c;
}

.heart-count {
    font-weight: bold;
    font-size: 0.9rem;
    color: #666;
}

.share-sort-controls {
    display: flex;
    gap: 10px;
}

.sort-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sort-btn.active {
    background: #e67e22;
    border-color: #e67e22;
}

.admin-delete-btn {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.admin-delete-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.share-search-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.12);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 4px 10px;
    gap: 6px;
    transition: border-color 0.2s;
}

.share-search-box:focus-within {
    border-color: #3498db;
    background: rgba(255, 255, 255, 0.18);
}

.search-icon {
    font-size: 0.85rem;
    opacity: 0.7;
}

#share-search-input {
    background: none;
    border: none;
    outline: none;
    color: white;
    font-size: 0.85rem;
    width: 140px;
}

#share-search-input::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

#share-search-clear {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 11px;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

#share-search-clear:hover {
    color: white;
}

.modal-card.mini {
    max-width: 400px;
    padding: 30px;
    text-align: center;
    gap: 15px;
}

.modal-card.mini input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid #ddd;
    font-size: 1rem;
    outline: none;
}

.modal-card.mini input:focus {
    border-color: #e67e22;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons button {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: bold;
    cursor: pointer;
}

.modal-buttons button.primary {
    background: #e67e22;
    color: white;
}

.modal-buttons button:hover {
    filter: brightness(1.1);
}

/* Visibility Toggles */
.labels-hidden .grid-label,
.labels-hidden .shape-id-tag {
    display: none !important;
}