/* components.css - Reusable UI elements, buttons, inputs, animations, and achievements */

/* --- SETTINGS & DEBUG UI --- */
#settings-button-container { position: fixed; top: 15px; right: 15px; z-index: 102; }
#open-settings-button {
    background-color: rgba(40,40,40,0.8);
    border: 2px solid var(--grey-border);
    color: var(--light-text);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.8rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--button-transition); /* Restored */
    box-shadow: 0 3px 0 #333; /* Restored */
}

/* Hover/Active states (Restored) */
#open-settings-button:hover {
    background-color: rgba(255, 215, 0, 0.2);
    transform: scale(1.05) translateY(-1px);
    box-shadow: 0 4px 0 #333;
}

#open-settings-button:active {
    transform: scale(0.95) translateY(1px);
    box-shadow: 0 2px 0 #333;
}

#version-display { position: absolute; bottom: 20px; left: 20px; font-size: 0.7rem; color: #888; }

/* === PHASE 1: Enhanced Button Tactility (Juice) (Restored) === */
.game-button {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
    padding: 15px 30px;
    background-color: var(--main-gold);
    color: var(--dark-bg);
    border: 2px solid var(--light-text);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--button-transition);
    box-shadow: 0 4px 0 #b8860b; /* Add depth (darker gold shadow) */
    position: relative;
    outline: none;
}

/* Hover state */
.game-button:hover:not(:disabled) {
    background-color: var(--light-text);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #b8860b;
}

/* Active (Pressed) state */
.game-button:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #b8860b;
}

.game-button:disabled {
    background-color: var(--grey-border);
    color: #888;
    cursor: not-allowed;
    box-shadow: 0 4px 0 #333;
}

.game-button.secondary {
    background-color: #757575;
    color: var(--light-text);
    box-shadow: 0 4px 0 #444;
}

.game-button.secondary:hover:not(:disabled) {
    background-color: #999;
    box-shadow: 0 6px 0 #444;
}

.game-button.secondary:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #444;
}

.stat-increase-button {
    margin: 5px;
    width: 280px;
    text-align: left;
    max-width: 90%;
}

/* === PHASE 1: Optimized "Juice" Animations (Restored) === */
/* Enhanced Damage Float (Pop and hold) */
@keyframes damageFloat {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
        text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -80%) scale(1.3);
        text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    } /* Pop and hold briefly */
    100% {
        opacity: 0;
        transform: translate(-50%, -150%) scale(0.5);
        text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    }
}

/* Class for the elements that will float */
.floating-text {
    position: absolute;
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(10px, 1.2rem, 16px);
    font-weight: bold;
    color: #ff6666;
    pointer-events: none;
    animation: damageFloat 1.5s ease-out forwards;
    z-index: 75;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    white-space: nowrap;
}

.floating-text.crit {
    color: var(--main-gold);
    font-size: clamp(12px, 1.5rem, 20px);
    text-shadow: 0 0 8px rgba(255, 200, 37, 0.8), 2px 2px 4px rgba(0,0,0,0.8);
}

.floating-text.heal {
    color: #4CAF50;
    text-shadow: 0 0 6px rgba(76, 175, 80, 0.6), 2px 2px 4px rgba(0,0,0,0.8);
}

.floating-text.loot {
    color: var(--main-gold);
    text-shadow: 0 0 6px rgba(255, 200, 37, 0.6), 2px 2px 4px rgba(0,0,0,0.8);
}

.floating-text.levelup {
    color: #fff;
    font-size: clamp(14px, 1.8rem, 24px);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8), 2px 2px 4px rgba(0,0,0,0.8);
}

/* PHASE 1: Screen Shake */
@keyframes screenShake {
    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); }
}

.shake {
    animation: screenShake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* === PHASE 1: Event Log Clarity (Restored) === */
.log-damage-taken {
    color: #ff6347 !important;
    text-shadow: 0 0 4px rgba(255, 99, 71, 0.4);
} /* Red with glow */

.log-damage-dealt {
    color: #ffffff !important;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.3);
} /* White with subtle glow */

.log-loot {
    color: var(--main-gold) !important;
    text-shadow: 0 0 4px rgba(255, 200, 37, 0.4);
} /* Gold with glow */

.log-system {
    color: #42a5f5 !important;
    text-shadow: 0 0 4px rgba(66, 165, 245, 0.3);
} /* Blue with glow */

/* === PHASE 2: Enhanced UI Panels with 9-Slice Borders (Updated) === */
.stats-box, .log-box, .actions-box {
    background-color: var(--dark-ui);
    padding: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    width: 50%;
    cursor: pointer;
    height: 160px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    justify-content: space-between;

    /* ACTIVATED: Thematic borders (Replaced fallback styles) */
    border-radius: 0;
    border-style: solid;
    border-width: 15px; /* Slightly thinner for panels */
    border-image-slice: 20 fill; /* Use same slice as dialogs */
    border-image-repeat: stretch;
    border-image-source: var(--ui-border-image);
}

.actions-box {
    display: none; /* Hidden by default, shown on desktop */
}

/* --- Log Box Internals --- */
.log-box #portrait-message-log, .log-box #landscape-message-log {
    flex-grow: 1;
    overflow-y: scroll;
    scrollbar-width: none;
}

#portrait-message-log::-webkit-scrollbar, #landscape-message-log::-webkit-scrollbar {
    display: none;
}

/* Applied also to full-log-content for consistency */
#portrait-message-log, #landscape-message-log, #full-log-content {
    display: flex;
    flex-direction: column-reverse;
    gap: 5px;
}

.stats-box p, #portrait-message-log p, #landscape-message-log p {
    font-size: clamp(9px, 2.0vmin, 0.95rem);
    margin: 2px 0;
    word-wrap: break-word;
}

/* --- Stats Box Internals & Bars --- */
.stat-bar-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
}

.stat-bar-line p {
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

.hp-bar, .xp-bar {
    background-color: #444;
    border-radius: 5px;
    height: 10px;
    width: 100%;
    border: 1px solid #777;
    overflow: hidden;
    flex-grow: 1;
}

/* PHASE 2: Improved Bar Visuals (Gradients) (Restored) */
.hp-fill {
    background-color: #d32f2f;
    background-image: linear-gradient(to bottom, #e57373, #d32f2f 50%, #b71c1c);
    height: 100%;
    transition: width 0.3s ease;
}

.xp-fill {
    background-color: #42a5f5;
    background-image: linear-gradient(to bottom, #64b5f6, #42a5f5 50%, #1976d2);
    height: 100%;
    transition: width 0.3s ease;
}

.core-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
}

.stat-bars-container {
    margin-top: auto;
    padding-top: 4px;
}

/* --- ACHIEVEMENT SYSTEM STYLES --- */
.achievement-popup {
    position: fixed;
    top: 50px;
    right: -400px;
    background: linear-gradient(135deg, #ffd700, #ffb300);
    color: #000;
    padding: 15px;
    border-radius: 12px;
    border: 3px solid #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.6);
    z-index: 200;
    font-family: 'Press Start 2P', cursive;
    transition: right 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-width: 350px;
}

.achievement-popup.show {
    right: 20px;
}

.achievement-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.achievement-icon {
    font-size: 2rem;
}

.achievement-text h3 {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
}

.achievement-text p {
    margin: 0;
    font-size: 0.7rem;
}

/* Restored from original */
.achievements-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #555;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #555;
}

.achievement-item.unlocked {
    background-color: rgba(255, 215, 0, 0.1);
    border-color: #ffd700;
}

.achievement-item.locked {
    opacity: 0.5;
}

.achievement-info {
    flex-grow: 1;
}

.achievement-info strong {
    display: block;
    font-size: 0.8rem;
}

.achievement-info small {
    display: block;
    font-size: 0.6rem;
    color: #ccc;
}

/* --- Toasts and Indicators --- */
.game-toast {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0, 0, 0, 0.9);
    color: #ffd700;
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #ffd700;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    z-index: 150;
    opacity: 0;
    transition: all 0.3s ease;
}

.game-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.save-indicator {
    position: fixed;
    top: 20px;
    right: 80px;
    font-size: 1.5rem;
    animation: saveFloat 1s ease-out;
    z-index: 60;
}

@keyframes saveFloat {
    0% { opacity: 0; transform: translateY(10px); }
    50% { opacity: 1; transform: translateY(-5px); }
    100% { opacity: 0; transform: translateY(-15px); }
}

/* === PHASE 2: New Sprite Selection UI (Restored) === */
/* Remove the old emoji-based options and input styles */
#player-sprite-input[type="text"], .sprite-options {
    display: none;
}

/* New Sprite Selector Styling */
.sprite-selection-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

.sprite-selector {
    background: var(--dark-bg);
    border: 3px solid var(--grey-border);
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.7;
    outline: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 80px;
    position: relative;
}

/* Placeholder for future sprite images */
.sprite-selector img {
    width: 48px;
    height: 48px;
    display: block;
    image-rendering: pixelated; /* Crucial for crisp pixel art scaling */
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Temporary emoji placeholder styling */
.sprite-placeholder {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    line-height: 1;
}

.sprite-label {
    font-size: 0.7rem;
    color: var(--light-text);
    text-align: center;
    font-family: 'Press Start 2P', cursive;
}

/* Hover and active states */
.sprite-selector:hover {
    opacity: 1;
    background: var(--grey-border);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.sprite-selector.active {
    opacity: 1;
    background: var(--grey-border);
    border-color: var(--main-gold);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 200, 37, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.sprite-selector.active .sprite-label {
    color: var(--main-gold);
}

/* Class description styling */
#class-description {
    transition: color 0.2s ease;
    font-style: italic;
}

/* --- Input Fields (Restored) --- */
.personalization-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-row label {
    font-size: 0.9rem;
}

/* General Input Styling */
#player-name-input, #player-sprite-input, #save-code-input {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid var(--grey-border);
    color: var(--light-text);
    border-radius: 5px;
    text-align: center;
    font-size: 1rem;
    padding: 8px;
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    transition: border-color 0.2s ease;
}

#player-name-input:focus, #player-sprite-input:focus, #save-code-input:focus {
    border-color: var(--main-gold);
    outline: none;
}

#player-name-input { width: 200px; }
#player-sprite-input { width: 60px; font-size: 1.5rem; }
#save-code-input { width: 80%; max-width: 300px; padding: 10px; }

/* Specific styles for room code input from original */
#room-code-input {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid #555;
    color: #fff;
    border-radius: 5px;
    padding: 10px;
    font-size: 1rem;
    text-align: center;
    margin-right: 10px;
    max-width: 150px;
    transition: border-color 0.2s ease;
}

#room-code-input:focus {
    border-color: var(--main-gold);
    outline: none;
}


/* Slider and Toggle Controls (Restored) */
.slider {
    -webkit-appearance: none;
    width: 50%;
    height: 8px;
    background: #555;
    outline: none;
    border-radius: 4px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--main-gold);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.1s ease;
}

.slider::-webkit-slider-thumb:hover {
    background: #fff;
    transform: scale(1.1);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: .4s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--main-gold);
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

/* Keybind Inputs (Restored) */
.keybind-input {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid var(--grey-border);
    color: var(--light-text);
    border-radius: 5px;
    width: 120px;
    text-align: center;
    font-size: 0.9rem;
    padding: 5px;
    cursor: pointer;
    text-transform: capitalize;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.keybind-input.listening {
    border-color: var(--main-gold);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Inventory and Equipment Lists (Restored) */
.inventory-list, .equipment-list, .shop-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden !important;
    box-sizing: border-box;
}

.inventory-list li, .equipment-list li, .shop-list li {
    padding: 8px;
    margin-bottom: 5px;
    background-color: #333;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    box-sizing: border-box;
}

.inventory-list li:hover, .shop-list li:hover:not(.disabled) {
    background-color: #444;
}

.shop-list li.disabled {
    color: #888;
    cursor: not-allowed;
    background-color: #2a2a2a;
}

/* Settings Select (Restored) */
.settings-row select {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid #555;
    color: #fff;
    border-radius: 5px;
    padding: 5px;
    font-size: 0.8rem;
    transition: border-color 0.2s ease;
}

.settings-row select:focus {
    border-color: var(--main-gold);
    outline: none;
}

/* Multiplayer Components (Restored) */
.lobby-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    border: 2px solid #757575;
}

.lobby-player.ready {
    border-color: #4caf50;
}

#multiplayer-turn-indicator {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #ffd700;
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #ffd700;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    z-index: 60;
    display: none;
}
