/* Shared visual foundation for every Shattered Realms Blade page. */
:root {
    color-scheme: dark;
    --realm-ink: #11131d;
    --realm-panel: rgba(24, 27, 39, .95);
    --realm-panel-border: rgba(199, 165, 107, .32);
    --realm-text: #eee4d0;
    --realm-muted: #aaa9a5;
    --realm-gold: #c7a56b;
    --realm-gold-light: #f0d39a;
    --realm-gold-hover: #e4c58b;
    --realm-button-text: #171820;
    --realm-danger: #8d5148;
}

html body {
    color: var(--realm-text) !important;
    background:
        linear-gradient(rgba(10, 12, 20, .92), rgba(10, 12, 20, .98)),
        radial-gradient(circle at top, #34445d, var(--realm-ink) 70%) !important;
    font-family: Georgia, 'Times New Roman', serif !important;
}

html body :is(h1, h2, h3, h4) {
    color: var(--realm-gold-light);
    font-family: Georgia, 'Times New Roman', serif;
}

html body :is(p, label, input, select, textarea, table, nav, small, [class*="stat"], [class*="description"]) {
    font-family: Arial, sans-serif;
}

html body :is(.brand, [class$="-brand"], .realm-brand) {
    color: var(--realm-gold) !important;
}

/* Normalize the surfaces while keeping each page's existing grid and spacing. */
html body :is(
    .card, [class*="-card"], [class*="-panel"], .auth-panel, .detail-box,
    .reward-box, .error-box, .skill, .progress, .wallet, .notice, .table-panel
) {
    border-color: var(--realm-panel-border) !important;
    border-radius: 12px !important;
    background-color: var(--realm-panel) !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .2);
}

html body :is(.card, [class*="-card"], [class$="-panel"], .auth-panel, .detail-box, .reward-box, .error-box) :is(h2, h3, h4) {
    color: var(--realm-gold-light) !important;
}

/* Shared gold action button; secondary and destructive actions retain their meaning. */
html body :is(
    button, input[type="submit"], .button, [class*="-button"], .realm-button,
    .primary-button, [role="button"]
) {
    border: 1px solid var(--realm-gold) !important;
    border-radius: 6px !important;
    color: var(--realm-button-text) !important;
    background: var(--realm-gold) !important;
    font-family: Arial, sans-serif !important;
    font-weight: 600;
    text-decoration: none;
    transition: background .2s ease, border-color .2s ease, transform .2s ease;
}

html body :is(
    button, input[type="submit"], .button, [class*="-button"], .realm-button,
    .primary-button, [role="button"]
):not(:disabled):not([aria-disabled="true"]):hover {
    border-color: var(--realm-gold-hover) !important;
    background: var(--realm-gold-hover) !important;
    transform: translateY(-1px);
}

html body :is(button, input[type="submit"]):disabled,
html body :is(button, input[type="submit"])[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: .5;
    transform: none;
}

.scrapyard-return {
    display: flex;
    justify-content: center;
    margin: -18px 0 24px;
}

html body .realm-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
}

html body :is(.secondary, .secondary-button, .back-button, .small-button.secondary) {
    border-color: var(--realm-panel-border) !important;
    color: var(--realm-text) !important;
    background: rgba(24, 27, 39, .85) !important;
}

html body :is(.danger-button, .delete-button, .stop, .logout-button) {
    border-color: var(--realm-danger) !important;
    color: #fff !important;
    background: var(--realm-danger) !important;
}

html body :is(input, select, textarea) {
    border-color: rgba(199, 165, 107, .45);
    border-radius: 6px;
    color: var(--realm-text);
    background-color: #11131d;
}

html body :is(input, select, textarea):focus {
    border-color: var(--realm-gold);
    outline-color: var(--realm-gold);
}

/* Shared navigation used by all player-facing gameplay pages. */
html body .city-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border: 1px solid rgba(199, 165, 107, .28);
    border-radius: 12px;
    background: rgba(16, 19, 29, .9);
}
html body .city-brand {
    color: var(--realm-gold) !important;
    font-family: Georgia, 'Times New Roman', serif !important;
    font-size: 1.2rem;
    font-weight: 700;
}
html body .city-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}
html body .city-header .header-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid rgba(199, 165, 107, .4) !important;
    border-radius: 7px !important;
    color: var(--realm-text) !important;
    background: rgba(36, 39, 51, .9) !important;
    font: 600 12.6px Arial, sans-serif !important;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
html body .city-header .header-link:hover {
    border-color: var(--realm-gold) !important;
    color: var(--realm-gold-light) !important;
    background: rgba(68, 57, 39, .75) !important;
}
html body .player-logout-form { margin: 0; }
html body .city-header .logout-button {
    border-color: #92564e !important;
    color: #fff0eb !important;
    background: #713d39 !important;
}
html body .city-header .logout-button:hover {
    border-color: #c27a6e !important;
    background: #8b4b43 !important;
}
@media (max-width: 700px) {
    html body .city-header { align-items: flex-start; }
    html body .city-nav { justify-content: flex-start; }
}


/* Header-only sizing: 70% of original. Keep independent of card/panel scaling. */
html body .city-header .header-link {
    box-sizing: border-box;
    height: 39.2px;
    min-height: 39.2px;
    padding: 0 11.2px;
    font-size: 12.6px;
    line-height: 1;
}
html body .city-nav .player-logout-form {
    display: flex;
    align-items: stretch;
}
html body .city-nav .player-logout-form .logout-button {
    height: 39.2px;
    min-height: 39.2px;
}
html body .guild-container > .city-header {
    margin-bottom: 35px;
}

/* Keep the shared player header clear of the page content below it. */
html body .city-header {
    margin-bottom: 28px;
}


/* Shared navigation for Headquarters management pages. */
html body .headquarters-player-header {
    width: min(1400px, 96%);
    margin: 20px auto 0;
}
html body .headquarters-player-header .city-nav {
    padding: 0;
    border: 0;
}

/* Scale only player-facing destination cards to 80% of their original size. */
html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
    width: 100%;
    margin-inline: auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}
html body :is(.city-card, .world-card, .region-card, .location-card) {
    zoom: .8;
}
/* This location card sits outside a destination grid. */
html body .location-card.market-location-card {
    margin-inline: auto;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 850px) {
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 600px) {
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Match the compact destination cards without changing interaction behaviour. */
html body :is(.quest-story, .location-combat-area, .npc-section) {
    zoom: .8;
    width: 100%;
    box-sizing: border-box;
    margin-inline: auto;
}

/* Compact service and crafting cards; retain their existing column breakpoints. */
html body .scrapyard-grid,
html body :is(#anvil-screen, #smelting-screen, .scrap-dealer-page) > .grid {
    width: 80%;
    margin-inline: auto;
    gap: 16px;
}
html body .scrapyard-card,
html body :is(#anvil-screen, #smelting-screen, .scrap-dealer-page) .card {
    zoom: .8;
}
/* The tool upgrade card is standalone rather than inside a grid. */
html body .scrap-dealer-page > .card {
    width: 100%;
    box-sizing: border-box;
    margin-inline: auto;
}

/* Alchemists' Workshop cards at 80%; shared header sizing stays independent. */
html body .alchemy-layout {
    width: 80%;
    margin-inline: auto;
    gap: 16px;
}
html body .alchemy-layout > .alchemy-panel {
    zoom: .8;
}

/* Character cards at 80%, including their widths. */
html body .character-page .character-grid {
    width: 80%;
    margin-inline: auto;
    gap: 16px;
}
html body .character-page .character-card {
    zoom: .8;
    box-sizing: border-box;
}
html body .character-page .character-container > .character-card {
    width: 80%;
    margin-inline: auto;
}
/* Include the portrait panel in the character page's compact presentation. */
html body .character-page .character-intro {
    zoom: .8;
    width: 80%;
    box-sizing: border-box;
    margin-inline: auto;
}

/* Headquarters cards only: preserve shared headers, hero sections and live chat. */
html body:has(.headquarters-player-header) main :is(.tools, .news-list, .market-list) {
    width: 80%;
    margin-inline: auto;
}
html body:has(.headquarters-player-header) main .tools {
    gap: 14.4px;
}
html body:has(.headquarters-player-header) main :is(
    .tool-link, .panel, .form-panel, .form-wrapper, .form-card,
    .table-panel, .table-wrapper, .table-wrap, .card, .market-row, .item-group
) {
    zoom: .8;
    box-sizing: border-box;
}
html body:has(.headquarters-player-header) main :is(
    .panel, .form-panel, .form-wrapper, .form-card,
    .table-panel, .table-wrapper, .table-wrap, .item-group
) {
    width: 80%;
    margin-inline: auto;
}
/* Nested card contents inherit their enclosing panel's reduction exactly once. */
html body:has(.headquarters-player-header) main :is(
    .panel, .form-panel, .form-wrapper, .form-card, .table-panel,
    .table-wrapper, .table-wrap, .card, .market-row, .item-group
) :is(
    .panel, .form-panel, .form-wrapper, .form-card, .table-panel,
    .table-wrapper, .table-wrap, .card, .market-row, .item-group
) {
    zoom: 1;
    width: auto;
}

/* UI-006A: centre incomplete rows only at widths with multiple cards. */
@media (min-width: 851px) {
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :is(.city-card, .world-card, .region-card, .location-card) {
        grid-column: span 2;
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(4n + 1):nth-last-child(1) {
        grid-column: 4 / span 2;
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(4n + 1):nth-last-child(2) {
        grid-column: 3 / span 2;
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(4n + 1):nth-last-child(3) {
        grid-column: 2 / span 2;
    }
}
@media (min-width: 601px) and (max-width: 850px) {
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(n) {
        grid-column: auto / span 2;
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(2n + 1):last-child {
        grid-column: 2 / span 2;
    }
}
@media (max-width: 600px) {
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) {
        grid-template-columns: minmax(0, 1fr);
    }
    html body :is(.city-grid, .world-grid, .region-grid, .location-grid) > :nth-child(n) {
        grid-column: auto;
    }
}

/* Allow generated names, descriptions and action labels to fit their tracks.
   Do not hide overflow: content must wrap and remain available. */
html body :is(.city-card, .world-card, .region-card, .location-card) {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
html body :is(.city-card, .world-card, .region-card, .location-card) > * {
    min-width: 0;
    max-width: 100%;
}
html body :is(.city-card, .world-card, .region-card, .location-card)
    :is(.city-button, .world-button, .region-button, .location-button) {
    box-sizing: border-box;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Custom account/character/quest headers share the player header appearance. */
html body .city-header .city-brand {
    margin: 0;
    font: 700 1.2rem Georgia, 'Times New Roman', serif !important;
    letter-spacing: normal;
    text-transform: none;
}
html body .city-header .header-link {
    letter-spacing: normal;
    text-transform: none;
    line-height: 1 !important;
    width: auto;
    margin: 0;
}
html body .account-header {
    margin: 20px auto 28px;
    width: min(1400px, 96%);
}
html body .account-header-inner {
    width: 100%;
    max-width: none;
    padding: 0;
}
html body .account-header-row {
    height: auto;
    align-items: center;
    gap: 18px;
}
html body .account-header-links {
    margin-block: 0;
    align-items: center;
}

/* Keep skill entries and locks aligned below varying descriptions. */
html body :is(.woodcutting-destination-card, .fishing-destination-card, .mining-destination-card, .smithing-destination-card) {
    display: flex;
    flex-direction: column;
}
html body :is(.woodcutting-card-footer, .fishing-card-footer, .mining-card-footer, .smithing-card-footer) {
    margin-top: auto;
    padding-top: 16px;
}
html body .woodcutting-card-footer .woodcutting-card-requirement {
    margin: 0;
    color: var(--realm-gold-light);
}

/* One return control for every location and activity, outside its feature cards. */
html body .realm-return-navigation {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0;
    margin: 24px 0 0;
    padding: 0;
    border: 0;
    background: transparent;
}
html body .realm-return-navigation .realm-return-button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
    min-height: 46px;
    margin: 0;
    padding: 11px 18px;
    border: 1px solid var(--realm-gold) !important;
    border-radius: 6px !important;
    background: var(--realm-gold) !important;
    color: var(--realm-button-text) !important;
    font: 600 16px/22px Arial, sans-serif !important;
    text-align: center;
    text-decoration: none;
    white-space: normal;
    overflow-wrap: anywhere;
}
html body .realm-return-navigation .realm-return-button:hover {
    background: var(--realm-gold-hover) !important;
    border-color: var(--realm-gold-hover) !important;
    transform: none;
}
html body .realm-return-navigation .realm-return-button:focus-visible {
    outline: 2px solid var(--realm-gold-light);
    outline-offset: 4px;
}
@media (max-width: 480px) {
    html body .realm-return-navigation .realm-return-button { width: 100%; }
}

/* UI-005: let shared headers use desktop space independently of content cards. */
html body .city-header {
    --realm-header-width: min(1600px, calc(100vw - 40px));
    box-sizing: border-box;
    width: var(--realm-header-width);
    max-width: none;
    margin-inline: calc((100% - var(--realm-header-width)) / 2);
    flex-direction: row;
}
html body .city-header > .city-nav {
    flex: 1 1 max-content;
    min-width: 0;
    max-width: 100%;
    margin-left: auto;
}
html body .city-header > :first-child:not(.city-nav) {
    flex-shrink: 0;
    max-width: 100%;
}
@media (max-width: 700px) {
    html body .city-header {
        --realm-header-width: calc(100vw - 24px);
        padding-inline: 12px;
    }
    html body .city-header > .city-nav {
        flex-basis: 100%;
        justify-content: flex-start;
    }
    html body .city-header .header-link {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

/* UI-006B: one set of navigation controls, disclosed on phones and tablets.
   Without JavaScript the existing navigation remains available. */
html body .city-header .realm-menu-toggle { display: none; }
@media (max-width: 850px) {
    html body .city-header.realm-mobile-navigation {
        align-items: center;
        gap: 12px;
        padding: 12px;
    }
    html body .city-header.realm-mobile-navigation > :first-child {
        flex: 1 1 0;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    html body .city-header.realm-mobile-navigation .city-brand {
        font-size: 1.2rem !important;
    }
    html body .city-header.realm-mobile-navigation .realm-menu-toggle {
        display: inline-flex;
        flex: 0 0 auto;
        height: auto;
        min-height: 44px;
        margin: 0;
        padding: 10px 12px;
    }
    html body .city-header.realm-mobile-navigation .header-link.realm-menu-toggle:hover {
        color: var(--realm-gold-light) !important;
        background: rgba(68, 57, 39, .75) !important;
        border-color: var(--realm-gold) !important;
    }
    html body .city-header.realm-mobile-navigation > .city-nav {
        display: none;
        flex: 0 0 100%;
        width: 100%;
        min-width: 0;
        margin: 0;
        padding: 12px 0 0;
        border-top: 1px solid var(--realm-panel-border);
    }
    html body .city-header.realm-menu-open > .city-nav {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    html body .city-header.realm-mobile-navigation .city-nav .header-link {
        width: 100%;
        height: auto;
        min-height: 44px;
        padding: 11px 13px;
        font-size: 14px !important;
        line-height: 22px !important;
        justify-content: flex-start;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    html body .city-header.realm-mobile-navigation .player-logout-form {
        width: 100%;
    }
    html body .city-header.realm-mobile-navigation .header-link:focus-visible {
        outline: 2px solid var(--realm-gold-light);
        outline-offset: 2px;
    }
}

/* Quest access notice uses the same flex footer placement as entry buttons. */
html body .region-card > .region-card-lock-footer {
    margin-top: auto;
    margin-bottom: 0;
    color: var(--realm-gold-light);
}

/* Mining activity cards use the same gold outline and footer in every placement. */
html body .mining-destination-card {
    border: 1px solid var(--realm-panel-border);
}
html body .mining-card-footer .mining-card-requirement {
    margin: 0;
    color: var(--realm-gold-light);
}
