/* style.css */
/* 現代響應式架構：軸心限制 560px、44px 觸控安全區、多階斷點與 100dvh 單屏防滾動 */

:root {
    --bg-color-top: #3A4D67;
    --bg-color-bottom: #243145;
    --card-ratio: 1.38;
    --card-max-width: min(80px, 18vw);
    
    --card-face-bg: #FFFDF5;
    --card-text: #4A2B14;
    
    --slot-bg: rgba(30, 42, 60, 0.6);
    --slot-border: rgba(45, 62, 86, 0.8);
    
    --cat-header-bg: #F59E0B;
    --cat-border: #F59E0B;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(180deg, var(--bg-color-top) 0%, var(--bg-color-bottom) 100%);
    color: white;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden; /* 防止遊戲主體滾動傳遞 */
    overscroll-behavior: none;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

/* 1. 軸心限制：中央卡片容器 (max-width: 560px + margin: 0 auto) */
.app-container {
    width: min(100%, 560px);
    max-width: 560px;
    margin: 0 auto;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 6px;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.coin-display {
    background: rgba(0,0,0,0.35);
    border-radius: 20px;
    padding: 4px 14px 4px 4px;
    display: flex;
    align-items: center;
    font-weight: 700;
    min-height: 36px;
}
.coin-icon {
    background: #FBBF24;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 6px;
    font-size: 0.85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.level-title {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: 900;
    color: #E2E8F0;
    letter-spacing: 1px;
}
.settings-icon {
    font-size: 1.5rem;
    color: #94A3B8;
    cursor: pointer;
    padding: 4px 8px;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Grid layout for Board */
.foundations, .tableau {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    width: 100%;
    gap: min(6px, 1.5vw);
}

.foundations {
    margin-bottom: 12px;
    flex-shrink: 0;
}

.tableau {
    flex: 1;
    position: relative;
    min-height: 0;
}

.column {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    max-width: var(--card-max-width);
}

/* Empty Slot */
.slot {
    width: 100%;
    min-width: 0;
    max-width: var(--card-max-width);
    aspect-ratio: 1 / var(--card-ratio);
    background: var(--slot-bg);
    border: 2px solid var(--slot-border);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: rgba(255, 255, 255, 0.15);
    position: relative;
}
.slot > svg {
    width: 50%;
    height: 50%;
}

.locked-slot {
    background: rgba(0,0,0,0.55);
    border: 2px dashed #94A3B8;
    color: #F87171;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
}
.locked-slot .lock-icon {
    font-size: 1.4rem;
    margin-bottom: 3px;
}
.locked-slot .price {
    font-size: 0.8rem;
    font-weight: 900;
    color: #FCD34D;
}
.locked-slot:active {
    transform: scale(0.95);
}

/* Base Card Style */
.card {
    width: 100%;
    aspect-ratio: 1 / var(--card-ratio);
    border-radius: 8px;
    position: absolute;
    top: 0; left: 0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.35);
    cursor: grab;
    transition: transform 0.15s ease-out;
    border-bottom: 2px solid #ccc;
    border-right: 1px solid #ddd;
}
.card:active {
    cursor: grabbing;
}

/* Face Down (Orange Back) */
.card.face-down {
    background: #F97316;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M0 50 Q 25 25, 50 50 T 100 50" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/><path d="M0 20 Q 25 -5, 50 20 T 100 20" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/><path d="M0 80 Q 25 55, 50 80 T 100 80" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/></svg>');
    background-size: cover;
    border: 2px solid #FFF;
    border-bottom: 3px solid #E5E7EB;
}

/* Face Up Normal */
.card.face-up {
    background: var(--card-face-bg);
    color: var(--card-text);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
    font-size: clamp(0.85rem, 3.2vw, 1.2rem);
    font-weight: 900;
    text-align: center;
    border: 2px solid #FFF;
}

/* Category Card */
.card.category-card {
    background: var(--card-face-bg);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    border: 2px solid var(--cat-border);
    overflow: hidden;
}
.cat-header {
    background: var(--cat-header-bg);
    color: white;
    width: 100%;
    height: 30%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.7rem, 2.5vw, 0.9rem);
    font-weight: 700;
}
.cat-body {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    color: var(--card-text);
}
.cat-progress {
    width: 100%;
    padding: 3px 5px 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: #B45309;
    display: flex;
    align-items: center;
    gap: 3px;
    line-height: 1;
}
.progress-icon {
    width: 11px; height: 11px;
    fill: #B45309;
}
.latest-word {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0 3px 6px;
    word-break: keep-all;
    font-size: clamp(0.85rem, 3.2vw, 1.2rem);
    font-weight: 900;
}

/* Dragging state */
.card.dragging {
    z-index: 1000 !important;
    opacity: 0.92;
    box-shadow: 0 12px 24px rgba(0,0,0,0.6);
}

/* Bottom Area (Step counter + Controls + Deck) */
.bottom-area {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding-top: 10px;
    flex-shrink: 0;
}

.step-counter {
    background: rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 8px 12px;
    text-align: center;
    min-width: 72px;
}
.step-label {
    font-size: 0.75rem;
    color: #94A3B8;
}
.step-num {
    font-size: 1.4rem;
    font-weight: 900;
    color: #E2E8F0;
}
.step-counter.danger .step-num {
    color: #EF4444;
}

.tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.tool-btn {
    background: #3B82F6;
    border: none;
    color: white;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-bottom: 3px solid #2563EB;
    cursor: pointer;
    min-height: 44px; /* 44px 人體工學觸控目標 */
    touch-action: manipulation;
}
.tool-btn:active {
    transform: translateY(2px);
    border-bottom: 1px solid #2563EB;
}

/* Deck & Waste */
.deck-area {
    display: flex;
    gap: 8px;
    width: calc(var(--card-max-width) * 2 + 8px);
}

.waste-pile, .stock-pile {
    width: var(--card-max-width);
    aspect-ratio: 1 / var(--card-ratio);
    position: relative;
}

.stock-pile {
    background: #F97316;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M0 50 Q 25 25, 50 50 T 100 50" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/><path d="M0 20 Q 25 -5, 50 20 T 100 20" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/><path d="M0 80 Q 25 55, 50 80 T 100 80" fill="none" stroke="%23EA580C" stroke-width="15" opacity="0.5"/></svg>');
    border-radius: 8px;
    border: 2px solid #FFF;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 5px;
    cursor: pointer;
    box-shadow: -2px -2px 0 #FFF, -4px -4px 0 #F97316;
    min-height: 44px;
    touch-action: manipulation;
}
.deck-count {
    color: white;
    font-weight: 900;
    font-size: 1.1rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

.stock-pile:active {
    transform: scale(0.95);
}

/* Toast Notification */
.toast {
    position: absolute;
    bottom: 22%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 10px 22px;
    border-radius: 20px;
    font-size: 0.9rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in-out;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.show {
    opacity: 1;
}

/* Modal & Overlays (overscroll-behavior: contain) */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    overscroll-behavior: contain;
}
.modal {
    background: #FFF;
    border-radius: 18px;
    padding: 28px 24px;
    text-align: center;
    color: #333;
    width: min(90vw, 400px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    overscroll-behavior: contain;
}
.modal h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}
.modal .btn {
    background: #4ADE80;
    border: none;
    padding: 12px 36px;
    border-radius: 24px;
    font-weight: 900;
    font-size: 1rem;
    color: white;
    margin-top: 15px;
    cursor: pointer;
    border-bottom: 4px solid #16A34A;
    min-height: 44px;
    touch-action: manipulation;
}
.modal .btn:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

/* ====================================================
   多階斷點與裝置優化 (Multi-Tier Breakpoints)
   ==================================================== */

/* 1. 手機標準斷點 (< 767px) - 觸控目標與安全區 */
@media (max-width: 767px) {
    button, .tool-btn, .modal .btn, .stock-pile, .locked-slot {
        min-height: 44px; /* iOS & Material Design 44px Touch Target */
    }
}

/* 2. 小平板 / 大手機 (< 560px) */
@media (max-width: 560px) {
    .app-container {
        width: 100%;
        padding-left: 8px;
        padding-right: 8px;
    }
}

/* 3. 標準手機 (< 480px) */
@media (max-width: 480px) {
    .header {
        margin-bottom: 8px;
    }
    .foundations {
        margin-bottom: 8px;
    }
    .tool-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
}

/* 4. 極小螢幕手機 (< 374px, 如 iPhone SE) */
@media (max-width: 374px) {
    .app-container {
        padding-left: 4px;
        padding-right: 4px;
    }
    .header {
        padding: 2px 4px;
    }
    .level-title {
        font-size: 1.1rem;
    }
    .tool-btn {
        padding: 4px 8px;
        font-size: 0.75rem;
    }
    .step-counter {
        min-width: 60px;
        padding: 6px 8px;
    }
    .step-num {
        font-size: 1.2rem;
    }
}
