/* ---------- RESET & GLOBAL ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Quicksand', sans-serif;
    background: #1a1410;
    background-image: radial-gradient(circle at 10% 20%, #2d241e, #0f0b09);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 1rem;
    color: #f0e6d3;
}

/* ---------- MAIN CARD (scrollable) ---------- */
.adventure-card {
    max-width: 1000px;
    width: 100%;
    background: #2a1f1a;
    background-image: linear-gradient(145deg, #3b2c24 0%, #1f1612 100%);
    border: 2px solid #b78a5f;
    border-radius: 3rem 3rem 2rem 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 0 2px #5a3f2e inset, 0 0 0 4px #2f1f18 inset;
    padding: 2rem 2rem 2.5rem;
    transition: all 0.2s ease;
    position: relative;
}

/* decorative corner runes */
.adventure-card::before {
    content: "⚔️ 🛡️ 🧙";
    position: absolute;
    top: -12px;
    left: 20px;
    background: #1f1612;
    padding: 0 12px;
    font-size: 1.4rem;
    letter-spacing: 6px;
    color: #dbba8a;
    text-shadow: 0 0 6px #b78a5f;
    border-radius: 30px;
    border: 1px solid #b78a5f;
}

h1 {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.8rem;
    font-weight: 400;
    color: #f5e2c1;
    text-shadow: 0 4px 0 #5a3f2e, 0 6px 12px #0a0604;
    letter-spacing: 3px;
    margin-top: 0.2rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

h1 small {
    font-family: 'Quicksand', sans-serif;
    font-size: 1rem;
    font-weight: 400;
    background: #3f2d23;
    padding: 0.2rem 1.2rem;
    border-radius: 40px;
    border: 1px solid #b78a5f;
    color: #dbba8a;
    letter-spacing: 1px;
}

/* ---------- FORM ---------- */
.form-group {
    margin-top: 1.8rem;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: #1f1612b3;
    padding: 1.2rem 1.5rem;
    border-radius: 3rem;
    border: 1px solid #7a5d42;
    backdrop-filter: blur(2px);
    box-shadow: inset 0 4px 8px #0b0705;
}

.form-group label {
    font-weight: 600;
    color: #dbba8a;
    letter-spacing: 1px;
    font-size: 0.9rem;
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 140px;
}

.form-group label span {
    font-size: 0.7rem;
    color: #b78a5f;
    text-transform: none;
    font-weight: 400;
}

select,
input[type="text"] {
    background: #2d1f18;
    border: 1px solid #7a5d42;
    color: #f5e2c1;
    padding: 10px 16px;
    border-radius: 40px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    outline: none;
    transition: 0.2s;
    width: 100%;
}

select:focus,
input[type="text"]:focus {
    border-color: #dbba8a;
    box-shadow: 0 0 12px #b78a5f55;
    background: #3b2c24;
}

select option {
    background: #2d1f18;
}

select optgroup {
    background: #2d1f18;
    color: #dbba8a;
    font-weight: 700;
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-left: auto;
}

.btn {
    background: #4d3527;
    border: 1px solid #b78a5f;
    color: #f5e2c1;
    padding: 10px 28px;
    border-radius: 60px;
    font-weight: 700;
    font-family: 'Quicksand', sans-serif;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 0 #1f130e;
    text-shadow: 0 1px 0 #1f130e;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: #a77b55;
    border-color: #eac29a;
    color: #1f1612;
    box-shadow: 0 4px 0 #5a3f2e;
    text-shadow: 0 1px 0 #eac29a;
}

.btn-primary:hover {
    background: #c99d73;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #5a3f2e;
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #5a3f2e;
}

.btn-outline {
    background: transparent;
    border-color: #7a5d42;
    box-shadow: 0 4px 0 #1f130e;
}

.btn-outline:hover {
    background: #3b2c24;
    border-color: #dbba8a;
}

.btn-danger {
    border-color: #9f5a4a;
    color: #f0c8b8;
    box-shadow: 0 4px 0 #4f2a20;
}

.btn-danger:hover {
    background: #5a3a2e;
    border-color: #d48a72;
}

.btn-play {
    background: #2d5a3a;
    border-color: #5aaa7a;
    color: #d0f0d0;
    box-shadow: 0 4px 0 #1a3a2a;
}

.btn-play:hover {
    background: #3a7a4a;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #1a3a2a;
}

/* TTS Controls */
.tts-controls {
    margin-top: 0.5rem;
}

.tts-controls .form-group {
    margin-top: 0;
    padding: 0.8rem 1.2rem;
    background: #1a110e;
    border-radius: 2rem;
}

.tts-controls input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #3f2d23;
    border-radius: 3px;
    outline: none;
}

.tts-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #b78a5f;
    cursor: pointer;
    border: 2px solid #eac29a;
}

/* ---------- CHAT HISTORY (scrollable) ---------- */
.history-container {
    margin-top: 2rem;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 6px;
    scroll-behavior: smooth;
}

.history-container::-webkit-scrollbar {
    width: 8px;
}

.history-container::-webkit-scrollbar-track {
    background: #1f1612;
    border-radius: 20px;
}

.history-container::-webkit-scrollbar-thumb {
    background: #7a5d42;
    border-radius: 20px;
    border: 1px solid #b78a5f;
}

/* each message card */
.message-card {
    background: #251c17e0;
    backdrop-filter: blur(2px);
    border-left: 6px solid #b78a5f;
    border-radius: 1.2rem 1.2rem 1.2rem 0.8rem;
    padding: 1.2rem 1.5rem;
    margin-bottom: 1.2rem;
    box-shadow: 0 6px 12px #0b0705, 0 0 0 1px #3f2d23 inset;
    transition: 0.15s;
}

.message-card:hover {
    border-left-color: #eac29a;
    background: #2f221c;
}

.message-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 0.75rem;
    color: #b78a5f;
    margin-bottom: 10px;
    border-bottom: 1px dashed #3f2d23;
    padding-bottom: 8px;
}

.message-header .model-badge {
    background: #1f1612;
    padding: 0.2rem 1.2rem;
    border-radius: 40px;
    border: 1px solid #7a5d42;
    font-weight: 700;
    font-size: 0.8rem;
    color: #eac29a;
    letter-spacing: 0.5px;
}

.message-header .type-badge {
    background: #2d241e;
    padding: 0.15rem 0.9rem;
    border-radius: 30px;
    color: #dbba8a;
    border: 1px solid #5a3f2e;
    font-size: 0.7rem;
}

.message-prompt {
    font-size: 0.95rem;
    background: #1a110e;
    padding: 0.7rem 1.2rem;
    border-radius: 2rem;
    color: #dbba8a;
    margin: 8px 0 12px 0;
    border: 1px solid #3f2d23;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

.message-response {
    font-size: 1.05rem;
    line-height: 1.8;
    background: #0f0b09;
    padding: 1rem 1.5rem;
    border-radius: 1.2rem;
    border: 1px solid #5a3f2e;
    color: #f5f0e8;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: inset 0 2px 6px #00000055;
}

/* Image response */
.message-response img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    border: 2px solid #5a3f2e;
    margin: 8px 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Audio player for TTS */
.message-response audio {
    width: 100%;
    margin: 8px 0;
    border-radius: 30px;
    background: #1f1612;
}

.message-response audio::-webkit-media-controls-panel {
    background: #2d241e;
}

/* Response formatting styles */
.message-response strong {
    color: #eac29a;
    font-weight: 700;
}

.message-response em {
    color: #dbba8a;
    font-style: italic;
}

.message-response code {
    background: #1f1612;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #eac29a;
    border: 1px solid #3f2d23;
}

.message-response .response-header {
    color: #eac29a;
    margin: 0.8rem 0 0.4rem 0;
    font-weight: 700;
    font-size: 1.2rem;
}

.message-response .response-list {
    margin: 0.4rem 0 0.4rem 1.5rem;
    padding-left: 0.5rem;
}

.message-response .response-list li {
    margin: 0.3rem 0;
    color: #f0e6d3;
}

.message-response .response-quote {
    background: #1f1612;
    border-left: 4px solid #b78a5f;
    padding: 0.5rem 1rem;
    margin: 0.5rem 0;
    border-radius: 0 8px 8px 0;
    color: #dbba8a;
    font-style: italic;
}

.empty-history {
    text-align: center;
    padding: 2.5rem 1rem;
    color: #7a5d42;
    font-style: italic;
    border: 2px dashed #3f2d23;
    border-radius: 3rem;
    background: #1a110e55;
}

.empty-history span {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 6px;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 700px) {
    .adventure-card {
        padding: 1.2rem;
    }

    .form-group {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
    }

    .form-actions {
        margin-left: 0;
        justify-content: stretch;
    }

    .form-actions .btn {
        flex: 1;
        justify-content: center;
    }

    h1 {
        font-size: 2rem;
    }

    h1 small {
        font-size: 0.8rem;
    }

    .message-card {
        padding: 0.8rem;
    }

    .message-response {
        font-size: 0.95rem;
        padding: 0.8rem 1rem;
    }
}

@media (max-width: 460px) {
    .message-card {
        padding: 0.6rem;
    }

    .message-response {
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
    }

    .message-prompt {
        font-size: 0.85rem;
        padding: 0.5rem 0.8rem;
    }
}