/* ================================================================
   FidgCraft – Global Styles
   ================================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --topbar-height: 52px;
    --topbar-bg: #0d0d12;
    --topbar-border: rgba(255, 255, 255, 0.08);
    --topbar-text: #f0f0f0;
    --topbar-accent: #7c5cfc;
    --topbar-arrow-hover: rgba(255, 255, 255, 0.12);
    --topbar-glow: rgba(124, 92, 252, 0.35);
    --star-color: #ffc940;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0a0a0e;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    user-select: none;
}

#topbar-controls {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 15px;
}

/* ── Logo / Title ─────────────────────────────────────────────── */
#topbar-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    pointer-events: none;
}

#topbar-logo .brand {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--topbar-text);
    text-shadow: 0 0 14px var(--topbar-glow);
}

#topbar-logo .sim-name {
    font-size: 0.62rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.38);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* ── Navigation Arrows ────────────────────────────────────────── */
.nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--topbar-height);
    height: var(--topbar-height);
    cursor: pointer;
    background: none;
    border: none;
    color: var(--topbar-text);
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.nav-arrow:hover {
    background: var(--topbar-arrow-hover);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.07);
}

.nav-arrow:active {
    background: rgba(255, 255, 255, 0.06);
}

.nav-arrow svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.nav-arrow.disabled {
    opacity: 0.25;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Sim Counter ──────────────────────────────────────────────── */
#sim-counter {
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.3);
    min-width: 50px;
    text-align: center;
    font-family: monospace;
}

/* ════════════════════════════════════════════════════════════════
   TOP RATED BUTTON
   ════════════════════════════════════════════════════════════════ */
#btn-top-rated {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 14px;
    height: var(--topbar-height);
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.45);
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

#btn-top-rated:hover {
    background: var(--topbar-arrow-hover);
    color: var(--star-color);
}

#btn-top-rated.active {
    color: var(--star-color);
    background: rgba(255, 201, 64, 0.08);
}

#btn-top-rated .tr-btn-icon {
    font-size: 1rem;
    line-height: 1;
}

#btn-top-rated .tr-btn-label {
    font-size: 0.52rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-family: 'Segoe UI', sans-serif;
}

/* ════════════════════════════════════════════════════════════════
   TOP RATED DROPDOWN PANEL
   ════════════════════════════════════════════════════════════════ */
#top-rated-panel {
    position: fixed;
    top: var(--topbar-height);
    left: 50%;
    transform: translateX(-50%);
    width: min(400px, 96vw);
    background: #13131e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
    z-index: 990;

    /* Slide-down animation via max-height */
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

#top-rated-panel.open {
    max-height: 480px;
}

/* Inner scrollable area – separate from outer so overflow:hidden
   doesn't prevent scrolling once fully open */
#top-rated-list {
    overflow-y: auto;
    max-height: 440px;
    padding: 6px 0 8px;
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

#top-rated-list::-webkit-scrollbar {
    width: 4px;
}

#top-rated-list::-webkit-scrollbar-track {
    background: transparent;
}

#top-rated-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

/* Panel header */
#top-rated-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 0.7rem;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
}

#top-rated-heading .tr-head-star {
    color: var(--star-color);
    font-size: 0.85rem;
}

/* Each row */
.tr-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.tr-item:last-child {
    border-bottom: none;
}

.tr-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tr-item:active {
    background: rgba(124, 92, 252, 0.12);
}

.tr-rank {
    font-size: 0.65rem;
    font-family: monospace;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.25);
    min-width: 20px;
    text-align: right;
    flex-shrink: 0;
}

/* Gold / silver / bronze for top 3 */
.tr-item:nth-child(1) .tr-rank { color: #ffc940; font-weight: 700; }
.tr-item:nth-child(2) .tr-rank { color: #c0c0c0; font-weight: 600; }
.tr-item:nth-child(3) .tr-rank { color: #cd7f32; font-weight: 600; }

.tr-title {
    flex: 1;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.75);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tr-item:hover .tr-title {
    color: #fff;
}

.tr-rating-info {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.tr-stars {
    color: var(--star-color);
    font-size: 0.7rem;
    letter-spacing: 1px;
}

.tr-stars.unrated {
    color: rgba(255, 255, 255, 0.15);
}

.tr-avg {
    font-size: 0.65rem;
    font-family: monospace;
    color: rgba(255, 255, 255, 0.5);
    min-width: 24px;
}

.tr-count {
    font-size: 0.6rem;
    font-family: monospace;
    color: rgba(255, 255, 255, 0.25);
}

.tr-loading,
.tr-error,
.tr-empty {
    text-align: center;
    padding: 24px 16px;
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.25);
}

.tr-error { color: rgba(255, 80, 80, 0.6); }

/* ════════════════════════════════════════════════════════════════
   STAR RATING WIDGET
   ════════════════════════════════════════════════════════════════ */
#rating-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 12px;
    flex-shrink: 0;
}

#rating-label {
    font-size: 0.52rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.28);
    white-space: nowrap;
}

#rating-stars {
    display: flex;
    gap: 2px;
    align-items: center;
}

/* Default (unlit): yellow outline on black background */
.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 1px;
    line-height: 1;
    transition: transform 0.1s;
    user-select: none;
    -webkit-user-select: none;

    /* Yellow outline star – raw ★ character with transparent fill */
    color: transparent;
    -webkit-text-stroke: 1.5px var(--star-color);
}

.star-btn:hover {
    transform: scale(1.2);
}

/* Lit (rated / hovered): solid yellow fill */
.star-btn.lit {
    color: var(--star-color);
    -webkit-text-stroke: 0;
    text-shadow: 0 0 8px rgba(255, 201, 64, 0.5);
}

/* Pop animation on click */
@keyframes star-pop {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.star-btn.pop {
    animation: star-pop 0.22s ease-out forwards;
}

/* Average + vote count row */
#rating-info {
    display: flex;
    gap: 4px;
    align-items: center;
    font-family: monospace;
    font-size: 0.6rem;
    letter-spacing: 1px;
    white-space: nowrap;
    min-height: 9px;
}

#rating-avg-val {
    color: rgba(255, 255, 255, 0.45);
}

#rating-count-val {
    color: rgba(255, 255, 255, 0.22);
}

/* ════════════════════════════════════════════════════════════════
   SIMULATION IFRAME
   ════════════════════════════════════════════════════════════════ */
#sim-frame-wrap {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: #0a0a0e;
}

#sim-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ── Loading Overlay ──────────────────────────────────────────── */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: #0a0a0e;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    transition: opacity 0.4s;
    pointer-events: none;
}

#loading-overlay.hidden {
    opacity: 0;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,0.08);
    border-top-color: var(--topbar-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay span {
    font-size: 0.75rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.3);
}

/* ════════════════════════════════════════════════════════════════
   CRAFT BUTTON (topbar)
   ════════════════════════════════════════════════════════════════ */
#btn-craft {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 14px;
    height: var(--topbar-height);
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.55);
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
    position: relative;
}

#btn-craft:hover {
    background: rgba(124, 92, 252, 0.12);
    color: #c8b8ff;
}

#btn-craft:active {
    background: rgba(124, 92, 252, 0.2);
}

.craft-topbtn-icon {
    font-size: 1rem;
    line-height: 1;
    color: var(--topbar-accent);
}

.craft-topbtn-label {
    font-size: 0.52rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-family: 'Segoe UI', sans-serif;
}

/* ════════════════════════════════════════════════════════════════
   CRAFT LIGHTBOX OVERLAY
   ════════════════════════════════════════════════════════════════ */
#craft-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;

    /* Hidden by default */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#craft-lightbox.open {
    opacity: 1;
    pointer-events: all;
}

/* ── Craft Box ────────────────────────────────────────────────── */
#craft-box {
    position: relative;
    background: #111118;
    border: 1px solid rgba(124, 92, 252, 0.25);
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.8),
                0 0 0 1px rgba(124, 92, 252, 0.08);
    width: min(620px, 96vw);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    transform: scale(0.95) translateY(12px);
    transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
}

#craft-lightbox.open #craft-box {
    transform: scale(1) translateY(0);
}

/* Expand to fill screen when in preview view */
#craft-box[data-view="preview"] {
    width: min(1100px, 96vw);
    height: min(840px, 90vh);
}

/* ── Close button ─────────────────────────────────────────────── */
#craft-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

#craft-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* ════════════════════════════════════════════════════════════════
   CRAFT VIEWS (shared)
   ════════════════════════════════════════════════════════════════ */
.craft-view {
    padding: 36px 36px 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: 90vh;
}

/* Common button styles */
.craft-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 24px;
    background: var(--topbar-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}

.craft-btn-primary:hover {
    background: #9070ff;
    box-shadow: 0 0 18px rgba(124, 92, 252, 0.5);
}

.craft-btn-primary:active {
    transform: scale(0.97);
}

.craft-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.craft-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 22px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 0.82rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.craft-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.craft-btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 14px;
    background: none;
    color: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.craft-btn-ghost:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

/* Error message */
.craft-error {
    font-size: 0.78rem;
    color: #ff7070;
    background: rgba(255, 60, 60, 0.08);
    border: 1px solid rgba(255, 60, 60, 0.2);
    border-radius: 6px;
    padding: 10px 14px;
    margin: 0;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: INPUT
   ════════════════════════════════════════════════════════════════ */
.craft-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding-bottom: 4px;
}

.craft-header-icon {
    font-size: 1.8rem;
    color: var(--topbar-accent);
    filter: drop-shadow(0 0 10px rgba(124, 92, 252, 0.6));
    line-height: 1;
}

.craft-header h2 {
    color: #f0f0f0;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

.craft-header p {
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.82rem;
    line-height: 1.5;
    max-width: 420px;
    margin: 0;
}

#craft-instructions {
    width: 100%;
    min-height: 140px;
    max-height: 240px;
    resize: vertical;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #e8e8e8;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.88rem;
    line-height: 1.6;
    padding: 14px 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#craft-instructions:focus {
    border-color: rgba(124, 92, 252, 0.5);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.12);
}

#craft-instructions::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.craft-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: -8px;
}

.craft-char-count {
    font-size: 0.68rem;
    font-family: monospace;
    color: rgba(255, 255, 255, 0.2);
    letter-spacing: 1px;
}

.craft-hint-key {
    font-size: 0.65rem;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.18);
    text-transform: uppercase;
}

#craft-view-input .craft-btn-primary {
    align-self: stretch;
    padding: 14px;
    font-size: 0.88rem;
    letter-spacing: 2px;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: LOADING
   ════════════════════════════════════════════════════════════════ */
#craft-view-loading {
    align-items: center;
    justify-content: center;
    min-height: 280px;
    text-align: center;
    gap: 20px;
}

.craft-spinner-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main spinner ring */
.craft-spinner-ring {
    width: 64px;
    height: 64px;
    border: 4px solid rgba(124, 92, 252, 0.15);
    border-top-color: var(--topbar-accent);
    border-radius: 50%;
    animation: craft-spin 1s linear infinite;
}

.craft-spinner-ring.craft-spinner-sm {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

@keyframes craft-spin {
    to { transform: rotate(360deg); }
}

.craft-loading-title {
    color: #e0e0e0;
    font-size: 1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

.craft-loading-sub {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.78rem;
    letter-spacing: 1px;
    margin: 0;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: READY
   ════════════════════════════════════════════════════════════════ */
#craft-view-ready {
    align-items: center;
    justify-content: center;
    min-height: 280px;
    text-align: center;
    gap: 14px;
}

.craft-ready-icon {
    font-size: 2.5rem;
    color: var(--topbar-accent);
    filter: drop-shadow(0 0 16px rgba(124, 92, 252, 0.7));
    animation: craft-pulse 2s ease-in-out infinite;
}

@keyframes craft-pulse {
    0%, 100% { filter: drop-shadow(0 0 10px rgba(124, 92, 252, 0.5)); }
    50%       { filter: drop-shadow(0 0 22px rgba(124, 92, 252, 0.9)); }
}

.craft-ready-title {
    color: #f0f0f0;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

.craft-ready-simname {
    color: rgba(124, 92, 252, 0.9);
    font-size: 0.88rem;
    letter-spacing: 1.5px;
    font-style: italic;
    margin: 0;
}

.craft-ready-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: PREVIEW
   ════════════════════════════════════════════════════════════════ */
#craft-view-preview {
    padding: 0;
    gap: 0;
    height: 100%;
    overflow: hidden;
}

#craft-preview-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

#craft-preview-title-label {
    flex: 1;
    font-size: 0.78rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#craft-frame-wrap {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: #0a0a0e;
}

#craft-preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    transition: opacity 0.3s;
}

#craft-frame-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: #0a0a0e;
    z-index: 5;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: SAVE FORM
   ════════════════════════════════════════════════════════════════ */
#craft-view-save {
    align-items: stretch;
}

.craft-save-inner {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.craft-save-inner h3 {
    color: #f0f0f0;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
    padding-right: 40px; /* room for close button */
}

.craft-save-sub {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.8rem;
    line-height: 1.5;
    margin: 0;
}

.craft-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.craft-field label {
    font-size: 0.72rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
}

.craft-optional {
    color: rgba(255, 255, 255, 0.22);
    font-size: 0.68rem;
    letter-spacing: 0.5px;
    text-transform: none;
    font-style: italic;
}

.craft-field input[type="text"] {
    width: 100%;
    padding: 11px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #e8e8e8;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.craft-field input[type="text"]:focus {
    border-color: rgba(124, 92, 252, 0.5);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.12);
}

.craft-field input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.craft-save-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ════════════════════════════════════════════════════════════════
   VIEW: SAVED
   ════════════════════════════════════════════════════════════════ */
#craft-view-saved {
    align-items: center;
    justify-content: center;
    min-height: 280px;
    text-align: center;
    gap: 14px;
}

.craft-saved-checkmark {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(76, 255, 145, 0.12);
    border: 2px solid rgba(76, 255, 145, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #4cff91;
    animation: craft-pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes craft-pop-in {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.craft-saved-title {
    color: #f0f0f0;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

.craft-saved-sub {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.82rem;
    line-height: 1.5;
    max-width: 360px;
    margin: 0;
}

.craft-saved-name {
    color: rgba(124, 92, 252, 0.9);
    font-size: 0.88rem;
    font-style: italic;
    letter-spacing: 1px;
    margin: 0;
}

.craft-saved-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}

/* ════════════════════════════════════════════════════════════════
   PREVENT TOPBAR ARROW NAVIGATION WHILE LIGHTBOX IS OPEN
   ════════════════════════════════════════════════════════════════ */
body.craft-open #sim-frame-wrap,
body.refine-open #sim-frame-wrap {
    pointer-events: none;
}

/* ════════════════════════════════════════════════════════════════
   IMAGE ATTACHMENT — textarea wrapper & drop zone
   ════════════════════════════════════════════════════════════════ */

/* Wrapper that becomes the drop target */
#craft-textarea-wrap {
    position: relative;
}

/* Drop overlay — visible only when dragging over the wrapper */
#craft-drop-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(124, 92, 252, 0.18);
    border: 2px dashed rgba(124, 92, 252, 0.8);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.88rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    pointer-events: none;     /* clicks pass through to textarea */
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
}

/* Show overlay when dragging */
#craft-textarea-wrap.drag-over #craft-drop-overlay {
    opacity: 1;
}

/* Glow effect on the textarea during drag */
#craft-textarea-wrap.drag-over #craft-instructions {
    border-color: rgba(124, 92, 252, 0.6);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.2);
}

/* ════════════════════════════════════════════════════════════════
   IMAGE ATTACHMENT — attach button & preview strip
   ════════════════════════════════════════════════════════════════ */

#craft-attach-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    margin-top: -4px;   /* tighten gap after meta-row */
}

/* ── Attach button ──────────────────────────────────────────── */
#craft-attach-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.75rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

#craft-attach-btn:hover {
    background: rgba(124, 92, 252, 0.1);
    border-color: rgba(124, 92, 252, 0.35);
    color: #c8b8ff;
}

#craft-attach-btn:active {
    background: rgba(124, 92, 252, 0.18);
}

.craft-attach-icon {
    font-size: 1rem;
    line-height: 1;
}

/* ── Image preview strip (thumbnail + info + remove) ────────── */
#craft-image-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 6px 6px;
    background: rgba(124, 92, 252, 0.08);
    border: 1px solid rgba(124, 92, 252, 0.25);
    border-radius: 8px;
    flex: 1;
    min-width: 0;
    animation: craft-img-appear 0.2s ease-out forwards;
}

@keyframes craft-img-appear {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Thumbnail */
#craft-image-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    display: block;
}

/* File info block */
#craft-image-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

#craft-image-name {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#craft-image-size {
    font-size: 0.65rem;
    font-family: monospace;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.3);
}

/* Remove button */
#craft-image-remove {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

#craft-image-remove:hover {
    background: rgba(255, 80, 80, 0.15);
    border-color: rgba(255, 80, 80, 0.4);
    color: #ff7070;
}

/* ════════════════════════════════════════════════════════════════
   REFINE BAR  (inside the preview view)
   ════════════════════════════════════════════════════════════════ */

#craft-refine-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    transition: background 0.2s;
}

/* Pulse background while a refine job is running */
#craft-refine-bar.refining {
    background: rgba(124, 92, 252, 0.06);
    animation: refine-pulse 2s ease-in-out infinite;
}

@keyframes refine-pulse {
    0%, 100% { background: rgba(124, 92, 252, 0.04); }
    50%       { background: rgba(124, 92, 252, 0.12); }
}

/* ✦ accent icon */
.craft-refine-icon {
    color: var(--topbar-accent);
    font-size: 0.85rem;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.75;
}

/* Text input */
#craft-refine-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #e8e8e8;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#craft-refine-input:focus {
    border-color: rgba(124, 92, 252, 0.5);
    box-shadow: 0 0 0 2px rgba(124, 92, 252, 0.12);
}

#craft-refine-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

#craft-refine-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Refine button */
#craft-refine-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    height: 32px;
    background: rgba(124, 92, 252, 0.15);
    border: 1px solid rgba(124, 92, 252, 0.3);
    border-radius: 6px;
    color: #c8b8ff;
    font-size: 0.78rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 0.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#craft-refine-btn:hover:not(:disabled) {
    background: rgba(124, 92, 252, 0.28);
    color: #fff;
}

#craft-refine-btn:active:not(:disabled) {
    background: rgba(124, 92, 252, 0.38);
}

#craft-refine-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Error bar below the refine bar */
.craft-refine-error-bar {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    padding: 7px 14px;
    font-size: 0.75rem;
    margin: 0;
    flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════
   REFINE BUTTON (topbar)
   ════════════════════════════════════════════════════════════════ */
#btn-refine {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 14px;
    height: var(--topbar-height);
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.55);
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

#btn-refine:hover {
    background: rgba(124, 92, 252, 0.12);
    color: #c8b8ff;
}

#btn-refine:active {
    background: rgba(124, 92, 252, 0.2);
}

.refine-topbtn-icon {
    font-size: 1rem;
    line-height: 1;
    color: var(--topbar-accent);
    filter: drop-shadow(0 0 6px rgba(124, 92, 252, 0.5));
}

.refine-topbtn-label {
    font-size: 0.52rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-family: 'Segoe UI', sans-serif;
}

/* ════════════════════════════════════════════════════════════════
   REFINE LIGHTBOX OVERLAY
   ════════════════════════════════════════════════════════════════ */
#refine-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#refine-lightbox.open {
    opacity: 1;
    pointer-events: all;
}

/* ── Refine Box ───────────────────────────────────────────────── */
#refine-box {
    position: relative;
    background: #111118;
    border: 1px solid rgba(124, 92, 252, 0.25);
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.8),
                0 0 0 1px rgba(124, 92, 252, 0.08);
    width: min(660px, 96vw);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(12px);
    transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
}

#refine-lightbox.open #refine-box {
    transform: scale(1) translateY(0);
}

/* Expand to full preview size when showing the iframe */
#refine-box[data-view="preview"] {
    width: min(1100px, 96vw);
    height: min(840px, 90vh);
}

/* ── Close button ─────────────────────────────────────────────── */
#refine-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

#refine-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* ── View containers ──────────────────────────────────────────── */
.refine-view {
    padding: 36px 36px 32px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    max-height: 90vh;
}

/* ════════════════════════════════════════════════════════════════
   REFINE VIEW: INPUT
   ════════════════════════════════════════════════════════════════ */
.refine-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding-bottom: 4px;
}

.refine-header-icon {
    font-size: 1.8rem;
    line-height: 1;
    color: var(--topbar-accent);
    filter: drop-shadow(0 0 10px rgba(124, 92, 252, 0.6));
    animation: craft-pulse 2.5s ease-in-out infinite;
}

.refine-header h2 {
    color: #f0f0f0;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 0;
}

.refine-header p {
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.82rem;
    line-height: 1.5;
    max-width: 480px;
    margin: 0;
}

/* Single-line input + button in a flex row */
#refine-input-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

#refine-instructions {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: #e8e8e8;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#refine-instructions:focus {
    border-color: rgba(124, 92, 252, 0.5);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.12);
}

#refine-instructions::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

#refine-instructions:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ════════════════════════════════════════════════════════════════
   REFINE VIEW: LOADING
   ════════════════════════════════════════════════════════════════ */
#refine-view-loading {
    align-items: center;
    justify-content: center;
    min-height: 280px;
    text-align: center;
    gap: 20px;
}

/* ════════════════════════════════════════════════════════════════
   REFINE VIEW: PREVIEW
   ════════════════════════════════════════════════════════════════ */
#refine-view-preview {
    padding: 0;
    gap: 0;
    height: 100%;
    overflow: hidden;
}

#refine-preview-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

#refine-preview-title-label {
    flex: 1;
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Refine-again bar — identical pattern to #craft-refine-bar */
#refine-again-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    transition: background 0.2s;
}

#refine-again-bar.refining {
    animation: refine-pulse 2s ease-in-out infinite;
}

#refine-again-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #e8e8e8;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#refine-again-input:focus {
    border-color: rgba(124, 92, 252, 0.5);
    box-shadow: 0 0 0 2px rgba(124, 92, 252, 0.12);
}

#refine-again-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

#refine-again-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#refine-again-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    height: 32px;
    background: rgba(124, 92, 252, 0.15);
    border: 1px solid rgba(124, 92, 252, 0.3);
    border-radius: 6px;
    color: #c8b8ff;
    font-size: 0.78rem;
    font-family: 'Segoe UI', sans-serif;
    letter-spacing: 0.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#refine-again-btn:hover:not(:disabled) {
    background: rgba(124, 92, 252, 0.28);
    color: #fff;
}

#refine-again-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#refine-frame-wrap {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: #0a0a0e;
}

#refine-preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    transition: opacity 0.3s;
}

#refine-frame-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: #0a0a0e;
    z-index: 5;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ════════════════════════════════════════════════════════════════
   REFINE VIEW: SAVED
   ════════════════════════════════════════════════════════════════ */
#refine-view-saved {
    align-items: center;
    justify-content: center;
    min-height: 280px;
    text-align: center;
    gap: 14px;
}
