/* ============================================
   MegaTown – Global Styles & Theme
   Premium Mobile-First Design
   ============================================ */

:root {
    /* Renkler */
    --bg-deep:    #080c1f;
    --bg-surface: #0f1430;
    --bg-card:    rgba(16, 21, 52, 0.92);
    --bg-glass:   rgba(255, 255, 255, 0.06);
    --border:     rgba(255, 255, 255, 0.10);
    --border-accent: rgba(0, 229, 255, 0.25);

    --text-1: #f0f2ff;
    --text-2: #8892c8;
    --text-3: #4a5490;

    --cyan:   #00e5ff;
    --gold:   #ffd740;
    --green:  #00e676;
    --red:    #ff5252;
    --purple: #b388ff;
    --orange: #ffab40;

    /* Alias (eski kod uyumu) */
    --text-primary:   var(--text-1);
    --text-secondary: var(--text-2);
    --text-muted:     var(--text-3);
    --accent-cyan:    var(--cyan);
    --accent-gold:    var(--gold);
    --accent-green:   var(--green);
    --accent-red:     var(--red);
    --accent-purple:  var(--purple);
    --bg-primary:     var(--bg-deep);
    --bg-secondary:   var(--bg-surface);
    --border-glass:   var(--border);
    --shadow-glow:    0 0 30px rgba(0, 229, 255, 0.12);

    /* Ölçüler */
    --r: 16px;
    --r-sm: 10px;
    --r-xs: 6px;
    --radius: var(--r);
    --radius-sm: var(--r-sm);

    /* Animasyon */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition: all 0.25s var(--ease);

    /* Safe area (notch desteği) */
    --safe-top:    env(safe-area-inset-top,    0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left,   0px);
    --safe-right:  env(safe-area-inset-right,  0px);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-deep);
    color: var(--text-1);
    height: 100dvh; width: 100vw;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

h1, h2, h3, h4 { font-family: 'Outfit', sans-serif; }

::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-3); border-radius: 99px; }

/* ---- Tam Ekran Butonu ---- */
.btn-fullscreen {
    position: fixed;
    top: calc(var(--safe-top, 0px) + 0.625rem);
    right: 0.75rem;
    z-index: 9999;
    width: 38px; height: 38px;
    background: rgba(15, 20, 48, 0.85);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-2);
    font-size: 1.1rem;
    cursor: pointer;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
}
.btn-fullscreen:hover {
    background: rgba(0, 229, 255, 0.15);
    color: var(--cyan);
    box-shadow: 0 0 12px rgba(0,229,255,0.25);
    border-color: var(--cyan);
}
.btn-fullscreen:active { transform: scale(0.92); }

/* iOS Safari fullscreen desteklemediği için gizle (isteğe bağlı) */
/* @media not all and (display-mode: fullscreen) {} */

/* ============================================
   SCREEN SİSTEMİ
   ============================================ */
.screen {
    display: none;
    width: 100%;
    height: 100dvh;
}
.screen.active { display: flex; }

/* ============================================
   LOBİ EKRANI
   ============================================ */
.lobby-screen {
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(var(--safe-top) + 1rem) 1rem calc(var(--safe-bottom) + 1rem);
    overflow-y: auto;
    gap: 0;
}

/* Arkaplan Orblar */
.lobby-bg {
    position: absolute; inset: 0;
    overflow: hidden; pointer-events: none;
    z-index: 0;
}
.orb {
    position: absolute; border-radius: 50%;
    filter: blur(80px); opacity: 0.35;
    animation: orbFloat 8s ease-in-out infinite;
}
.orb-1 {
    width: 400px; height: 400px;
    background: radial-gradient(circle, #00e5ff 0%, transparent 70%);
    top: -100px; left: -100px;
    animation-delay: 0s;
}
.orb-2 {
    width: 350px; height: 350px;
    background: radial-gradient(circle, #b388ff 0%, transparent 70%);
    bottom: -80px; right: -80px;
    animation-delay: -3s;
}
.orb-3 {
    width: 300px; height: 300px;
    background: radial-gradient(circle, #ffd740 0%, transparent 70%);
    top: 40%; left: 50%; transform: translate(-50%,-50%);
    opacity: 0.15;
    animation-delay: -6s;
}
@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(20px, -20px) scale(1.05); }
    66% { transform: translate(-15px, 15px) scale(0.95); }
}

/* Lobi içerik */
.lobby-content {
    position: relative; z-index: 1;
    display: flex; flex-direction: column;
    align-items: center; gap: 1.25rem;
    width: 100%; max-width: 420px;
}

/* Hero bölümü */
.lobby-hero { text-align: center; }

.lobby-logo {
    font-size: clamp(3rem, 10vw, 5rem);
    line-height: 1;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 20px rgba(0, 229, 255, 0.4));
    animation: logoFloat 4s ease-in-out infinite;
}
@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.lobby-title {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(2.8rem, 10vw, 4.5rem);
    font-weight: 900;
    letter-spacing: 4px;
    color: var(--text-1);
    line-height: 1;
}
.lobby-title span {
    background: linear-gradient(135deg, var(--cyan) 0%, var(--purple) 50%, var(--gold) 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lobby-subtitle {
    font-size: clamp(0.75rem, 2.5vw, 0.95rem);
    color: var(--text-2);
    margin-top: 0.5rem;
    letter-spacing: 0.5px;
}

/* Ana kart */
.lobby-card {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 0.875rem;
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04) inset;
}

.input-group {
    display: flex; flex-direction: column; gap: 0.375rem;
}
.input-group label {
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-2); letter-spacing: 0.3px;
    text-transform: uppercase;
}

.input-field {
    background: rgba(255,255,255,0.04);
    border: 1.5px solid var(--border);
    color: var(--text-1);
    padding: 0.8rem 1rem;
    border-radius: var(--r-sm);
    font-size: 1rem; font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    -webkit-appearance: none;
}
.input-field:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(0, 229, 255, 0.18);
}
.input-field::placeholder { color: var(--text-3); }

.input-code {
    text-align: center;
    font-family: 'Outfit', monospace;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 8px;
    text-transform: uppercase;
    color: var(--cyan);
}

/* Divider */
.divider {
    display: flex; align-items: center; gap: 0.75rem;
    color: var(--text-3); font-size: 0.75rem;
    margin: 0.125rem 0;
}
.divider::before, .divider::after {
    content: ''; flex: 1; height: 1px;
    background: var(--border);
}

/* ---- Kayıtlı Oyun ---- */
.saved-game-card {
    width: 100%;
    background: rgba(255, 215, 64, 0.06);
    border: 1.5px solid rgba(255, 215, 64, 0.3);
    border-radius: var(--r);
    padding: 1rem 1.25rem;
    display: flex; flex-direction: column; gap: 0.625rem;
    backdrop-filter: blur(20px);
}
.saved-game-header {
    display: flex; align-items: center; gap: 0.5rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700; font-size: 0.9rem;
    color: var(--gold);
}
.saved-icon { font-size: 1.2rem; }
.save-info { font-size: 0.82rem; color: var(--text-2); line-height: 1.6; }
.save-detail { margin: 0; }
.save-detail strong { color: var(--cyan); }
.saved-game-actions {
    display: flex; gap: 0.5rem; align-items: center;
}

.lobby-hint {
    font-size: 0.72rem; color: var(--text-3);
    text-align: center; letter-spacing: 0.5px;
}

/* ============================================
   BUTONLAR
   ============================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    border: none; border-radius: var(--r-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem; font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease), opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none; white-space: nowrap;
    position: relative; overflow: hidden;
    min-height: 48px; /* Apple HIG touch target */
}

.btn::after {
    content: '';
    position: absolute; inset: 0;
    background: rgba(255,255,255,0);
    transition: background 0.15s;
}
.btn:hover::after { background: rgba(255,255,255,0.07); }
.btn:active:not(:disabled) { transform: scale(0.965); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

/* Primary — Cyan */
.btn-primary {
    background: linear-gradient(135deg, #00c8e8, #00e5ff);
    color: #060d1e;
    box-shadow: 0 4px 20px rgba(0, 229, 255, 0.35);
    font-weight: 700;
}
.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 28px rgba(0, 229, 255, 0.55);
}

/* Success — Green */
.btn-success {
    background: linear-gradient(135deg, #00b248, #00e676);
    color: #060d1e; font-weight: 700;
    box-shadow: 0 4px 20px rgba(0, 230, 118, 0.3);
}

/* Gold */
.btn-gold {
    background: linear-gradient(135deg, #f0a800, #ffd740);
    color: #1a0f00; font-weight: 700;
    box-shadow: 0 4px 20px rgba(255, 215, 64, 0.3);
}

/* Outline */
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-1);
}
.btn-outline:hover:not(:disabled) {
    border-color: var(--cyan);
    color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(0,229,255,0.12);
}

/* Ghost */
.btn-ghost {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.1); }

/* Warning */
.btn-warning {
    background: linear-gradient(135deg, #e67200, #ffab40);
    color: #1a0800; font-weight: 700;
}

/* Sizes */
.btn-sm  { padding: 0.5rem 1rem; font-size: 0.82rem; min-height: 36px; }
.btn-lg  { padding: 1rem 2rem; font-size: 1.05rem; min-height: 56px; }
.btn-block { width: 100%; }
.btn-flex { flex: 1; }
.btn-icon-only { padding: 0.6rem; min-width: 44px; min-height: 44px; border-radius: var(--r-sm); }

/* ============================================
   SETUP EKRANI (Host bekleme)
   ============================================ */
.setup-screen {
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: calc(var(--safe-top) + 0.5rem) 1rem calc(var(--safe-bottom) + 1rem);
    overflow-y: auto;
}

.setup-content {
    display: flex; flex-direction: column;
    gap: 1rem; width: 100%; max-width: 480px;
    padding-top: 0.5rem;
}

.setup-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.setup-header h2 {
    font-size: 1.4rem; color: var(--cyan);
}

.room-code-card {
    background: var(--bg-card);
    border: 1px solid var(--border-accent);
    border-radius: var(--r);
    padding: 1.5rem;
    text-align: center;
    backdrop-filter: blur(20px);
    box-shadow: 0 0 30px rgba(0, 229, 255, 0.08);
}
.room-code-label {
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-2); text-transform: uppercase;
    letter-spacing: 1.5px; margin-bottom: 0.5rem;
}
.room-code {
    font-family: 'Outfit', monospace;
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 900;
    letter-spacing: 12px;
    color: var(--cyan);
    text-shadow: 0 0 30px rgba(0, 229, 255, 0.6);
    animation: codeGlow 2.5s ease-in-out infinite alternate;
    margin-bottom: 0.875rem;
    display: block;
}
@keyframes codeGlow {
    from { text-shadow: 0 0 15px rgba(0,229,255,0.4); }
    to   { text-shadow: 0 0 40px rgba(0,229,255,0.8); }
}
.room-code-hint {
    font-size: 0.75rem; color: var(--text-3); margin-top: 0.625rem;
}

.players-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 1.25rem;
    backdrop-filter: blur(20px);
}
.players-card h3 {
    font-size: 0.9rem; color: var(--gold);
    margin-bottom: 0.75rem;
}

.lobby-player {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: var(--bg-glass);
    border-radius: var(--r-sm);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}
.lobby-player-color {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.lobby-player span:last-child {
    font-size: 0.9rem; font-weight: 500;
}

/* Status */
.status-connected { color: var(--green) !important; font-weight: 600; }

/* Btn group */
.btn-group { display: flex; gap: 0.5rem; }

/* ============================================
   OYUN EKRANI — DESKTOP LAYOUT
   ============================================ */
.game-screen {
    display: flex;
    align-items: stretch;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    position: relative;
    background: var(--bg-deep);
}

/* Tahta alanı */
.game-board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    min-width: 0;
    height: 100%;
    transition: padding-right 0.3s var(--ease);
}

/* Desktop Sidebar */
.game-sidebar {
    width: 300px;
    flex-shrink: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: rgba(10, 14, 39, 0.97);
    border-left: 1px solid var(--border);
    backdrop-filter: blur(24px);
    transition: width 0.3s var(--ease), opacity 0.3s;
    overflow: hidden;
}
.game-sidebar.collapsed {
    width: 0;
    opacity: 0;
    pointer-events: none;
}

.sidebar-inner {
    width: 300px; /* Sabit genişlik — kaymada içerik sıkışmasın */
    height: 100%;
    display: flex; flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    overflow: hidden;
}

.sidebar-section {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 0.75rem;
}
.sidebar-log {
    flex: 1;
    display: flex; flex-direction: column;
    min-height: 0;
}
.section-label {
    font-size: 0.75rem; font-weight: 700;
    color: var(--gold); letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.log-list {
    flex: 1; overflow-y: auto;
}
.log-entry {
    font-size: 0.72rem; color: var(--text-2);
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    line-height: 1.4;
}

/* Sidebar toggle */
.sidebar-toggle {
    position: fixed; right: 300px; top: 50%;
    transform: translateY(-50%);
    z-index: 51;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-right: none;
    color: var(--text-2);
    border-radius: 8px 0 0 8px;
    padding: 0.875rem 0.4rem;
    cursor: pointer; font-size: 0.9rem;
    transition: right 0.3s var(--ease), background 0.2s;
    -webkit-tap-highlight-color: transparent;
    display: flex; align-items: center;
    min-height: 48px;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.1); color: var(--text-1); }
.game-sidebar.collapsed ~ .sidebar-toggle { right: 0; }

/* Oyun logu — game-log backward compat */
.game-log {
    background: var(--bg-glass); border: 1px solid var(--border);
    border-radius: var(--r); padding: 0.5rem;
    flex: 1; overflow: hidden;
    display: flex; flex-direction: column;
}
.game-log h3 { font-size: 0.8rem; color: var(--gold); margin-bottom: 0.3rem; }
#game-log-list { flex: 1; overflow-y: auto; }

/* ============================================
   MOBİL: ALT ÇEKMECE
   ============================================ */
.mobile-drawer {
    display: none; /* Desktop'ta gizli */
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 900px) {

    /* Tahta tüm ekrana yayılsın */
    .game-board-wrapper {
        padding: calc(var(--safe-top, 0px) + 0.5rem) 0.5rem 0.5rem;
        padding-bottom: calc(var(--safe-bottom, 0px) + 0.5rem);
        height: 100dvh;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar mobilde sağdan gelen overlay */
    .game-sidebar {
        position: fixed;
        top: 0; right: 0;
        height: 100dvh;
        width: min(300px, 85vw);
        z-index: 60;
        transform: translateX(100%);
        border-left: 1px solid var(--border);
        box-shadow: -8px 0 32px rgba(0,0,0,0.5);
        transition: transform 0.3s var(--ease);
    }
    .game-sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    .game-sidebar.collapsed {
        transform: translateX(100%);
        opacity: 1; /* Override desktop collapsed opacity */
        pointer-events: none;
    }

    /* Toggle butonu — mobilde her zaman solda görünür */
    .sidebar-toggle {
        right: 0;
    }
    .game-sidebar:not(.collapsed) ~ .sidebar-toggle {
        right: min(300px, 85vw);
    }

    /* Overlay karartma — sidebar açıkken arkaplanı koyulaştır */
    .game-sidebar:not(.collapsed)::before {
        content: '';
        position: fixed;
        inset: 0;
        right: min(300px, 85vw);
        background: rgba(0,0,0,0.55);
        z-index: -1;
        backdrop-filter: blur(2px);
    }
}

@media (max-width: 480px) {
    .lobby-card { padding: 1.25rem; }
    .lobby-logo { font-size: 2.5rem; }
    .lobby-title { font-size: 2.5rem; letter-spacing: 2px; }
    .input-code { font-size: 1.5rem; letter-spacing: 5px; }
    .room-code { font-size: 2.5rem; letter-spacing: 8px; }

    .game-sidebar {
        width: 90vw;
    }
    .game-sidebar:not(.collapsed) ~ .sidebar-toggle {
        right: 90vw;
    }
}

/* Landscape küçük ekran */
@media (max-height: 500px) and (max-width: 900px) {
    .game-board-wrapper {
        padding: 0.25rem calc(var(--safe-right, 0px) + 0.25rem)
                 0.25rem calc(var(--safe-left, 0px) + 0.25rem);
    }
    .game-sidebar {
        width: min(260px, 80vw);
    }
}
