/**
 * Character Creation & Editor CSS
 * Handles the overlays and forms for creating and editing characters or scenery.
 */

.char-input-overlay {
    position: absolute;
    inset: 0;
    background: #0f172a;
    backdrop-filter: blur(12px);
    z-index: 1000 !important;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 1rem;
    gap: 0.75rem;
    border-radius: 16px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

/* ── Hub Panel ─────────────────────────────────── */
.char-hub-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.char-hub-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.5rem 0;
    flex: 1;
    justify-content: center;
}

.char-hub-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.char-hub-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.hub-btn-icon {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #a5b4fc;
    transition: background 0.2s;
}

.char-hub-btn:hover .hub-btn-icon {
    background: rgba(99, 102, 241, 0.35);
}

.hub-btn-label {
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    display: block;
    letter-spacing: -0.01em;
}

.hub-btn-sub {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.45);
    display: block;
    margin-top: 2px;
}

/* The text column inside a hub button */
.char-hub-btn>span:not(.hub-btn-icon) {
    display: flex;
    flex-direction: column;
}

/* ── Creation Panel ─────────────────────────────── */
.char-creation-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    gap: 0.75rem;
}

/* ── Edit Panel ─────────────────────────────────── */
.char-edit-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.char-edit-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    min-height: 0;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) rgba(0, 0, 0, 0.2);
}

.hub-edit-textarea {
    min-height: 80px;
    resize: none;
    overflow: hidden;
    flex-shrink: 0;
}

/* ── Load Panel ─────────────────────────────────── */
.char-load-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.hub-load-grid-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 0;
    overflow: hidden;
}

.hub-load-grid {
    flex: 1;
    min-height: 0;
    /* inherits char-selector-grid styles */
}

.hub-load-upload-row {
    flex-shrink: 0;
    padding-top: 0.25rem;
}

/* Smaller upload button inside load panel */
.hub-upload-btn {
    padding: 0.65rem 1rem;
}

.hub-upload-btn .hub-btn-icon {
    width: 34px;
    height: 34px;
}

/* Footer at the bottom of hub sub-panels */
.hub-panel-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 0.5rem;
}

/* ── Edit Panel Two-Column Layout ───────────────── */
.edit-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 0.4rem;
}

.edit-top-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: stretch;
    flex-shrink: 0;
}

.edit-about-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.edit-about-col .hub-edit-textarea {
    flex: 1;
    min-height: 130px;
}

/* ── Portrait column ── */
.edit-portrait-col {
    width: 130px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.edit-portrait-wrap {
    position: relative;
    width: 130px;
    height: 130px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.edit-portrait-img,
.edit-portrait-pending {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

/* Pending floats on top of current */
.edit-portrait-pending {
    z-index: 2;
}

.edit-portrait-spinner {
    position: absolute;
    inset: 0;
    margin: auto;
    z-index: 3;
    width: 32px;
    height: 32px;
}

/* Controls row: the "Edit" label button, anchored bottom */
.edit-portrait-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    padding: 0.4rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
    z-index: 4;
}

.edit-portrait-label-btn {
    background: rgba(99, 102, 241, 0.85);
    border: none;
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.25rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.edit-portrait-label-btn:hover {
    background: rgba(99, 102, 241, 1);
}

/* Accept / reject row that appears over the pending image */
.edit-portrait-accept-row {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    z-index: 5;
}

.edit-accept-btn,
.edit-reject-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, box-shadow 0.15s;
}

.edit-accept-btn {
    background: #22c55e;
    color: white;
}

.edit-reject-btn {
    background: #ef4444;
    color: white;
}

.edit-accept-btn:hover,
.edit-reject-btn:hover {
    transform: scale(1.12);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ── Portrait prompt area ── */
.edit-prompt-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
    animation: slideIn 0.2s ease-out;
}

.edit-prompt-textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
}

.edit-generate-btn {
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-generate-btn:hover {
    background: var(--primary-hover, #4f46e5);
    transform: translateY(-1px);
}

.edit-generate-btn:disabled {
    opacity: 0.6;
    cursor: default;
    transform: none;
}


.char-input-overlay:not(.hidden) {
    border-color: rgba(34, 197, 94, 0.4);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(34, 197, 94, 0.1);
}

.char-input-group {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: auto 0;
    min-height: min-content;
}

.char-input-group h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    margin: 0;
    text-align: center;
    letter-spacing: -0.02em;
}

.char-input-header {
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.75rem;
}

.char-input-header h3 {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 800;
    color: white;
    text-align: center;
}

/* Edit Mode Overlay */
.char-sheet-overlay {
    position: absolute;
    inset: 0;
    background: #0f172a;
    z-index: 1100 !important;
    display: flex;
    flex-direction: column;
    padding: 1rem 1rem 4rem 1rem;
    gap: 0.75rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    overflow-y: auto;
}

.char-sheet-overlay:not(.hidden) {
    border-color: var(--primary);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.2);
}

.char-sheet-textarea {
    flex: 1;
    width: 100%;
    min-height: 80px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.25rem;
    color: #e2e8f0;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
    overflow: hidden;
    outline: none;
}

.char-sheet-textarea:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
}

/* Character Selector */
.char-selector-overlay {
    position: absolute;
    inset: 0;
    background: #0f172a;
    z-index: 1200 !important;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.char-selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.char-selector-header h3 {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    color: white;
    font-weight: 700;
}

.char-selector-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* Force 2 columns to prevent overlap in small containers */
    gap: 1rem;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    align-content: start;
    /* Prevent items from stretching vertically */
    scrollbar-width: thin;
    scrollbar-color: var(--primary) rgba(0, 0, 0, 0.2);
}

.archive-item {
    position: relative;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    height: 0;
    padding-bottom: 100%;
    /* Robust aspect-ratio 1:1 trick */
}

.archive-item:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.archive-thumb {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.archive-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.archive-item:hover .archive-actions {
    opacity: 1;
}

@media (max-width: 1024px) {
    .archive-actions {
        opacity: 1;
        /* Always show actions on touch devices */
    }
}

.archive-delete {
    background: rgba(239, 68, 68, 0.9);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
}

.archive-deploy {
    background: rgba(99, 102, 241, 0.9);
    border: none;
    color: white;
    padding: 0 8px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
}

.archive-deploy:hover {
    background: rgba(99, 102, 241, 1);
}

/* Hide Deploy Button on Desktop */
@media (min-width: 1025px) {
    .mobile-only-btn {
        display: none !important;
    }
}

.archive-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 0.5rem 0.5rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
    color: white;
    font-size: 0.75rem;
    text-align: center;
    pointer-events: none;
    z-index: 5;
}

.archive-name {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Preset Styles - Using same robust grid layout */
.preset-item {
    position: relative;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    height: 0;
    padding-bottom: 100%;
}

.preset-item:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

.preset-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Creation Body & Tools */
.char-input-body {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.creation-body-new {
    width: 100%;
    max-width: 850px;
    align-items: stretch;
    gap: 0.75rem;
    overflow-y: auto;
}

.creation-layout-split {
    display: flex;
    gap: 1.5rem;
    width: 100%;
}

.creation-col-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.creation-col-right {
    width: 320px;
    /* Fixed width for the portrait box */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.creation-field-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.creation-field-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
}

.creation-field-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.creation-field-actions {
    display: flex;
    gap: 0.3rem;
}

/* Small inline icon buttons (mic, upload) next to field labels */
.creation-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.creation-action-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.5);
    color: white;
}

.creation-action-btn.recording {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.7);
    color: #ef4444;
    animation: pulse 1.2s infinite;
}

.char-name-input {
    width: 100%;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem;
    color: white;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: all 0.2s;
}

.char-name-input:focus {
    border-color: var(--primary);
    background: rgba(30, 41, 59, 0.8);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.creation-tools {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.tool-btn {
    background: white;
    border: none;
    color: #0f172a;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #f1f5f9;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.tool-btn.mic-btn:hover {
    color: #ef4444;
}

.tool-btn.pro-btn:hover {
    color: #f59e0b;
}

/* Creation Preview */
.creation-preview {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    min-height: 200px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.creation-preview.droppable {
    border: 2px dashed rgba(255, 255, 255, 0.3);
    transition: all 0.2s ease;
}

.creation-preview.drag-over {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.preview-placeholder-text {
    position: absolute;
    color: rgba(255, 255, 255, 0.3);
    font-weight: 600;
    font-size: 0.9rem;
    font-family: 'Outfit', sans-serif;
    text-align: center;
    z-index: 0;
    pointer-events: none;
}

.creation-redo-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
    transition: all 0.2s ease;
}

.creation-redo-btn:hover {
    background: var(--primary);
    border-color: transparent;
    transform: rotate(-15deg) scale(1.1);
}

/* Description Area */
.description-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: slideIn 0.3s ease-out;
}

.char-input-field {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    overflow: hidden;
    outline: none;
    min-height: 60px;
}

.char-input-field:focus {
    border-color: var(--primary);
}

/* Footer & Action Buttons */
.overlay-footer {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: nowrap;
}

.char-cancel-btn,
.char-archive-btn,
.char-generate-btn {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    padding: 0.6rem 0.5rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-cancel-btn {
    background: white;
    color: #0f172a;
    border: none;
}

.char-archive-btn {
    background: rgba(51, 65, 85, 0.8);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.char-generate-btn {
    background: var(--primary);
    color: white;
    border: none;
}

.char-cancel-btn:hover,
.char-archive-btn:hover,
.char-generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.char-generate-btn:hover {
    background: var(--primary-hover);
}

/* Shared UI Elements */
.icon-btn.cancel-btn {
    position: absolute;
    right: -0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: #ef4444 !important;
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border-radius: 50%;
}

.icon-btn.cancel-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    transform: translateY(-50%) scale(1.1);
}