/* =====================================================
   ราชาแห่งความโชคดี — Mobile-first CSS
   ===================================================== */

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

:root {
    --gold:        #FFB300;
    --gold-dark:   #C28000;
    --purple:      #4A1FAD;
    --purple-dark: #1A0E3D;
    --pink:        #FF4D8D;
    --green:       #4CD964;
    --red:         #FF3B30;
    --text:        #FFFFFF;
    --text-mute:   #C8B9E8;
    --shadow:      0 4px 24px rgba(0, 0, 0, .35);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(180deg, #1A0E3D 0%, #4A1FAD 100%);
    font-family: 'Kanit', 'Prompt', 'Noto Sans Thai', system-ui, sans-serif;
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;     /* ปิด double-tap zoom */
    overscroll-behavior: none;      /* ปิด pull-to-refresh */
}

/* ====== Phaser canvas mount ====== */
#game-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    /* ปล่อยให้ Phaser autoCenter จัดการ centering — ไม่ใช้ flex
       เพราะ flex + Phaser transform จะสู้กัน ทำให้ canvas เคลื่อนไปด้านขวาบนจอ desktop */
    overflow: hidden;
}
#game-container canvas {
    display: block !important;
    margin: 0 auto !important;
    image-rendering: auto;          /* SVG/raster ไม่ต้อง pixelated */
}

/* Desktop: vignette + radial glow รอบ canvas เพื่อให้ดูสวย letterbox */
@media (min-width: 768px) {
    body {
        background:
            radial-gradient(ellipse 60% 80% at center, rgba(255, 213, 79, .08) 0%, transparent 70%),
            radial-gradient(circle at 30% 20%, rgba(255, 77, 141, .06) 0%, transparent 50%),
            linear-gradient(180deg, #1A0E3D 0%, #2A1556 100%);
    }
}

/* ====== Overlay (login / boot) ====== */
.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: radial-gradient(circle at 50% 30%, rgba(255, 179, 0, .12), transparent 60%),
                linear-gradient(180deg, #1A0E3D 0%, #2A1556 100%);
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.overlay.hidden { display: none; }

/* ====== Boot loader ====== */
.boot-spin {
    font-size: 72px;
    animation: spin 1.4s cubic-bezier(.5, .1, .5, .9) infinite;
    text-align: center;
    margin-bottom: 16px;
}
.boot-text {
    text-align: center;
    color: var(--text-mute);
    font-size: 18px;
    letter-spacing: .04em;
}
@keyframes spin {
    0%   { transform: rotate(0deg)   scale(1);   }
    50%  { transform: rotate(180deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1);   }
}

/* ====== Auth card ====== */
.auth-card {
    width: 100%;
    max-width: 420px;
    background: rgba(26, 14, 61, .85);
    backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 179, 0, .4);
    border-radius: 24px;
    padding: 28px 22px;
    box-shadow: var(--shadow);
    animation: pop 320ms cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes pop {
    from { transform: scale(.85); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.auth-logo {
    text-align: center;
    margin-bottom: 18px;
}
.auth-logo-icon {
    font-size: 56px;
    filter: drop-shadow(0 0 12px rgba(255, 179, 0, .6));
    animation: float 3s ease-in-out infinite;
}
.auth-logo-text {
    margin-top: 4px;
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(180deg, #FFE082, #FFB300);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

.auth-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
    background: rgba(0, 0, 0, .25);
    padding: 4px;
    border-radius: 14px;
}
.tab {
    flex: 1;
    background: transparent;
    color: var(--text-mute);
    border: 0;
    padding: 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .2s;
}
.tab.active {
    background: linear-gradient(180deg, #FFB300, #C28000);
    color: #FFF;
    box-shadow: 0 2px 8px rgba(255, 179, 0, .4);
}

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form.hidden { display: none; }
.auth-form input {
    background: rgba(0, 0, 0, .3);
    border: 1.5px solid rgba(255, 255, 255, .15);
    color: #FFF;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 16px;       /* 16px = iOS ไม่ zoom เวลาโฟกัส */
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}
.auth-form input:focus {
    border-color: var(--gold);
    background: rgba(0, 0, 0, .45);
}

.btn-primary {
    margin-top: 6px;
    background: linear-gradient(180deg, #FFD54F, #FF8F00);
    color: #2A1556;
    border: 0;
    padding: 16px;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 0 #C28000, 0 6px 16px rgba(0,0,0,.25);
    transition: transform .12s, box-shadow .12s;
    letter-spacing: .04em;
}
.btn-primary:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #C28000, 0 3px 6px rgba(0,0,0,.25);
}
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.auth-error {
    margin-top: 12px;
    padding: 10px;
    background: rgba(255, 59, 48, .15);
    border: 1px solid rgba(255, 59, 48, .5);
    color: #FFB0AB;
    border-radius: 10px;
    font-size: 14px;
    text-align: center;
}
.auth-error.hidden { display: none; }

/* ===== Settings Modal ===== */
.settings-card {
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
    background: rgba(26, 14, 61, .95);
    backdrop-filter: blur(14px);
    border: 2px solid rgba(255, 213, 79, 0.5);
    border-radius: 24px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
    animation: pop 280ms cubic-bezier(.34, 1.56, .64, 1);
}
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 213, 79, .25);
}
.settings-title {
    font-size: 22px; font-weight: 700;
    color: var(--gold);
}
.settings-close {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #FFF;
    width: 36px; height: 36px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
}
.settings-close:active { transform: scale(0.92); }

.settings-section {
    margin-bottom: 16px;
}
.settings-label {
    display: block;
    color: var(--gold);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Profile preview */
.profile-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    background: rgba(255, 213, 79, .08);
    border: 1px solid rgba(255, 213, 79, .25);
    border-radius: 14px;
}
.profile-avatar {
    font-size: 48px;
    width: 64px; height: 64px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(180deg, rgba(255,213,79,0.3), rgba(255,143,0,0.3));
    border: 2px solid var(--gold);
    border-radius: 50%;
}
.profile-name { font-size: 18px; font-weight: 700; color: #FFF; }
.profile-id   { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

/* Avatar grid */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}
.avatar-cell {
    aspect-ratio: 1;
    font-size: 28px;
    background: rgba(0,0,0,0.25);
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform .12s, border-color .12s;
    font-family: inherit;
}
.avatar-cell:active { transform: scale(0.9); }
.avatar-cell.selected {
    border-color: var(--gold);
    background: rgba(255, 213, 79, 0.18);
    box-shadow: 0 0 12px rgba(255, 213, 79, 0.5);
}

/* Birth row */
.birth-input-row {
    display: flex;
    gap: 8px;
}
.birth-input-row input {
    flex: 1;
    background: rgba(0, 0, 0, .3);
    border: 1.5px solid rgba(255, 255, 255, .15);
    color: #FFF;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 16px;
    color-scheme: dark;
    font-family: inherit;
}
.birth-save-btn {
    background: linear-gradient(180deg, #FFD54F, #FF8F00);
    color: #2A1556;
    border: 0;
    padding: 0 18px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.birth-display {
    padding: 12px 14px;
    background: rgba(255, 213, 79, 0.1);
    border: 1px dashed rgba(255, 213, 79, 0.4);
    border-radius: 10px;
    color: var(--gold);
    font-size: 14px;
}
.birth-display .num {
    display: inline-block;
    background: var(--gold);
    color: #2A1556;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
}
.birth-locked-note {
    font-size: 11px;
    color: var(--text-mute);
    margin-top: 4px;
}

/* Sound toggle */
.settings-toggle {
    background: rgba(76, 217, 100, 0.2);
    border: 1.5px solid #4CD964;
    color: #4CD964;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.settings-toggle.off {
    background: rgba(255, 59, 48, 0.15);
    border-color: var(--red);
    color: var(--red);
}

/* Danger zone */
.btn-danger {
    width: 100%;
    background: linear-gradient(180deg, #EF5350, #B71C1C);
    color: #FFF;
    border: 0;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 0 #7F0000;
    transition: transform .1s, box-shadow .1s;
}
.btn-danger:active { transform: translateY(3px); box-shadow: 0 1px 0 #7F0000; }

/* ===== Birth date section (in register form) ===== */
.birth-section {
    margin-top: 4px;
    padding: 12px;
    background: rgba(255, 213, 79, 0.08);
    border: 1px dashed rgba(255, 213, 79, .4);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.birth-label {
    font-size: 13px;
    color: var(--gold);
    font-weight: 600;
}
.birth-date {
    background: rgba(0, 0, 0, .3) !important;
    color: #FFF;
    color-scheme: dark;       /* iOS calendar dark theme */
}
.birth-hint {
    font-size: 11px;
    color: var(--text-mute);
    margin-top: 2px;
}

/* ====== Toast (เรียกจาก JS) ====== */
.kof-toast {
    position: fixed;
    top: max(24px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .82);
    color: #FFF;
    padding: 12px 20px;
    border-radius: 999px;
    font-size: 14px;
    z-index: 9999;
    animation: toast-in .3s ease-out, toast-out .3s ease-in 2.4s forwards;
    pointer-events: none;
}
@keyframes toast-in  { from { opacity: 0; transform: translate(-50%, -16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-out { to   { opacity: 0; transform: translate(-50%, -16px); } }

/* iPhone safe-area helper สำหรับ canvas overlay */
@supports (padding: max(0px)) {
    .overlay { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
