* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --- iOS / Android tarayici kabugu icin genel ayarlar --- */
html {
    /* iOS'ta asagi cekme (pull-to-refresh) ve sayfa sicramasini engelle.
       --sat: notch/status bar, --sab: alt home indicator guvenli alan. */
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    overscroll-behavior: none;
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    background: #0c1524;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    color: #fff;
    /* iOS: uzun basma ile metin secimi / context menusunu kapat,
        cift tik ile sayfa zoom yapilmasin. */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    height: 100%;
}

#game-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    /* Eski iOS'ta 100dvh desteklenmez; geri donus olarak flex doldur. */
    min-height: 100%;
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 40%, #16283c 0%, #0c1524 55%, #070d16 100%);
}

#game-canvas {
    position: absolute;
    display: block;
    background: #08111a;
    box-shadow: 0 0 0 1px rgba(90,160,220,0.18), 0 10px 40px rgba(0,0,0,0.7);
}

/* ---------------- ekran uzayı efektleri (canvas dışında) ---------------- */
#flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #e74c3c;
    opacity: 0;
    pointer-events: none;
    z-index: 40;
}

#boss-bar {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 20;
    pointer-events: none;
}

#boss-bar span {
    font-size: 11px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px #000;
}

#boss-bar .track {
    width: 260px;
    max-width: 60vw;
    height: 14px;
    background: rgba(8, 18, 30, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

#boss-bar i {
    display: block;
    height: 100%;
    width: 100%;
    background: #e74c3c;
    transition: width 0.12s linear;
}

#level-banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    z-index: 50;
    pointer-events: none;
}

#level-banner .lb-box {
    background: rgba(20, 26, 38, 0.95);
    border: 2px solid #00cec9;
    padding: 18px 44px;
    text-align: center;
}

#level-banner b {
    display: block;
    font-size: 32px;
    color: #fff;
}

#level-banner span {
    font-size: 14px;
    color: #00cec9;
}

/* ---------------- HUD ---------------- */
#ui-panel {
    position: absolute;
    /* Notch / status cubugunun altinda kalmasin. */
    top: calc(10px + var(--sat, 0px));
    left: calc(10px + var(--sal, 0px));
    right: calc(10px + var(--sar, 0px));
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    z-index: 10;
    pointer-events: none;
    }

.ui-box {
    background: rgba(8, 18, 30, 0.82);
    padding: 6px 12px;
    border-radius: 20px;
    color: #d9e8f7;
    min-width: 74px;
    text-align: center;
    font-size: 13px;
    border: 1px solid rgba(110, 180, 240, 0.3);
    box-shadow: 0 0 12px rgba(20, 90, 150, 0.25) inset;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.ui-box b {
    color: #fff;
    font-size: 15px;
}

.bar {
    display: inline-block;
    width: 52px;
    height: 8px;
    background: #101a26;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.bar i {
    display: block;
    height: 100%;
    width: 100%;
    transition: width 0.15s linear;
}

.bar-hp { background: #2ee86f; }
.bar-armor { background: #22b0ff; }

#ui-buttons {
    margin-left: auto;
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.icon-btn {
    margin: 0;
    padding: 6px 12px;
    font-size: 16px;
    line-height: 1;
    background: rgba(8, 18, 30, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* ---------------- profil paneli ---------------- */
#profile-btn {
    font-size: 13px;
    font-weight: bold;
    color: #ffd23f;
    gap: 6px;
}

#who {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#who.offline { color: #7d8ea3; }

.menu-content.wide {
    width: min(880px, 94vw);
    max-width: 94vw;
    text-align: left;
}

.menu-content.wide h2,
.menu-content.wide > .tiny {
    text-align: center;
}

.menu-content h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #00cec9;
    margin: 4px 0 6px;
}

.prof-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 12px 0;
}

.prof-stats div {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(110, 180, 240, 0.2);
    border-radius: 8px;
    padding: 8px 14px;
    min-width: 92px;
    text-align: center;
}

.prof-stats span {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.65;
}

.prof-stats b {
    font-size: 20px;
    color: #ffd23f;
}

.prof-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

@media (max-width: 640px) {
    .prof-cols { grid-template-columns: 1fr; }
}

#prof-runs, #prof-lb {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#prof-runs td, #prof-lb td {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.9;
}

#prof-runs td:last-child, #prof-lb td:last-child {
    text-align: right;
    color: #ffd23f;
    font-weight: bold;
}

#prof-lb tr.me td { color: #00cec9; }
#prof-lb tr.me td:last-child { color: #00cec9; }

#prof-runs .empty, #prof-lb .empty {
    opacity: 0.5;
    text-align: center;
    padding: 14px 0;
}

#prof-note { text-align: center; }
#prof-logout { display: none; }

/* ---------------- dokunmatik kontroller ---------------- */
/* (kurallar asagida "HIZALAMA TABANI" basliginda) */

/* ===================================================================
   DOKUNMATIK KONTROLLER - HIZALAMA TABANI
   -------------------------------------------------------------------
   Joystick (sol) ve ates butonu (sag) BIRBIRINE MIRROR (ayna) sekilde
   hizali. Ikisi de asagidaki tek tabandan olcer:
     --ctl-size    buton capi (joystick taban capi = bunun 0.8'i)
     --ctl-margin  kenardan ic bosluk (ates sagda, joystick solda)
     --ctl-bottom  alt kenardan yukseklik (home indicator uzerinde kalir)
   Boylece birini degistirince digeri de otomatik hizalanir; elle
   "px degerleri" tutmak yok olur.
   =================================================================== */
#touch-ui {
    --ctl-size: 92px;
    --ctl-margin: 20px;
    --ctl-bottom: 18px;
    display: none;
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Sol yarida dokunulan alan. Genislik/yukseklik ortam modunda degisir,
   ama hizalama daima --ctl-margin/--ctl-bottom tarafindan hesaplanir. */
#stick-zone {
    position: absolute;
    left: var(--sal, 0px);
    bottom: var(--sab, 0px);
    width: 42%;
    height: 72%;
    pointer-events: auto;
    touch-action: none;
}

/* Konum transform ile verilir (left/top DEGIL): left/top degistirmek
   her dokunusta layout (yeniden hesaplama) tetikler ve girdi
   gecikmesi yaratir. transform yalnizca compositor'i uyarir, aninda
   uygulanir. Bu, joystick'in "tutuk" hissinin ana kaynagidi. */
#stick-base {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--stick-size, 74px);
    height: var(--stick-size, 74px);
    /* transform merkezden konumlandiracak; yarim boyut kadar cek */
    margin-left: calc(var(--stick-size, 74px) / -2);
    margin-top: calc(var(--stick-size, 74px) / -2);
    border-radius: 50%;
    background: rgba(20, 35, 55, 0.42);
    border: 2px solid rgba(120, 190, 255, 0.35);
    opacity: 0;
    transition: opacity 0.12s;
    pointer-events: none;
    /* transform JS tarafindan surulur; gecis YALNIZCA opacity icin,
       yoksa joystick parmak hareketinde geri kalir (gecikmeli his). */
    will-change: transform;
}

#stick-base.on { opacity: 1; }

#stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: calc(var(--stick-size, 74px) * 0.46);
    height: calc(var(--stick-size, 74px) * 0.46);
    border-radius: 50%;
    background: rgba(120, 200, 255, 0.55);
    border: 2px solid rgba(190, 230, 255, 0.8);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

#btn-fire {
    position: absolute;
    /* Ayna hizalama: ates sag kenarda, joystick sol kenarda -- ayni
       margin ve alt bosluk. */
    right: calc(var(--ctl-margin) + var(--sar, 0px));
    bottom: calc(var(--ctl-bottom) + var(--sab, 0px));
    width: var(--ctl-size);
    height: var(--ctl-size);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ff6b4a, #d0341c);
    border: 3px solid rgba(255, 200, 180, 0.55);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    touch-action: none;
    transition: transform 0.08s, filter 0.08s;
}

#btn-fire span {
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#btn-fire.on {
    transform: scale(0.92);
    filter: brightness(1.35);
}

.touchmode { display: none; }

/* ---------------- yatay mod ipucu ---------------- */
#rotate-tip {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    z-index: 60;
    background: rgba(10, 18, 30, 0.94);
    border: 1px solid rgba(120, 190, 255, 0.4);
    color: #dceaf8;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    text-align: center;
    pointer-events: none;
    animation: rotatePulse 2s ease-in-out infinite;
}

@keyframes rotatePulse {
    0%, 100% { opacity: 0.92; transform: translate(-50%, -50%) scale(1); }
    50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.04); }
}

/* ---------------- yatay mod: kontroller kenarlarda ---------------- */
@media (pointer: coarse) and (orientation: landscape) {
    #rotate-tip { display: none; }

    /* Yatayda ekran genis, oyun alani ortada; kontroller siyah bosluklara
       oturur. Joystick ve ates ayni olcude (--ctl-*) ve ayna hizada.
       Oyun alaninin altinda bosluk birakmaya GEREK YOK -> bottomPad
       resizeCanvas icinde kucultuluyor, oyun alani buyuyor. */
    #touch-ui {
        --ctl-size: 78px;
        --ctl-margin: 16px;
        --ctl-bottom: 14px;
        --stick-size: 64px;
    }
    /* Sol dokunma alani: ekranin sol %32'si, tum yukseklik */
    #stick-zone {
        left: var(--sal, 0px);
        bottom: var(--sab, 0px);
        width: 32%;
        height: 100%;
    }
    /* Dinlenme halinde taban gorunur (kumanda yerini belli eder) */
    #stick-base { opacity: 0.4; }
    #stick-base.on { opacity: 1; }
    #btn-fire span { font-size: 13px; }
    #controls-hint { display: none; }
    #boss-bar { transform: translateX(-50%) scale(0.85); }
}

/* cok kisa ekranlar (yatay cep telefonlari) */
@media (max-height: 400px) and (pointer: coarse) {
    .ui-box { padding: 2px 6px; font-size: 10px; }
    .ui-box b { font-size: 11px; }
    .bar { width: 24px; height: 5px; }
    #ui-panel { top: calc(3px + var(--sat, 0px)); gap: 3px; }
    .icon-btn { padding: 3px 6px; font-size: 12px; }
    /* Kontrolleri biraz daha kucult, ama HIZALAMA bozulmaz:
       --ctl-* ve --stick-size birlikte olceklendirilir. */
    #touch-ui { --ctl-size: 68px; --ctl-margin: 12px; --ctl-bottom: 10px; --stick-size: 56px; }
}
@media (pointer: coarse) {
    #controls-hint .kbmode { display: none; }
    #controls-hint .touchmode { display: inline; }
    /* Mobilde ipucu gizli -> oyun alani tum ekrani kullanir */
    #controls-hint { display: none; }
    .ui-box { background: rgba(8, 18, 30, 0.72); }
    #controls-hint { bottom: 3px; font-size: 10px; }

    /* HUD yerlesimi: kucuk ve sikilmis */
    #ui-panel {
        top: 5px;
        left: 5px;
        right: 5px;
        gap: 4px;
    }
    .ui-box {
        min-width: 0;
        padding: 3px 8px;
        font-size: 11px;
        gap: 4px;
        border-radius: 12px;
    }
    .ui-box b { font-size: 12px; }
    .bar { width: 30px; height: 6px; }

    /* mobilde yer kaplamayan bilgiler gizlenir */
    #ui-panel .ui-box.opt { display: none; }
    #who { max-width: 56px; }
    .icon-btn { padding: 4px 7px; font-size: 13px; }
    #ui-buttons { gap: 5px; }

    /* Menuler tam genislik, kaydirilabilir */
    .menu-content { padding: 1.1rem 1.2rem; max-width: 96%; }
    .menu-content h2 { font-size: 20px; }
    .menu-content .lead { font-size: 12px; margin-bottom: 9px; }
    .menu-content .keys { font-size: 11px; line-height: 1.5; }
    .field input { min-width: 100px; }
    .stats { grid-template-columns: 1fr 1fr; gap: 3px 8px; }
    .prof-stats div { min-width: 70px; padding: 5px 8px; }
    .prof-stats b { font-size: 16px; }
    .menu-content.wide { padding: 1rem 1.1rem; }
    #rotate-tip { top: 30%; font-size: 13px; padding: 10px 16px; }
}

/* Dikeyde: joystick ve ates oyun alaninin uzerine biner (yarı saydam),
   boylece oyun alani tum ekrani kullanir. */
@media (pointer: coarse) and (orientation: portrait) {
    /* Dikeyde parmak erisimi icin kontroller biraz buyuk ve alt kenara
       yakin; hizalama yine ayni --ctl-* tabanindan. */
    #touch-ui {
        --ctl-size: 84px;
        --ctl-margin: 18px;
        --ctl-bottom: 26px;
        --stick-size: 70px;
    }
    #stick-zone {
        width: 46%;
        height: 46%;
        left: var(--sal, 0px);
        bottom: var(--sab, 0px);
    }
    /* Dinlenme halinde soluk taban: kumanda nerede oldugunu belli eder */
    #stick-base { opacity: 0.4; }
    #stick-base.on { opacity: 1; }
    #btn-fire { opacity: 0.9; }
}

#controls-hint {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.45);
    font-size: 11px;
    text-align: center;
    width: 90%;
    pointer-events: none;
    z-index: 10;
}

/* ---------------- menüler ---------------- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 16px;
    overflow: auto;
}

#menu-overlay {
    display: flex;
}

.menu-content {
    background: #1b2c42;
    border: 1px solid rgba(110, 180, 240, 0.22);
    padding: 1.6rem 2.2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 92%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.menu-content h2 {
    margin-bottom: 8px;
    font-size: 26px;
}

.menu-content p {
    margin: 4px 0;
    font-size: 14px;
    opacity: 0.85;
}

.menu-content .lead {
    font-size: 15px;
    margin-bottom: 14px;
}

.menu-content .keys {
    font-size: 12px;
    line-height: 1.7;
    margin-top: 12px;
}

.menu-content .tiny {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 12px;
}

.field {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    margin: 10px 0 4px;
}

.field select,
.field input {
    background: #0e1a2a;
    color: #fff;
    border: 1px solid rgba(110, 180, 240, 0.3);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

.field input {
    cursor: text;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: bold;
    color: #f1c40f;
    min-width: 130px;
    text-align: center;
}

.field input:focus-visible {
    outline: 2px solid #f1c40f;
    outline-offset: 1px;
    border-color: #f1c40f;
}

.menu-content .who {
    color: #f1c40f;
    font-weight: bold;
    font-size: 17px;
    letter-spacing: 1px;
    margin: 2px 0 4px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 6px 18px;
    margin: 14px 0 6px;
    text-align: left;
}

.stats div {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    opacity: 0.9;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
    padding-bottom: 3px;
}

.stats b {
    color: #ffd93d;
}

button {
    margin-top: 12px;
    padding: 10px 22px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-family: inherit;
    display: block;
    margin-left: auto;
    margin-right: auto;
    transition: background 0.2s;
}

button:hover {
    background: #c0392b;
}

button:focus-visible {
    outline: 2px solid #ffd93d;
    outline-offset: 2px;
}

button.secondary {
    background: #34495e;
    font-size: 14px;
    padding: 8px 18px;
}

button.secondary:hover {
    background: #1b2c42;
}
