:root {
    --bg-color: #0b0f19;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #6366f1;
    --surface-bg: rgba(17, 24, 39, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent 400px),
                      radial-gradient(circle at bottom left, rgba(236, 72, 153, 0.1), transparent 400px);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3 { font-family: 'Playfair Display', serif; }

#app {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.8s ease-out;
}

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

/* --- Selection Screen Styles --- */
.selection-header {
    text-align: center;
    margin-bottom: 4rem;
    margin-top: 2rem;
}

.selection-header h1 {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #e0e7ff 0%, #818cf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -1px;
}

.selection-header p {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.philosopher-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2.5rem;
    padding: 1rem;
}

/* --- 3D Card Flip Mechanism --- */
.card {
    background: transparent;
    border: none;
    border-radius: 16px;
    perspective: 1000px; /* Gives the 3D depth to the flip */
    cursor: pointer;
    min-height: 480px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border-radius: 16px;
}

.card:hover .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 16px;
    background: var(--surface-bg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
}

/* Front styling */
.portrait-container {
    width: 100%;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(255,255,255,0.02) 0%, transparent 60%);
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
}

.portrait {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    object-position: top;
    border: 3px solid var(--bust-color);
    box-shadow: 0 0 15px var(--bust-color);
    animation: floatBust 4s ease-in-out infinite;
}

@keyframes floatBust {
    0%, 100% { transform: translateY(0) scale(1); box-shadow: 0 0 10px var(--bust-color); }
    50% { transform: translateY(-7px) scale(1.05); box-shadow: 0 0 25px var(--bust-color); }
}

.card-content {
    padding: 1.5rem;
    flex: 1;
}

.card-content h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: #fff;
}

.card-content p {
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 0.95rem;
}

/* Back styling */
.card-back {
    transform: rotateY(180deg);
    padding: 2rem;
    text-align: left;
    background: rgba(10, 15, 25, 0.95);
}

.card-back h3 {
    font-size: 1.6rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
}

.card-back .details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    font-size: 0.95rem;
    color: #e2e8f0;
}

.card-back .details strong {
    color: var(--text-secondary);
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-now-btn {
    margin-top: auto;
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    transition: filter 0.2s, transform 0.2s;
    font-size: 1rem;
}

.card-inner:hover .chat-now-btn {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

/* --- Chat Screen Styles --- */
#app.chat-mode {
    padding: 0;
    max-width: 900px;
    height: 100vh;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(17, 24, 39, 0.85);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    margin-right: 1rem;
    display: flex;
    transition: background 0.2s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    object-position: top;
    margin-right: 1rem;
    border: 2px solid var(--bust-color);
    box-shadow: 0 0 8px var(--bust-color);
}

.chat-title h2 {
    font-size: 1.2rem;
    margin: 0;
    font-family: 'Inter', sans-serif;
}

.chat-title .status {
    font-size: 0.8rem;
    color: #10b981;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    max-width: 80%;
    animation: fadeIn 0.3s ease-out;
}

.message.user-message { align-self: flex-end; }
.message.ai-message { align-self: flex-start; }
.message.system-message { align-self: center; max-width: 100%; }

.system-message p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 1rem;
    border-radius: 1rem;
}

.message-content {
    background: var(--surface-bg);
    padding: 1rem 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    line-height: 1.5;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.user-message .message-content {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    border-radius: 12px 12px 0 12px;
}

.ai-message .message-content {
    border-left-width: 4px;
    border-radius: 12px 12px 12px 0;
    background: rgba(17, 24, 39, 0.9);
}

.chat-input-area {
    padding: 1.2rem 1.5rem;
    background: rgba(17, 24, 39, 0.9);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    align-items: center;
    position: sticky;
    bottom: 0;
}

#message-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 2rem;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
}

#message-input:focus {
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(0, 0, 0, 0.5);
}

.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, filter 0.2s;
    color: #fff;
}

.send-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* Typing Dots Animation */
.dot-flashing {
    position: relative;
    width: 8px;
    height: 8px;
    border-radius: 5px;
    background-color: var(--text-secondary);
    animation: dot-flashing 1s infinite linear alternate;
    animation-delay: 0.5s;
    margin-left: 15px;
    margin-right: 15px;
}
.dot-flashing::before, .dot-flashing::after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 0;
    width: 8px;
    height: 8px;
    border-radius: 5px;
    background-color: var(--text-secondary);
}
.dot-flashing::before {
    left: -15px;
    animation: dot-flashing 1s infinite alternate;
    animation-delay: 0s;
}
.dot-flashing::after {
    left: 15px;
    animation: dot-flashing 1s infinite alternate;
    animation-delay: 1s;
}

@keyframes dot-flashing {
    0% { background-color: var(--text-secondary); }
    50%, 100% { background-color: rgba(255,255,255,0.1); }
}

/* --- Added Phase 4 Styles --- */

.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.mode-btn {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem 2rem;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.card.selected-debater .card-inner {
    outline: 3px solid var(--accent-color);
    box-shadow: 0 0 25px rgba(99, 102, 241, 0.6);
}

#start-debate-btn {
    display: none;
    margin: 0 auto 2rem;
    padding: 1rem 3rem;
    background: linear-gradient(135deg, var(--accent-color), #ec4899);
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
    box-shadow: 0 5px 20px rgba(236, 72, 153, 0.4);
}

#start-debate-btn:hover { transform: scale(1.05); }

.creativity-control {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.creativity-control label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.creativity-control input[type="range"] {
    width: 80px;
    accent-color: var(--accent-color);
}

/* --- Added Phase 6 Engagement Styles --- */

.speak-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    margin-top: 4px;
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.2s;
}
.speak-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Sentiment Animations */
@keyframes shakeFurious {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}
.sentiment-furious .chat-avatar {
    animation: shakeFurious 0.5s;
    animation-iteration-count: 2;
    box-shadow: 0 0 15px rgba(220, 38, 38, 0.8) !important;
}

@keyframes pulseMystical {
    0% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.4); }
    50% { box-shadow: 0 0 25px rgba(168, 85, 247, 1); }
    100% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.4); }
}
.sentiment-mystical .chat-avatar {
    animation: pulseMystical 2s infinite;
}

.sentiment-passionate .message-content {
    background: linear-gradient(145deg, rgba(234, 88, 12, 0.1), rgba(17, 24, 39, 0.9));
}

/* Verdict UI */
.verdict-banner-floating {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.98));
    border-top: 1px solid rgba(255,255,255,0.1);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 0.6rem 1.5rem;
    box-shadow: 0 -4px 15px rgba(0,0,0,0.5);
    z-index: 100;
    animation: slideUp 0.4s ease-out;
}
.verdict-content-floating {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.verdict-content-floating span {
    font-weight: 600;
    color: var(--text-primary);
}
.verdict-btn-small {
    padding: 0.4rem 1rem;
    border: none;
    border-radius: 4px;
    background: var(--surface-bg);
    border: 1px solid var(--accent-light, #818cf8);
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}
.verdict-btn-small:hover {
    background: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.victory-burst {
    animation: popIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.victory-text {
    font-size: 2rem;
    background: linear-gradient(to right, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

/* Phase 7 Addictive Mechanics */
.global-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2.5rem;
    background: rgba(11, 15, 25, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    position: sticky;
    top: 0;
    z-index: 1000;
}
#home-logo {
    margin: 0;
    font-family: var(--font-primary);
    font-size: 1.5rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: color 0.3s, text-shadow 0.3s;
}
#home-logo:hover {
    color: var(--accent-light);
    text-shadow: 0 0 10px var(--accent-color);
}
#user-name-display {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--accent-light);
    cursor: pointer;
    transition: color 0.2s;
}
.xp-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}
.xp-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.2), rgba(180, 83, 9, 0.1));
    border: 1px solid rgba(251, 191, 36, 0.4);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    box-shadow: 0 0 15px rgba(217, 119, 6, 0.1);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.xp-title {
    font-size: 0.85rem;
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.xp-amount {
    font-size: 1.1rem;
    color: #fff;
    font-weight: 700;
}
.xp-progress-bar {
    width: 150px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
}
.xp-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
    transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.xp-next {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.xp-floating {
    position: absolute;
    color: #fbbf24;
    font-weight: bold;
    font-size: 2rem;
    pointer-events: none;
    animation: floatUp 1.5s ease-out forwards;
    z-index: 2000;
    text-shadow: 0 0 15px rgba(217, 119, 6, 0.8);
}
@keyframes floatUp {
    0% { transform: translate(-50%, 0) scale(0.8); opacity: 0; }
    20% { transform: translate(-50%, -40px) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -150px) scale(1); opacity: 0; }
}

/* Phase 8 Community */
.nav-btn {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-light);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    font-weight: 600;
}
.nav-btn:hover {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 0 15px rgba(217, 119, 6, 0.5);
    transform: scale(1.05);
}
.intro-btn {
    background: linear-gradient(135deg, var(--accent-color), #f59e0b);
    color: #fff;
    padding: 12px 40px;
    border-radius: 30px;
    border: none;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
    box-shadow: 0 10px 20px rgba(217, 119, 6, 0.4);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    letter-spacing: 1px;
}
.intro-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 15px 30px rgba(217, 119, 6, 0.6);
}
.intro-overlay {
    position: fixed; top:0; left:0; right:0; bottom:0;
    background: rgba(11, 15, 25, 0.4);
    z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(20px);
}
.intro-content {
    background: var(--surface-bg);
    padding: 3rem;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    animation: popIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.intro-content input {
    width: 100%;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    margin-top: 20px;
    font-size: 1.1rem;
    text-align: center;
}
.communiti-screen {
    display: none;
    flex-direction: column;
    margin: 0 auto;
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    flex: 1;
    animation: fadeIn 0.4s ease;
}
.community-compose {
    padding: 2rem;
    border: 1px solid rgba(255,255,255,0.05);
    background: rgba(17, 24, 39, 0.4);
    border-radius: 12px;
    margin-bottom: 10px;
}
.community-compose textarea {
    width: 100%;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    resize: none;
    font-family: var(--font-primary);
}
.community-feed {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 1rem;
}
.post-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 1.2rem;
    border-radius: 12px;
}
.post-header {
    display: flex; justify-content: space-between;
    margin-bottom: 0.8rem;
}
.post-author { font-weight: bold; color: var(--accent-light); }
.post-time { color: var(--text-secondary); font-size: 0.8rem; }
.post-body { line-height: 1.5; margin-bottom: 1rem; }
.post-actions {
    display: flex; align-items: center;
}
.vote-btn {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; display: flex; align-items: center; gap: 5px; font-weight: bold;
    transition: all 0.2s;
    font-size: 1.1rem;
}
.vote-btn:hover { color: var(--accent-light); }
.vote-btn.voted { color: #fbbf24; }
.post-comments {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.comment-bubble {
    background: rgba(0,0,0,0.4);
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}
.comment-input {
    flex: 1;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff; padding: 8px; border-radius: 6px;
}

.card.locked {
    filter: grayscale(1) opacity(0.6);
    cursor: not-allowed;
    position: relative;
    pointer-events: none; /* Block clicking mechanics */
}
.card.locked:hover {
    transform: none;
    box-shadow: none;
}
.lock-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(11, 15, 25, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    color: #fff;
    border-radius: 12px;
}
.lock-overlay span {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 10px rgba(0,0,0,0.8));
}
.export-card {
    position: absolute;
    top: -9999px;
    left: -9999px;
    width: 600px;
    padding: 3rem;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    font-family: var(--font-primary);
}
.export-card h2 {
    font-weight: 400;
    line-height: 1.6;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    /* Navbar stacking to prevent overlap */
    .global-navbar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    #user-name-display {
        position: relative;
        left: 0;
        transform: none;
    }
    
    /* Header Scaling */
    .selection-header h1 {
        font-size: 2.2rem;
    }
    .selection-header p {
        font-size: 0.95rem;
    }
    
    /* Grid adjustments */
    .philosopher-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 0.5rem;
    }
    
    /* Typography scaling in cards */
    .card-content h2 { font-size: 1.5rem; }
    
    /* Chat adjustments */
    #app.chat-mode {
        height: 100dvh; /* Mobile viewport height fix */
    }
    .chat-messages {
        padding: 1rem;
    }
    .message { max-width: 90%; }
}

.app-footer {
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}
.about-content {
    max-width: 600px;
    width: 100%;
    padding: 2.5rem;
}
@media (max-width: 768px) {
    .about-content { padding: 1.5rem; }
}
