/* ============================================
   CJWORLD Thai — Gold & Red Premium Theme
   Mobile-First / Modern / Glassmorphism
   ============================================ */

:root {
    --red-900: #2D0A0A;
    --red-800: #4A0E0E;
    --red-700: #6B1515;
    --red-600: #8B1A1A;
    --red-500: #A52A2A;
    --red-400: #C0392B;

    --gold-600: #9E7B16;
    --gold-500: #C8A415;
    --gold-400: #D4AF37;
    --gold-300: #E8C547;
    --gold-200: #F0D664;

    --gold-gradient: linear-gradient(135deg, #F0D664 0%, #D4AF37 35%, #C8A415 65%, #9E7B16 100%);
    --red-gradient: linear-gradient(135deg, #C0392B 0%, #8B1A1A 50%, #4A0E0E 100%);
    --dark-gradient: linear-gradient(160deg, #1a0808 0%, #2D0A0A 40%, #4A0E0E 100%);

    --bg: #0f0505;
    --card-bg: rgba(45, 10, 10, 0.85);
    --card-border: rgba(212, 175, 55, 0.25);
    --text: #F5E6D0;
    --text-muted: rgba(245, 230, 208, 0.6);
    --shadow: rgba(0, 0, 0, 0.4);

    --radius: 16px;
    --radius-sm: 10px;
    --nav-height: 64px;
    --header-height: 64px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Kanit', sans-serif;
    background: var(--dark-gradient);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ── Splash Screen ── */
.splash {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.splash-bg {
    position: absolute;
    inset: 0;
    background: var(--dark-gradient);
}

.splash-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 32px 24px;
}

.splash-logo-wrap {
    width: 100px;
    height: 100px;
    margin: 0 auto 20px;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(212, 175, 55, 0.3);
    animation: logoPulse 2s ease-in-out infinite;
}

.splash-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.splash-title {
    font-size: 28px;
    font-weight: 700;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.splash-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 300;
    margin-bottom: 24px;
}

.splash-progress-track {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin: 0 auto 12px;
    overflow: hidden;
}

.splash-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gold-gradient);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.splash-percent {
    color: var(--gold-400);
    font-size: 13px;
    font-weight: 500;
}

@keyframes logoPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 32px rgba(212, 175, 55, 0.3); }
    50% { transform: scale(1.03); box-shadow: 0 12px 40px rgba(212, 175, 55, 0.45); }
}

/* ── Header ── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(180deg, rgba(45, 10, 10, 0.98) 0%, rgba(45, 10, 10, 0.92) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    max-width: 600px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.2);
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 300;
}

.lang-select {
    background: rgba(212, 175, 55, 0.12);
    color: var(--gold-400);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.lang-select option {
    background: var(--red-900);
    color: var(--text);
}

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    margin: 12px 16px;
    padding: 0;
    overflow: hidden;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--red-gradient);
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}

.card-header i {
    color: var(--gold-400);
    font-size: 18px;
}

.card-header h2 {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: var(--gold-300);
}

.card-desc {
    padding: 12px 16px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.date-badge {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold-400);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid rgba(212, 175, 55, 0.25);
}

/* ── Check Form ── */
.check-form {
    padding: 16px;
}

.input-group {
    position: relative;
    margin-bottom: 12px;
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold-500);
    font-size: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px 14px 14px 44px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 18px;
    font-family: inherit;
    font-weight: 600;
    letter-spacing: 4px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: var(--gold-400);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

.input-group input::placeholder {
    color: var(--text-muted);
    letter-spacing: 1px;
    font-weight: 400;
    font-size: 14px;
}

.check-actions {
    display: flex;
    gap: 10px;
}

.check-result {
    padding: 0 16px 16px;
    font-size: 15px;
    font-weight: 500;
    text-align: center;
}

.check-result:empty {
    display: none;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    flex: 1;
    background: var(--red-gradient);
    color: var(--gold-300);
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-outline {
    background: transparent;
    color: var(--gold-400);
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.btn-outline:active {
    background: rgba(212, 175, 55, 0.1);
}

.btn-gold {
    background: var(--gold-gradient);
    color: var(--red-900);
    font-weight: 700;
    border: none;
    box-shadow: 0 2px 12px rgba(212, 175, 55, 0.3);
}

.btn-gold:active {
    transform: scale(0.97);
    box-shadow: 0 1px 6px rgba(212, 175, 55, 0.2);
}

.btn-send {
    background: var(--gold-gradient);
    color: var(--red-900);
    font-weight: 700;
    padding: 12px 20px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

/* ── Stock Grid ── */
.stock-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    background: rgba(212, 175, 55, 0.08);
}

.stock-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--card-bg);
    transition: background 0.2s;
}

.stock-item:active {
    background: rgba(212, 175, 55, 0.05);
}

.stock-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
}

.stock-name img {
    width: 22px;
    height: 16px;
    border-radius: 2px;
    object-fit: cover;
}

.stock-nums {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.stock-nums b {
    color: var(--gold-400);
    font-weight: 700;
    font-size: 14px;
}

/* ── Prize Display ── */
.prize-main {
    padding: 20px 16px;
    text-align: center;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.08) 0%, rgba(139, 26, 26, 0.15) 100%);
}

.prize-number {
    font-size: 36px;
    font-weight: 700;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 6px;
    text-shadow: none;
}

.prize-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: rgba(212, 175, 55, 0.08);
}

.prize-box {
    text-align: center;
    padding: 12px 8px;
    background: var(--card-bg);
}

.prize-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 400;
}

.prize-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--gold-400);
}

/* ── Lucky Numbers ── */
.lucky-main {
    text-align: center;
    padding: 24px 16px;
}

.lucky-main h3 {
    font-size: 16px;
    color: var(--gold-300);
    margin-bottom: 12px;
}

.lucky-big-number {
    font-size: 56px;
    font-weight: 700;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    line-height: 1;
}

.lucky-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.tips-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 16px 16px;
}

.tip-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 14px 10px;
    text-align: center;
}

.tip-icon {
    font-size: 24px;
    margin-bottom: 6px;
}

.tip-card h4 {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 8px;
}

.tip-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--gold-400);
}

/* ── Games ── */
.game-section {
    padding: 16px;
}

.game-instruction {
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.number-btn {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    font-family: inherit;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    border: 2px solid var(--card-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.number-btn:active,
.number-btn.selected {
    background: var(--gold-gradient);
    color: var(--red-900);
    border-color: var(--gold-400);
    transform: scale(0.95);
    box-shadow: 0 0 16px rgba(212, 175, 55, 0.4);
}

.game-result-area {
    text-align: center;
    margin-bottom: 16px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--card-border);
}

.selected-display {
    font-size: 14px;
    color: var(--gold-400);
    margin-bottom: 8px;
    font-weight: 500;
}

.result-display {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.result-display.correct {
    color: #4CAF50;
    font-weight: 600;
}

.result-display.wrong {
    color: var(--red-400);
    font-weight: 600;
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat {
    font-size: 13px;
    color: var(--text-muted);
}

.stat b {
    color: var(--gold-400);
}

.game-actions {
    display: flex;
    gap: 10px;
}

.game-actions .btn {
    flex: 1;
}

.section-title {
    padding: 16px 16px 10px;
    font-size: 16px;
    color: var(--gold-300);
}

.mini-games {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 16px 16px;
}

.mini-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.mini-card h4 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 10px;
    font-weight: 500;
}

.mini-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--gold-400);
    margin-bottom: 12px;
}

/* ── Chat ── */
.chat-card {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--nav-height) - 24px);
    margin-bottom: calc(var(--nav-height) + 12px);
}

.chat-tips {
    padding: 12px 16px;
    border-bottom: 1px solid var(--card-border);
}

.tips-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--gold-300);
    margin-bottom: 6px;
}

.tip-item {
    font-size: 12px;
    color: var(--text-muted);
    padding: 2px 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: msgSlide 0.3s ease;
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.user-message .message-avatar {
    background: var(--gold-gradient);
    color: var(--red-900);
}

.ai-message .message-avatar {
    background: var(--red-gradient);
    color: var(--gold-400);
    border: 1px solid var(--card-border);
}

.message-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.user-message .message-content {
    background: var(--gold-gradient);
    color: var(--red-900);
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    border: 1px solid var(--card-border);
    border-bottom-left-radius: 4px;
}

.typing-indicator .typing-dots {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 14px;
    border: 1px solid var(--card-border);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--gold-400);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes msgSlide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--card-border);
    background: rgba(0, 0, 0, 0.2);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--gold-400);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

/* ── Message Actions ── */
.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.message-actions button {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.message-actions button.active {
    color: var(--gold-400);
    border-color: var(--gold-400);
}

/* ── History ── */
.history-section {
    padding: 16px;
    border-top: 1px solid var(--card-border);
}

.history-section h3 {
    font-size: 15px;
    color: var(--gold-300);
    margin-bottom: 10px;
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.history-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(212, 175, 55, 0.08);
}

.history-item:last-child {
    border-bottom: none;
}

/* ── Bottom Navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    display: flex;
    z-index: 200;
    background: linear-gradient(180deg, rgba(30, 8, 8, 0.95) 0%, rgba(20, 5, 5, 0.98) 100%);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--card-border);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tab-icon {
    font-size: 18px;
    transition: all 0.2s;
}

.tab.active {
    color: var(--gold-400);
}

.tab.active .tab-icon {
    transform: scale(1.1);
}

.tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--gold-gradient);
    border-radius: 0 0 4px 4px;
}

.tab:active {
    transform: scale(0.92);
}

/* ── Content Areas ── */
.lotto-results,
.tab-content {
    padding-bottom: calc(var(--nav-height) + 16px);
    max-width: 600px;
    margin: 0 auto;
}

/* ── Notification ── */
.notification {
    position: fixed;
    top: 16px;
    right: 16px;
    left: 16px;
    max-width: 400px;
    margin: 0 auto;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    text-align: center;
    animation: notifSlide 0.3s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.notification.success {
    background: rgba(76, 175, 80, 0.9);
    color: #fff;
    border: 1px solid rgba(76, 175, 80, 0.5);
}

.notification.error {
    background: rgba(244, 67, 54, 0.9);
    color: #fff;
    border: 1px solid rgba(244, 67, 54, 0.5);
}

@keyframes notifSlide {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.2);
    border-radius: 4px;
}

/* ── Responsive: Tablet+ ── */
@media (min-width: 600px) {
    .stock-grid {
        grid-template-columns: 1fr 1fr;
    }

    .number-grid {
        grid-template-columns: repeat(5, 60px);
        justify-content: center;
    }

    .tips-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ── Safe area for notch devices ── */
@supports (padding: env(safe-area-inset-bottom)) {
    .bottom-nav {
        height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    }

    .lotto-results,
    .tab-content {
        padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
    }
}
