body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #05050a;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #e6e6e6;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Global Controls */
#global-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.generate-action {
    position: relative;
    display: flex;
}

#global-controls button,
#global-controls .analysis-link {
    background: linear-gradient(135deg, #4361ee, #4cc9f0);
    padding: 12px 28px;
    font-size: 0.95rem;
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(67, 97, 238, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 22px;
}

#global-controls .secondary-btn {
    background: rgba(22, 22, 40, 0.9);
    color: #4cc9f0;
    border: 2px solid #4cc9f0;
    width: auto;
}

#global-controls .analysis-link {
    background: rgba(22, 22, 40, 0.92);
    color: #8fe8ff;
    border-color: rgba(76, 201, 240, 0.65);
}

#global-controls .analysis-link:hover {
    background: rgba(76, 201, 240, 0.16);
}

.generate-hint {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    transform: translateX(-50%);
    width: max-content;
    max-width: min(320px, calc(100vw - 32px));
    padding: 9px 13px;
    border-radius: 12px;
    background: rgba(9, 12, 24, 0.92);
    border: 1px solid rgba(76, 201, 240, 0.48);
    color: #eaf9ff;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.32);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
}

.generate-hint::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top-color: rgba(9, 12, 24, 0.92);
}

.generate-action.needs-generation .generate-hint {
    opacity: 1;
    visibility: visible;
    animation: hint-bob 1.4s ease-in-out infinite;
}

.generate-action.needs-generation #btn-generate-all {
    position: relative;
    overflow: hidden;
    animation: generate-pulse 1.4s ease-in-out infinite;
}

.generate-action.needs-generation #btn-generate-all::after {
    content: "";
    position: absolute;
    inset: -40% auto -40% -65%;
    width: 46%;
    transform: rotate(20deg);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.52), transparent);
    animation: generate-shine 1.8s ease-in-out infinite;
}

@keyframes hint-bob {
    0%, 100% {
        transform: translate(-50%, 0);
    }
    50% {
        transform: translate(-50%, -5px);
    }
}

@keyframes generate-pulse {
    0%, 100% {
        box-shadow: 0 10px 25px rgba(67, 97, 238, 0.4), 0 0 0 0 rgba(76, 201, 240, 0.36);
    }
    50% {
        box-shadow: 0 12px 28px rgba(67, 97, 238, 0.52), 0 0 0 9px rgba(76, 201, 240, 0);
    }
}

@keyframes generate-shine {
    0% {
        left: -65%;
    }
    55%, 100% {
        left: 125%;
    }
}

.mode-toggle {
    min-width: 72px;
}

#view-controls {
    position: fixed;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    background: rgba(22, 22, 40, 0.74);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    backdrop-filter: blur(12px);
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.24);
}

.view-btn {
    min-width: 72px;
    justify-content: center;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #f2f6ff;
    border-radius: 7px;
    font-size: 0.78rem;
}

.view-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

/* Comparison Bar */
#comparison-container {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 800px;
    z-index: 40;
    text-align: center;
}

.comparison-bar {
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    display: flex;
    overflow: hidden;
    margin-bottom: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.bar-segment {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: bold;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    color: #fff;
    white-space: nowrap;
}

.bar-segment.left { background: #5c7aff; }
.bar-segment.right { background: #ff6b9d; }

.comparison-label {
    font-size: 0.75rem;
    opacity: 0.5;
    letter-spacing: 1px;
}

/* Simulation Wrapper */
#simulation-wrapper {
    display: flex;
    flex: 1;
    width: 100vw;
    height: 100%;
}

.city-container {
    flex: 1;
    position: relative;
    border-right: 2px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

#city-right {
    border-right: none;
}

/* City UI */
.city-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px; /* Stretch to avoid overlap with center */
    z-index: 10;
    background: rgba(22, 22, 40, 0.85);
    backdrop-filter: blur(12px);
    padding: 12px 18px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.city-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    flex-shrink: 0;
    white-space: nowrap;
}

.city-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #4cc9f0;
    background: rgba(76, 201, 240, 0.1);
    padding: 4px 10px;
    border-radius: 6px;
}

.stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px 12px;
    min-width: 0;
}

.stat-box {
    display: flex;
    align-items: baseline;
    gap: 5px;
    white-space: nowrap;
}

.label {
    font-size: 0.66rem;
    opacity: 0.6;
}

.value {
    font-size: 0.98rem;
    font-weight: bold;
    color: #fff;
}

.simulation-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Common UI Elements */
button {
    background: #4361ee;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

button:hover {
    background: #3a56d4;
}

button:active {
    transform: scale(0.98);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 5px 9px;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-toggle-types {
    min-width: 72px;
    justify-content: center;
}

.btn-toggle-types.is-active {
    background: rgba(76, 201, 240, 0.24);
    border-color: rgba(76, 201, 240, 0.72);
    color: #e9fbff;
}

.btn-random-ratio {
    color: #d8fbff;
    border-color: rgba(76, 201, 240, 0.28);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
}

.modal-content {
    background: rgba(22, 22, 40, 0.98);
    margin: 3% auto;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    width: 95%;
    max-width: 550px; /* Increased width */
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 20px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    animation: modalFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #4cc9f0;
}

.close-btn {
    color: #aaa;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover { color: #fff; }

.modal-body {
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-group > label {
    font-size: 0.9rem;
    color: #4cc9f0;
    font-weight: 600;
}

.ratio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    background: rgba(0, 0, 0, 0.25);
    padding: 15px;
    border-radius: 12px;
}

.ratio-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ratio-item label {
    font-size: 0.75rem;
    font-weight: 500;
}

.ratio-item input[type="range"] {
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

.checkbox-group, .range-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.checkbox-group label { font-size: 0.8rem; cursor: pointer; }

.range-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    width: 100%;
}

.range-group label { font-size: 0.75rem; opacity: 0.6; }

input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.range-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.range-header label {
    font-size: 0.75rem;
    opacity: 0.6;
}

.range-header input[type="number"] {
    width: 86px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.range-value {
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.waste-scale-guide {
    width: 100%;
    display: flex;
    justify-content: space-between;
    color: rgba(255, 255, 255, 0.46);
    font-size: 0.68rem;
}

.waste-scale-status {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
}

.waste-scale-status strong {
    font-size: 0.86rem;
}

.waste-scale-status span {
    color: rgba(255, 255, 255, 0.66);
    font-size: 0.74rem;
    line-height: 1.35;
}

.waste-scale-status.saving {
    background: rgba(80, 200, 140, 0.12);
    border-color: rgba(80, 200, 140, 0.34);
}

.waste-scale-status.saving strong {
    color: #85e6b1;
}

.waste-scale-status.normal {
    background: rgba(76, 201, 240, 0.12);
    border-color: rgba(76, 201, 240, 0.34);
}

.waste-scale-status.normal strong {
    color: #8ee8ff;
}

.waste-scale-status.wasteful {
    background: rgba(255, 118, 118, 0.12);
    border-color: rgba(255, 118, 118, 0.36);
}

.waste-scale-status.wasteful strong {
    color: #ffaaa8;
}

.city-data-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.city-data-field {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.city-data-field label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.62);
}

.city-data-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
}

.fit-result {
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.74rem;
    line-height: 1.4;
}

.estimate-panel {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    background: rgba(76, 201, 240, 0.08);
    border: 1px solid rgba(76, 201, 240, 0.18);
    border-radius: 8px;
}

.estimate-item {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.estimate-label {
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.62);
}

.estimate-item strong {
    font-size: 0.88rem;
    color: #fff;
    white-space: nowrap;
}

.styled-select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.styled-select option {
    background: #161628;
    color: #fff;
}

.preset-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.preset-header label {
    margin-bottom: 0 !important;
}

.preset-select {
    width: auto;
    padding: 4px 8px;
    font-size: 0.75rem;
}

.secondary-btn {
    background: #4cc9f0;
    color: #05050a;
    width: 100%;
    justify-content: center;
}

#btn-reset-city {
    background: #f72585;
    width: 100%;
    justify-content: center;
}

body.light-mode {
    background-color: #f7f8fb;
    color: #24272d;
}

body.light-mode .city-container {
    border-right-color: rgba(45, 49, 57, 0.16);
}

body.light-mode .city-header {
    background: rgba(255, 255, 255, 0.86);
    border-color: rgba(65, 70, 82, 0.18);
    box-shadow: 0 12px 30px rgba(35, 42, 55, 0.12);
}

body.light-mode .city-label {
    color: #2d465d;
    background: rgba(82, 93, 108, 0.1);
}

body.light-mode .label,
body.light-mode .comparison-label,
body.light-mode .range-group label,
body.light-mode .range-header label {
    color: #4f5663;
    opacity: 0.78;
}

body.light-mode .value,
body.light-mode .range-value,
body.light-mode .estimate-item strong {
    color: #24272d;
}

body.light-mode .icon-btn {
    background: rgba(68, 74, 86, 0.08);
    border-color: rgba(68, 74, 86, 0.22);
    color: #2c3139;
}

body.light-mode .icon-btn:hover,
body.light-mode .btn-toggle-types.is-active {
    background: rgba(58, 73, 92, 0.16);
    border-color: rgba(58, 73, 92, 0.42);
    color: #1f252c;
}

body.light-mode .btn-random-ratio {
    color: #2f4d61;
    border-color: rgba(58, 73, 92, 0.28);
}

body.light-mode #global-controls button {
    box-shadow: 0 10px 25px rgba(58, 73, 92, 0.18);
}

body.light-mode .generate-hint {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(58, 73, 92, 0.24);
    color: #253340;
    box-shadow: 0 14px 32px rgba(35, 42, 55, 0.18);
}

body.light-mode .generate-hint::after {
    border-top-color: rgba(255, 255, 255, 0.96);
}

body.light-mode #global-controls .analysis-link {
    background: rgba(255, 255, 255, 0.92);
    color: #2c3139;
    border-color: #616976;
}

body.light-mode #global-controls .secondary-btn {
    background: rgba(255, 255, 255, 0.92);
    color: #2c3139;
    border-color: #616976;
}

body.light-mode #view-controls {
    background: rgba(255, 255, 255, 0.82);
    border-color: rgba(65, 70, 82, 0.16);
    box-shadow: 0 14px 35px rgba(35, 42, 55, 0.14);
}

body.light-mode .view-btn {
    background: rgba(68, 74, 86, 0.07);
    border-color: rgba(68, 74, 86, 0.2);
    color: #2c3139;
}

body.light-mode .view-btn:hover,
body.light-mode .view-btn.is-active {
    background: rgba(58, 73, 92, 0.16);
    border-color: rgba(58, 73, 92, 0.42);
    color: #1f252c;
}

body.light-mode .comparison-bar {
    background: rgba(45, 49, 57, 0.08);
    border-color: rgba(45, 49, 57, 0.14);
}

body.light-mode .modal {
    background-color: rgba(244, 246, 249, 0.72);
}

body.light-mode .modal-content {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(65, 70, 82, 0.16);
    box-shadow: 0 30px 60px rgba(35, 42, 55, 0.18);
}

body.light-mode .modal-header {
    border-bottom-color: rgba(65, 70, 82, 0.12);
}

body.light-mode .modal-header h2,
body.light-mode .setting-group > label {
    color: #2d465d;
}

body.light-mode .ratio-grid,
body.light-mode .estimate-panel,
body.light-mode .fit-result {
    background: rgba(45, 49, 57, 0.06);
    border-color: rgba(45, 49, 57, 0.12);
    color: #505762;
}

body.light-mode .range-header input[type="number"],
body.light-mode .city-data-field input,
body.light-mode .styled-select {
    background: rgba(45, 49, 57, 0.06);
    color: #24272d;
    border-color: rgba(45, 49, 57, 0.2);
}

body.light-mode .city-data-field label,
body.light-mode .estimate-label,
body.light-mode .waste-scale-guide {
    color: rgba(45, 49, 57, 0.7);
}

body.light-mode .waste-scale-status {
    border-color: rgba(45, 49, 57, 0.14);
}

body.light-mode .waste-scale-status span {
    color: rgba(45, 49, 57, 0.74);
}

body.light-mode .waste-scale-status.saving {
    background: #e6f7ee;
    border-color: #a8dec1;
}

body.light-mode .waste-scale-status.saving strong {
    color: #25734b;
}

body.light-mode .waste-scale-status.normal {
    background: #e7f5fb;
    border-color: #aad7e9;
}

body.light-mode .waste-scale-status.normal strong {
    color: #2d687d;
}

body.light-mode .waste-scale-status.wasteful {
    background: #fff0ed;
    border-color: #efb6ad;
}

body.light-mode .waste-scale-status.wasteful strong {
    color: #9c4338;
}

body.light-mode .styled-select option {
    background: #ffffff;
    color: #24272d;
}

body.light-mode .tooltip {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(65, 70, 82, 0.32);
    color: #24272d;
    box-shadow: 0 10px 25px rgba(35, 42, 55, 0.16);
}

body.light-mode .tooltip-title {
    color: #2d465d;
    border-bottom-color: rgba(45, 49, 57, 0.14);
}

/* Tooltip */
.tooltip {
    position: fixed;
    pointer-events: auto;
    background: rgba(10, 10, 25, 0.95);
    border: 1px solid rgba(76, 201, 240, 0.5);
    padding: 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 1000;
    display: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    color: #fff;
    min-width: 150px;
    max-width: min(360px, calc(100vw - 24px));
    max-height: min(72vh, 620px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tooltip-title {
    font-weight: bold;
    color: #4cc9f0;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.tooltip-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 5px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.tooltip-section {
    color: #9ff6ff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.tooltip-label {
    opacity: 0.7;
    font-size: 0.75rem;
}

.tooltip-value {
    font-weight: 600;
}

@media (max-width: 900px) {
    #view-controls {
        top: auto;
        right: 50%;
        bottom: 104px;
        transform: translateX(50%);
        flex-direction: row;
    }

    .view-btn {
        min-width: 64px;
    }
}

@media (max-width: 700px) {
    body {
        width: 100vw;
        min-height: 100dvh;
        touch-action: manipulation;
    }

    button,
    input,
    select {
        font-size: 16px;
    }

    #simulation-wrapper {
        flex-direction: column;
        height: 100dvh;
    }

    .city-container {
        flex: 1 1 50%;
        min-height: 0;
        border-right: none;
        border-bottom: 2px solid rgba(255, 255, 255, 0.12);
    }

    #city-right {
        border-bottom: none;
    }

    body.light-mode .city-container {
        border-bottom-color: rgba(45, 49, 57, 0.16);
    }

    .city-header {
        top: 8px;
        left: 8px;
        right: 8px;
        padding: 8px;
        border-radius: 10px;
        flex-direction: column;
        align-items: stretch;
        gap: 7px;
    }

    .city-title {
        width: 100%;
        justify-content: space-between;
        gap: 6px;
    }

    .city-label {
        padding: 4px 8px;
        font-size: 0.78rem;
    }

    .icon-btn {
        min-height: 34px;
        padding: 6px 8px;
        border-radius: 8px;
        font-size: 0.74rem;
        gap: 5px;
    }

    .stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        justify-content: stretch;
        gap: 5px;
    }

    .stat-box {
        min-width: 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 1px;
        padding: 5px 6px;
        border-radius: 7px;
        background: rgba(255, 255, 255, 0.055);
        line-height: 1.08;
    }

    body.light-mode .stat-box {
        background: rgba(45, 49, 57, 0.055);
    }

    .label {
        font-size: 0.56rem;
    }

    .value {
        max-width: 100%;
        font-size: 0.78rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #comparison-container {
        top: calc(50% - 20px);
        bottom: auto;
        width: calc(100vw - 20px);
        z-index: 55;
        pointer-events: none;
    }

    .comparison-bar {
        height: 10px;
        margin-bottom: 4px;
    }

    .bar-segment {
        font-size: 0;
    }

    .comparison-label {
        font-size: 0.62rem;
        letter-spacing: 0;
    }

    #view-controls {
        left: 8px;
        right: 8px;
        bottom: calc(env(safe-area-inset-bottom) + 118px);
        transform: none;
        width: auto;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        padding: 7px;
        border-radius: 12px;
    }

    .view-btn {
        min-width: 0;
        min-height: 38px;
        padding: 8px 6px;
        border-radius: 9px;
        font-size: 0.72rem;
    }

    #global-controls {
        left: 8px;
        right: 8px;
        bottom: calc(env(safe-area-inset-bottom) + 10px);
        transform: none;
        z-index: 65;
    }

    .generate-action {
        width: 100%;
    }

    #global-controls button,
    #global-controls .analysis-link {
        width: 100%;
        min-height: 44px;
        justify-content: center;
        padding: 10px 16px;
        border-radius: 12px;
        font-size: 0.88rem;
    }

    .generate-hint {
        bottom: calc(100% + 8px);
        max-width: calc(100vw - 32px);
        white-space: normal;
    }

    .modal {
        padding: 0;
    }

    .modal-content {
        width: 100%;
        max-width: none;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        padding: 14px 16px;
        background: rgba(22, 22, 40, 0.98);
        backdrop-filter: blur(12px);
    }

    body.light-mode .modal-header {
        background: rgba(255, 255, 255, 0.98);
    }

    .close-btn {
        min-width: 42px;
        min-height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal-body {
        padding: 16px;
        gap: 18px;
        padding-bottom: calc(env(safe-area-inset-bottom) + 28px);
    }

    .city-data-grid,
    .estimate-panel,
    .ratio-grid {
        grid-template-columns: 1fr;
    }

    .preset-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .preset-select {
        width: 100%;
        padding: 10px 12px;
        font-size: 0.92rem;
    }

    .range-header {
        align-items: flex-start;
    }

    .range-header input[type="number"] {
        width: 104px;
        min-height: 38px;
    }

    input[type="range"] {
        min-height: 30px;
    }

    .styled-select,
    .city-data-field input {
        min-height: 42px;
    }

    .secondary-btn,
    #btn-reset-city {
        min-height: 44px;
        border-radius: 10px;
    }

    .tooltip {
        left: 10px !important;
        right: 10px;
        bottom: calc(env(safe-area-inset-bottom) + 118px);
        top: auto !important;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: min(42dvh, 360px);
        border-radius: 12px;
        font-size: 0.78rem;
    }
}

@media (max-width: 420px) {
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .city-title {
        flex-wrap: wrap;
    }

    .city-label {
        flex: 1 0 100%;
        text-align: center;
    }

    .icon-btn {
        flex: 1 1 calc(50% - 3px);
        justify-content: center;
    }
}

@media (max-height: 680px) and (max-width: 700px) {
    .stats {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .stat-box {
        padding: 4px;
    }

    .label {
        display: none;
    }

    .value {
        font-size: 0.7rem;
    }
}
