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

button, input[type="button"], input[type="submit"], a {
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* Accessibility: Provide visible focus indicators instead of removing them */
button:focus-visible,
input:focus-visible,
a:focus-visible,
.item-slot:focus-visible,
.rarity-filter-btn:focus-visible,
.shg-btn:focus-visible,
.fv-hv-toggle:focus-visible,
#reset-trade-btn:focus-visible {
    outline: 2px solid var(--focus-shadow);
    outline-offset: 2px;
}

/* Remove tap highlight on mobile but keep focus for keyboard */
button, input[type="button"], input[type="submit"], a {
    -webkit-tap-highlight-color: transparent;
}

/* Remove outline for mouse clicks but keep for keyboard */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* CSS Custom Properties - Purple Theme */
:root {
    --bg-gradient: linear-gradient(135deg, #27004a 0%, #1a0033 100%);
    --bg-container: linear-gradient(160deg, #400078 0%, #2d0054 100%);
    --bg-light: rgba(0, 0, 0, 0.2);
    --bg-lighter: rgba(0, 0, 0, 0.3);
    --bg-hover: rgba(255, 255, 255, 0.1);
    
    --color-primary: #8a2be2;
    --color-secondary: #6400c1;
    --color-accent: #6a1ee0;
    --color-text: #ffffff;
    --color-text-secondary: #ccc;
    
    --border-color: var(--color-secondary);
    --button-bg: var(--color-accent);
    --button-hover: #5400b5;
    --button-active: #431686;
    
    --rarity-active: hsl(267, 100%, 50%);
    --shg-hover: var(--button-active);
    --shg-active: hsl(267, 100%, 50%);
    --item-hover: hsl(276, 100%, 44%);
    --focus-shadow: rgba(138, 43, 226, 0.25);
    --knob-shadow: rgba(106, 30, 224, 0.25);
    
    --modal-bg: linear-gradient(160deg, #400078 0%, #2d0054 100%);
    --modal-overlay: rgba(0, 0, 0, 0.7);
    
    --scrollbar-bg: #2d0054;
    --scrollbar-thumb: var(--color-accent);
}

/* Dark Theme variables */
html.dark-theme {
    --bg-gradient: linear-gradient(135deg, #0a0a0a 0%, #141414 100%);
    --bg-container: linear-gradient(160deg, #1a1a1a 0%, #0d0d0d 100%);
    --bg-light: rgba(255, 255, 255, 0.05);
    --bg-lighter: rgba(0, 0, 0, 0.4);
    --bg-hover: rgba(255, 255, 255, 0.08);
    
    --color-primary: #363636;
    --color-secondary: #3e3e3e;
    --color-accent: #2a2a2a;
    --color-text: #ffffff;
    --color-text-secondary: #c0c0c0;
    
    --border-color: var(--color-secondary);
    --button-bg: var(--color-accent);
    --button-hover: #3a3a3a;
    
    --rarity-active: #3e3e3e;
    --shg-hover: #3a3a3a;
    --shg-active: var(--rarity-active);
    --item-hover: #606060;
    --focus-shadow: rgba(85, 85, 85, 0.25);
    --knob-shadow: rgba(42, 42, 42, 0.25);
    
    --modal-bg: linear-gradient(160deg, #1a1a1a 0%, #0d0d0d 100%);
    --modal-overlay: rgba(0, 0, 0, 0.85);
    
    --scrollbar-bg: #0b0b0b;
    --scrollbar-thumb: var(--color-primary);
}

html {
    overflow-x: hidden;
    background: var(--bg-gradient);
    background-attachment: fixed;
    font-size: clamp(12px, 2vw, 16px);
}
  
/* Background and fonts */
body {
    background: transparent;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(0.3rem, 1vw, 2rem) clamp(0.5rem, 3vw, 2rem);
    overflow-x: hidden;
}

.site-header {
    width: 100%;
    max-width: 87.5rem;
    padding: 0.5rem 2rem;
    margin-bottom: 1rem;
    border-bottom: 0.125rem solid var(--color-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.site-title {
    color: var(--color-text);
    font-size: 1.5rem;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    letter-spacing: 0.3px;
    opacity: 0.95;
}

.nav-links {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    white-space: nowrap;
}

.nav-link {
    color: var(--color-text);
    text-decoration: none;
    font-size: 1.1rem;
    position: relative;
    padding: 0 0.5rem;
}

.nav-link:not(:last-child)::after {
    content: '|';
    position: absolute;
    right: -0.4rem;
    opacity: 0.8;
}

.nav-link:hover {
    font-weight: 500;
    box-shadow: var(--focus-shadow);
}

/* Removed unused .container-wrapper and .second-container styles */

.trade-page-container {
    background: var(--bg-container);
    padding: 1rem 2rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 60rem;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    margin-top: 2rem;
    height: auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.trade-layout {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: clamp(0.5rem, 2vw, 1rem);
    width: 100%;
    margin-top: -1rem;
    position: relative;
    flex-wrap: nowrap;
}

/* WFL Bar Styles */
.wfl-bar-wrapper {
    width: 100%;
    margin-bottom: 2rem;
    padding-top: 0.5rem;
}

.wfl-bar-labels {
    position: relative;
    height: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--color-text);
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    gap: 2rem;
}

.wfl-bar-labels span {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.wfl-bar-labels span::after {
    content: '|';
    margin: 0 1rem;
    opacity: 0.5;
    position: absolute;
    right: -2rem;
}

.wfl-bar-labels span:last-child::after {
    display: none;
}

.wfl-bar-track {
    width: 100%;
    height: 1rem;
    background-color: var(--bg-light);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.wfl-bar-track::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 1px;
    background-color: var(--color-text);
    z-index: 1;
}

.wfl-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    background-color: transparent;
    border: none;
    border-radius: 0.5rem;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.wfl-bar-fill.active {
    background: linear-gradient(90deg, var(--color-accent), var(--color-primary));
    border: none;
}

.offer-container {
    flex: 1 1 0; /* Updated: Allows containers to shrink equally */
    min-width: 0; /* Updated: Prevents flex items from overflowing horizontally */
    display: flex;
    color: var(--color-text);
    flex-direction: column;
    align-items: center;
    position: relative;
    min-height: 25rem;
    width: 100%;
}

.trade-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr); /* Updated: Locks visible area to 3x3 */
    grid-auto-rows: 1fr; /* Updated: Ensures hidden slots maintain size */
    gap: 0.25rem;
    width: 100%; /* Updated: Fits to parent */
    max-width: 22rem;
    aspect-ratio: 1 / 1;
    background-color: var(--bg-light);
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
    margin-top: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
}

.trade-grid::-webkit-scrollbar {
    width: 8px;
}

.trade-grid::-webkit-scrollbar-track {
    background: var(--scrollbar-bg);
    border-radius: 4px;
}

.trade-grid::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 4px;
}

.item-slot {
    background-color: var(--bg-lighter);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--color-text);
    padding: 0.25rem;
    position: relative;
    aspect-ratio: 1 / 1;
}

.item-slot[data-shg="h"]::before,
.item-slot[data-shg="g"]::before {
    content: attr(data-shg);
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    background: var(--color-accent);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    color: var(--color-text);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
    text-transform: uppercase;
    pointer-events: none;
}

.item-slot-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    overflow: hidden;
    padding-bottom: 0.2rem;
    position: relative;
    /* Safari fix: prevent content from expanding parent */
    max-width: 100%;
    max-height: 100%;
}

.item-slot-img {
    width: 92%;
    height: 86%; /* Constrains image height */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    /* Safari fix: strict size constraints */
    flex-shrink: 1;
    min-height: 0;
}

.item-slot-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.item-slot-name {
    font-size: 0.65rem;
    line-height: 1.1;
    text-align: center;
    width: 85%;
    max-width: 85%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Stability Border Indicators */
.item-slot.filled[data-stability="doing-well"] {
    border-color: #02f7b2;
}
.item-slot.filled[data-stability="dropping"] {
    border-color: #ff0000;
}
.item-slot.filled[data-stability="struggling"] {
    border-color: #f2ff00;
}
.item-slot.filled[data-stability="fluctuating"] {
    border-color: #00ff3c;
}
.item-slot.filled[data-stability="receding"] {
    border-color: #ffa200;
}

.single-line {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-slot:hover {
    background-color: var(--bg-hover);
}

.item-slot.filled {
    border: 1px solid var(--color-primary);
    font-weight: 500;
    .item-slot.filled {
        border: 1px solid var(--color-primary);
        font-weight: 500;
        /* Force filled slots to stay within bounds */
        max-width: 100%;
        max-height: 100%;
        overflow: hidden;
    }
}

.qty-control {
    position: absolute;
    bottom: 3%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.28);
    border-radius: 999px;
    padding: 0.25rem;
    z-index: 30;
    width: calc(100% - 8px);
    height: 25%;
}

.qty-btn {
    width: 1.3em;
    height: 1.3em;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--color-text);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: none;
    font-size: 0.8em;
    line-height: 1;
    flex-shrink: 0;
}

.qty-btn:active {
    transform: translateY(1px);
}

.qty-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--color-text);
    text-align: center;
    font-weight: 700;
    font-size: 0.8em;
    appearance: none;
    -moz-appearance: textfield;
    padding: 0.3em;
    flex-shrink: 0;
    max-width: calc(100% - 3em);
}

.qty-input:focus {
    outline: none;
}

.qty-input:focus-visible {
    outline: none;
}

.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.total-value {
    color: var(--color-text);
    font-size: 2.5rem;
    font-weight: 700;
    position: absolute;
    top: -5.5rem;
    min-width: 200px;
}

.offer-container:first-child .total-value {
    left: 0;
    text-align: left;
}

.offer-container:last-child .total-value {
    right: 0;
    text-align: right;
}

#their-total {
    right: 0 !important;
    text-align: right !important;
}

.wfl-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    align-self: center;
    padding: 0 1rem;
}

/* FV/HV slider */
.fv-hv-switch {
    position: absolute;
    right: 1rem;
    bottom: -0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 100;
}

.fv-hv-switch .label {
    color: var(--color-text);
    font-weight: 600;
    font-size: 0.9rem;
}

.fv-hv-toggle {
    --width: 8.5rem;
    --height: 2rem;
    width: var(--width);
    height: var(--height);
    background: rgba(0,0,0,0.18);
    border: 2px solid var(--border-color);
    border-radius: 999px;
    position: relative;
    display: flex;
    align-items: center;
    padding: 0;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.fv-hv-toggle .option {
    flex: 1 1 50%;
    text-align: center;
    color: var(--color-text-secondary);
    font-weight: 700;
    font-size: 0.95rem;
    pointer-events: none;
}

.fv-hv-toggle .knob {
    position: absolute;
    width: calc(var(--width) / 2);
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent), var(--color-primary));
    border-radius: 999px;
    top: 0;
    left: 0;
    transition: left 0.18s cubic-bezier(.2,.9,.2,1);
    box-shadow: 0 4px 12px var(--knob-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    font-weight: 700;
}

.fv-hv-toggle.hv .knob {
    left: 50%;
}

.fv-hv-toggle.hv {
    border-color: var(--color-primary);
}

.fv-hv-toggle.hv .option {
    color: var(--color-text);
}

#wfl-result {
    font-size: 2rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    min-width: 8rem;
    text-align: center;
    height: auto;
    display: inline-block;
    line-height: 1.1;
    margin-bottom: 1rem;
}

.wfl-result-win {
    color: #00eb37;
}

.wfl-result-fair {
    display: none;
    color: #ffffff;
}

.wfl-result-fair[data-difference="0"] {
    display: block;
    color: #ffffff;
}

.wfl-result-lose {
    color: #e00016;
}

.wfl-mode {
    display: block;
    font-size: 1em;
    font-weight: 700;
    opacity: 0.95;
    margin-top: 0.1rem;
}

#reset-trade-btn {
    background: var(--button-bg);
    color: var(--color-text);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
    width: 6rem;
}

#reset-trade-btn:hover {
    background: var(--button-hover);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-container);
    padding: 2rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 60rem;
    height: 80vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    color: var(--color-text);
    cursor: pointer;
}

.modal-content h3 {
    color: var(--color-text);
    text-align: center;
    margin-bottom: 1rem;
}

.modal-body {
    display: flex;
    gap: 1.5rem;
    flex-grow: 1;
    overflow: hidden;
    margin-top: 1rem;
}

.rarity-sidebar {
    flex: 0 0 10rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rarity-filter-btn {
    background-color: var(--bg-light);
    color: var(--color-text);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.rarity-filter-btn:hover {
    background-color: var(--rarity-active);
    border-color: var(--color-primary);
}

.rarity-filter-btn.active {
    background-color: var(--rarity-active);
    border-color: var(--color-primary);
}

.shg-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.75rem;
}

.shg-btn {
    background-color: var(--bg-light);
    color: var(--color-text);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 3rem;
}


.shg-btn:hover {
    background-color: var(--shg-hover);
    border-color: var(--color-primary);
}

.shg-btn.active {
    background-color: var(--shg-active);
    border-color: var(--color-primary);
}

.item-display-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#item-search {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
    background-color: var(--bg-lighter);
    color: var(--color-text);
    font-size: 1rem;
    margin-bottom: 1rem;
    outline: none;
}

#item-search:focus-visible {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--focus-shadow);
    outline: none;
}

.item-list {
    flex-grow: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
    gap: 0.3rem 0.5rem;
    padding: 0.25rem;
    align-content: start;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
}

.item-list::-webkit-scrollbar {
    width: 12px;
}

.item-list::-webkit-scrollbar-track {
    background: var(--scrollbar-bg);
    border-radius: 10px;
}

.item-list::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 3px solid var(--scrollbar-bg);
}

.item-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-primary);
}

.modal-item {
    background-color: var(--bg-light);
    color: var(--color-text);
    border-radius: 0.5rem;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    padding: 0.5rem;
    gap: 0.5rem;
}

.modal-item:hover {
    background: var(--item-hover);
}

.modal-item-img {
    width: 70%;
    height: 70%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-item-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.modal-item-name {
    font-size: 0.8rem;
    word-break: break-word;
    line-height: 1.2;
}

/* Guide Page Styling */
.guide-content {
    width: 100%;
    max-width: 900px;
    padding: 3rem 2.5rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.guide-section {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(138, 43, 226, 0.2);
}

.guide-section:last-child {
    border-bottom: none;
}

.guide-section h2 {
    color: #e0b0ff;
    font-size: 2.2rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.guide-section p {
    color: #e8e8e8;
    font-size: clamp(1rem, 2.5vw, 1.15rem);
    line-height: 1.8;
    margin-bottom: 1.5rem;
    font-weight: 400;
    letter-spacing: 0.2px;
}

.guide-content a {
    color: #e0b0ff;
    text-decoration: none;
}

.guide-content a:hover,
.guide-content a:focus {
    color: #b366ff;
    text-decoration: underline;
}

.guide-list {
    list-style: none;
    margin-left: 0;
    margin-bottom: 2rem;
}

.guide-list li {
    background: rgba(138, 43, 226, 0.08);
    border-left: 4px solid var(--color-primary);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    border-radius: 0.5rem;
    color: #e0e0e0;
    line-height: 1.8;
    font-size: clamp(0.95rem, 2.5vw, 1.05rem);
    transition: all 0.3s ease;
}

.guide-list li:hover {
    background: rgba(138, 43, 226, 0.15);
    border-left-color: #b366ff;
    transform: translateX(8px);
}

.guide-list li strong {
    color: #d0a0ff;
    font-weight: 600;
    display: inline-block;
    margin-bottom: 0.25rem;
}

.guide-closing {
    font-style: italic;
    color: #c8a8d8;
    background: rgba(138, 43, 226, 0.1);
    padding: 1.5rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--color-primary);
    font-size: 1.05rem;
    margin-top: 2rem;
}

/* Dark mode styles for guide */
html.dark-theme .guide-section h2 {
    color: #b0b0b0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

html.dark-theme .guide-section p {
    color: #cccccc;
}

html.dark-theme .guide-content a {
    color: #a0a0a0;
}

html.dark-theme .guide-content a:hover,
html.dark-theme .guide-content a:focus {
    color: #808080;
}

html.dark-theme .guide-list li {
    background: rgba(255, 255, 255, 0.05);
    color: #cccccc;
}

html.dark-theme .guide-list li:hover {
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--color-secondary);
    transform: translateX(8px);
}

html.dark-theme .guide-list li strong {
    color: #fcfcfc;
}

html.dark-theme .guide-closing {
    color: #aaaaaa;
    background: rgba(255, 255, 255, 0.05);
}

html.dark-theme .guide-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* ========== RESPONSIVE SCALING ========== */
/* All elements scale proportionally based on viewport width */
/* Tablet and below */
@media screen and (max-width: 68rem) {
    .site-header {
        border-bottom: 1px solid var(--color-primary);
    }

    .trade-grid {
        border: 1px solid var(--color-secondary);
    }

    .fv-hv-toggle {
        border: 1px solid var(--color-secondary);
    }
}

/* Mobile - Small tablets */
@media screen and (max-width: 59rem) {
    html {
        font-size: clamp(10px, 2.2vw, 14px);
    }
    
    body {
        padding: 0.5rem 0.5rem;
    }
    
    .site-header {
        border-bottom: 0.75px solid var(--color-primary);
    }

    .site-title {
        font-size: 1.2rem;
    }

    .nav-links {
        gap: 0.5rem;
    }

    .nav-link {
        font-size: 1rem;
        padding: 0 0.3rem;
    }

    .trade-page-container {
        padding: 0.75rem 0.75rem 3.5rem 0.75rem; 
        margin-top: 0.75rem;
        min-height: auto;
        border-radius: 0.75rem;
        position: relative;
    }

    .trade-layout {
        gap: 0.5rem;
        margin-top: 0;
        /* Keep side-by-side layout */
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .wfl-bar-wrapper {
        margin-bottom: 1rem;
        padding-top: 0.25rem;
    }

    .wfl-bar-labels {
        font-size: 1rem;
        gap: 1rem;
        margin-bottom: 0.4rem;
        height: 1.5rem;
    }

    .wfl-bar-labels span::after {
        margin: 0 0.5rem;
        right: -1rem;
    }

    .wfl-bar-track {
        height: 0.75rem;
    }

    .offer-container {
        min-height: auto;
        width: 100%;
        flex: 1;
    }

    .trade-grid {
        max-width: 100%;
        gap: 0.15rem;
        margin-top: 0.5rem;
        border: 1px solid var(--color-secondary);
    }

    .item-slot {
        min-width: auto;
        padding: 0.15rem;
    }

    .item-slot[data-shg="h"]::before,
    .item-slot[data-shg="g"]::before {
        width: 14px;
        height: 14px;
        font-size: 9px;
        top: 2px;
        right: 2px;
    }

    .item-slot-name {
        font-size: 0.7rem;
    }

    #reset-trade-btn {
        font-size: 1rem;
    }

    .item-list {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.2rem 0.3rem;
    }

    .total-value {
        font-size: 1.5rem;
        top: -3.5rem;
        min-width: auto;
    }

    .wfl-container {
        gap: 0.5rem;
        padding: 0 0.5rem;
    }

    #wfl-result {
        font-size: 1.4rem;
        padding: 0.35rem 0.7rem;
        min-width: auto;
        margin-bottom: 0.5rem;
        line-height: 1.2;
    }

    .wfl-mode {
        margin-top: 0.05rem;
    }

    #reset-trade-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
        width: auto;
        min-width: 4rem;
    }

    .fv-hv-switch {
        position: absolute;
        right: 0.5rem;
        bottom: -2.5rem; /* Lower position - well below the grid */
        gap: 0.3rem;
    }

    .fv-hv-switch .label {
        font-size: 1rem;
    }

    .fv-hv-toggle {
        --width: 8rem;
        --height: 1.8rem;
        border: 1px solid var(--color-secondary);
        padding: 0.15rem;
    }

    .fv-hv-toggle .option {
        font-size: 0.85rem;
    }

    .fv-hv-toggle .knob {
        font-size: 0.8rem;
    }

    .modal-content {
        width: 95vw;
        height: 85vh;
        padding: 0.75rem;
    }

    .modal-body {
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 0.5rem;
    }

    .rarity-sidebar {
        flex: 0 0 auto;
        flex-direction: row;
    
        gap: 0.4rem;
    }

    .rarity-filter-btn {
        flex: 1 1 calc(33.333% - 0.7rem);
        min-width: 5rem;
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .shg-buttons {
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    .shg-btn {
        width: auto;
        height: auto;
        min-width: 2.75rem;
        font-size: 0.85rem;
        padding: 0.5rem;
    }

    .item-list {
        grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
        gap: 0.5rem;
    }

    .modal-item {
        padding: 0.3rem;
        gap: 0.3rem;
    }

    .modal-item-name {
        font-size: 0.65rem;
    }

    #item-search {
        font-size: 0.85rem;
        padding: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .close-modal {
        font-size: 1.5rem;
        top: 0.5rem;
        right: 0.75rem;
    }

    .modal-content h3 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .guide-content {
        padding: 1.5rem 1rem;
        max-width: 100%;
    }
    
    .guide-section {
        margin-bottom: 2rem;
        padding-bottom: 1.5rem;
    }
    
    .guide-section h2 {
        font-size: 2rem;
        margin-bottom: 1rem;
    }

    .guide-section p {
        font-size: 1.15rem;
    }
    
    .guide-list li {
        padding: 0.85rem 1rem;
        margin-bottom: 0.85rem;
        font-size: 1.25rem;
    }

    .guide-closing {
        padding: 1rem;
        font-size: 1.15rem;
    }
}

/* Very small mobile devices */
@media screen and (max-width: 26rem) {
    html {
        font-size: clamp(9px, 2.5vw, 11px);
    }

    .site-header {
        padding: 0.4rem 0.5rem;
        gap: 0.5rem;
    }

    .site-title {
        font-size: 1.2rem;
    }

    .nav-link {
        font-size: 1.1rem;
        padding: 0 0.25rem;
    }

    .trade-page-container {
        padding: 0.5rem 0.5rem 3.25rem 0.5rem; /* Increased bottom padding for FV/HV toggle */
        position: relative;
    }

    .wfl-bar-labels {
        font-size: 0.9rem;
        gap: 0.75rem;
    }

    .wfl-bar-labels span::after {
        margin: 0 0.35rem;
        right: -0.75rem;
    }

    .wfl-bar-track {
        height: 0.6rem;
    }

    .trade-grid {
        gap: 0.1rem;
    }

    .item-slot {
        padding: 0.1rem;
    }

    .item-slot[data-shg="h"]::before,
    .item-slot[data-shg="g"]::before {
        width: 12px;
        height: 12px;
        font-size: 8px;
        top: 1px;
        right: 1px;
    }

    .item-slot-name {
        font-size: 0.5rem;
    }

    .qty-btn {
        font-size: 0.55em;
    }

    .qty-input {
        font-size: 0.55em;
    }

    .total-value {
        font-size: 1.2rem;
        top: -3rem;
    }

    .wfl-container {
        gap: 0.4rem;
        padding: 0 0.3rem;
    }

    #wfl-result {
        font-size: 1.15rem;
        padding: 0.3rem 0.55rem;
    }

    #reset-trade-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.65rem;
        min-width: 3.5rem;
    }

    .fv-hv-switch {
        position: absolute;
        right: 0.3rem;
        bottom: -2rem; /* Lower position - well below the grid */
    }

    .fv-hv-switch .label {
        font-size: 0.65rem;
    }

    .fv-hv-toggle {
        --width: 6rem;
        --height: 1.5rem;
    }

    .fv-hv-toggle .option {
        font-size: 0.65rem;
    }

    .modal-content {
        width: 98vw;
        height: 90vh;
        padding: 0.5rem;
    }

    .rarity-filter-btn {
        flex: 1 1 calc(50% - 0.4rem);
        padding: 0.45rem;
        font-size: 0.8rem;
    }

    .shg-btn {
        width: auto;
        height: auto;
        min-width: 2.5rem;
        font-size: 0.8rem;
        padding: 0.45rem;
    }

    .item-list {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.1rem 0.15rem;
    }

    .modal-item {
        padding: 0.3rem;
        gap: 0.3rem;
    }

    .modal-item-name {
        font-size: 0.6rem;
    }

    #item-search {
        font-size: 0.75rem;
        padding: 0.4rem;
    }

    .close-modal {
        font-size: 1.3rem;
    }

    .modal-content h3 {
        font-size: 0.9rem;
    }
}

/* Landscape mobile adjustments */
@media screen and (max-height: 37rem) and (orientation: landscape) {
    html {
        font-size: clamp(13px, 3vh, 16px);
    }

    body {
        padding: 0.3rem 0.5rem;
    }

    .site-header {
        padding: 0.4rem 1rem;
        margin-bottom: 0.3rem;
        border-bottom: 1px solid var(--color-primary);
        gap: 1rem;
    }

    .site-title {
        font-size: 1.4rem;
        font-weight: 600;
    }

    .nav-links {
        gap: 0.8rem;
    }

    .nav-link {
        font-size: 1.1rem;
    }

    .trade-page-container {
        padding: 0.7rem 0.8rem 3.5rem 0.8rem;
        margin-top: 0.3rem;
        height: auto;
    }

    .wfl-bar-wrapper {
        margin-bottom: 0.8rem;
        padding-top: 0.3rem;
    }

    .wfl-bar-labels {
        font-size: 1.1rem;
        gap: 1.2rem;
        margin-bottom: 0.4rem;
        height: 1.8rem;
    }

    .wfl-bar-labels span::after {
        margin: 0 0.6rem;
        right: -1.2rem;
    }

    .wfl-bar-track {
        height: 0.8rem;
    }

    .trade-layout {
        gap: 0.4rem;
        margin-top: 0;
        justify-content: center;
    }

    .offer-container {
        min-height: auto;
        flex: 0 1 100%;
    }

    .offer-container h2 {
        font-size: 1.2rem;
        margin-bottom: 0.4rem;
    }

    .trade-grid {
        border: 1px solid var(--color-secondary);
        gap: 0.25rem;
        margin-top: 0.4rem;
        max-width: 100%;
        width: 100%;
        aspect-ratio: 1 / 1;
    }

    .item-slot {
        padding: 0.15rem;
    }

    .item-slot[data-shg="h"]::before,
    .item-slot[data-shg="g"]::before {
        width: 20px;
        height: 20px;
        font-size: 14px;
        top: 1px;
        right: 1px;
    }

    .item-slot-name {
        font-size: 0.7rem;
    }

    .total-value {
        font-size: 1.5rem;
        top: -3.7rem;
        font-weight: 600;
    }

    .wfl-container {
        gap: 0.8rem;
        padding: 0 0.8rem;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    #wfl-result {
        font-size: 2rem;
        padding: 0.4rem 0.8rem;
        min-width: auto;
    }

    #reset-trade-btn {
        padding: 0.4rem 0.8rem;
        font-size: 1rem;
        min-width: auto;
    }

    .fv-hv-switch {
        position: absolute;
        right: 1.2rem;
        bottom: -2.5rem;
        gap: 0.5rem;
    }

    .fv-hv-switch .label {
        font-size: 0.95rem;
        font-weight: 600;
    }

    .fv-hv-toggle {
        --width: 8rem;
        --height: 1.8rem;
        border: 1px solid var(--color-secondary);
    }

    .fv-hv-toggle .option {
        font-size: 0.9rem;
    }

    .fv-hv-toggle .knob {
        font-size: 0.85rem;
    }

    .modal-content {
        width: 95vw;
        height: 80vh;
    }

    .rarity-sidebar {
        flex: 0 0 auto;
        gap: 0.4rem;
    }

    .rarity-filter-btn {
        padding: 0.5rem 0.4rem;
        font-size: 0.8rem;
        min-width: 4.5rem;
    }

    .shg-buttons {
        gap: 0.5rem;
        margin-top: 0.4rem;
    }
    .shg-btn {
        width: auto;
        height: auto;
        min-width: 2.5rem;
        font-size: 0.8rem;
        padding: 0.5rem 0.4rem;
    }

    #item-search {
        font-size: 0.85rem;
        padding: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .item-list {
        grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
        gap: 0.4rem;
    }

    .modal-item-name {
        font-size: 0.65rem;
    }
}

/* Wide screens with sufficient height */
@media screen and (min-width: 59.1rem) and (min-height: 37.1rem) {
    .trade-page-container {
        height: auto;
        min-height: auto;
        padding-bottom: 4rem;
    }

    .fv-hv-switch {
        position: absolute;
        right: 1rem;
        bottom: -3rem;
    }
}

/* Theme Toggle Button */
.theme-toggle {
    background: none;
    border: none;
    color: var(--color-text);
    text-decoration: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.5rem;
    transition: font-weight 0.2s ease;
    font-weight: normal;
}

.theme-toggle:hover {
    font-weight: 500;
    box-shadow: var(--focus-shadow);
}