:root {
    --bg: #000000;
    --card-bg: #1a1f2e;
    --primary: #4a8cff;
    --primary-glow: rgba(74, 140, 255, 0.3);
    --text: #ffffff;
    --text-secondary: #8e9ab4;
    --text-muted: #5a6478;
    --border: rgba(255, 255, 255, 0.06);
    --danger: #ff4757;
    --success: #2ed573;
    --purple: #8b5cf6;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#content {
    flex: 1;
    padding: 0 16px 16px;
    padding-bottom: 80px;
}

.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
    font-size: 14px;
}

/* ── Top Bar ──────────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-back {
    background: none;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.topbar-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.topbar-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 400;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.topbar-currency {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
}

.topbar-currency.energy {
    color: #ffd700;
}

.topbar-currency.gems {
    color: var(--primary);
}

.topbar-plus {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    padding: 0 4px;
}

.topbar-menu {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
}

/* ── Bottom Navbar ────────────────────────────────────── */

.navbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s;
}

.nav-tab.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 22px;
}

.nav-label {
    font-size: 11px;
}

/* ── Characters Page ──────────────────────────────────── */

.tab-switcher {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 3px;
}

.tab-btn {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: #fff;
}

.char-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.char-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.char-card:active {
    transform: scale(0.96);
}

.char-card .card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background: #111827;
}

.char-card .card-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.char-card .card-img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    display: block;
    background: #111827;
}

.char-card .card-img-placeholder {
    width: 100%;
    aspect-ratio: 3 / 4;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1f2e, #2a3040);
    font-size: 48px;
}

.char-card .card-body {
    padding: 12px;
}

.char-card .card-name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
}

.char-card .card-tagline {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Story Page ───────────────────────────────────────── */

.story-header {
    text-align: center;
    margin-bottom: 16px;
}

.story-hero-video {
    width: 100%;
    max-width: 280px;
    border-radius: 16px;
    margin-bottom: 12px;
}

.story-header h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.story-header p {
    color: var(--text-secondary);
    font-size: 13px;
}

.story-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.story-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    background: var(--card-bg);
}

.story-card:active {
    transform: scale(0.98);
}

.story-card .story-img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
    background: #111827;
}

.story-card .story-img-placeholder {
    width: 100%;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1f2e, #2a3040);
    font-size: 28px;
    color: var(--text-secondary);
}

.story-card .story-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
}

.story-card .story-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.story-card .story-desc {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
}

/* ── Chat View ────────────────────────────────────────── */

.chat-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0 -16px;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-back {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px 4px 0;
}

.chat-title-block {
    flex: 1;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-story-name {
    font-size: 12px;
    color: var(--primary);
}

.chat-reset {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
}

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

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: bubbleIn 0.2s ease;
}

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

.chat-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: var(--card-bg);
    color: var(--text);
    border-bottom-left-radius: 6px;
}

.chat-system {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 8px;
}

.chat-bubble.typing {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
}

.chat-bubble.typing .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingBounce 1.2s infinite;
}

.chat-bubble.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble.typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.bubble-play-btn {
    display: inline-block;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
    margin-left: 4px;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
    vertical-align: middle;
}

.bubble-play-btn:active {
    transform: scale(1.3);
    opacity: 1;
}

.bubble-play-btn.playing {
    opacity: 1;
    animation: playPulse 1s infinite;
}

@keyframes playPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.9); }
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    outline: none;
}

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

.chat-send {
    padding: 10px 18px;
    border: none;
    border-radius: 20px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.chat-send:active {
    opacity: 0.8;
}

/* ── Items Page ───────────────────────────────────────── */

.items-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.item-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    text-align: center;
}

.item-card .item-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: #111827;
}

.item-card .item-img-placeholder {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1f2e, #2a3040);
    font-size: 40px;
}

.item-card .item-body {
    padding: 12px;
}

.item-card .item-name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-bottom: 8px;
}

.item-card .item-name {
    font-size: 14px;
    font-weight: 600;
}

.item-card .item-info-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
}

.item-card .item-price-btn {
    display: inline-block;
    padding: 6px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.item-card .item-price-btn:active {
    opacity: 0.8;
}

/* ── Insufficient Gems Modal ──────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}

.modal {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.modal h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.modal .modal-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.modal-packages {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.modal-pkg {
    flex: 1;
    background: var(--bg);
    border-radius: 12px;
    padding: 12px 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
    position: relative;
}

.modal-pkg.best {
    border-color: var(--primary);
}

.modal-pkg-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 8px;
    white-space: nowrap;
}

.modal-pkg-gems {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal-pkg-price {
    font-size: 12px;
    color: var(--text-secondary);
}

.modal-view-more {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.modal-close {
    margin-top: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}

/* ── Store Page ───────────────────────────────────────── */

.store-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

.store-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.store-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px 8px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.15s;
    position: relative;
}

.store-card:active {
    transform: scale(0.96);
}

.store-card.best-offer {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

.store-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 8px;
    white-space: nowrap;
}

.store-gem-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.store-gem-count {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.store-price {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── Chats Page ───────────────────────────────────────── */

.chats-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
}

.chats-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.chat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.chat-row:active {
    background: rgba(255, 255, 255, 0.03);
}

.chat-row-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--card-bg);
}

.chat-row-avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.chat-row-body {
    flex: 1;
    min-width: 0;
}

.chat-row-top {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.chat-row-name {
    font-size: 15px;
    font-weight: 600;
}

.chat-row-story {
    font-size: 12px;
    color: var(--primary);
}

.chat-row-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-row-time {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 2px;
}

.chats-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
    font-size: 14px;
}

/* ── Settings Page ────────────────────────────────────── */

.settings-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
}

.sub-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
}

.sub-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sub-card-name {
    font-size: 18px;
    font-weight: 700;
}

.sub-card-expires {
    font-size: 13px;
    color: var(--text-secondary);
}

.sub-card-actions {
    display: flex;
    gap: 8px;
}

.sub-card-actions .btn-extend {
    flex: 1;
    padding: 10px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.settings-row-icon {
    font-size: 20px;
}

.settings-row-label {
    flex: 1;
    font-size: 15px;
}

.settings-row-value {
    font-size: 14px;
    color: var(--text-secondary);
}

.settings-row-arrow {
    color: var(--text-muted);
    font-size: 16px;
}

/* ── Choose Your Plan ─────────────────────────────────── */

.plan-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}

.plan-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.plan-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 14px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.plan-option.selected {
    border-color: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
}

.plan-radio {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.plan-option.selected .plan-radio {
    border-color: var(--primary);
    background: var(--primary);
}

.plan-radio-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    display: none;
}

.plan-option.selected .plan-radio-dot {
    display: block;
}

.plan-info {
    flex: 1;
}

.plan-name {
    font-size: 16px;
    font-weight: 600;
}

.plan-price {
    font-size: 14px;
    color: var(--primary);
    font-weight: 600;
}

.plan-benefits {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    padding: 0 4px;
}

.plan-benefit {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.plan-benefit-icon {
    font-size: 16px;
}

.plan-upgrade-btn {
    display: block;
    width: 100%;
    padding: 16px;
    background: var(--purple);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
}

.plan-upgrade-btn:active {
    opacity: 0.8;
}

.plan-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 12px;
}

/* ── Language Page ─────────────────────────────────────── */

.lang-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
}

.lang-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.lang-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 15px;
}

.lang-option .lang-check {
    color: var(--primary);
    font-size: 18px;
    font-weight: 700;
    visibility: hidden;
}

.lang-option.selected .lang-check {
    visibility: visible;
}

.lang-note {
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

/* ── General Utilities ────────────────────────────────── */

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    margin-top: 20px;
}
