/* === RESET & BASE === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --parchment: #f4e4c1;
    --parchment-dark: #d4c4a1;
    --ink: #2c1810;
    --gold: #c9a84c;
    --gold-light: #e8d48b;
    --blood: #8b1a1a;
    --blood-light: #c0392b;
    --forest: #2d5016;
    --magic: #6c3483;
    --magic-light: #a569bd;
    --shadow: rgba(0, 0, 0, 0.7);
    --glass-bg: rgba(44, 24, 16, 0.7);
    --glass-border: rgba(201, 168, 76, 0.4);
    --panel-border: #c9a84c;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Crimson Text', Georgia, serif;
    background: #0a0a0a;
    color: var(--parchment);
    line-height: 1.7;
    font-size: 18px;
}

/* === PARTICLES === */
#particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: var(--gold);
    border-radius: 50%;
    opacity: 0;
    animation: float-up 6s ease-in infinite;
}

@keyframes float-up {
    0% { opacity: 0; transform: translateY(0) scale(0); }
    20% { opacity: 0.8; }
    100% { opacity: 0; transform: translateY(-100vh) scale(1); }
}

/* === SCREENS === */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 1;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.8s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === TITLE SCREEN === */
#title-screen {
    background:
        radial-gradient(ellipse at center, rgba(44, 24, 16, 0.3) 0%, rgba(0,0,0,0.9) 70%),
        linear-gradient(180deg, #1a0a00 0%, #0d0d2b 50%, #1a0a00 100%);
}

.title-content {
    text-align: center;
    animation: fadeIn 2s ease;
}

.title-ornament {
    font-size: 2.5rem;
    color: var(--gold);
    margin: 0.5rem 0;
    filter: drop-shadow(0 0 10px rgba(201, 168, 76, 0.5));
}

.title-content h1 {
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(2.5rem, 6vw, 5rem);
    color: var(--gold);
    text-shadow:
        0 0 20px rgba(201, 168, 76, 0.4),
        2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
}

.subtitle {
    font-style: italic;
    font-size: 1.3rem;
    color: var(--parchment-dark);
    margin: 0.5rem 0 1.5rem;
}

/* === BUTTONS === */
.btn-medieval {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.2rem;
    padding: 12px 36px;
    background: linear-gradient(180deg, var(--gold) 0%, #a07830 100%);
    color: var(--ink);
    border: 2px solid var(--gold-light);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-shadow: 0 1px 0 rgba(255,255,255,0.2);
    box-shadow: 0 4px 15px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}

.btn-medieval:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 168, 76, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 100%);
}

.btn-medieval:active {
    transform: translateY(0);
}

.btn-medieval:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* === CHARACTER SCREEN === */
#character-screen {
    background: linear-gradient(180deg, #1a0a00 0%, #0d0d2b 50%, #1a0a00 100%);
    overflow-y: auto;
    padding: 2rem;
}

#character-screen .panel {
    max-width: 800px;
    width: 100%;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-family: 'MedievalSharp', cursive;
    font-size: 1.2rem;
    color: var(--gold);
    margin-bottom: 0.5rem;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px 16px;
    font-family: 'Crimson Text', serif;
    font-size: 1.1rem;
    background: rgba(244, 228, 193, 0.1);
    border: 1px solid var(--gold);
    border-radius: 4px;
    color: var(--parchment);
    outline: none;
    transition: border-color 0.3s;
}

.form-group input[type="text"]:focus {
    border-color: var(--gold-light);
    box-shadow: 0 0 10px rgba(201, 168, 76, 0.3);
}

.class-selection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.class-card {
    background: rgba(244, 228, 193, 0.05);
    border: 2px solid rgba(201, 168, 76, 0.3);
    border-radius: 8px;
    padding: 1.2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.class-card:hover {
    border-color: var(--gold);
    background: rgba(244, 228, 193, 0.1);
    transform: translateY(-3px);
}

.class-card.selected {
    border-color: var(--gold);
    background: rgba(201, 168, 76, 0.15);
    box-shadow: 0 0 20px rgba(201, 168, 76, 0.2);
}

.class-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.class-card h3 {
    font-family: 'MedievalSharp', cursive;
    color: var(--gold);
    margin-bottom: 0.3rem;
}

.class-card p {
    font-size: 0.9rem;
    color: var(--parchment-dark);
    margin-bottom: 0.5rem;
}

.class-stats {
    font-size: 0.8rem;
    color: var(--gold-light);
    font-weight: 600;
}

/* === STORY SELECTION === */
#story-selection-screen {
    background: linear-gradient(180deg, #1a0a00 0%, #0d0d2b 50%, #1a0a00 100%);
    padding: 2rem;
    overflow-y: auto;
}

.selection-panel {
    max-width: 1000px;
    width: 100%;
}

.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.story-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    cursor: default;
}

.story-thumb {
    height: 180px;
    background-size: cover;
    background-position: center;
    border-bottom: 1px solid var(--glass-border);
}

.story-info {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    flex: 1;
}

.story-info h3 {
    font-family: 'MedievalSharp', cursive;
    color: var(--gold);
    font-size: 1.4rem;
}

.story-info p {
    font-size: 0.95rem;
    color: var(--parchment-dark);
    line-height: 1.5;
    flex: 1;
}

.select-story-btn {
    align-self: flex-start;
    padding: 8px 24px;
    font-size: 1rem;
}

/* === PROFILES & SAVES === */
.profile-list, .save-slots {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1.5rem 0;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.profile-item, .save-slot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.profile-item:hover, .save-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(5px);
}

.profile-info, .save-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.profile-info h4, .save-info h4 {
    margin: 0;
    color: var(--gold);
}

.profile-info span, .save-info span {
    font-size: 0.85rem;
    color: var(--parchment-dark);
}

.profile-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.profile-actions input {
    flex: 1;
}

.hud-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* === PANELS === */
.panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.6),
        inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.panel:hover {
    border-color: var(--gold);
    box-shadow: 
        0 12px 48px rgba(0, 0, 0, 0.8),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* === GAME SCREEN === */
#game-screen {
    background: linear-gradient(180deg, #1a0a00 0%, #0d0d2b 50%, #1a0a00 100%);
}

.game-layout {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 1rem;
    padding: 1rem;
    overflow: hidden;
}

/* === STATS PANEL === */
#stats-panel {
    width: 260px;
    min-width: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.char-header {
    text-align: center;
    border-bottom: 1px solid rgba(201, 168, 76, 0.3);
    padding-bottom: 0.8rem;
}

.char-header h3 {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.4rem;
    color: var(--gold);
}

.badge {
    display: inline-block;
    font-size: 0.8rem;
    padding: 2px 10px;
    background: rgba(201, 168, 76, 0.2);
    border: 1px solid var(--gold);
    border-radius: 12px;
    color: var(--gold-light);
    margin-top: 0.3rem;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.stat-label {
    font-family: 'MedievalSharp', cursive;
    color: var(--gold);
    font-size: 0.95rem;
    min-width: 40px;
}

.stat-value {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--parchment);
}

.hp-bar-container {
    flex: 1;
    margin-left: 0.5rem;
    height: 22px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 11px;
    border: 1px solid rgba(201, 168, 76, 0.3);
    position: relative;
    overflow: hidden;
}

.hp-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blood), #c0392b);
    border-radius: 10px;
    transition: width 0.5s ease;
}

.hp-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.inventory h4, .quest-log h4 {
    font-family: 'MedievalSharp', cursive;
    color: var(--gold);
    margin-bottom: 0.4rem;
    font-size: 1rem;
}

.inventory ul {
    list-style: none;
    font-size: 0.9rem;
}

.inventory li {
    padding: 3px 0;
    border-bottom: 1px solid rgba(201, 168, 76, 0.1);
}

.inventory li.empty {
    color: rgba(244, 228, 193, 0.4);
    font-style: italic;
}

.quest-log p {
    font-size: 0.9rem;
    font-style: italic;
    color: var(--parchment-dark);
}

/* === NARRATIVE AREA === */
.narrative-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 1rem;
}

.scene-image {
    height: 200px;
    border-radius: 8px;
    background-size: cover;
    background-position: center;
    border: 1px solid var(--panel-border);
    display: none;
    position: relative;
    overflow: hidden;
}

.scene-image::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 50%, var(--panel-bg) 100%);
}

.narrative-panel {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.story-text {
    flex: 1;
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 1.5rem;
}

.story-text p {
    margin-bottom: 0.8rem;
    opacity: 0;
    animation: textAppear 0.5s ease forwards;
}

.story-text p:nth-child(1) { animation-delay: 0.1s; }
.story-text p:nth-child(2) { animation-delay: 0.4s; }
.story-text p:nth-child(3) { animation-delay: 0.7s; }
.story-text p:nth-child(4) { animation-delay: 1.0s; }
.story-text p:nth-child(5) { animation-delay: 1.3s; }

@keyframes textAppear {
    from { opacity: 0; transform: translateY(15px) scale(0.98); filter: blur(4px); }
    to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.story-text .highlight {
    color: var(--gold);
    font-weight: 600;
}

.story-text .danger {
    color: var(--blood-light);
    font-weight: 600;
}

.story-text .magic {
    color: var(--magic-light);
    font-weight: 600;
}

/* === CHOICES === */
.choices {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.choice-btn {
    font-family: 'Crimson Text', serif;
    font-size: 1.05rem;
    padding: 12px 20px;
    background: rgba(201, 168, 76, 0.08);
    border: 1px solid rgba(201, 168, 76, 0.4);
    border-radius: 6px;
    color: var(--parchment);
    cursor: pointer;
    text-align: left;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.choice-btn::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gold);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.choice-btn:hover {
    background: rgba(201, 168, 76, 0.15);
    border-color: var(--gold);
    transform: translateX(4px);
}

.choice-btn:hover::before {
    transform: scaleY(1);
}

.choice-btn .choice-tag {
    font-size: 0.75rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 2px;
}

.choice-btn .dice-tag {
    float: right;
    font-size: 0.75rem;
    color: var(--magic-light);
    background: rgba(108, 52, 131, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
}

/* === DICE MODAL === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--panel-bg);
    border: 2px solid var(--gold);
    border-radius: 12px;
    padding: 2rem 3rem;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 0 60px rgba(201, 168, 76, 0.2);
}

.modal-content h2, .modal-content h3 {
    font-family: 'MedievalSharp', cursive;
    color: var(--gold);
    margin-bottom: 1rem;
}

.dice-container {
    display: flex;
    justify-content: center;
    margin: 1.5rem 0;
}

.dice {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, #3d2914 0%, #2c1810 50%, #1a0f08 100%);
    border: 3px solid var(--gold);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'MedievalSharp', cursive;
    font-size: 2.8rem;
    color: var(--gold);
    box-shadow: 0 0 30px rgba(201, 168, 76, 0.3), inset 0 0 20px rgba(0,0,0,0.5);
    transition: transform 0.1s;
}

.dice.rolling {
    animation: diceRoll 0.1s infinite;
}

@keyframes diceRoll {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(10deg) scale(1.05); }
    50% { transform: rotate(-5deg) scale(0.95); }
    75% { transform: rotate(8deg) scale(1.02); }
    100% { transform: rotate(0deg) scale(1); }
}

.dice.result {
    animation: diceResult 0.5s ease;
}

@keyframes diceResult {
    0% { transform: scale(1.3) rotate(15deg); }
    50% { transform: scale(0.9) rotate(-5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.dice-detail {
    color: var(--parchment-dark);
    font-size: 0.95rem;
    margin: 0.5rem 0;
}

.dice-result {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.3rem;
    margin: 0.8rem 0;
    min-height: 1.5em;
}

.dice-result.success {
    color: #27ae60;
}

.dice-result.failure {
    color: var(--blood-light);
}

.dice-result.critical-success {
    color: var(--gold);
    text-shadow: 0 0 15px rgba(201, 168, 76, 0.6);
    font-size: 1.5rem;
}

.dice-result.critical-failure {
    color: var(--blood);
    text-shadow: 0 0 15px rgba(139, 26, 26, 0.6);
    font-size: 1.5rem;
}

/* === END MODAL === */
#end-modal .modal-content {
    max-width: 500px;
}

#end-modal h2 {
    font-size: 2rem;
}

#end-modal p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    color: var(--parchment-dark);
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-thumb {
    background: rgba(201, 168, 76, 0.4);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(201, 168, 76, 0.6);
}

/* === DAMAGE FLASH === */
.damage-flash {
    animation: damageFlash 0.5s ease;
}

@keyframes damageFlash {
    0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5); }
    50% { box-shadow: 0 0 30px rgba(192, 57, 43, 0.6); }
}

.heal-flash {
    animation: healFlash 0.5s ease;
}

@keyframes healFlash {
    0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5); }
    50% { box-shadow: 0 0 30px rgba(39, 174, 96, 0.6); }
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .game-layout {
        flex-direction: column;
    }

    #stats-panel {
        width: 100%;
        min-width: 100%;
        max-height: 180px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .char-header {
        width: 100%;
    }

    .stats-grid {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .stat-item {
        width: 48%;
    }

    .inventory, .quest-log {
        display: none;
    }

    .narrative-area {
        min-height: 0;
    }

    .scene-image {
        height: 120px;
    }

    .class-selection {
        grid-template-columns: 1fr 1fr;
    }
}
