:root {
    --wood-bg: #c89f65;
    --wood-border: #4a2511;
    --dark-point: #5c2f0a;
    --light-point: #f2d2a2;
    --p1-piece: #f9f9f9;
    --p2-piece: #222222;
    --bg-dark: #2c3e50;
    --panel-bg: #1a252f;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Helvetica Neue', Arial, sans-serif; user-select: none; }

/* FIX: Ekrana sığmadığında kitlenmemesi için body güncellendi */
body { 
    background-color: var(--bg-dark); 
    color: #fff; 
    height: 100vh;
    height: 100dvh; /* iOS Safari Address Bar Fix */
    width: 100vw;
    display: flex; 
    justify-content: center; 
    align-items: center; 
    overflow: hidden; /* Lock scroll to prevent bouncing */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-container { 
    display: flex; 
    width: 100%; 
    height: 100%;
    max-width: 1400px; 
    padding: 1rem; 
    gap: 1rem; 
    flex-direction: row; 
    align-items: stretch;
}

/* Paneller */
.panel { background-color: var(--panel-bg); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; width: 250px; box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.panel h2 { font-size: 1.2rem; text-align: center; border-bottom: 2px solid #fff; padding-bottom: 0.5rem; }

button { padding: 10px; border: none; border-radius: 5px; cursor: pointer; font-weight: bold; transition: 0.2s; font-size: 1rem; }
.mode-selectors { display: flex; gap: 5px; }
.mode-selectors button { flex: 1; background: #34495e; color: #fff; }
.mode-selectors button.active { background: #e74c3c; }
.action-btn { background: #3498db; color: white; }
.action-btn:hover:not(:disabled) { background: #2980b9; }
.action-btn:disabled { background: #555; cursor: not-allowed; opacity: 0.7; }
.action-btn.highlight { background: #2ecc71; animation: pulse 1.5s infinite; }
.danger-btn { background: #c0392b; color: white; margin-top: auto; }
.danger-btn:hover { background: #a53125; }

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.history-log { flex: 1; overflow-y: auto; background: #111; padding: 10px; border-radius: 5px; font-family: monospace; font-size: 0.9rem; line-height: 1.4; min-height: 100px; }
#scoreBoard { background: #222; padding: 10px; border-radius: 5px; text-align: center; }

/* Tahta Konteyneri */
.board-container { flex: 3; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.status-bar { display: flex; justify-content: space-between; align-items: center; background: var(--panel-bg); padding: 10px 20px; border-radius: 10px; font-size: 1.2rem; font-weight: bold; }
.dice-display { display: flex; gap: 10px; min-width: 80px; justify-content: center; font-size: 2rem;}

/* Oyun Tahtası */
.tavla-board { min-height: 60vh; flex: 1; background-color: var(--wood-bg); border: 15px solid var(--wood-border); border-radius: 10px; display: flex; position: relative; box-shadow: inset 0 0 20px rgba(0,0,0,0.5); overflow: hidden;}
.board-half { flex: 1; display: flex; flex-direction: column; position: relative; z-index: 2; }
.board-bar { width: 40px; background-color: var(--wood-border); border-left: 2px solid #2a1106; border-right: 2px solid #2a1106; display: flex; flex-direction: column; position: relative; z-index: 2;}
.bear-off-zone { width: 60px; background-color: #8c6a43; border-left: 5px solid var(--wood-border); display: flex; flex-direction: column; position: relative; z-index: 2;}

.row { flex: 1; display: flex; position: relative; }
.top-row { flex-direction: row; }
.bottom-row { flex-direction: row; }
.bar-top, .bar-bottom, .bear-off-top, .bear-off-bottom { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 5px 0; overflow: hidden; position: relative; }
.bar-top, .bear-off-top { justify-content: flex-start; }
.bar-bottom, .bear-off-bottom { justify-content: flex-end; }

/* Bear-off counter label */
.bear-off-count {
    font-size: 10px;
    font-weight: bold;
    color: rgba(255,255,255,0.85);
    background: rgba(0,0,0,0.45);
    border-radius: 4px;
    padding: 1px 3px;
    margin: 2px 0;
    text-align: center;
    z-index: 5;
    flex-shrink: 0;
    line-height: 1.2;
    max-width: 100%;
}

/* Haneler (Üçgenler) */
.point { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; height: 100%; cursor: pointer; }
.point::before { content: ''; position: absolute; left: 0; right: 0; width: 100%; height: 80%; z-index: 1; clip-path: polygon(50% 100%, 0 0, 100% 0); }
.bottom-row .point::before { bottom: 0; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.top-row .point::before { top: 0; }

.point.dark::before { background-color: var(--dark-point); }
.point.light::before { background-color: var(--light-point); }
.point.highlight::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(46, 204, 113, 0.4); z-index: 2; pointer-events: none; }

/* Pullar */
.checker-container { position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; z-index: 3; padding: 5px 0; pointer-events: none; }
.bottom-row .checker-container { justify-content: flex-end; }
.top-row .checker-container { justify-content: flex-start; }
.checker { width: 80%; aspect-ratio: 1; border-radius: 50%; box-shadow: 0 3px 5px rgba(0,0,0,0.5), inset 0 0 5px rgba(255,255,255,0.2); border: 2px solid rgba(0,0,0,0.2); position: relative; pointer-events: auto; cursor: grab; margin: -5% 0; transition: transform 0.2s; }
.checker:active { cursor: grabbing; }
.checker.p1 { background-color: var(--p1-piece); }
.checker.p2 { background-color: var(--p2-piece); }
.checker.selected { transform: scale(1.1); box-shadow: 0 0 15px #f1c40f; border-color: #f1c40f; z-index: 10; }

/* Bear-off checkers: very tight stacking so 15 never overflow */
.bear-off-top .checker, .bear-off-bottom .checker { margin: -18% 0; width: 75%; }

/* Win modal */
#winModal .modal-content { text-align: center; }
#winModal h2 { font-size: 2rem; color: #f1c40f; margin-bottom: 1rem; }
#winModal p { font-size: 1.1rem; margin-bottom: 1.5rem; }
#winModal .btn-next { background: #2ecc71; color: #fff; padding: 14px 30px; font-size: 1.2rem; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; width: 100%; }

/* Zarlar */
.die { width: 40px; height: 40px; background: #fff; border-radius: 8px; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
.die span { display: block; width: 8px; height: 8px; background: #000; border-radius: 50%; justify-self: center; align-self: center; }
.rolling { animation: roll 0.5s ease-in-out; }
@keyframes roll { 0% { transform: rotate(0deg) scale(1); } 50% { transform: rotate(180deg) scale(1.2); } 100% { transform: rotate(360deg) scale(1); } }

/* Modallar */
.modal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); justify-content: center; align-items: center; }
.modal-content { background-color: var(--panel-bg); padding: 20px; border-radius: 10px; width: 80%; max-width: 600px; position: relative; color: #fff; }
.close-btn { position: absolute; top: 10px; right: 15px; color: #aaa; font-size: 28px; font-weight: bold; cursor: pointer; }
.rules-btn { position: absolute; bottom: 1rem; left: 1rem; width: 40px; height: 40px; background: #e67e22; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1.5rem; font-weight: bold; cursor: pointer; color: #fff; }

/* YÖN OKLARI & NUMARALAR */
.direction-arrows { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.point-number { position: absolute; font-size: 11px; font-weight: bold; z-index: 2; pointer-events: none; }
.top-row .point-number { top: 3px; }
.bottom-row .point-number { bottom: 3px; }
.point.dark .point-number { color: rgba(255, 255, 255, 0.6); }
.point.light .point-number { color: rgba(0, 0, 0, 0.5); }


/* ============================================== */
/* RESPONSIVE (MOBIL / IPAD)          */
/* ============================================== */

/* Masaüstü detay ayarları */
.mobile-flex-row { display: none; }
.details-content { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.history-flex { flex: 1; }
details.mobile-details summary { display: none; }

/* TABLET / IPAD PORTRAIT */
@media (max-width: 1024px) {
    .app-container { flex-direction: column; }
    .left-panel { order: 1; }
    .board-container { order: 2; min-height: 50vh; }
    .right-panel { order: 3; }
    .panel { width: 100%; height: auto; }
    .tavla-board { max-height: 70vh; } /* Squashes the board vertically on iPads */
}

/* MOBIL (TELEFONLAR) */
@media (max-width: 768px) {
    .app-container { padding: 0.5rem; gap: 0.5rem; }
    .tavla-board { border-width: 8px; min-height: 45vh; }
    .board-bar { width: 25px; }
    .bear-off-zone { width: 40px; }
    .checker { margin: -10% 0; } /* Pullar küçük ekranda daha çok iç içe geçer */
    .status-bar { font-size: 1rem; padding: 5px 10px; }
    .dice-display { transform: scale(0.8); }
    .point-number { font-size: 9px; }
    
    .panel { flex-direction: column; padding: 10px; }
    
    /* Yeni Oyun ve Geri Al Butonları Mobilde En Üstte Yan Yana */
    .mobile-flex-row { display: flex; width: 100%; gap: 10px; margin-bottom: 10px; }
    .mobile-flex-row button { flex: 1; margin: 0; padding: 12px 5px; }
    
    /* Detayları (Ayarlar & Geçmiş) Mobilde Açılır Kapanır (Accordion) Yap */
    details.mobile-details { width: 100%; }
    details.mobile-details summary {
        display: block;
        background: #34495e;
        padding: 12px;
        font-weight: bold;
        text-align: center;
        border-radius: 5px;
        cursor: pointer;
        outline: none;
    }
    details.mobile-details[open] summary { margin-bottom: 10px; background: #2c3e50; border: 1px solid #34495e; }
    
    .panel h2 { display: none; } /* Kalabalık yapmaması için panel başlıklarını gizle */
    .rules-btn { position: fixed; bottom: 15px; right: 15px; z-index: 50; box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
}


/* GLOBAL HUB BUTTON */
.global-hub-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255,255,255,0.2);
    text-decoration: none;
    font-size: 1.5rem;
    min-width: 44px; /* Touch friendly width */
    height: 44px;
    border-radius: 8px;
    transition: transform 0.2s, background 0.2s;
    flex-shrink: 0;
}
.global-hub-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.3);
}

/* Ensure mobile-flex-row works beautifully with the new button */
.mobile-flex-row { display: flex; width: 100%; gap: 10px; margin-bottom: 10px; align-items: stretch; }
.mobile-flex-row button { flex: 1; margin: 0; padding: 12px 5px; }

.landscape-warning {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-dark); z-index: 9999;
    justify-content: center; align-items: center; text-align: center; padding: 20px;
}
.landscape-warning h2 { color: #e74c3c; margin-bottom: 15px; font-size: 2rem; }
.landscape-warning p { font-size: 1.2rem; }

/* Trigger warning ONLY on mobile phones in landscape (targets small heights) */
@media (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
    .landscape-warning { display: flex; }
    .app-container { display: none; }
}