* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --paper: #f4e4bc;
    --paper-dark: #d4c4a4;
    --blueprint: #1a4a6e;
    --copper: #b87333;
    --text: #3d2b1f;
    --gold: #c4a35a;
    --ink: #2a1f14;
    --error-red: #c44b4b;
}

body {
    font-family: 'Share Tech Mono', monospace;
    background: var(--paper);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    position: relative;
    min-height: 100vh;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

.paper-texture {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E"),
        linear-gradient(135deg, var(--paper) 0%, var(--paper-dark) 100%);
    pointer-events: none;
    z-index: -2;
}

.blueprint-lines {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(26, 74, 110, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(26, 74, 110, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: -1;
}

.header {
    text-align: center;
    padding: 2rem 1rem;
    border: 4px double var(--blueprint);
    background: linear-gradient(180deg, rgba(244, 228, 188, 0.9) 0%, rgba(212, 196, 164, 0.9) 100%);
    margin-bottom: 2rem;
    position: relative;
}

.header::before,
.header::after {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border: 2px solid var(--copper);
}

.header::before {
    top: 10px;
    left: 10px;
    border-right: none;
    border-bottom: none;
}

.header::after {
    bottom: 10px;
    right: 10px;
    border-left: none;
    border-top: none;
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.5rem, 5vw, 3rem);
    font-weight: 900;
    color: var(--blueprint);
    text-shadow: 2px 2px 0 var(--copper);
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: clamp(0.8rem, 2vw, 1rem);
    color: var(--text);
    opacity: 0.8;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.wheels-section {
    background: linear-gradient(180deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0.1) 100%);
    border: 3px solid var(--blueprint);
    padding: 1.5rem;
    position: relative;
}

.wheels-section::before {
    content: 'INVENTION COMPONENT SELECTOR';
    position: absolute;
    top: -12px;
    left: 20px;
    background: var(--paper);
    padding: 0 10px;
    font-size: 0.75rem;
    color: var(--blueprint);
    font-weight: bold;
}

.wheels-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.wheel-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.wheel-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.wheel-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--blueprint);
    letter-spacing: 0.1em;
}

.wheel-display {
    width: 100%;
    max-width: 180px;
    height: 120px;
    background: linear-gradient(180deg, #2a1f14 0%, #3d2b1f 50%, #2a1f14 100%);
    border: 3px solid var(--copper);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    box-shadow: 
        inset 0 0 20px rgba(0,0,0,0.5),
        0 4px 8px rgba(0,0,0,0.3);
}

.wheel-item {
    position: absolute;
    left: 0;
    right: 0;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.65rem, 1.5vw, 0.85rem);
    font-weight: bold;
    color: var(--gold);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    padding: 0 5px;
    text-align: center;
}

.wheel-item-prev {
    top: 0;
    opacity: 0.3;
    transform: scale(0.85);
}

.wheel-item-current {
    top: 40px;
    font-size: clamp(0.75rem, 1.8vw, 1rem);
    color: #fff;
}

.wheel-item-next {
    top: 80px;
    opacity: 0.3;
    transform: scale(0.85);
}

.wheel-highlight {
    position: absolute;
    top: 35px;
    left: 5px;
    right: 5px;
    height: 50px;
    border: 2px solid var(--gold);
    border-radius: 4px;
    pointer-events: none;
    box-shadow: 
        inset 0 0 10px rgba(196, 163, 90, 0.3),
        0 0 10px rgba(196, 163, 90, 0.2);
}

.wheel-display.spinning .wheel-item {
    animation: wheelBlur 0.1s infinite;
}

@keyframes wheelBlur {
    0%, 100% { filter: blur(0); }
    50% { filter: blur(2px); }
}

.spin-single-btn {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    padding: 0.4rem 1rem;
    background: var(--blueprint);
    color: var(--paper);
    border: 2px solid var(--copper);
    cursor: pointer;
    transition: all 0.2s;
}

.spin-single-btn:hover:not(:disabled) {
    background: var(--copper);
    transform: translateY(-2px);
}

.spin-single-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.spin-all-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    font-weight: 700;
    padding: 1rem 2rem;
    background: linear-gradient(180deg, var(--copper) 0%, #8b5a2b 100%);
    color: var(--paper);
    border: 3px solid var(--gold);
    cursor: pointer;
    transition: all 0.3s;
    display: block;
    margin: 0 auto;
    box-shadow: 
        0 4px 0 #5a3a1a,
        0 8px 15px rgba(0,0,0,0.3);
}

.spin-all-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 
        0 7px 0 #5a3a1a,
        0 12px 20px rgba(0,0,0,0.4);
}

.spin-all-btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 
        0 2px 0 #5a3a1a,
        0 4px 10px rgba(0,0,0,0.3);
}

.spin-all-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.invention-display {
    text-align: center;
}

.invention-plate {
    display: inline-block;
    background: linear-gradient(180deg, #f8f0d8 0%, var(--paper-dark) 100%);
    border: 4px double var(--blueprint);
    padding: 1.5rem 2rem;
    position: relative;
}

.invention-plate::before {
    content: '★ INVENTION DESIGNATION ★';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--paper);
    padding: 0 15px;
    font-size: 0.65rem;
    color: var(--copper);
    white-space: nowrap;
}

.invention-name {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: 700;
    color: var(--blueprint);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.patent-number {
    font-size: 0.85rem;
    color: var(--copper);
}

.invention-components {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.component-tag {
    font-size: 0.7rem;
    padding: 0.3rem 0.6rem;
    background: var(--blueprint);
    color: var(--gold);
    border-radius: 3px;
    font-family: 'Share Tech Mono', monospace;
}

.generate-section {
    text-align: center;
}

.generate-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    font-weight: 700;
    padding: 1.2rem 2.5rem;
    background: linear-gradient(180deg, var(--blueprint) 0%, #0d2840 100%);
    color: var(--gold);
    border: 3px solid var(--gold);
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.generate-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.1) 50%, transparent 60%);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.generate-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #2a6090 0%, var(--blueprint) 100%);
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(26, 74, 110, 0.5);
}

.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.schematic-section {
    background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0.05) 100%);
    border: 3px solid var(--blueprint);
    padding: 1.5rem;
    position: relative;
}

.schematic-section::before {
    content: 'TECHNICAL SCHEMATIC OUTPUT';
    position: absolute;
    top: -12px;
    left: 20px;
    background: var(--paper);
    padding: 0 10px;
    font-size: 0.75rem;
    color: var(--blueprint);
    font-weight: bold;
}

.schematic-placeholder {
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--blueprint);
    opacity: 0.6;
    position: relative;
    border: 2px dashed var(--blueprint);
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 19px,
        rgba(26, 74, 110, 0.1) 19px,
        rgba(26, 74, 110, 0.1) 20px
    ),
    repeating-linear-gradient(
        90deg,
        transparent,
        transparent 19px,
        rgba(26, 74, 110, 0.1) 19px,
        rgba(26, 74, 110, 0.1) 20px
    );
}

.schematic-placeholder p {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.8rem, 2vw, 1rem);
    text-align: center;
}

.schematic-loading {
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.schematic-error {
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    border: 2px dashed var(--error-red);
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(196, 75, 75, 0.05) 10px,
        rgba(196, 75, 75, 0.05) 20px
    );
    padding: 2rem;
}

.error-icon {
    font-size: 3rem;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

.error-message {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    color: var(--error-red);
    font-weight: 700;
}

.error-hint {
    font-size: 0.9rem;
    color: var(--text);
    opacity: 0.8;
    text-align: center;
    max-width: 400px;
}

.gear-spinner {
    position: relative;
    width: 80px;
    height: 80px;
}

.gear {
    position: absolute;
    border: 4px solid var(--copper);
    border-radius: 50%;
}

.gear::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    background: var(--copper);
    border-radius: 50%;
}

.gear-1 {
    width: 60px;
    height: 60px;
    top: 0;
    left: 0;
    animation: spin 2s linear infinite;
}

.gear-2 {
    width: 40px;
    height: 40px;
    bottom: 0;
    right: 0;
    animation: spin 1.5s linear infinite reverse;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading-message {
    font-family: 'Share Tech Mono', monospace;
    color: var(--blueprint);
    animation: pulse 1s ease-in-out infinite;
}

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

.schematic-viewer {
    position: relative;
}

.schematic-image {
    width: 100%;
    max-width: 800px;
    display: block;
    margin: 0 auto;
    border: 4px solid var(--ink);
    box-shadow: 
        8px 8px 0 rgba(0,0,0,0.2),
        inset 0 0 50px rgba(244, 228, 188, 0.5);
}

.schematic-annotations {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.annotation {
    position: absolute;
    font-size: 0.7rem;
    color: var(--blueprint);
    background: rgba(244, 228, 188, 0.9);
    padding: 2px 6px;
    border: 1px solid var(--blueprint);
}

.annotation-1 { top: 10%; left: 5%; }
.annotation-2 { top: 30%; right: 5%; }
.annotation-3 { bottom: 20%; left: 10%; }

.schematic-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.control-btn {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
    padding: 0.6rem 1.5rem;
    background: var(--paper);
    color: var(--blueprint);
    border: 2px solid var(--blueprint);
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background: var(--blueprint);
    color: var(--paper);
}

.control-btn-primary {
    background: var(--copper);
    color: var(--paper);
    border-color: var(--gold);
    font-weight: bold;
    animation: glow 1.5s ease-in-out infinite;
}

.control-btn-primary:hover {
    background: var(--gold);
    color: var(--ink);
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--copper); }
    50% { box-shadow: 0 0 15px var(--copper), 0 0 25px var(--gold); }
}

.seed-display {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    color: var(--copper);
    background: rgba(255,255,255,0.5);
    padding: 0.4rem 0.8rem;
    border: 1px dashed var(--copper);
    border-radius: 3px;
}

.history-section {
    border: 2px solid var(--copper);
    padding: 1rem;
    background: rgba(255,255,255,0.1);
}

.history-toggle {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--copper);
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.history-toggle:hover {
    color: var(--blueprint);
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.history-item {
    background: var(--paper);
    border: 2px solid var(--blueprint);
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.history-thumbnail {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--ink);
}

.history-info {
    padding: 0.5rem 0;
}

.history-name {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--blueprint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-patent {
    font-size: 0.65rem;
    color: var(--copper);
}

.footer {
    margin-top: 3rem;
    padding: 1.5rem;
    text-align: center;
    border-top: 2px solid var(--blueprint);
    background: linear-gradient(180deg, transparent 0%, rgba(26, 74, 110, 0.05) 100%);
}

.footer p {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.footer a {
    color: var(--copper);
    text-decoration: none;
    font-weight: bold;
}

.footer a:hover {
    text-decoration: underline;
}

.disclaimer {
    font-size: 0.7rem !important;
    opacity: 0.7;
    max-width: 600px;
    margin: 0 auto;
}

@media (max-width: 640px) {
    .app-container {
        padding: 0.5rem;
    }
    
    .header {
        padding: 1rem 0.5rem;
    }
    
    .wheels-container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .wheel-display {
        height: 100px;
    }
    
    .wheel-item {
        height: 33px;
    }
    
    .wheel-item-current {
        top: 33px;
    }
    
    .wheel-item-next {
        top: 66px;
    }
    
    .wheel-highlight {
        top: 28px;
        height: 44px;
    }
    
    .invention-plate {
        padding: 1rem;
    }
    
    .generate-btn {
        padding: 1rem 1.5rem;
    }
    
    .invention-components {
        gap: 0.3rem;
    }
    
    .component-tag {
        font-size: 0.6rem;
        padding: 0.2rem 0.4rem;
    }
}