/* =============================================================
   polish.css — non-destructive visual refinement layer
   Keeps the original SchreckNet language while unifying motion,
   focus, depth and responsive behavior.
   ============================================================= */

:root {
    --bg-elevated: #0a0a0b;
    --bg-panel: rgba(8, 8, 9, 0.92);
    --text-strong: #f0eded;
    --text-muted: #969194;
    --blood-bright: #c51f24;
    --blood-deep: #570508;
    --border-subtle: rgba(255, 255, 255, 0.09);
    --border-blood: rgba(197, 31, 36, 0.52);
    --shadow-panel: 0 24px 80px rgba(0, 0, 0, 0.72);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 160ms;
    --duration-base: 260ms;
    --duration-slow: 420ms;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    min-width: 320px;
    line-height: 1.5;
    background:
        radial-gradient(circle at 50% 45%, rgba(92, 8, 11, 0.1), transparent 42%),
        var(--bg-color);
}

body::selection {
    color: #fff;
    background: rgba(197, 31, 36, 0.72);
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

:where(button, input, [role="button"]:not(path), .city-marker):focus-visible {
    outline: 2px solid var(--blood-bright);
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(197, 31, 36, 0.17);
}

/* Ambient map surface */

#map-container {
    isolation: isolate;
    min-height: 100dvh;
    background:
        linear-gradient(rgba(255, 255, 255, 0.014) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.014) 1px, transparent 1px),
        radial-gradient(circle at 50% 47%, rgba(138, 3, 3, 0.14), transparent 46%),
        linear-gradient(180deg, #070708 0%, #030304 100%);
    background-size: 48px 48px, 48px 48px, auto, auto;
}

#map-container::before,
#map-container::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#map-container::before {
    z-index: 2;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.62), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.62)),
        radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.66) 100%);
}

#map-container::after {
    z-index: 3;
    opacity: 0.13;
    background: repeating-linear-gradient(
        180deg,
        transparent 0,
        transparent 3px,
        rgba(255, 255, 255, 0.035) 4px
    );
    mix-blend-mode: screen;
}

#map-wrapper {
    z-index: 1;
    width: min(1000px, 92vw);
    filter: drop-shadow(0 30px 55px rgba(0, 0, 0, 0.72));
    will-change: transform;
}

body:not(.app-revealed) #map-wrapper {
    opacity: 0.42;
    filter: blur(3px) drop-shadow(0 30px 55px rgba(0, 0, 0, 0.72));
}

body.app-revealed #map-wrapper {
    animation: mapReveal 720ms var(--ease-out) both;
}

#svg path {
    vector-effect: non-scaling-stroke;
    transition:
        fill var(--duration-base) ease,
        stroke var(--duration-base) ease,
        filter var(--duration-base) ease !important;
}

#svg path:focus,
#svg path:focus-visible {
    outline: none;
    box-shadow: none;
}

#svg path:hover,
#svg path:focus-visible {
    fill: #310d10 !important;
    stroke: var(--blood-bright) !important;
    filter: drop-shadow(0 0 4px rgba(197, 31, 36, 0.58));
}

#svg path.active-state {
    fill: #641b20 !important;
    stroke: var(--blood-bright) !important;
    filter: drop-shadow(0 0 7px rgba(197, 31, 36, 0.62));
}

.city-marker {
    width: 14px;
    height: 14px;
    background: transparent;
    box-shadow: none;
    transition:
        filter var(--duration-base) ease,
        background-color var(--duration-base) ease;
}

.city-marker::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.city-pulse {
    background: transparent;
    box-shadow: none;
    animation: none;
}

.city-pulse::after {
    background: var(--blood-red);
    box-shadow: 0 0 10px var(--blood-red-glow);
    animation: pulse 2s infinite;
}

.city-marker:hover,
.city-marker:focus-visible {
    filter: brightness(1.65) drop-shadow(0 0 5px var(--blood-bright));
}

.city-marker::before {
    bottom: 50%;
    padding: 3px 6px;
    border: 1px solid transparent;
    background: rgba(3, 3, 4, 0.68);
    letter-spacing: 0.06em;
    transition:
        color var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        background var(--duration-fast) ease;
}

.city-marker:hover::before,
.city-marker:focus-visible::before {
    color: #fff;
    border-color: var(--border-blood);
    background: rgba(18, 5, 6, 0.94);
}

.city-locked::after {
    content: "";
    top: 50%;
    left: 50%;
    width: 7px;
    height: 7px;
    border-radius: 0;
    background: #111;
    border: 1px solid #5c5759;
    transform: translate(-50%, -50%) rotate(45deg);
}

/* Primary overlay and terminal controls */

#ui-overlay {
    top: clamp(14px, 2.2vw, 28px);
    left: clamp(14px, 2.2vw, 28px);
    z-index: 20;
    max-width: min(460px, calc(100vw - 28px));
}

#ui-overlay > h1 {
    width: fit-content;
    max-width: 100%;
    margin: 0;
    padding: 10px 14px 9px;
    border-left: 2px solid var(--blood-bright);
    background: linear-gradient(90deg, rgba(138, 3, 3, 0.13), transparent);
    color: #ba2428;
    font-size: clamp(13px, 1.45vw, 20px);
    line-height: 1.3;
    text-shadow: 0 0 18px rgba(138, 3, 3, 0.42);
}

body:not(.app-revealed) #ui-overlay {
    opacity: 0;
}

body.app-revealed #ui-overlay {
    animation: interfaceReveal 560ms 90ms var(--ease-out) both;
}

#search-widget,
#inbox-widget,
#layer-controls,
#layer-legend {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 45%),
        var(--bg-panel);
    border-color: var(--border-subtle);
    backdrop-filter: blur(14px) saturate(110%);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.42);
}

#search-widget {
    min-height: 46px;
    padding: 11px 14px;
    border-left: 2px solid var(--blood-red);
    transition:
        border-color var(--duration-fast) ease,
        box-shadow var(--duration-base) ease,
        background var(--duration-base) ease;
}

#search-widget:focus-within {
    border-color: var(--blood-bright);
    background-color: rgba(13, 6, 7, 0.96);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.52), 0 0 0 1px rgba(197, 31, 36, 0.2);
}

#terminal-search {
    height: 24px;
    width: clamp(130px, 16vw, 210px);
    color: #d74347;
    caret-color: var(--blood-bright);
}

#terminal-search::-webkit-search-cancel-button {
    filter: invert(1) opacity(0.55);
}

#search-suggestions {
    border-color: var(--border-blood);
    background: rgba(5, 5, 6, 0.98);
    animation: suggestionsIn var(--duration-fast) var(--ease-out) both;
    transform-origin: top;
}

#search-suggestions li {
    min-height: 44px;
    align-items: center;
    gap: 14px;
    transition:
        background var(--duration-fast) ease,
        color var(--duration-fast) ease,
        padding-left var(--duration-fast) ease;
}

#search-suggestions li:hover {
    padding-left: 19px;
    color: #f0dfe0;
    background: linear-gradient(90deg, rgba(138, 3, 3, 0.24), rgba(138, 3, 3, 0.06));
}

#inbox-widget {
    position: relative;
    min-height: 44px;
    border-left: 2px solid var(--blood-red);
    color: var(--text-muted);
    appearance: none;
    text-align: left;
    overflow: hidden;
}

#inbox-widget::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(197, 31, 36, 0.08), transparent 65%);
    transform: translateX(-100%);
    transition: transform 600ms var(--ease-out);
}

#inbox-widget:hover::after,
#inbox-widget:focus-visible::after {
    transform: translateX(100%);
}

#layer-controls {
    min-width: 236px;
    padding: 14px;
    border-left-color: var(--blood-red);
    border-left-width: 2px;
}

.layer-btn {
    position: relative;
    min-height: 44px;
    padding: 10px 12px 10px 17px;
    border-color: rgba(255, 255, 255, 0.12);
    border-radius: 0;
    transition:
        color var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        background var(--duration-fast) ease,
        transform var(--duration-fast) var(--ease-out);
}

.layer-btn::before {
    content: "";
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 6px;
    width: 2px;
    background: transparent;
    transition: background var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.layer-btn:hover,
.layer-btn:focus-visible {
    color: var(--text-strong);
    border-color: var(--border-blood);
    background: rgba(138, 3, 3, 0.09);
    transform: translateX(2px);
}

.layer-btn.active::before {
    background: var(--blood-bright);
    box-shadow: 0 0 9px var(--blood-bright);
}

#layer-legend {
    border-left: 2px solid var(--blood-red);
}

/* Modals and dossiers */

.modal {
    opacity: 0;
    background: rgba(0, 0, 0, 0.82);
    transition: opacity 220ms ease;
}

.modal.active-modal {
    display: flex !important;
    opacity: 1;
}

.modal.active-modal > .modal-wrapper,
.modal.active-modal > .modal-content {
    animation: dossierEnter 360ms var(--ease-out) both;
}

.modal-content,
.dossier-style,
.char-dossier {
    border-color: var(--border-blood) !important;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 36%),
        #070708 !important;
    box-shadow: var(--shadow-panel), 0 0 36px rgba(138, 3, 3, 0.16) !important;
}

.modal-content::before,
.char-dossier::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 112px;
    height: 2px;
    background: linear-gradient(90deg, var(--blood-bright), transparent);
    box-shadow: 0 0 12px rgba(197, 31, 36, 0.55);
    pointer-events: none;
}

.close-btn,
.close-side {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid rgba(197, 31, 36, 0.32);
    background: rgba(5, 5, 6, 0.88);
    color: var(--blood-bright);
    cursor: pointer;
    appearance: none;
    transition:
        color var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        background var(--duration-fast) ease,
        transform var(--duration-fast) var(--ease-out);
}

.close-btn:hover,
.close-side:hover {
    color: #fff;
    border-color: var(--blood-bright);
    background: rgba(138, 3, 3, 0.28);
    transform: scale(1.04);
}

.intelligence-body,
.stat-box,
.detail-section,
.connection-group {
    border-color: var(--border-subtle);
    background: rgba(255, 255, 255, 0.022);
}

.intelligence-body {
    line-height: 1.65;
}

.tech-label {
    color: #8a8587;
    border-color: var(--border-subtle);
}

.clearance-tag {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    border-color: var(--border-blood);
    color: #cf3a3f;
    background: rgba(138, 3, 3, 0.08);
}

.stat-box {
    min-height: 54px;
    padding: 8px 11px;
    transition: border-color var(--duration-base) ease, background var(--duration-base) ease;
}

.stat-box:hover {
    border-color: rgba(197, 31, 36, 0.28);
    background: rgba(138, 3, 3, 0.055);
}

.terminal-text,
.details-text {
    color: #b8b2b4;
    line-height: 1.65;
}

.dossier-style .scanline {
    top: 0;
    opacity: 0.52;
    animation: scanDossierRefined 5.8s linear infinite;
    will-change: transform;
}

/* Factions and hierarchy */

.faction-icons-container {
    gap: 12px;
}

.faction-icon {
    min-width: 96px;
    min-height: 96px;
    padding: 12px 10px;
    border: 1px solid transparent;
    background: transparent;
    appearance: none;
    color: #918b8e;
    transition:
        color var(--duration-fast) ease,
        border-color var(--duration-fast) ease,
        background var(--duration-fast) ease,
        transform var(--duration-base) var(--ease-out);
}

.faction-icon:hover,
.faction-icon:focus-visible,
.faction-icon.active-icon {
    border-color: rgba(197, 31, 36, 0.26);
    background: linear-gradient(180deg, rgba(138, 3, 3, 0.13), rgba(138, 3, 3, 0.035));
    transform: translateY(-3px);
}

.faction-icon:active {
    transform: translateY(-1px) scale(0.98);
}

.faction-icons-container .faction-icon img {
    width: 48px;
    height: 48px;
    transition: opacity var(--duration-fast) ease, filter var(--duration-base) ease, transform var(--duration-base) var(--ease-out);
}

.faction-icon:hover img,
.faction-icon:focus-visible img,
.faction-icon.active-icon img {
    transform: scale(1.05);
}

.faction-scroll {
    max-height: 0;
    padding: 0 30px;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-8px);
    transition:
        max-height 380ms var(--ease-standard),
        padding 300ms var(--ease-standard),
        opacity 180ms ease,
        transform 300ms var(--ease-out);
}

.faction-scroll.open {
    max-height: 700px;
    opacity: 1;
    padding: 30px;
    transform: translateY(0);
}

.dossier-footer {
    color: #777173;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.sugg-type {
    color: #7d7779;
}

.hierarchy-call-btn {
    width: 100%;
    min-height: 46px;
    border: 1px solid rgba(138, 3, 3, 0.28);
    border-left: 0;
    border-right: 0;
    background: transparent;
    appearance: none;
}

.hierarchy-call-btn:hover,
.hierarchy-call-btn:focus-visible {
    background: linear-gradient(90deg, transparent, rgba(138, 3, 3, 0.14), transparent);
}

#hierarchy-panel {
    padding: clamp(20px, 3vw, 40px);
    background:
        linear-gradient(90deg, rgba(138, 3, 3, 0.08), transparent 18%),
        rgba(4, 4, 5, 0.985);
    box-shadow: -30px 0 90px rgba(0, 0, 0, 0.86);
    transition: transform var(--duration-slow) var(--ease-out);
    will-change: transform;
}

.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 48px;
}

.close-side {
    font-size: 22px;
}

#hierarchy-tree-container {
    height: calc(100dvh - 150px);
    padding: 40px 24px 64px;
    mask-image: linear-gradient(to bottom, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}

.tree-card {
    min-width: 116px;
    padding: 12px;
    border-color: var(--border-subtle);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
    transition:
        border-color var(--duration-fast) ease,
        background var(--duration-fast) ease,
        box-shadow var(--duration-base) ease,
        transform var(--duration-base) var(--ease-out);
}

.tree-card:hover,
.tree-card:focus-visible {
    border-color: var(--border-blood);
    background: rgba(138, 3, 3, 0.08);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.38), 0 0 20px rgba(138, 3, 3, 0.18);
    transform: translateY(-4px);
}

.tree-portrait {
    width: 64px;
    height: 84px;
    border-color: var(--border-subtle);
    transition: filter var(--duration-base) ease;
}

.tree-card:hover .tree-portrait,
.tree-card:focus-visible .tree-portrait {
    filter: grayscale(45%) contrast(115%);
}

/* Motion */

@keyframes mapReveal {
    /* map.js owns transform for state zoom; keep this animation visual-only. */
    from { opacity: 0.35; filter: blur(4px) drop-shadow(0 30px 55px rgba(0, 0, 0, 0.72)); }
    to { opacity: 1; filter: blur(0) drop-shadow(0 30px 55px rgba(0, 0, 0, 0.72)); }
}

@keyframes interfaceReveal {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes terminalBoot {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes dossierEnter {
    from { opacity: 0; transform: translateY(18px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes scanDossierRefined {
    from { transform: translateY(-70px); }
    to { transform: translateY(100vh); }
}

/* Responsive refinement */

@media (max-width: 900px) {
    #map-wrapper {
        width: 100vw;
    }

    #layer-controls {
        margin-top: 24px;
    }

    .modal {
        padding: 24px 12px;
    }

    #hierarchy-panel {
        width: 100vw;
        max-width: none;
        border-left: 0;
    }
}

@media (max-width: 680px) {
    #ui-overlay {
        inset: 10px 10px auto;
        max-width: none;
    }

    #ui-overlay > h1 {
        font-size: 12px;
        padding: 8px 10px;
    }

    #search-widget {
        display: flex;
        width: 100%;
        align-items: center;
        margin-top: 10px;
        font-size: 11px;
    }

    #terminal-search {
        flex: 1;
        min-width: 0;
        width: auto;
    }

    #inbox-widget {
        margin: 10px 0 0;
        font-size: 12px;
    }

    #layer-controls {
        position: fixed;
        inset: auto 10px 10px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        width: auto;
        min-width: 0;
        margin: 0;
        padding: 10px;
    }

    #layer-controls h3 {
        grid-column: 1 / -1;
        margin-bottom: 2px !important;
        font-size: 11px !important;
    }

    .layer-btn {
        min-height: 44px;
        padding: 8px 8px 8px 13px;
        font-size: 10px;
    }

    #layer-legend {
        position: fixed;
        right: 10px;
        bottom: 150px;
        left: 10px;
        min-width: 0;
    }

    .modal {
        padding: 10px 8px;
        align-items: stretch;
    }

    .modal-content,
    .modal-content.dossier-style,
    .dossier-style {
        max-height: calc(100dvh - 20px);
        padding: 24px 16px !important;
    }

    .close-btn {
        top: 8px;
        right: 8px;
    }

    .dossier-header {
        flex-direction: column;
        gap: 14px;
        padding-right: 42px;
    }

    .dossier-photo-frame {
        width: min(150px, 48vw);
        align-self: center;
    }

    .dossier-stats-grid {
        width: 100%;
    }

    .faction-icons-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding-top: 16px;
    }

    .faction-icon {
        min-width: 0;
        min-height: 88px;
    }

    .faction-scroll,
    .faction-scroll.open {
        padding-left: 16px;
        padding-right: 16px;
    }

    .dossier-connections {
        flex-direction: column;
    }

    .dossier-footer {
        text-align: left;
        letter-spacing: 1px;
    }

    #hierarchy-panel {
        padding: 16px;
    }

    #hierarchy-panel > h2 {
        font-size: 18px;
        padding-right: 12px;
    }

    #hierarchy-tree-container {
        justify-content: flex-start;
        height: calc(100dvh - 130px);
        padding: 28px 16px 52px;
    }
}

@media (max-height: 620px) and (orientation: landscape) {
    #ui-overlay > h1 {
        display: none;
    }

    #search-widget,
    #inbox-widget {
        margin-top: 6px;
    }

    #layer-controls {
        max-height: calc(100dvh - 24px);
        margin-top: 8px;
        overflow-y: auto;
    }
}

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

    #map-wrapper,
    #ui-overlay {
        opacity: 1 !important;
        filter: none !important;
    }
}
