/* mesobags v2.0 - Refined, not redesigned */

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

:root {
    /* Color palette */
    --bg-primary: #FAF7F2;
    --text-primary: #222;
    --text-secondary: #666;
    --text-tertiary: #888;
    --maple-brown: #8B7355;
    --maple-brown-dark: #6B5345;
    --border-warm: #CDB99F;

    /* Spacing scale */
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 20px;
    --space-lg: 30px;
    --space-xl: 40px;

    /* Animation timing */
    --duration-fast: 0.15s;
    --duration-normal: 0.2s;
    --duration-slow: 0.3s;
}

body {
    font-family: Georgia, serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Subtle paper texture */
    background-image:
        radial-gradient(circle at 20% 50%, rgba(139, 115, 85, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(139, 115, 85, 0.02) 0%, transparent 50%);
}

/* Layout Structure */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Left Sidebar - Paul Graham Style */
.sidebar {
    width: 180px;
    padding: var(--space-lg) var(--space-md);
    background: var(--bg-primary);
    border-right: 1px solid #E8E0D5;
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.logo {
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm);
    border-radius: 4px;
    transition: background var(--duration-normal) ease;
}

.logo:hover {
    background: rgba(139, 115, 85, 0.04);
}

.logo img {
    width: 24px;
    height: auto;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    transition: transform var(--duration-fast) ease;
}

.logo:hover img {
    transform: scale(1.1) rotate(-2deg);
}

.logo h1 {
    font-size: 20px;
    font-weight: normal;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.sidebar-nav a {
    color: var(--maple-brown);
    text-decoration: none;
    font-size: 14px;
    transition: color var(--duration-normal);
}

.sidebar-nav a:hover {
    color: var(--maple-brown-dark);
}

.sidebar-nav a:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: 2px;
    border-radius: 2px;
}

.sidebar-footer {
    margin-top: auto;
}

.tagline {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
    line-height: 1.4;
}

.help-icon {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 1px solid var(--maple-brown);
    background: transparent;
    color: var(--maple-brown);
    font-size: 8px;
    font-weight: bold;
    font-style: normal;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    margin-left: 4px;
    padding: 0;
    line-height: 11px;
    vertical-align: middle;
}

.help-icon:hover {
    background: var(--maple-brown);
    color: var(--bg-primary);
    transform: scale(1.1);
}

.help-icon:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: 2px;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: 180px;
    padding: var(--space-xl);
    max-width: 900px;
    padding-bottom: 100px;
}

main {
    min-height: calc(100vh - 100px);
}

/* MapleStory Inventory Window */
.inventory-window {
    width: min(340px, 90vw);
    margin: 0 auto var(--space-xl);
    background: #D4C4A0;
    border: 2px solid #8B7355;
    border-radius: 3px;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.15),
        0 1px 3px rgba(0,0,0,0.1),
        inset 0 1px 0 rgba(255,255,255,0.1);
    font-family: 'Courier New', monospace;
    font-size: 11px;
    overflow: visible;
    transition: transform var(--duration-normal) ease, box-shadow var(--duration-normal) ease;
}

.inventory-window:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 16px rgba(0,0,0,0.18),
        0 2px 4px rgba(0,0,0,0.12),
        inset 0 1px 0 rgba(255,255,255,0.1);
}

.inventory-header {
    background: linear-gradient(to bottom, #C4B49C, #B0A088);
    padding: 5px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #8B7355;
}

.inventory-title {
    color: #FFF;
    font-weight: bold;
    text-shadow: 1px 1px 0 #666;
    font-size: 10px;
    letter-spacing: 0.5px;
}

.close-btn {
    background: #E8D8C0;
    border: 1px solid #8B7355;
    color: #333;
    width: 16px;
    height: 16px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    border-radius: 2px;
    transition: background var(--duration-normal);
}

.close-btn:hover {
    background: #F0E0C8;
}

.close-btn:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: 2px;
}

/* Inventory Tabs */
.inventory-tabs {
    display: flex;
    background: #B8A088;
    border-bottom: 1px solid #8B7355;
}

.tab {
    flex: 1;
    padding: 6px;
    background: #B0A088;
    border: none;
    border-right: 1px solid #8B7355;
    color: #4A3A2A;
    cursor: pointer;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    transition: all var(--duration-normal) ease;
}

.tab:last-child {
    border-right: none;
}

.tab:hover {
    background: #C0B098;
}

.tab:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: -2px;
    z-index: 1;
}

.tab.active {
    background: #D4C4A0;
    color: #2A1A0A;
    font-weight: bold;
}

/* Inventory Grid - Sacred 4x6 */
.inventory-grid {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    background: #D4C4A0;
    overflow: visible;
}

.inventory-slot {
    width: 72px;
    height: 64px;
    background: #B8A088;
    border: 1px solid #8B7355;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) ease;
    overflow: visible;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.inventory-slot.empty {
    background: #A89880;
    opacity: 0.6;
}

.inventory-slot:hover {
    background: #C8B8A0;
    transform: scale(1.02);
}

.inventory-slot.occupied {
    background: linear-gradient(135deg, #C8B8A0 0%, #B8A088 100%);
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.15),
        0 1px 3px rgba(0,0,0,0.1);
}

.inventory-slot.occupied:hover {
    background: linear-gradient(135deg, #E8D8C0 0%, #D8C8B0 100%);
    box-shadow:
        0 0 12px rgba(255, 220, 100, 0.4),
        0 3px 6px rgba(139, 115, 85, 0.25),
        inset 0 1px 0 rgba(255,255,255,0.25);
    transform: scale(1.05) translateY(-1px);
}

.inventory-slot.occupied img {
    transition: filter var(--duration-fast) ease;
}

.inventory-slot.occupied:hover img {
    filter: drop-shadow(0 2px 4px rgba(139, 115, 85, 0.3)) brightness(1.03);
}

.inventory-slot:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: -2px;
    z-index: 2;
}

.inventory-slot img {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Tooltip */
.tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #F5EBD8 0%, #E8DCC8 100%);
    color: #2A1A0A;
    padding: 8px 10px;
    border: 2px solid #8B7355;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(139, 115, 85, 0.3);
    font-family: Georgia, serif;
    pointer-events: none;
    line-height: 1.4;
    text-align: center;
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #8B7355;
}

.tooltip strong {
    color: #8B7355;
    font-size: 12px;
    font-weight: bold;
    display: block;
    margin-bottom: 4px;
}

.inventory-slot:hover .tooltip,
.inventory-slot:focus .tooltip {
    display: block;
    animation: tooltipFadeIn var(--duration-normal) ease-out;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Meso Display */
.inventory-footer {
    padding: 6px;
    background: #B8A088;
    border-top: 1px solid #8B7355;
}

.meso-container {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    justify-content: space-between;
    padding: 0 4px;
}

.meso-coin {
    width: 18px;
    height: 18px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    animation: coinPulse 2s ease-in-out infinite;
    filter: drop-shadow(0 1px 3px rgba(255, 215, 0, 0.3));
}

@keyframes coinPulse {
    0%, 100% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(1.05) rotate(5deg);
    }
}

.meso-display {
    flex: 1;
    background: #F5F5F5;
    border: 1px solid #999;
    border-radius: 2px;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.meso-drop-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: right;
    transition: all var(--duration-normal) ease;
    padding: 0;
    border-radius: 2px;
}

.meso-drop-btn:hover {
    background: rgba(255, 215, 0, 0.03);
}

.meso-drop-btn:hover .meso-amount {
    color: var(--maple-brown);
}

.meso-drop-btn:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: 2px;
}

.meso-drop-btn:active {
    transform: scale(0.98);
}

.meso-drop-btn:active .meso-amount {
    transform: scale(0.95);
}

.meso-amount {
    color: #333;
    font-weight: normal;
    font-size: 11px;
    font-family: 'Courier New', monospace;
    letter-spacing: 0.5px;
    transition: color var(--duration-fast) ease;
}

.meso-text {
    color: #4A3A2A;
    font-size: 10px;
    font-family: 'Courier New', monospace;
    margin-left: 4px;
}

/* Bankruptcy Message */
.bankruptcy-message {
    text-align: center;
    padding: 8px;
    margin-top: 6px;
    background: rgba(196, 69, 54, 0.1);
    border-radius: 4px;
    animation: bankruptcyFade 0.3s ease-in;
}

.bankruptcy-message.hidden {
    display: none;
}

.bankruptcy-message p {
    color: #C44536;
    font-size: 11px;
    font-style: italic;
    margin: 0 0 6px 0;
}

.grind-btn {
    background: #8B7355;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-family: Georgia, serif;
    font-size: 11px;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
}

.grind-btn:hover {
    background: #6B5345;
    transform: scale(1.05);
}

.grind-btn:active {
    transform: scale(0.95);
}

@keyframes bankruptcyFade {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Meso Drop Animation */
#meso-drop-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.meso-bag {
    position: absolute;
    width: 32px;
    height: 32px;
    pointer-events: none;
    animation: mesoDropMaple 2.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    filter: drop-shadow(0 2px 8px rgba(255, 215, 0, 0.4));
}

.meso-bag img {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    animation: mesoGlow 0.8s ease-in-out infinite alternate;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

@keyframes mesoDropMaple {
    0% {
        transform: translateY(0) scale(0.8) rotate(0deg);
        opacity: 0;
    }
    5% {
        transform: translateY(-20px) scale(1) rotate(-2deg);
        opacity: 1;
    }
    12% {
        transform: translateY(-28px) scale(1.05) rotate(3deg);
    }
    20% {
        transform: translateY(-18px) scale(1) rotate(-3deg);
    }
    30% {
        transform: translateY(-10px) scale(0.98) rotate(2deg);
    }
    40% {
        transform: translateY(50px) rotate(-4deg);
    }
    50% {
        transform: translateY(150px) rotate(3deg);
    }
    60% {
        transform: translateY(300px) rotate(-2deg);
    }
    75% {
        transform: translateY(500px) rotate(4deg);
    }
    100% {
        transform: translateY(calc(100vh + 40px)) scale(0.95) rotate(-3deg);
        opacity: 0.7;
    }
}

@keyframes mesoGlow {
    0% {
        filter: brightness(1) drop-shadow(0 0 2px rgba(255, 215, 0, 0.3));
    }
    100% {
        filter: brightness(1.15) drop-shadow(0 0 6px rgba(255, 215, 0, 0.6));
    }
}

/* Shortcuts Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-primary);
    border: 2px solid var(--maple-brown);
    border-radius: 4px;
    padding: var(--space-lg);
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-content h3 {
    font-size: 18px;
    font-weight: normal;
    margin-bottom: var(--space-md);
    color: var(--text-primary);
}

.shortcuts-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-sm) var(--space-lg);
}

.shortcuts-list dt {
    font-family: 'Courier New', monospace;
    color: var(--maple-brown);
    font-weight: bold;
    font-size: 14px;
}

.shortcuts-list dd {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Content Sections */
.about, .ultrathink {
    margin: var(--space-xl) 0;
    scroll-margin-top: var(--space-md);
    clear: both;
}

h2 {
    font-size: 18px;
    font-weight: normal;
    margin-bottom: 15px;
    color: #333;
}

.about p {
    font-size: 16px;
    line-height: 1.8;
    color: #333;
}

/* Ultrathink */
.thoughts {
    list-style: none;
}

.thoughts li {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    gap: 15px;
}

.thoughts li:last-child {
    border-bottom: none;
}

.date {
    color: var(--text-tertiary);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    min-width: 80px;
}

.thought {
    flex: 1;
    font-size: 15px;
    color: #333;
}

/* Footer */
footer {
    margin-top: 60px;
    padding-top: var(--space-md);
    border-top: 1px solid #ddd;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Smooth scroll */
html {
    scroll-behavior: smooth;
}

/* Focus visible improvements */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--maple-brown);
    outline-offset: 2px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-warm);
        padding: var(--space-md);
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 15px;
        flex-wrap: wrap;
        margin-bottom: var(--space-md);
    }

    .sidebar-footer {
        margin-top: 10px;
    }

    .tagline {
        font-size: 13px;
        line-height: 1.5;
    }

    .main-content {
        margin-left: 0;
        padding: var(--space-md);
    }

    .layout {
        flex-direction: column;
    }

    .inventory-window {
        width: 100%;
        max-width: 100%;
        margin: 0 auto var(--space-lg);
    }

    .inventory-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
        padding: var(--space-xs);
    }

    .inventory-slot {
        width: 100%;
        aspect-ratio: 1;
        min-width: 50px;
    }

    .thoughts li {
        flex-direction: column;
        gap: 5px;
    }

    .modal-content {
        padding: var(--space-md);
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 15px;
    }

    .main-content {
        padding: 15px;
    }

    .inventory-grid {
        gap: 2px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}
