﻿@media (max-width: 900px) {
    .toolpage-shell {
        overflow: clip;
    }

    .toolpage-layout {
        position: relative;
    }

    .toolpage-preview-area {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 14px 12px 26px;
    }

    .toolpage-preview-area > * {
        margin: 0;
    }

    .mobile-tool-rail {
        position: sticky;
        top: 10px;
        z-index: 14;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        padding: 8px;
        border: 1px solid rgba(96, 165, 250, 0.18);
        border-radius: 10px;
        background: rgba(11, 18, 33, 0.82);
        backdrop-filter: blur(16px);
        box-shadow: 0 16px 34px rgba(0, 0, 0, 0.24);
    }

    .mobile-rail-button {
        min-height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 0 10px;
        border: 1px solid rgba(96, 165, 250, 0.18);
        border-radius: 8px;
        background: rgba(19, 30, 49, 0.9);
        color: #eef5ff;
        font-size: 0.79rem;
        font-weight: 850;
        text-decoration: none;
        white-space: nowrap;
    }

    .mobile-rail-button i {
        color: #89bfff;
        font-size: 0.84rem;
    }

    .mobile-rail-button.is-link {
        background: linear-gradient(135deg, rgba(31, 120, 255, 0.24), rgba(56, 213, 255, 0.12));
    }

    .mobile-rail-button:active,
    .mobile-rail-button:hover {
        border-color: rgba(96, 165, 250, 0.38);
        color: #ffffff;
    }

    .tool-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 30;
        width: min(84vw, 312px);
        min-height: 100dvh;
        padding: 86px 12px 18px;
        overflow-y: auto;
        border-right: 1px solid var(--tool-line);
        border-bottom: 0;
        background: linear-gradient(180deg, rgba(10, 17, 32, 0.98), rgba(7, 13, 25, 0.98));
        box-shadow: 24px 0 50px rgba(0, 0, 0, 0.38);
        transform: translateX(-104%);
        opacity: 0;
        visibility: hidden;
        transition: transform .22s ease, opacity .22s ease, visibility .22s ease;
    }

    body.mainroute-sidebar-open {
        overflow: hidden;
    }

    body.mainroute-sidebar-open .tool-sidebar {
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
    }

    body.mainroute-sidebar-open::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 24;
        background: rgba(3, 8, 18, 0.62);
        backdrop-filter: blur(3px);
    }

    .bookmark-card {
        display: none;
    }

    .breadcrumb-list {
        margin-top: 2px;
        font-size: 0.72rem;
    }

    .tool-main-header {
        gap: 10px;
        margin-bottom: 4px;
    }

    .tool-title-group {
        gap: 12px;
    }

    .tool-image-box {
        width: 52px;
        height: 52px;
        flex-basis: 52px;
    }

    .tool-image-box i {
        font-size: 1.42rem;
    }

    .tool-main-hero h1 {
        font-size: 1.28rem;
        line-height: 1.08;
    }

    .tool-main-hero p {
        margin-top: 5px;
        font-size: 0.84rem;
        line-height: 1.42;
    }

    .tool-header-actions {
        gap: 8px;
    }

    .tool-header-actions .header-ad,
    .tool-header-actions .share-button {
        display: none;
    }

    .ad-placeholder.header-ad {
        min-height: 64px;
    }

    .before-work {
        order: 2;
    }

    #tool-console {
        order: 3;
    }

    .benefit-row {
        order: 4;
        gap: 10px 14px;
        margin-top: 2px;
    }

    .after-work {
        order: 5;
    }

    .stat-strip {
        order: 6;
    }

    .tool-info-tabs {
        order: 7;
    }

    .below-tabs-ad {
        order: 8;
    }

    .tool-preview-empty,
    .tool-preview-stage {
        min-height: 260px;
    }

    .tool-preview-stage {
        padding: 10px;
    }

    .tool-settings-panel,
    .tool-form-panel,
    .tool-preview-panel {
        padding: 16px;
    }

    .tool-settings-panel h2,
    .tool-form-panel h2,
    .tool-panel-heading {
        margin-bottom: 10px;
        font-size: 0.96rem;
    }

    .field-label {
        margin: 10px 0 6px;
        font-size: 0.8rem;
    }

    .tool-input,
    .file-picker {
        min-height: 42px;
    }

    .primary-action,
    .secondary-action,
    .tool-download-link,
    .accent-action {
        min-height: 39px;
        margin-top: 12px;
        font-size: 0.84rem;
    }

    .stat-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-item {
        min-height: 64px;
        padding: 12px;
    }

    .stat-item:nth-child(2n) {
        border-right: 0;
    }

    .stat-item:nth-last-child(-n + 2) {
        border-bottom: 0;
    }

    .stat-icon,
    .step-icon {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
    }

    .stat-title,
    .step-title {
        font-size: 0.82rem;
    }

    .stat-text,
    .step-text {
        font-size: 0.7rem;
    }

    .tab-controls {
        gap: 0;
        padding: 0 10px;
        scroll-snap-type: x proximity;
    }

    .tab-controls label {
        min-height: 40px;
        padding: 0 12px;
        font-size: 0.79rem;
        white-space: nowrap;
        scroll-snap-align: start;
    }

    .tab-panel {
        padding: 16px 14px 18px;
    }

    .tab-panel h2 {
        font-size: 0.95rem;
    }

    .tab-panel p,
    .tab-panel li,
    .tab-panel summary {
        font-size: 0.84rem;
        line-height: 1.62;
    }

    .tool-rightbar {
        padding: 0 12px 22px;
    }

    .related-tools-card {
        padding: 14px;
    }

    .related-tools-card h2 {
        font-size: 0.92rem;
        margin-bottom: 10px;
    }

    .related-tool-link {
        grid-template-columns: 34px minmax(0, 1fr) 14px;
        gap: 9px;
        padding: 8px 2px;
    }

    .related-tool-icon {
        width: 32px;
        height: 32px;
        font-size: 0.88rem;
    }

    .related-tool-title {
        font-size: 0.82rem;
    }

    .related-tool-description {
        font-size: 0.7rem;
    }

    .ad-placeholder.sidebar-ad {
        display: none;
    }

    .formatter-editor-grid,
    .editor-body,
    .monaco-editor-host {
        min-height: 360px;
        height: 360px;
    }

    .formatter-action-bar {
        gap: 10px;
        padding: 12px;
    }

    .formatter-status {
        min-width: 0;
        font-size: 0.8rem;
    }

    .formatter-buttons {
        gap: 8px;
    }

    .editor-action {
        min-height: 36px;
        padding: 0 12px;
        font-size: 0.8rem;
    }
}

.tool-preview-jump-toggle {
    display: none;
}

/* Mobile preview navigator: paired with the fixed related-tools toggle. */
@media (max-width: 900px) {
    .tool-preview-jump-toggle {
        top: calc(clamp(250px, 34dvh, 320px) + 64px);
        display: grid;
    }

    .tool-preview-jump-toggle[hidden] {
        display: none !important;
    }
}

@media (max-width: 560px) {
    .toolpage-preview-area {
        padding: 12px 10px 24px;
        gap: 10px;
    }

    .mobile-tool-rail {
        top: 8px;
        padding: 7px;
        gap: 7px;
    }

    .mobile-rail-button {
        min-height: 36px;
        gap: 6px;
        padding: 0 8px;
        font-size: 0.74rem;
    }

    .tool-main-header {
        gap: 8px;
    }

    .tool-main-hero h1 {
        font-size: 1.18rem;
    }

    .tool-main-hero p {
        font-size: 0.8rem;
    }

    .benefit-row li {
        font-size: 0.75rem;
    }

    .stat-strip {
        grid-template-columns: 1fr;
    }

    .stat-item,
    .stat-item:nth-child(2n),
    .stat-item:nth-last-child(-n + 2) {
        border-right: 0;
        border-bottom: 1px solid var(--tool-line);
    }

    .stat-item:last-child {
        border-bottom: 0;
    }

    .tool-preview-empty,
    .tool-preview-stage {
        min-height: 224px;
    }

    .tool-rightbar {
        padding-inline: 10px;
    }
}

/* ===== MAINROUTE MOBILE OVERLAP FIX ===== */
@media (max-width: 900px){
    .mobile-tool-rail{
        position:relative;
        top:auto;
        z-index:5;
    }

    .benefit-row{
        display:flex;
        flex-wrap:wrap;
        overflow:visible;
    }

    .benefit-row li{
        flex:0 0 auto;
    }

    .tool-main-header{
        padding:12px;
        border-radius:12px;
    }

    .tool-title-group{
        align-items:center;
    }

    .tool-work-area{
        overflow:hidden;
    }

    .formatter-editor-grid,
    .editor-body,
    .monaco-editor-host{
        min-height:300px;
        height:300px;
    }
}

@media (max-width: 560px){
    .mobile-rail-button{
        min-height:40px;
        font-size:.82rem;
    }

    .tool-main-hero h1{ font-size:1.24rem; }
    .tool-main-hero p{ font-size:.88rem; }
}

/* ===== MAINROUTE MOBILE FIT FINAL ===== */
@media(max-width:900px){
    .mobile-tool-rail{ margin-top:8px; }
    .toolpage-preview-area{ padding-top:18px; }
    .tool-main-header,
    .tool-title-group,
    .tool-main-hero,
    .tool-work-area,
    .tool-form-panel,
    .tool-settings-panel,
    .tool-preview-panel{
        min-width:0;
        max-width:100%;
    }

    .tool-main-hero p{
        overflow-wrap:anywhere;
    }

    .range-control{
        grid-template-columns:minmax(0, 1fr) 58px;
    }

    .primary-action.full-width-action,
    .tool-download-link.full-width-action{
        width:100%;
        max-width:100%;
    }
}

/* ===== MOBILE TOOL WIDTH GUARD ===== */
@media(max-width:900px){
    .toolpage-shell,.toolpage-preview-area,.tool-main-header,.tool-work-area,.tool-form-panel,.tool-preview-panel,.stat-strip,.tool-info-tabs{max-width:100%;min-width:0;}
    .benefit-row{flex-wrap:wrap;overflow:visible;}
}

@media (max-width: 900px) {
    .tool-feedback-card {
        order: 12;
        margin-top: 8px;
        padding: 16px;
    }

    .below-tabs-ad {
        order: 13;
    }

    .tool-feedback-copy h2 {
        font-size: 1rem;
    }

    .tool-feedback-form textarea {
        min-height: 150px;
    }
}

/* ===== RATING PANEL MOBILE ORDER FIX ===== */
@media (max-width: 900px) {
    .tool-rating-panel {
        order: 11 !important;
        margin: 18px 0 0 !important;
    }

    .tool-feedback-card {
        order: 12 !important;
        margin-top: 8px;
    }

    .below-tabs-ad {
        order: 13 !important;
    }
}

/* ===== TOOL PAGE MOBILE FINAL POLISH ===== */
@media(max-width:900px){
    .mobile-tool-rail{
        margin-top:5px !important;
    }

    .tool-main-hero h1{
        line-height:1.22 !important;
        padding-bottom:2px;
    }

    .stat-strip{
        grid-template-columns:repeat(2, minmax(0, 1fr)) !important;
    }

    .stat-item,
    .stat-item:nth-child(2n),
    .stat-item:nth-last-child(-n + 2){
        min-height:86px;
        flex-direction:column;
        justify-content:center;
        align-items:center;
        gap:8px;
        padding:12px 8px;
        border-right:1px solid var(--tool-line) !important;
        border-bottom:1px solid var(--tool-line) !important;
        text-align:center;
    }

    .stat-item:nth-child(2n){
        border-right:0 !important;
    }

    .stat-item:nth-last-child(-n + 2){
        border-bottom:0 !important;
    }

    .stat-item:last-child:nth-child(odd){
        grid-column:1 / -1;
        width:min(50%, 180px);
        justify-self:center;
        border-right:0 !important;
    }
}
