:root {
    --bg: #101318;
    --panel: #1b222b;
    --panel-2: #242e38;
    --line: #354351;
    --text: #edf3f7;
    --muted: #a7b4bd;
    --accent: #4fb477;
    --accent-2: #e2b15c;
    --danger: #e66a64;
    --water: #5aa0c8;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
    font-family: Arial, Helvetica, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

button,
.topbar a {
    min-height: 38px;
    border: 1px solid #5f765f;
    border-radius: 6px;
    background: #2f6f4d;
    color: #fff;
    cursor: pointer;
    padding: 0 14px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button:hover,
.topbar a:hover {
    filter: brightness(1.12);
}

.auth-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 24% 18%, rgba(79, 180, 119, 0.16), transparent 28%),
        linear-gradient(135deg, #15191f, #24313a 52%, #18201c);
}

.auth-shell {
    width: min(980px, 100%);
}

.auth-brand {
    margin-bottom: 24px;
}

.auth-brand h1 {
    margin: 10px 0 6px;
    font-size: clamp(34px, 7vw, 68px);
    letter-spacing: 0;
}

.auth-brand p {
    max-width: 640px;
    margin: 0;
    color: var(--muted);
    font-size: 18px;
}

.crest {
    width: 74px;
    height: 74px;
    background: conic-gradient(from 40deg, #4fb477, #e2b15c, #75a9d6, #4fb477);
    clip-path: polygon(50% 0, 90% 18%, 78% 86%, 50% 100%, 22% 86%, 10% 18%);
}

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

.panel,
.side-panel {
    background: rgba(27, 34, 43, 0.96);
    border: 1px solid var(--line);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.42), var(--shadow);
}

.auth-panel {
    border-radius: 8px;
    padding: 22px;
}

.auth-panel h2,
.side-panel h2 {
    margin: 0 0 16px;
    font-size: 22px;
}

label {
    display: grid;
    gap: 7px;
    margin-bottom: 14px;
    color: var(--muted);
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #111820;
    color: var(--text);
    padding: 0 11px;
}

.flash {
    margin: 18px 0 0;
    padding: 12px 14px;
    border-radius: 6px;
}

.flash.error {
    background: rgba(230, 106, 100, 0.16);
    color: #ffd6d4;
}

.flash.success {
    background: rgba(79, 180, 119, 0.16);
}

.game-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 18px;
    background: #151b21;
    border-bottom: 1px solid var(--line);
}

.topbar span {
    margin-left: 14px;
    color: var(--muted);
    font-size: 14px;
}

.topbar nav {
    display: flex;
    gap: 8px;
}

.game-layout {
    height: calc(100vh - 58px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 14px;
    padding: 14px;
    box-sizing: border-box;
    overflow: hidden;
}

.world-wrap {
    min-width: 0;
    position: relative;
    overflow: hidden; /* clip icons and overlay canvas */
}

#gameCanvas {
    display: block;
    width: 100%;
    max-height: calc(100vh - 170px);
    aspect-ratio: 960 / 608;
    background: #233027;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 1;
}

#gameTopCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.hud {
    display: grid;
    grid-template-columns: repeat(6, minmax(90px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.hud div {
    min-height: 54px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
}

.hud span,
.hud strong {
    display: block;
}

.hud span {
    color: var(--muted);
    font-size: 12px;
}

.hud strong {
    margin-top: 4px;
}

.side-panel {
    border-radius: 8px;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-bottom: 1px solid var(--line);
}

.tab {
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: var(--panel-2);
}

.tab {
    padding: 4px 6px;
    font-size: 12px;
    min-height: 26px;
}

.tab:last-child {
    border-right: 0;
}

.tab.active {
    background: var(--accent);
}

.tab-page {
    display: none;
    padding: 16px;
}

.tab-page.active {
    display: block;
    flex: 1 1 auto;
    overflow: auto;
}

#heroClass {
    color: var(--accent-2);
    margin-top: -8px;
}

dl {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 14px;
    margin: 0;
}

dt {
    color: var(--muted);
}

dd {
    margin: 0;
    font-weight: 700;
}

.help {
    margin-top: 18px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    line-height: 1.45;
}

.item-row,
.skill-node,
.action-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    min-height: 48px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #151c23;
    margin-bottom: 8px;
}

.item-row small,
.skill-node small,
.action-card small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.skill-node button {
    min-width: 94px;
}

.item-row button,
.action-card button {
    min-width: 88px;
}

.world-form {
    display: grid;
    gap: 8px;
}

.world-form input {
    margin-bottom: 8px;
}

.interaction-popup {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(680px, calc(100% - 28px));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(42, 53, 64, 0.98);
    box-shadow: var(--shadow);
    padding: 18px;
    z-index: 10;
}

/* feature icons overlay */
#featureIconsContainer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    overflow: hidden; /* avoid icons leaking outside the map area */
}
.map-icon {
    position: absolute; /* positioned relative to #featureIconsContainer */
    transform: translate(-50%, -50%);
    font-size: 12px; /* 20% larger */
    pointer-events: none;
    text-shadow: 0 2px 6px rgba(0,0,0,0.25);
    color: #000; /* default color */
    opacity: 0.5;
}

/* shop grid for 3 columns */
.shop-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.shop-grid.shop-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

.sell-list {
    max-height: 320px;
    overflow-y: auto;
}
.shop-card {
    border: 1px solid var(--line);
    padding: 8px;
    border-radius: 6px;
    background: #12181b;
}

.sell-sidebar {
    background: var(--panel);
    border-left: 1px solid var(--line);
    padding: 12px;
    border-radius: 6px;
    min-height: 120px;
    color: var(--text);
}
.shop-card.selected {
    outline: 2px solid rgba(79,180,119,0.18);
}

/* sell button style: green text, 20% smaller */
.sell-btn {
    background: transparent !important;
    color: #4fb477 !important;
    font-size: 80% !important;
    border: 1px solid var(--line) !important;
}

.interaction-popup.hidden {
    display: none;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9;
}

.modal-backdrop.hidden {
    display: none;
}

.popup-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}

.popup-head h2 {
    margin: 0 0 4px;
    font-size: 20px;
}

.popup-head p {
    margin: 0;
    color: var(--muted);
}

.popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.skill-node.locked {
    opacity: 0.72;
}

.points {
    color: var(--muted);
}

@media (max-width: 980px) {
    .game-layout {
        grid-template-columns: 1fr;
    }

    .side-panel {
        min-height: 0;
    }

    .hud {
        grid-template-columns: repeat(3, minmax(90px, 1fr));
    }
}

@media (max-width: 700px) {
    .auth-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        height: auto;
        padding: 12px;
        align-items: flex-start;
        flex-direction: column;
    }

    .game-layout {
        padding: 8px;
    }

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

    .tabs {
        grid-template-columns: repeat(2, 1fr);
    }

    .popup-head {
        grid-template-columns: 1fr;
    }
}
