        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :focus-visible {
            outline: 2px solid var(--gold);
            outline-offset: 2px;
        }

        .legend-dot-you { color: var(--color-positive-bright); }
        .legend-dot-other { color: var(--color-other-player); }

        #game-loading-screen {
            position: absolute;
            inset: 0;
            z-index: var(--z-hud-overlay);
            align-items: center;
            justify-content: center;
            background: linear-gradient(180deg, rgba(21,17,12,0.96), rgba(14,11,8,0.98));
            color: var(--stone-text);
            text-align: center;
            padding: 24px;
        }
        #game-loading-title {
            font-size: var(--fs-title);
            font-weight: bold;
            letter-spacing: 0.08em;
            color: var(--gold-light);
        }
        #game-loading-subtitle {
            margin-top: 10px;
            font-size: var(--fs-ui);
            color: var(--stone-text);
        }
        #game-loading-progress {
            width: min(320px, 70vw);
            height: 10px;
            margin: 14px auto 0;
            border: 1px solid rgba(200, 160, 80, 0.55);
            background: rgba(10, 8, 4, 0.72);
        }
        #game-loading-progress-fill {
            width: 0%;
            height: 100%;
            background: linear-gradient(90deg, var(--gold-dark), var(--gold-light));
        }
        #game-loading-debug {
            margin-top: 10px;
            font-size: var(--fs-body);
            color: var(--stone-muted);
            max-width: min(560px, 85vw);
            word-break: break-word;
        }

        body {
            font-family: Georgia, 'Courier New', monospace;
            /* Page backdrop is owned by theme.css `html, body` (the !important
               page-chrome rule). See the "Atmospheric backdrop" block there. */
            background: linear-gradient(180deg, #2b2218 0%, #1a1410 100%);
            color: #eadfc2;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            margin: 0;
        }

        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-family: Georgia, serif;
            color: var(--gold-light);
            font-size: var(--fs-title);
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
            margin: 0;
            letter-spacing: 0.06em;
            font-weight: normal;
        }

        nav a {
            color: var(--stone-muted);
            text-decoration: none;
            margin: 0 18px;
            font-size: var(--fs-fine);
            font-family: Georgia, serif;
            font-weight: normal;
            text-transform: uppercase;
            letter-spacing: 0.14em;
            transition: color 0.12s, border-bottom-color 0.12s;
            border-bottom: 1px solid transparent;
            padding-bottom: 4px;
        }

        nav a:hover {
            color: var(--gold-light);
            border-bottom-color: var(--gold);
        }

        main {
            display: flex;
            flex: 1;
            gap: 0;
            padding: 0;
            width: 100%;
            flex-wrap: nowrap;
            align-items: stretch;
            justify-content: flex-start;
        }

        #main-content {
            display: flex;
            flex-direction: column;
            gap: 10px;
            flex: 1;
            padding: 12px 16px;
            width: 100%;
        }

        #game-content-wrapper {
            display: flex;
            flex-direction: column;
            gap: 20px;
            align-items: stretch;
            flex: 1;
        }

        #game-and-sidebar {
            display: flex;
            gap: 20px;
            align-items: flex-start;
            width: 100%;
        }

        #sidebar {
            flex: 0 1 auto;
            width: 360px;
            min-width: 0;
            max-width: 400px;
            display: flex;
            flex-direction: column;
            gap: 20px;
            overflow: hidden;
        }

        .sidebar-panel {
            background: var(--stone-dark);
            border-style: solid;
            border-width: 12px;
            border-image: url('/static/assets/sprites/ui/ui_panel_frame.png') 12 fill / 12px / 0px;
            border-image-width: 12px;
            border-radius: 0;
            padding: 10px;
            color: var(--stone-text);
            box-shadow: none;
        }

        .sidebar-panel h3 {
            color: var(--gold);
            margin: 0 0 8px 0;
            font-size: var(--fs-ui);
            font-family: Georgia, serif;
            font-weight: normal;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            border-bottom: 1px solid var(--stone-light);
            padding-bottom: 5px;
        }

        .news-item {
            padding: 10px 0;
            border-bottom: 1px solid var(--stone-light);
            color: #b4a878;
            font-size: var(--fs-ui);
            line-height: 1.4;
        }

        .news-item:last-child {
            border-bottom: none;
        }

        .news-date {
            color: var(--gold);
            font-size: var(--fs-ui);
            font-weight: normal;
        }

        .info-row {
            display: flex;
            justify-content: space-between;
            padding: 6px 0;
            font-size: var(--fs-title);
        }

        .info-label {
            color: var(--stone-muted);
        }

        .info-value {
            color: var(--gold-light);
            font-weight: normal;
        }

        .server-status {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: #5a8a40;
            margin-right: 6px;
        }

        footer {
            background: var(--border-dark);
            border-top: 2px solid var(--gold);
            padding: 12px 30px;
            text-align: center;
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            margin-top: auto;
        }

        footer a {
            color: var(--gold);
            text-decoration: none;
            margin: 0 15px;
            transition: color 0.1s;
        }

        footer a:hover {
            color: var(--gold-light);
        }

        #version-badge {
            position: fixed;
            right: 12px;
            bottom: 10px;
            z-index: var(--z-hud);
            font-size: var(--fs-ui);
            color: rgba(234, 223, 194, 0.65);
            background: rgba(26, 20, 16, 0.78);
            border: 1px solid rgba(212, 175, 55, 0.25);
            border-radius: 0;
            padding: 4px 6px;
            letter-spacing: 0.08em;
            pointer-events: none;
        }

        h1 {
            font-family: Georgia, serif;
            margin-bottom: 20px;
            color: var(--gold-light);
            font-size: var(--fs-title);
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
            letter-spacing: 0.04em;
            font-weight: normal;
        }

        #game-container {
            display: flex;
            gap: 0;
            margin-bottom: 0;
            animation: slideIn 0.5s ease-out;
            position: relative;
            flex-shrink: 0;
        }

        #game-area {
            display: flex;
            flex-direction: column;
            gap: 15px;
            align-items: stretch;
            flex-shrink: 0;
        }

        /* Help button at the bottom of the rail — visually separated from the
           gameplay buttons by a top margin. */
        @keyframes slideIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        #game-canvas {
            border: 4px solid var(--stone-mid);
            box-shadow: 0 8px 32px rgba(0,0,0,0.5),
                        inset 0 0 20px rgba(200, 160, 80, 0.06);
            background-color: #4a7030;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            cursor: crosshair;
            transition: box-shadow 0.3s;
            /* Canvas buffer is fixed at 768×512 (see index.html width/height
               attributes). CSS dimensions are set dynamically by the
               viewport-scaling script in index.html (largest integer multiple
               that fits the viewport, preserving pixel-art crispness). */
        }

        #game-canvas:hover {
            box-shadow: 0 8px 32px rgba(200, 160, 80, 0.35),
                        inset 0 0 30px rgba(200, 160, 80, 0.1);
        }

        #canvas-wrap {
            position: relative;
            /* width/height set by the viewport-scaling script to match the canvas. */
        }

        /* Tier 2 Phase 2: death overlay + invuln badge.
           Overlay covers the canvas; greyscale tint + centered card. */
        #death-overlay {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(8, 6, 4, 0.78);
            backdrop-filter: grayscale(1) blur(2px);
            z-index: var(--z-hud-overlay);
            pointer-events: none;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.35s ease, visibility 0s linear 0.35s;
        }
        #death-overlay.visible {
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
            transition: opacity 0.35s ease, visibility 0s linear 0s;
        }
        #death-overlay-inner {
            background: var(--stone-dark);
            border: 2px solid rgba(180, 70, 70, 0.55);
            color: var(--stone-text);
            font-family: Georgia, serif;
            padding: 22px 28px;
            text-align: center;
            box-shadow: 0 12px 36px rgba(0,0,0,0.6);
        }
        #death-overlay-inner h2 {
            margin: 0 0 10px;
            font-size: var(--fs-hero);
            letter-spacing: 0.1em;
            color: #e76b6b;
        }
        #death-overlay-respawn-at {
            color: #cfbe8f;
            font-size: var(--fs-ui);
            margin-bottom: 6px;
        }
        #death-overlay-countdown {
            color: var(--gold-light);
            font-size: var(--fs-title);
            font-weight: bold;
            margin-bottom: 6px;
        }
        #death-overlay-penalty {
            color: var(--stone-muted);
            font-size: var(--fs-body);
        }
        #invuln-badge {
            position: absolute;
            top: 8px;
            left: 50%;
            transform: translateX(-50%);
            display: none;
            background: rgba(60, 100, 160, 0.85);
            color: var(--stone-text);
            border: 1px solid rgba(140, 180, 240, 0.55);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 4px 10px;
            letter-spacing: 0.06em;
            text-transform: uppercase;
            z-index: var(--z-hud-overlay);
            pointer-events: none;
        }
        #invuln-badge.visible { display: block; }

        #mail-hud-badge {
            position: absolute;
            top: 152px;
            right: 152px;
            background: rgba(12, 9, 5, 0.78);
            color: var(--gold-light);
            border: 1px solid var(--gold-dark);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            padding: 3px 10px;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            z-index: var(--z-hud-overlay);
            cursor: pointer;
            user-select: none;
            transition: border-color 0.12s, background 0.12s;
        }
        #mail-hud-badge:hover {
            background: rgba(58, 44, 16, 0.85);
            border-color: var(--gold);
        }

        #ui-panel {
            background: linear-gradient(135deg, rgba(34, 30, 20, 0.92) 0%, rgba(26, 22, 16, 0.92) 100%);
            padding: 0;
            border-radius: 0;
            border: 1px solid var(--gold-dark);
            box-shadow: 0 8px 32px rgba(0,0,0,0.5);
        }

        #ui-panel::-webkit-scrollbar {
            width: 8px;
        }

        #ui-panel::-webkit-scrollbar-track {
            background: rgba(0,0,0,0.2);
            border-radius: 0;
        }

        #ui-panel::-webkit-scrollbar-thumb {
            background: rgba(200, 160, 80, 0.3);
            border-radius: 0;
        }

        #ui-panel::-webkit-scrollbar-thumb:hover {
            background: rgba(200, 160, 80, 0.5);
        }

        .stat-section {
            margin-bottom: 18px;
            padding: 14px;
            background: linear-gradient(135deg, rgba(26, 22, 16, 0.8) 0%, rgba(20, 16, 10, 0.8) 100%);
            border-radius: 0;
            border: 1px solid rgba(200, 160, 80, 0.1);
            transition: all 0.3s;
        }

        .stat-section:hover {
            border-color: var(--gold-dark);
        }

        .stat-section h3 {
            color: var(--gold);
            margin-bottom: 10px;
            font-size: var(--fs-title);
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 1px;
            border-bottom: 2px solid rgba(200, 160, 80, 0.15);
            padding-bottom: 6px;
        }

        .stat-item {
            display: flex;
            justify-content: space-between;
            margin: 8px 0;
            font-size: var(--fs-title);
            padding: 4px 0;
        }

        .stat-item span:first-child {
            color: var(--stone-text);
        }

        .stat-item span:last-child {
            color: var(--gold-light);
            font-weight: bold;
        }

        .skill-icon {
            width: 16px;
            height: 16px;
            vertical-align: middle;
            image-rendering: pixelated;
            margin-right: 2px;
        }

        .skills-drilldown {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 12px;
            align-items: start;
            padding: 14px;
        }

        /* Tabbed-skills variant: top row of skill tabs, two-column body. */
        .skills-tabs {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0;
            padding: 0 12px;
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            margin: 0;
        }
        .skills-tab {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 10px 6px;
            background: transparent;
            border: none;
            border-bottom: 2px solid transparent;
            color: var(--stone-muted);
            font-family: var(--font-serif);
            font-size: var(--fs-ui);
            cursor: pointer;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: color 0.12s, border-bottom-color 0.12s, background 0.12s;
            min-width: 0;
        }
        .skills-tab:hover { color: var(--gold-light); background: rgba(200, 160, 80, 0.06); }
        .skills-tab.active {
            color: var(--gold-light);
            border-bottom-color: var(--gold);
        }
        .skills-tab .skills-node-icon {
            width: 20px;
            height: 20px;
            image-rendering: pixelated;
            vertical-align: middle;
            margin: 0;
            flex-shrink: 0;
        }
        .skills-tab-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .skills-tab-level {
            color: var(--gold);
            font-size: var(--fs-fine);
            letter-spacing: 0.04em;
            font-variant-numeric: tabular-nums;
            opacity: 0.85;
        }

        .skills-drilldown-tabbed {
            grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
            gap: 14px;
            padding: 14px 16px;
        }

        .skills-panel {
            border: 1px solid var(--stone-light);
            border-radius: 0;
            background: rgba(20, 17, 11, 0.55);
            padding: 12px;
            min-width: 0;
        }

        .skills-panel-title {
            color: var(--gold);
            font-size: var(--fs-ui);
            font-weight: normal;
            text-transform: uppercase;
            letter-spacing: 0.12em;
            margin-bottom: 10px;
            padding-bottom: 6px;
            border-bottom: 1px solid var(--stone-light);
        }

        .skills-node {
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: stretch;
            gap: 3px;
            border: 1px solid transparent;
            border-radius: 0;
            background: transparent;
            color: var(--stone-text);
            padding: 7px 10px;
            margin-bottom: 4px;
            font-size: var(--fs-ui);
            text-align: left;
            cursor: pointer;
            min-width: 0;
            transition: background 0.12s, border-color 0.12s;
        }

        .skills-node:last-child { margin-bottom: 0; }

        .skills-node:hover {
            background: rgba(200, 160, 80, 0.08);
            border-color: var(--gold-dark);
        }

        .skills-node.active {
            background: rgba(58, 44, 16, 0.6);
            border-color: var(--gold);
        }

        .skills-node.static { cursor: default; }

        .skills-node.static:hover {
            background: transparent;
            border-color: transparent;
        }

        .skills-node-name {
            color: var(--gold-light);
            display: flex;
            align-items: center;
            gap: 6px;
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: var(--fs-ui);
            letter-spacing: 0.02em;
        }

        .skills-node-value {
            color: var(--stone-text);
            font-weight: normal;
            font-size: var(--fs-body);
            white-space: nowrap;
            text-align: left;
            overflow: hidden;
            text-overflow: ellipsis;
            font-variant-numeric: tabular-nums;
            letter-spacing: 0.02em;
        }

        .skills-empty {
            color: var(--stone-muted);
            font-size: var(--fs-body);
            line-height: 1.5;
            padding: 18px;
            border: 1px dashed var(--stone-light);
            border-radius: 0;
            text-align: center;
            font-style: italic;
        }

        @media (max-width: 1200px) {
            .skills-drilldown {
                grid-template-columns: 1fr;
            }
        }

        .skill-bar-container {
            background-color: rgba(0,0,0,0.3);
            height: 16px;
            border-radius: 0;
            overflow: hidden;
            margin-top: 4px;
            border: 1px solid rgba(255,255,255,0.1);
        }

        .skill-bar {
            height: 100%;
            background: linear-gradient(90deg, #5a7840 0%, var(--gold) 100%);
            transition: width 0.5s ease;
            box-shadow: 0 0 10px rgba(90, 138, 64, 0.5);
        }

        #chat-box {
            background-color: rgba(0,0,0,0.3);
            padding: 10px;
            border-radius: 0;
            height: 150px;
            overflow-y: auto;
            font-size: var(--fs-ui);
            border: 1px solid rgba(200, 160, 80, 0.1);
        }

        #chat-box::-webkit-scrollbar {
            width: 6px;
        }

        #chat-box::-webkit-scrollbar-track {
            background: rgba(0,0,0,0.2);
        }

        #chat-box::-webkit-scrollbar-thumb {
            background: rgba(200, 160, 80, 0.3);
            border-radius: 0;
        }

        .chat-message {
            margin: 4px 0;
            padding: 3px 6px;
            border-radius: 0;
            background-color: rgba(255,255,255,0.05);
        }

        .system-message {
            color: var(--gold-light);
            font-style: italic;
            background-color: rgba(243, 156, 18, 0.1);
        }

        #status {
            margin-bottom: 20px;
            padding: 12px 24px;
            background: linear-gradient(135deg, var(--stone-mid) 0%, var(--stone-dark) 100%);
            border-radius: 0;
            text-align: center;
            font-weight: bold;
            box-shadow: 0 4px 12px rgba(90, 138, 64, 0.4);
            animation: statusPulse 2s ease-in-out infinite;
            border: 1px solid #5a8a40;
            color: #fff;
            font-size: var(--fs-title);
        }

        @keyframes statusPulse {
            0%, 100% { box-shadow: 0 4px 12px rgba(90, 138, 64, 0.4); }
            50% { box-shadow: 0 4px 20px rgba(90, 138, 64, 0.6); }
        }

        #status.disconnected {
            background: linear-gradient(135deg, var(--color-hp-low) 0%, var(--color-danger) 100%);
            box-shadow: 0 4px 12px rgba(138, 48, 32, 0.4);
            animation: none;
            border-color: var(--color-hp-low);
        }

        #login-screen {
            position: fixed;
            inset: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: #0a0804;
            z-index: var(--z-panel);
            overflow: hidden;
            animation: fadeIn 0.5s;
        }

        #login-screen::before {
            content: '';
            position: absolute;
            inset: 0;
            background: radial-gradient(ellipse 60% 50% at 50% 42%,
                rgba(200,160,80,0.09) 0%, transparent 70%);
            pointer-events: none;
        }

        #login-screen::after {
            content: '';
            position: absolute;
            inset: 0;
            background: radial-gradient(ellipse 100% 100% at 50% 50%,
                transparent 40%, rgba(0,0,0,0.7) 100%);
            pointer-events: none;
        }

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

        #login-screen.hidden {
            display: none;
        }

        .login-particle {
            position: absolute;
            background: var(--gold);
            border-radius: 50%;
            animation: loginParticleFloat 3.5s ease-in-out infinite;
            pointer-events: none;
        }

        @keyframes loginParticleFloat {
            0%   { transform: translateY(0px) translateX(0px); opacity: 0.4; }
            50%  { transform: translateY(-24px) translateX(4px); opacity: 0.7; }
            100% { transform: translateY(0px) translateX(0px); opacity: 0.4; }
        }

        @keyframes popIn {
            from { transform: scale(0.8); opacity: 0; }
            to { transform: scale(1); opacity: 1; }
        }

        #controls {
            margin-top: 15px;
            padding: 16px 24px;
            background: linear-gradient(135deg, rgba(78, 70, 48, 0.9) 0%, rgba(62, 56, 39, 0.9) 100%);
            border-radius: 0;
            text-align: center;
            border: 2px solid #5f533d;
            box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        #controls p {
            margin: 6px 0;
            font-size: var(--fs-title);
            color: #eadfc2;
        }

        #controls strong {
            color: #f2d17b;
        }

        #controls button {
            background: linear-gradient(135deg, #5f533d 0%, #4b4438 100%);
            color: #f2d17b;
            border: 1px solid #d4af37;
            padding: 8px 16px;
            margin: 5px;
            border-radius: 0;
            cursor: pointer;
            font-weight: bold;
            font-size: var(--fs-ui);
            transition: all 0.3s;
        }

        #controls button:hover {
            background: linear-gradient(135deg, #6b5f47 0%, #574f3f 100%);
            box-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
            color: #d4af37;
        }

        .player-list-item {
            padding: 6px 10px;
            margin: 4px 0;
            background-color: rgba(200, 160, 80, 0.06);
            border-radius: 0;
            border-left: 3px solid var(--gold);
            transition: all 0.3s;
        }

        .player-list-item:hover {
            background-color: rgba(200, 160, 80, 0.1);
        }

        #click-indicator {
            position: absolute;
            pointer-events: none;
            width: 20px;
            height: 20px;
            border: 2px solid var(--gold);
            border-radius: 50%;
            animation: clickPing 0.6s ease-out;
            opacity: 0;
        }

        @keyframes clickPing {
            0% {
                transform: scale(0.5);
                opacity: 1;
            }
            100% {
                transform: scale(2);
                opacity: 0;
            }
        }

        #map-toggle-btn {
            margin-top: 12px;
            padding: 10px 18px;
            border: none;
            border-radius: 0;
            color: #ffffff;
            font-weight: bold;
            cursor: pointer;
            font-family: 'Courier New', monospace;
            background: linear-gradient(135deg, var(--stone-light) 0%, var(--stone-mid) 100%);
            box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        }

        #map-toggle-btn:hover {
            background: linear-gradient(135deg, var(--stone-light) 0%, #2a2018 100%);
        }

        #map-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.65);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: var(--z-modal);
        }

        #map-modal.visible {
            display: flex;
        }

        #map-panel {
            padding: 0;
            max-width: 96vw;
            max-height: 92vh;
        }

        #map-canvas {
            border-top: 1px solid var(--stone-light);
            border-radius: 0;
            background: #2f4f2f;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            cursor: grab;
            display: block;
            max-width: 92vw;
            max-height: 78vh;
            margin: 0;
        }
        #map-canvas.dragging { cursor: grabbing; }
        #map-controls {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-left: auto;
            margin-right: 12px;
        }
        #map-controls button {
            background: rgba(20, 17, 11, 0.7);
            color: var(--stone-text);
            border: 1px solid var(--stone-light);
            padding: 4px 10px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            line-height: 1;
            cursor: pointer;
            min-width: 28px;
            transition: background 0.12s, border-color 0.12s, color 0.12s;
        }
        #map-controls button:hover {
            background: rgba(58, 48, 32, 0.85);
            border-color: var(--gold);
            color: var(--gold-light);
        }
        #map-zoom-readout {
            color: var(--stone-muted);
            font-size: var(--fs-fine);
            min-width: 52px;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            font-variant-numeric: tabular-nums;
        }

        /* Trade modal: contained within #canvas-wrap, matches the crafting /
           tanning / economy pattern — no fullscreen overlay. */
        #trade-modal {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: none;
            align-items: stretch;
            justify-content: center;
            z-index: var(--z-hud-overlay);
            pointer-events: none;
            padding: 10px 12px;
        }
        #trade-modal > * { pointer-events: auto; }

        #trade-modal.visible {
            display: flex;
        }

        #trade-panel {
            width: calc(100% - 2px);
            max-width: 100%;
            max-height: 100%;
            max-height: 90vh;
            display: flex;
            flex-direction: column;
            background: linear-gradient(160deg, rgba(44, 38, 28, 0.98) 0%, rgba(30, 25, 18, 0.98) 100%);
            border: 2px solid rgba(180, 150, 80, 0.5);
            border-radius: 0;
            box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 220, 120, 0.1);
            overflow: hidden;
        }

        #trade-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 16px 10px;
            background: linear-gradient(180deg, rgba(90, 72, 35, 0.6) 0%, rgba(50, 40, 20, 0.4) 100%);
            border-bottom: 1px solid rgba(180, 150, 80, 0.3);
            flex-shrink: 0;
        }

        #trade-header h3 {
            margin: 0;
            font-size: var(--fs-title);
            color: #f0d070;
            font-family: Georgia, serif;
            letter-spacing: 0.03em;
        }

        #trade-close-btn {
            border: 1px solid rgba(180, 150, 80, 0.4);
            border-radius: 0;
            padding: 4px 10px;
            cursor: pointer;
            color: #e8d4a0;
            font-weight: bold;
            font-size: var(--fs-title);
            background: rgba(100, 40, 30, 0.7);
            flex-shrink: 0;
        }
        #trade-close-btn:hover { background: rgba(150, 50, 35, 0.8); }

        #trade-gold {
            padding: 8px 16px;
            font-size: var(--fs-fine);
            color: var(--stone-muted);
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            flex-shrink: 0;
            display: flex;
            gap: 18px;
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }

        #trade-gold span {
            color: var(--gold-light);
            font-weight: normal;
            font-variant-numeric: tabular-nums;
        }

        #trade-items {
            display: grid;
            grid-template-columns: repeat(6, 1fr);
            gap: 8px;
            padding: 12px;
            overflow-y: auto;
            flex: 1;
        }

        #trade-items::-webkit-scrollbar { width: 6px; }
        #trade-items::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
        #trade-items::-webkit-scrollbar-thumb { background: rgba(180,150,80,0.4); border-radius: 0; }

        .shop-card {
            display: flex;
            flex-direction: column;
            align-items: center;
            background: rgba(20, 17, 11, 0.75);
            border: 1px solid var(--stone-light);
            border-radius: 0;
            padding: 10px 8px 8px;
            cursor: default;
            transition: border-color 0.15s, background 0.15s, transform 0.15s;
            gap: 6px;
        }
        .shop-card:hover {
            border-color: var(--gold-dark);
            background: rgba(58, 48, 32, 0.6);
        }

        .shop-card-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(8, 6, 4, 0.75);
            border: 1px solid var(--stone-light);
            border-radius: 0;
            overflow: hidden;
            flex-shrink: 0;
        }
        .shop-card-icon img {
            width: 40px;
            height: 40px;
            object-fit: contain;
            image-rendering: pixelated;
        }
        .shop-card-icon .icon-emoji {
            font-size: var(--fs-hero);
            line-height: 1;
        }

        .shop-card-name {
            font-size: var(--fs-body);
            font-weight: normal;
            color: var(--gold-light);
            text-align: center;
            line-height: 1.25;
            min-height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            letter-spacing: 0.02em;
        }

        .shop-card-owned {
            font-size: var(--fs-fine);
            color: var(--color-positive);
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            font-variant-numeric: tabular-nums;
        }
        .shop-card-owned.none { color: var(--stone-muted); }

        .shop-card-prices {
            display: flex;
            gap: 8px;
            font-size: var(--fs-fine);
            color: var(--stone-muted);
            width: 100%;
            justify-content: center;
            font-variant-numeric: tabular-nums;
        }
        .shop-card-prices .buy-p { color: var(--color-positive); }
        .shop-card-prices .sell-p { color: var(--color-other-player); }

        .shop-card-btns {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 4px;
            width: 100%;
            margin-top: 4px;
        }
        .shop-card-btns button {
            border: 1px solid var(--stone-light);
            border-radius: 0;
            padding: 5px 0;
            cursor: pointer;
            font-size: var(--fs-fine);
            font-weight: normal;
            color: var(--stone-text);
            line-height: 1.2;
            white-space: nowrap;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            transition: background 0.12s, border-color 0.12s, color 0.12s;
            background: rgba(20, 17, 11, 0.7);
        }
        .trade-buy:hover  { background: rgba(58, 110, 42, 0.4); border-color: var(--color-positive); color: #fff; }
        .trade-sell:hover { background: rgba(42, 78, 110, 0.4); border-color: var(--color-other-player); color: #fff; }
        .shop-card-btns button:disabled { opacity: 0.4; cursor: not-allowed; }
        /* Faction rank-gated stock: shown but not buyable below the standing. */
        .shop-lock {
            grid-column: 1 / -1;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 4px;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.06em;
            color: var(--gold-light);
            padding: 4px 0;
        }
        .shop-lock img { width: 12px; height: 12px; image-rendering: pixelated; }
        .shop-card.locked { opacity: 0.86; }

        #trade-message {
            padding: 8px 16px;
            font-size: var(--fs-body);
            color: var(--stone-text);
            min-height: 24px;
            text-align: center;
            background: rgba(8, 6, 4, 0.5);
            font-style: italic;
            border-top: 1px solid rgba(180,150,80,0.15);
            flex-shrink: 0;
        }

        #courier-modal,
        #letter-composer-modal,
        #mail-dispatch-modal,
        #confirm-modal,
        #bank-modal,
        #party-modal,
        #band-modal,
        #auction-modal,
        #dialogue-modal,
        #quest-journal-modal {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.65);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: var(--z-modal-high);
        }

        #courier-modal.visible,
        #letter-composer-modal.visible,
        #mail-dispatch-modal.visible,
        #confirm-modal.visible,
        #bank-modal.visible,
        #party-modal.visible,
        #band-modal.visible,
        #auction-modal.visible,
        #dialogue-modal.visible,
        #quest-journal-modal.visible {
            display: flex;
        }

        #courier-panel,
        #letter-composer-panel,
        #mail-dispatch-panel,
        #confirm-panel,
        #bank-panel,
        #party-panel,
        #band-panel,
        #auction-panel,
        #dialogue-panel,
        #quest-journal-panel {
            width: 760px;
            max-width: 96vw;
            max-height: 90vh;
            display: flex;
            flex-direction: column;
            background: linear-gradient(160deg, rgba(44, 38, 28, 0.98) 0%, rgba(30, 25, 18, 0.98) 100%);
            border: 2px solid rgba(180, 150, 80, 0.5);
            border-radius: 0;
            box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 220, 120, 0.1);
            overflow: hidden;
        }

        #letter-composer-panel {
            width: 640px;
        }

        /* Courier + letter composer headers — let the shared .panel-header
           style (modal.css) handle the chrome; only tweak per-instance bits. */

        #courier-meta,
        #courier-actions,
        #letter-composer-message,
        #courier-message {
            padding: 8px 16px;
            font-size: var(--fs-fine);
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            color: var(--stone-muted);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }

        #courier-meta {
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
        }
        #courier-meta strong {
            color: var(--gold-light);
            font-weight: normal;
            font-variant-numeric: tabular-nums;
        }

        #courier-actions {
            display: flex;
            justify-content: flex-end;
            text-transform: none;
            letter-spacing: 0;
        }

        /* Shared action-button rule for courier / mail / confirm / bank / party / auction
           non-state buttons — flat dark, gold-dark border, brightens on hover.
           State variants (send/cancel/active) override below. */
        #courier-compose-btn,
        #letter-composer-actions button,
        .courier-action-btn,
        #mail-dispatch-add-attachment-btn,
        #mail-dispatch-actions button,
        #confirm-actions button,
        #bank-deposit-all-btn,
        .bank-slot-action,
        .bank-inv-action,
        #party-modal-actions button,
        .party-loot-btn,
        #band-modal-actions button,
        #band-found-btn,
        #band-invite-btn,
        #auction-search-btn,
        #auction-prev-page-btn,
        #auction-next-page-btn,
        #auction-sell-confirm-btn,
        .auction-row-btn {
            border: 1px solid var(--gold-dark);
            border-radius: 0;
            padding: 6px 14px;
            cursor: pointer;
            background: var(--stone-mid);
            color: var(--gold-light);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            font-weight: normal;
            letter-spacing: 0.06em;
            text-transform: uppercase;
            transition: background 0.12s, border-color 0.12s, color 0.12s;
        }
        #courier-compose-btn:hover,
        #letter-composer-actions button:hover,
        .courier-action-btn:hover,
        #mail-dispatch-add-attachment-btn:hover,
        #mail-dispatch-actions button:hover,
        #confirm-actions button:hover,
        #bank-deposit-all-btn:hover,
        .bank-slot-action:hover,
        .bank-inv-action:hover,
        #party-modal-actions button:hover,
        .party-loot-btn:hover,
        #auction-search-btn:hover,
        #auction-prev-page-btn:hover,
        #auction-next-page-btn:hover,
        #auction-sell-confirm-btn:hover,
        .auction-row-btn:hover {
            background: var(--stone-light);
            border-color: var(--gold);
            color: #fff;
        }
        #courier-compose-btn:disabled,
        .courier-action-btn:disabled,
        #mail-dispatch-actions button:disabled,
        #auction-sell-confirm-btn:disabled {
            cursor: not-allowed;
            opacity: 0.4;
        }
        /* Affirmative action variants — green-tinted */
        .courier-action-btn.send,
        #letter-composer-save-btn,
        #mail-dispatch-send-btn,
        #confirm-ok-btn {
            border-color: var(--color-positive);
            color: #a0e8b0;
            background: rgba(45, 106, 63, 0.2);
        }
        .courier-action-btn.send:hover,
        #letter-composer-save-btn:hover,
        #mail-dispatch-send-btn:hover,
        #confirm-ok-btn:hover {
            background: rgba(58, 128, 80, 0.45);
            color: #fff;
        }
        /* Cancel / destructive variants — red-tinted (ghost) */
        .courier-action-btn.ghost,
        #letter-composer-cancel-btn,
        #mail-dispatch-cancel-btn,
        #confirm-cancel-btn,
        #party-leave-btn,
        #party-disband-btn {
            background: rgba(20, 17, 11, 0.6);
            border-color: var(--stone-light);
            color: var(--stone-muted);
        }
        .courier-action-btn.ghost:hover,
        #letter-composer-cancel-btn:hover,
        #mail-dispatch-cancel-btn:hover,
        #confirm-cancel-btn:hover,
        #party-leave-btn:hover,
        #party-disband-btn:hover {
            background: rgba(58, 48, 32, 0.7);
            border-color: var(--gold-dark);
            color: var(--stone-text);
        }
        .party-loot-btn.active {
            background: rgba(58, 44, 16, 0.85);
            border-color: var(--gold);
            color: var(--gold-light);
        }
        .party-loot-hint {
            margin-top: 8px;
            font-size: var(--fs-fine);
            color: var(--stone-muted);
            font-style: italic;
            line-height: 1.5;
        }

        #loot-roll-tray {
            position: absolute;
            top: 180px;
            right: 10px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            z-index: var(--z-hud-overlay);
            pointer-events: auto;
            max-width: 240px;
        }
        .loot-roll-card {
            min-width: 220px;
            background: rgba(12, 9, 5, 0.85);
            border: 1px solid var(--gold-dark);
            color: var(--stone-text);
            font-family: Georgia, serif;
            padding: 10px 12px;
            font-size: var(--fs-body);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
            backdrop-filter: blur(2px);
        }
        .loot-roll-card .lrc-title {
            font-weight: normal;
            color: var(--gold-light);
            margin-bottom: 4px;
            font-size: var(--fs-body);
            letter-spacing: 0.02em;
        }
        .loot-roll-card .lrc-meta {
            color: var(--stone-muted);
            font-size: var(--fs-fine);
            margin-bottom: 8px;
            text-transform: uppercase;
            letter-spacing: 0.06em;
        }
        .loot-roll-card .lrc-actions {
            display: flex;
            gap: 6px;
        }
        .loot-roll-card button {
            flex: 1;
            background: rgba(20, 17, 11, 0.75);
            color: var(--stone-text);
            border: 1px solid var(--color-positive);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            padding: 5px 8px;
            cursor: pointer;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: background 0.12s, color 0.12s;
        }
        .loot-roll-card button:hover {
            background: rgba(58, 128, 80, 0.45);
            color: #fff;
        }
        .loot-roll-card button.lrc-pass {
            border-color: rgba(138, 48, 48, 0.85);
            color: var(--color-hp-low);
        }
        .loot-roll-card button.lrc-pass:hover {
            background: rgba(138, 48, 48, 0.5);
            color: #fff;
        }
        .loot-roll-card.voted .lrc-actions { display: none; }
        .loot-roll-card.voted .lrc-result {
            color: var(--gold);
            font-style: italic;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }

        /* Tier 2 Phase 7: Phase 7 skills surface inside the existing
           left-hud skills tree (not a separate modal). The `.skills-node`
           styling from the existing tree is reused; the Phase 7-specific
           image-rendering hint just keeps the 32×32 pixel art crisp. */
        .skills-node .skills-node-icon {
            width: 16px;
            height: 16px;
            image-rendering: pixelated;
            vertical-align: middle;
            margin-right: 4px;
        }

        #courier-tabs {
            display: flex;
            gap: 0;
            padding: 0 16px;
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            flex-shrink: 0;
        }

        .courier-tab-btn {
            border: none;
            border-bottom: 2px solid transparent;
            background: transparent;
            color: var(--stone-muted);
            padding: 8px 14px;
            font-size: var(--fs-body);
            cursor: pointer;
            font-family: Georgia, serif;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: color 0.12s, border-bottom-color 0.12s;
        }
        .courier-tab-btn:hover { color: var(--gold-light); }
        .courier-tab-btn.active {
            color: var(--gold-light);
            border-bottom-color: var(--gold);
        }

        #courier-content {
            padding: 14px 16px 16px;
            overflow-y: auto;
            flex: 1;
            background: var(--stone-dark);
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .courier-empty {
            padding: 28px 14px;
            text-align: center;
            color: var(--stone-muted);
            border: 1px dashed var(--stone-light);
            background: rgba(8, 6, 4, 0.4);
            font-style: italic;
        }

        .courier-card {
            border-left: 3px solid var(--gold-dark);
            background: rgba(20, 17, 11, 0.7);
            border-radius: 0;
            padding: 12px 14px;
            display: flex;
            flex-direction: column;
            gap: 8px;
            transition: border-left-color 0.15s, background 0.15s;
        }
        .courier-card:hover { background: rgba(58, 48, 32, 0.5); }

        .courier-card.unread {
            border-left-color: var(--gold);
            background: rgba(58, 44, 16, 0.4);
        }

        .courier-card-top {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 12px;
        }

        .courier-card-top h4 {
            margin: 0 0 4px;
            color: var(--gold-light);
            font-size: var(--fs-ui);
            font-family: Georgia, serif;
            font-weight: normal;
            letter-spacing: 0.02em;
        }

        .courier-card-meta {
            color: var(--stone-muted);
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.06em;
        }

        .courier-badge {
            align-self: flex-start;
            border-radius: 0;
            padding: 2px 8px;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.1em;
            border: 1px solid;
            background: transparent;
        }
        .courier-badge.draft  { color: var(--stone-muted); border-color: var(--stone-muted); }
        .courier-badge.sealed { color: var(--gold); border-color: var(--gold); }
        .courier-badge.unread { color: var(--color-hp-low); border-color: var(--color-hp-low); }
        .courier-badge.read   { color: var(--color-positive); border-color: var(--color-positive); }

        .courier-letter-body {
            margin: 0;
            padding: 12px 14px;
            background: rgba(8, 6, 4, 0.55);
            border-left: 3px solid var(--gold-dark);
            color: var(--stone-text);
            white-space: pre-wrap;
            font-family: Georgia, serif;
            line-height: 1.55;
            font-size: var(--fs-body);
        }

        .courier-card-actions,
        #letter-composer-actions {
            display: flex;
            justify-content: flex-end;
            gap: 8px;
            flex-wrap: wrap;
        }

        #letter-composer-body {
            display: flex;
            flex-direction: column;
            gap: 14px;
            padding: 16px;
            background: var(--stone-dark);
        }

        .letter-field {
            display: flex;
            flex-direction: column;
            gap: 5px;
            color: var(--stone-muted);
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }

        .letter-field input,
        .letter-field textarea {
            width: 100%;
            border: 1px solid var(--stone-light);
            background: rgba(8, 6, 4, 0.85);
            color: var(--stone-text);
            padding: 8px 12px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            resize: vertical;
            text-transform: none;
            letter-spacing: 0;
        }
        .letter-field input:focus,
        .letter-field textarea:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold-dark);
        }

        .letter-field textarea {
            min-height: 180px;
        }

        #mail-dispatch-panel {
            width: 560px;
        }
        #confirm-panel {
            width: 440px;
        }

        /* Medicine: active status-effect chips (afflictions, buffs),
           top-center on the canvas. Red ring = debuff/dot/cc (medicine
           cures these), gold ring = buff/hot. Tooltip carries the
           cure hint. */
        #self-effects-bar {
            position: absolute;
            top: 46px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 6px;
            max-width: 60%;
            z-index: var(--z-hud);
            pointer-events: none;
        }
        .self-effect-chip {
            background: rgba(12, 9, 5, 0.78);
            border: 1px solid rgba(200, 160, 80, 0.35);
            padding: 2px 8px;
            display: flex;
            align-items: baseline;
            gap: 6px;
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            color: var(--stone-text);
            text-shadow: 0 1px 2px rgba(0,0,0,0.95);
            pointer-events: auto;
            backdrop-filter: blur(2px);
        }
        .self-effect-chip[data-category="debuff"],
        .self-effect-chip[data-category="dot"],
        .self-effect-chip[data-category="cc"] {
            border-color: rgba(205, 75, 60, 0.65);
        }
        .self-effect-chip[data-category="debuff"] .se-name,
        .self-effect-chip[data-category="dot"] .se-name,
        .self-effect-chip[data-category="cc"] .se-name {
            color: #e08a78;
        }
        .self-effect-chip .se-time {
            opacity: 0.7;
        }

        /* Tier 2 Phase 5: party HUD lives on the canvas, top-left.
           Empty when solo; renders 1–4 ally cards (leader card excluded
           since "you" already see your own HP elsewhere). */
        #party-hud {
            position: absolute;
            top: 72px;
            left: 10px;
            display: flex;
            flex-direction: column;
            gap: 4px;
            z-index: var(--z-hud);
            pointer-events: none;
        }
        .party-hud-card {
            background: rgba(12, 9, 5, 0.72);
            border: 1px solid rgba(200, 160, 80, 0.28);
            padding: 4px 8px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            min-width: 188px;
            display: flex;
            flex-direction: column;
            gap: 3px;
            pointer-events: auto;
            text-shadow: 0 1px 2px rgba(0,0,0,0.95);
            backdrop-filter: blur(2px);
        }
        .party-hud-card .pname {
            display: flex;
            justify-content: space-between;
            gap: 6px;
            align-items: center;
        }
        .party-hud-card .pname .leader-mark {
            color: var(--gold-light);
            font-size: 12px;
            letter-spacing: 0.05em;
        }
        .party-hud-card .hp-track {
            background: var(--stone-mid);
            height: 6px;
            border: 1px solid rgba(0,0,0,0.45);
        }
        .party-hud-card .hp-fill {
            background: linear-gradient(180deg, var(--color-hp-high) 0%, var(--color-hp-high-dark) 100%);
            height: 100%;
        }
        .party-hud-card .hp-fill.low { background: linear-gradient(180deg, var(--color-hp-low) 0%, var(--color-hp-low-dark) 100%); }
        .party-hud-card .pmeta {
            color: var(--stone-muted);
            font-size: 12px;
        }
        .party-hud-card.offmap {
            opacity: 0.6;
        }

        /* Party panel (modal). */
        #party-panel {
            width: 460px;
        }
        #party-modal-body {
            padding: 14px 16px;
            background: var(--stone-dark);
            display: flex;
            flex-direction: column;
            gap: 14px;
        }
        #party-modal-meta {
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }
        .party-section-title {
            color: var(--gold);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.14em;
            margin-bottom: 6px;
            padding-bottom: 4px;
            border-bottom: 1px solid var(--stone-light);
        }
        #party-loot-buttons {
            display: flex;
            gap: 6px;
        }
        .party-loot-btn {
            flex: 1;
            font-size: 14px !important;
            padding: 5px 6px !important;
        }
        #party-modal-members {
            display: flex;
            flex-direction: column;
            gap: 6px;
        }
        .party-member-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 6px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 4px 6px;
            background: rgba(0,0,0,0.18);
            border: 1px solid rgba(180, 150, 80, 0.15);
        }
        .party-member-row .pmem-name {
            flex: 1;
            word-break: break-word;
        }
        .party-member-row .pmem-actions button {
            font-size: 13px !important;
            padding: 3px 8px !important;
        }
        #party-modal-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
            padding: 12px 16px;
            background: #14110b;
        }

        /* Bands panel — mirrors the party modal chrome with a wider roster
           (rank + status columns + per-member actions). */
        #band-panel {
            width: 520px;
        }
        #band-modal-body {
            padding: 14px 16px;
            background: var(--stone-dark);
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        #band-modal-meta {
            color: var(--gold-light);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }
        .band-action-row {
            display: flex;
            gap: 8px;
            align-items: center;
            flex-wrap: wrap;
        }
        .band-action-row input {
            flex: 1;
            min-width: 160px;
            padding: 6px 10px;
            background: rgba(0,0,0,0.35);
            border: 1px solid var(--gold-dark);
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
        }
        .band-hint {
            flex-basis: 100%;
            color: var(--stone-muted);
            font-size: var(--fs-fine);
            font-style: italic;
        }
        #band-modal-error {
            display: none;
            color: var(--osrs-orange, #e8a33d);
            font-size: var(--fs-fine);
            margin-top: 4px;
        }
        #band-modal-members {
            display: flex;
            flex-direction: column;
            gap: 6px;
            max-height: 46vh;
            overflow-y: auto;
        }
        .band-member-row {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 5px 8px;
            background: rgba(0,0,0,0.18);
            border: 1px solid rgba(180, 150, 80, 0.15);
        }
        .band-member-row .bmem-name {
            flex: 1;
            word-break: break-word;
        }
        .band-member-row .bmem-role {
            color: var(--gold);
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.06em;
            min-width: 86px;
        }
        .band-member-row .bmem-status {
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.05em;
            min-width: 56px;
            text-align: right;
        }
        .band-member-row .bmem-status.on { color: #7fc77f; }
        .band-member-row .bmem-status.hall { color: var(--gold-light); }
        .band-member-row .bmem-status.off { color: var(--stone-muted); }
        .band-member-row .bmem-actions button {
            font-size: 13px !important;
            padding: 3px 8px !important;
        }
        #band-modal-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
            padding: 12px 16px;
            background: #14110b;
        }

        /* Tier 2 Phase 6: auction-house window. Wide panel with a tab
           strip + per-tab pane. Reuses the courier tab pattern. */
        #auction-panel { width: 820px; max-width: 96vw; max-height: 90vh; }
        #auction-tabs {
            display: flex;
            gap: 0;
            padding: 0 16px;
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            flex-shrink: 0;
        }
        .auction-tab-btn {
            border: none;
            border-bottom: 2px solid transparent;
            background: transparent;
            color: var(--stone-muted);
            padding: 8px 14px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            cursor: pointer;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: color 0.12s, border-bottom-color 0.12s;
        }
        .auction-tab-btn:hover { color: var(--gold-light); }
        .auction-tab-btn.active {
            color: var(--gold-light);
            border-bottom-color: var(--gold);
        }
        #auction-body {
            padding: 14px 16px;
            background: var(--stone-dark);
            overflow-y: auto;
            max-height: 60vh;
        }
        .auction-pane { display: block; }
        .auction-toolbar {
            display: flex;
            gap: 8px;
            margin-bottom: 12px;
            align-items: center;
        }
        #auction-search-input {
            flex: 1;
            background: rgba(8, 6, 4, 0.85);
            color: var(--stone-text);
            border: 1px solid var(--stone-light);
            padding: 7px 10px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
        }
        #auction-search-input:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold-dark);
        }
        #auction-page-label {
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            min-width: 70px;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            font-variant-numeric: tabular-nums;
        }
        #auction-browse-list,
        #auction-my-list {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        .auction-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
            background: rgba(20, 17, 11, 0.7);
            border: 1px solid var(--stone-light);
            padding: 8px 12px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            transition: border-color 0.12s, background 0.12s;
        }
        .auction-row:hover { border-color: var(--gold-dark); background: rgba(58, 48, 32, 0.55); }
        .auction-row .ar-icon {
            width: 42px;
            height: 42px;
            flex-shrink: 0;
            background: rgba(8, 6, 4, 0.7);
            border: 1px solid var(--stone-light);
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }
        .auction-row .ar-icon img {
            max-width: 36px;
            max-height: 36px;
            image-rendering: pixelated;
        }
        .auction-row .ar-icon-fallback {
            display: none;
            width: 100%;
            height: 100%;
            align-items: center;
            justify-content: center;
            font-size: var(--fs-title);
        }
        .auction-row .ar-text { flex: 1; min-width: 0; }
        .auction-row .ar-item { word-break: break-word; color: var(--gold-light); }
        .auction-row .ar-meta { color: var(--stone-muted); font-size: var(--fs-fine); text-transform: uppercase; letter-spacing: 0.06em; }
        .auction-row .ar-price {
            color: var(--gold-light);
            font-weight: normal;
            min-width: 96px;
            text-align: right;
            font-variant-numeric: tabular-nums;
        }
        .auction-row .ar-price::before {
            content: '◆ ';
            color: var(--gold);
            font-size: var(--fs-fine);
        }
        .auction-row .ar-state {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 0;
            border: 1px solid;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            margin-left: 6px;
            background: transparent;
        }
        .auction-row .ar-state.active    { color: var(--color-positive); border-color: var(--color-positive); }
        .auction-row .ar-state.sold      { color: var(--color-other-player); border-color: var(--color-other-player); }
        .auction-row .ar-state.expired   { color: var(--stone-muted); border-color: var(--stone-muted); }
        .auction-row .ar-state.cancelled { color: var(--color-hp-low); border-color: var(--color-hp-low); }
        .auction-row-btn { padding: 4px 10px !important; font-size: var(--fs-fine) !important; }
        .auction-sell-form {
            display: flex;
            flex-direction: column;
            gap: 12px;
            max-width: 480px;
        }
        .auction-form-row {
            display: flex;
            flex-direction: column;
            gap: 5px;
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }
        .auction-form-row select,
        .auction-form-row input {
            background: rgba(8, 6, 4, 0.85);
            color: var(--stone-text);
            border: 1px solid var(--stone-light);
            padding: 7px 10px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            text-transform: none;
            letter-spacing: 0;
        }
        .auction-form-row select:focus,
        .auction-form-row input:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold-dark);
        }
        #auction-sell-preview {
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            line-height: 1.5;
            background: rgba(20, 17, 11, 0.6);
            padding: 10px 14px;
            border-left: 3px solid var(--gold-dark);
        }
        #auction-sell-confirm-btn {
            align-self: flex-start;
            padding: 8px 22px !important;
            font-size: var(--fs-body) !important;
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }
        #auction-message {
            padding: 8px 16px 12px;
            min-height: 22px;
            color: #cfbe8f;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            background: #14110b;
        }

        /* Tier 2 Phase 3: bank window. Wide panel — grid on the left,
           inventory side-rail on the right. Tabs sit between the meta
           bar and the body so the layout reads top-down. */
        #bank-panel {
            width: 880px;
            max-width: 96vw;
            max-height: 92vh;
        }
        #bank-meta {
            padding: 8px 16px;
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            background: rgba(8, 6, 4, 0.5);
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }
        #bank-actions {
            display: flex;
            gap: 8px;
            padding: 10px 16px;
            background: rgba(20, 17, 11, 0.6);
            border-bottom: 1px solid var(--stone-light);
        }
        #bank-tabs {
            display: flex;
            gap: 0;
            padding: 0 16px;
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
            flex-shrink: 0;
        }
        .bank-tab-btn {
            border: none;
            border-bottom: 2px solid transparent;
            background: transparent;
            color: var(--stone-muted);
            padding: 8px 14px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            cursor: pointer;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: color 0.12s, border-bottom-color 0.12s;
        }
        .bank-tab-btn:hover { color: var(--gold-light); }
        .bank-tab-btn.active {
            color: var(--gold-light);
            border-bottom-color: var(--gold);
        }
        #bank-body {
            display: flex;
            gap: 14px;
            padding: 14px 16px 16px;
            background: var(--stone-dark);
            overflow: hidden;
        }
        #bank-grid {
            flex: 1;
            display: grid;
            grid-template-columns: repeat(10, 1fr);
            gap: 5px;
            align-content: start;
            overflow-y: auto;
            max-height: 56vh;
            padding-right: 4px;
        }
        .bank-slot {
            position: relative;
            min-height: 56px;
            border: 1px solid var(--stone-light);
            background: rgba(20, 17, 11, 0.7);
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            padding: 4px 5px;
            line-height: 1.2;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            transition: border-color 0.12s, background 0.12s;
        }
        .bank-slot.empty {
            cursor: default;
            background: rgba(8, 6, 4, 0.5);
            border-style: dashed;
            border-color: rgba(58, 48, 32, 0.6);
        }
        .bank-slot.occupied:hover {
            background: rgba(58, 48, 32, 0.6);
            border-color: var(--gold-dark);
        }
        .bank-slot .item-id {
            color: var(--gold-light);
            font-weight: normal;
            word-break: break-word;
            font-size: var(--fs-fine);
            line-height: 1.15;
        }
        .bank-slot .item-meta {
            color: var(--stone-muted);
            font-size: 10px;
            font-variant-numeric: tabular-nums;
        }
        #bank-inv-side {
            width: 260px;
            display: flex;
            flex-direction: column;
            gap: 4px;
            background: rgba(8, 6, 4, 0.6);
            border: 1px solid var(--stone-light);
            padding: 12px;
            overflow-y: auto;
            max-height: 56vh;
        }
        .bank-inv-title {
            color: var(--gold);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.14em;
            border-bottom: 1px solid var(--stone-light);
            padding-bottom: 6px;
            margin-bottom: 6px;
        }
        .bank-inv-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 6px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 4px 0;
            border-bottom: 1px solid rgba(58, 48, 32, 0.35);
        }
        .bank-inv-row:last-child { border-bottom: none; }
        .bank-inv-row:hover { background: rgba(200, 160, 80, 0.06); }
        .bank-inv-row .item-label {
            flex: 1;
            word-break: break-word;
        }
        .bank-inv-action,
        .bank-slot-action {
            padding: 4px 8px !important;
            font-size: 14px !important;
        }
        #bank-message {
            min-height: 22px;
            padding: 6px 16px 10px;
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            font-style: italic;
            text-align: center;
        }
        #confirm-body {
            padding: 20px 24px;
            background: var(--stone-dark);
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            line-height: 1.55;
            text-align: center;
        }
        #confirm-body p { margin: 0; }
        #confirm-actions {
            display: flex;
            gap: 10px;
            justify-content: center;
            padding: 14px 16px;
            background: rgba(8, 6, 4, 0.5);
            border-top: 1px solid var(--stone-light);
        }
        #mail-dispatch-body {
            display: flex;
            flex-direction: column;
            gap: 14px;
            padding: 16px;
            background: var(--stone-dark);
        }
        #mail-dispatch-summary {
            color: var(--stone-text);
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 8px 12px;
            background: rgba(8, 6, 4, 0.5);
            border-left: 3px solid var(--gold-dark);
        }
        .mail-dispatch-section-title {
            color: var(--gold);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            margin-bottom: 8px;
            text-transform: uppercase;
            letter-spacing: 0.14em;
            padding-bottom: 4px;
            border-bottom: 1px solid var(--stone-light);
        }
        .mail-dispatch-attachment-row {
            display: flex;
            gap: 6px;
            margin-bottom: 6px;
            align-items: center;
        }
        .mail-dispatch-attachment-row select,
        .mail-dispatch-attachment-row input.qty,
        #mail-dispatch-cod-input {
            background: rgba(8, 6, 4, 0.85);
            color: var(--stone-text);
            border: 1px solid var(--stone-light);
            padding: 7px 10px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
        }
        .mail-dispatch-attachment-row select:focus,
        .mail-dispatch-attachment-row input.qty:focus,
        #mail-dispatch-cod-input:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold-dark);
        }
        .mail-dispatch-attachment-row select { flex: 1; }
        .mail-dispatch-attachment-row input.qty { width: 86px; font-variant-numeric: tabular-nums; }
        .mail-dispatch-attachment-row button.remove-attach {
            background: rgba(106, 32, 32, 0.25);
            color: var(--color-hp-low);
            border: 1px solid rgba(138, 48, 48, 0.7);
            border-radius: 0;
            padding: 6px 10px;
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            font-weight: normal;
            cursor: pointer;
            transition: background 0.12s, color 0.12s;
        }
        .mail-dispatch-attachment-row button.remove-attach:hover {
            background: rgba(138, 48, 48, 0.5);
            color: #fff;
        }
        #mail-dispatch-actions {
            display: flex;
            gap: 8px;
            justify-content: flex-end;
            padding: 12px 16px;
            background: #14110b;
        }
        #mail-dispatch-message {
            padding: 0 16px;
            min-height: 22px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
        }
        /* Attachment chips + COD badge — mirror the .courier-badge
           pill shape, font, and uppercase treatment so they read as
           the same family as the existing Unread/Read/Sealed pills. */
        .courier-attachment-list {
            margin: 6px 0 8px 0;
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            align-items: center;
        }
        .courier-attachment-chip {
            background: #395046;
            border-radius: 999px;
            padding: 4px 10px;
            color: #f7ecd2;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            letter-spacing: 0.04em;
        }
        .courier-cod-badge {
            background: #6f4b24;
            border-radius: 999px;
            padding: 4px 10px;
            color: #fdecc6;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            margin-left: 4px;
        }

        #crafting-modal {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: none;
            align-items: stretch;
            justify-content: center;
            z-index: var(--z-hud-overlay);
            pointer-events: none;
            padding: 10px 12px;
        }

        #crafting-modal.visible {
            display: flex;
        }

        #crafting-panel {
            width: calc(100% - 2px);
            max-width: calc(100% - 2px);
            height: 100%;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            pointer-events: auto;
        }

        #crafting-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 9px 14px 8px;
            flex-shrink: 0;
        }
        #crafting-header h3 {
            margin: 0;
            font-size: var(--fs-title);
            color: var(--gold-light);
            font-family: Georgia, serif;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            font-weight: normal;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
        }
        #crafting-close-btn {
            border: 1px solid var(--color-danger-dark);
            border-radius: 0;
            padding: 0;
            width: 20px;
            height: 20px;
            min-width: 20px;
            color: #d05040;
            font-weight: bold;
            font-size: var(--fs-ui);
            line-height: 1;
            background: var(--color-danger-bg);
            flex-shrink: 0;
        }
        #crafting-close-btn:hover { background: #601808; color: #ff7060; border-color: #c04030; }

        #crafting-meta {
            padding: 6px 16px;
            font-size: var(--fs-ui);
            color: var(--stone-muted);
            background: #141008;
            border-bottom: 1px solid var(--stone-light);
            flex-shrink: 0;
            display: flex;
            justify-content: space-between;
            gap: 14px;
        }
        #crafting-meta strong { color: var(--gold-light); }

        #crafting-items {
            display: block;
            padding: 10px 12px;
            overflow-x: hidden;
            overflow-y: auto;
            flex: 1;
            background: var(--stone-dark);
        }
        #crafting-items::-webkit-scrollbar { height: 6px; width: 6px; }
        #crafting-items::-webkit-scrollbar-track { background: var(--border-dark); }
        #crafting-items::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 0; }

        .craft-tabs {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            padding: 0 0 10px;
            position: sticky;
            top: 0;
            z-index: 1;
            background: var(--stone-dark);
        }
        .craft-tab-btn {
            border: 1px solid #4a3a22;
            background: #20190f;
            color: #bfa66a;
            padding: 7px 10px;
            font-size: var(--fs-ui);
            line-height: 1.1;
            cursor: pointer;
            text-transform: uppercase;
        }
        .craft-tab-btn.active {
            border-color: var(--gold);
            background: #352816;
            color: #f1d58d;
        }
        .craft-tab-panel {
            padding-top: 2px;
        }
        .craft-group-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 6px;
        }

        .craft-card {
            border-radius: 0;
            border: 1px solid var(--stone-light);
            background: #1e1a10;
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 8px;
            padding: 6px 8px;
            min-width: 0;
        }
        .craft-card:hover {
            border-color: var(--gold);
            background: #2a2418;
        }
        .craft-card .shop-card-icon {
            width: 32px;
            height: 32px;
            flex-shrink: 0;
        }
        .craft-card .shop-card-icon img { width: 26px; height: 26px; }
        .craft-card-info {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 1px;
        }
        .craft-card .shop-card-name {
            color: var(--gold-light);
            text-align: left;
            font-size: var(--fs-ui);
            min-height: 0;
            justify-content: flex-start;
        }
        .craft-card .shop-card-owned {
            font-size: var(--fs-body);
            text-align: left;
        }
        .craft-card .craft-reqs {
            font-size: var(--fs-body);
            text-align: left;
            min-height: 0;
            line-height: 1.3;
        }
        .craft-card .shop-card-prices {
            font-size: var(--fs-body);
            flex-direction: column;
            gap: 1px;
            text-align: left;
            justify-content: flex-start;
        }
        .craft-reqs { font-size: var(--fs-body); color: var(--stone-muted); line-height: 1.25; min-height: 0; }
        .craft-reqs.bad { color: #d07060; }
        .craft-card-btns {
            display: flex;
            flex-direction: column;
            gap: 3px;
            flex-shrink: 0;
            margin-top: 0;
        }
        .craft-card-btns button {
            border: 1px solid var(--stone-light);
            border-radius: 0;
            padding: 4px 10px;
            cursor: pointer;
            font-size: var(--fs-body);
            font-weight: bold;
            color: var(--gold-light);
            line-height: 1.2;
            white-space: nowrap;
            background: var(--stone-mid);
        }
        .craft-card-btns button:hover { background: var(--stone-light); color: #f8d898; border-color: var(--gold); }
        .craft-card-btns button:disabled {
            cursor: not-allowed;
            opacity: 0.5;
            filter: grayscale(0.35);
        }

        #crafting-message {
            padding: 6px 16px;
            font-size: var(--fs-ui);
            color: var(--stone-muted);
            min-height: 22px;
            text-align: center;
            background: #141008;
            border-top: 1px solid var(--stone-light);
            flex-shrink: 0;
        }

        #leaderboard-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.65);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: var(--z-modal-high);
        }

        #leaderboard-modal.visible {
            display: flex;
        }

        #leaderboard-panel {
            width: 520px;
            max-width: 94vw;
            max-height: 82vh;
            display: flex;
            flex-direction: column;
            background: var(--stone-dark);
            border-style: solid;
            border-width: 12px;
            border-image: url('/static/assets/sprites/ui/ui_panel_frame.png') 12 fill / 12px / 0px;
            border-image-width: 12px;
            border-radius: 0;
            padding: 14px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
        }

        #leaderboard-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
        }

        #leaderboard-header h3 {
            margin: 0;
            font-size: var(--fs-title);
            color: var(--gold-light);
        }

        #leaderboard-close-btn {
            border: none;
            border-radius: 0;
            padding: 6px 10px;
            cursor: pointer;
            color: #fff;
            font-weight: bold;
            background: var(--color-danger);
        }

        #leaderboard-tabs {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 4px;
            margin-bottom: 8px;
        }

        /* Legacy sandstone .leaderboard-tab rules removed; canonical lean style
           lives in modal.css (flat tab + gold underline on active). */

        #leaderboard-meta {
            font-size: var(--fs-ui);
            color: #f2ddab;
            margin-bottom: 6px;
        }

        #leaderboard-table-wrap {
            overflow: auto;
            background: rgba(0, 0, 0, 0.22);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 0;
        }

        #leaderboard-table {
            width: 100%;
            border-collapse: collapse;
            font-size: var(--fs-ui);
            color: #ecf0f1;
        }

        #leaderboard-table thead th {
            position: sticky;
            top: 0;
            background: rgba(48, 37, 18, 0.92);
            color: #f6e7be;
            text-align: left;
            padding: 8px 10px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.12);
        }

        #leaderboard-table tbody td {
            padding: 6px 10px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        }

        #leaderboard-table tbody tr:nth-child(even) {
            background: rgba(255, 255, 255, 0.04);
        }

        /* Quest Journal: behaves like the other contained modals (crafting,
           tanning) — absolute-positioned within #canvas-wrap, full canvas
           area with the panel itself centered, no fullscreen overlay. */
        #economy-modal {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: none;
            align-items: stretch;
            justify-content: center;
            z-index: var(--z-hud-overlay);
            pointer-events: none;
            padding: 10px 12px;
        }
        #economy-modal > * { pointer-events: auto; }

        #economy-modal.visible {
            display: flex;
        }

        #economy-panel {
            width: calc(100% - 2px);
            max-width: 100%;
            max-height: 100%;
            align-self: stretch;
            overflow: auto;
            background: var(--stone-dark);
            border-style: solid;
            border-width: 12px;
            border-image: url('/static/assets/sprites/ui/ui_panel_frame.png') 12 fill / 12px / 0px;
            border-image-width: 12px;
            border-radius: 0;
            padding: 12px;
            color: var(--stone-text);
        }

        #economy-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
        }

        .journal-tabs {
            display: flex;
            gap: 0;
            padding: 0 16px;
            margin-bottom: 0;
            background: rgba(8, 6, 4, 0.5);
            border-bottom: 1px solid var(--stone-light);
        }
        .journal-tab {
            background: transparent;
            color: var(--stone-muted);
            border: none;
            border-bottom: 2px solid transparent;
            padding: 8px 14px;
            cursor: pointer;
            font: inherit;
            font-size: var(--fs-body);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: color 0.12s, border-bottom-color 0.12s;
        }
        .journal-tab:hover { color: var(--gold-light); }
        .journal-tab.active {
            color: var(--gold-light);
            background: transparent;
            border-bottom-color: var(--gold);
        }
        .journal-pane {
            flex: 1;
            overflow-y: auto;
            min-height: 0;
        }

        #economy-header h3 {
            margin: 0;
            color: var(--gold-light);
            font-size: var(--fs-title);
        }

        #economy-close-btn {
            width: auto;
            padding: 6px 10px;
        }

        #economy-actions {
            display: flex;
            gap: 8px;
            margin-bottom: 10px;
        }

        #economy-meta {
            margin-bottom: 10px;
            font-size: var(--fs-ui);
            color: #f5e7bf;
        }

        .economy-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
        }

        .economy-card {
            border: 1px solid rgba(255, 255, 255, 0.16);
            border-radius: 0;
            padding: 8px;
            background: rgba(255,255,255,0.05);
        }

        .economy-card h4 {
            margin: 0 0 6px 0;
            font-size: var(--fs-title);
            color: #ffeeb8;
        }

        .economy-table {
            width: 100%;
            border-collapse: collapse;
            font-size: var(--fs-ui);
        }

        .economy-table th,
        .economy-table td {
            text-align: left;
            padding: 4px 6px;
            border-bottom: 1px solid rgba(255,255,255,0.08);
        }

        .contract-list {
            display: flex;
            flex-direction: column;
            gap: 6px;
            max-height: 240px;
            overflow: auto;
        }

        .contract-item {
            border: 1px solid rgba(255,255,255,0.15);
            border-radius: 0;
            padding: 6px;
            background: rgba(0,0,0,0.22);
            font-size: var(--fs-ui);
        }

        .contract-item button {
            margin-top: 5px;
            width: auto;
            padding: 4px 8px;
        }

        #minimap-container {
            position: absolute;
            top: 10px;
            right: 10px;
            width: 132px;
            height: 132px;
            background: rgba(14, 22, 8, 0.78);
            border: 1px solid rgba(200, 160, 80, 0.45);
            border-radius: 50%;
            padding: 0;
            z-index: var(--z-hud);
            overflow: hidden;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
        }

        #minimap-toggle-btn {
            display: none;
        }

        #minimap-container.collapsed {
            width: 132px;
            height: 132px;
        }

        #minimap-container.collapsed #minimap-canvas,
        #minimap-container.collapsed #minimap-compass {
            display: block;
        }

        #minimap-container.expanded {
            width: 360px;
            height: 360px;
            z-index: var(--z-hud-overlay);
            box-shadow: 0 6px 18px rgba(0,0,0,0.55);
        }

        #minimap-container.expanded #minimap-canvas {
            width: 360px;
            height: 360px;
        }

        #minimap-canvas {
            width: 132px;
            height: 132px;
            border: none;
            background: #0e1608;
            border-radius: 50%;
            display: block;
            margin: 0;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
        }

        #minimap-compass {
            display: none;
        }

        /* Region label + nearby count overlaid on the minimap disc. */
        #minimap-region {
            position: absolute;
            top: 8px;
            left: 0;
            right: 0;
            text-align: center;
            color: var(--gold-light);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            font-style: italic;
            letter-spacing: 0.04em;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
            pointer-events: none;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            padding: 0 18px;
        }

        #minimap-nearby-count {
            position: absolute;
            bottom: 8px;
            left: 0;
            right: 0;
            text-align: center;
            color: var(--stone-muted);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
            pointer-events: none;
        }

        #minimap-orbs {
            position: absolute;
            right: -20px;
            top: 28px;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        #subzone-label {
            position: absolute;
            top: 152px;
            right: 10px;
            background: rgba(0, 0, 0, 0.6);
            color: var(--gold-light);
            padding: 4px 10px;
            border-radius: 0;
            font-size: var(--fs-body);
            font-family: Georgia, serif;
            font-style: italic;
            text-align: center;
            border: none;
            pointer-events: none;
            z-index: var(--z-panel);
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
            transition: opacity 0.2s ease-in-out;
            white-space: nowrap;
            max-width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            letter-spacing: 0.04em;
        }

        /* Unit frames — paired player + target, top-left of canvas. */
        #unit-frames {
            position: absolute;
            top: 10px;
            left: 10px;
            display: flex;
            gap: 6px;
            z-index: var(--z-panel);
            pointer-events: none;
        }
        /* Hide unit frames while the login/character-select or world-loading
           overlays are active — the player frame has no meaningful data yet. */
        body:has(#login-screen:not(.hidden)) #unit-frames,
        body:has(#game-loading-screen[style*="flex"]) #unit-frames {
            display: none;
        }
        .unit-frame {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 4px 8px 4px 4px;
            background: rgba(12, 9, 5, 0.72);
            border: 1px solid rgba(200, 160, 80, 0.35);
            color: #f5eacb;
            font-family: Georgia, serif;
            pointer-events: auto;
            user-select: none;
            min-width: 200px;
            backdrop-filter: blur(2px);
        }
        .unit-frame-portrait {
            width: 40px;
            height: 40px;
            background: rgba(0, 0, 0, 0.55);
            border: 1px solid rgba(200, 160, 80, 0.4);
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            flex: 0 0 auto;
        }
        .unit-frame-info {
            flex: 1 1 auto;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 3px;
        }
        .unit-frame-name-row {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            gap: 6px;
        }
        .unit-frame-name {
            font-size: var(--fs-body);
            font-weight: bold;
            text-transform: capitalize;
            letter-spacing: 0.02em;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .unit-frame-level {
            font-size: var(--fs-fine);
            color: var(--gold-light);
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95);
            letter-spacing: 0.04em;
            text-transform: uppercase;
            flex: 0 0 auto;
        }
        .unit-frame-close {
            background: transparent;
            color: var(--stone-muted);
            border: none;
            cursor: pointer;
            font-size: var(--fs-fine);
            padding: 0 2px;
            line-height: 1;
        }
        .unit-frame-close:hover { color: #fff; }
        .unit-frame-bar {
            position: relative;
            height: 12px;
            background: rgba(0, 0, 0, 0.6);
            border: 1px solid rgba(0, 0, 0, 0.6);
            overflow: hidden;
        }
        .unit-frame-bar-fill {
            height: 100%;
            width: 100%;
            background: linear-gradient(180deg, var(--color-hp-high), var(--color-hp-high-dark));
            transition: width 120ms linear;
        }
        .unit-frame-bar-fill.mid { background: linear-gradient(180deg, var(--color-hp-mid), var(--color-hp-mid-dark)); }
        .unit-frame-bar-fill.low { background: linear-gradient(180deg, var(--color-hp-low), var(--color-hp-low-dark)); }
        .unit-frame-bar-text {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: var(--fs-fine);
            font-weight: bold;
            color: #fff;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 1);
            letter-spacing: 0.02em;
            line-height: 1;
        }

        #left-rail {
            position: absolute;
            left: 10px;
            top: 60px;
            bottom: 10px;
            display: flex;
            flex-direction: column;
            gap: 5px;
            z-index: var(--z-hud-overlay);
        }

        .rail-btn {
            width: 44px;
            border-radius: 0;
            border: 1px solid rgba(200, 160, 80, 0.35);
            background: rgba(20, 17, 11, 0.78);
            color: var(--stone-text);
            cursor: pointer;
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 4px 0 2px;
            gap: 2px;
            backdrop-filter: blur(2px);
            transition: background 0.12s, border-color 0.12s;
        }

        .rail-btn:hover {
            background: rgba(58, 48, 32, 0.85);
            border-color: var(--gold);
        }

        /* "More" flyout — groups music/foley/news/server/bug behind one rail
           button. Column rail (this layout): opens to the right; the ≥900px
           horizontal-rail mode overrides it to open upward (theme.css). */
        #rail-more-wrap {
            position: relative;
            display: flex;
        }
        #rail-more-flyout {
            display: none;
            position: absolute;
            left: calc(100% + 6px);
            bottom: 0;
            flex-direction: column;
            gap: 4px;
            padding: 5px;
            background: rgba(12, 9, 5, 0.92);
            border: 1px solid var(--gold-dark);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
            z-index: var(--z-hud-overlay);
        }
        #rail-more-wrap.open #rail-more-flyout {
            display: flex;
        }

        .rail-tooltip {
            position: absolute;
            left: calc(100% + 10px);
            top: 50%;
            transform: translateY(-50%);
            background: rgba(12, 9, 5, 0.95);
            border: 1px solid var(--gold-dark);
            color: var(--gold-light);
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            padding: 4px 10px;
            white-space: nowrap;
            pointer-events: none;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            opacity: 0;
            transition: opacity 0.12s;
            z-index: var(--z-tooltip);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
        }
        .rail-btn:hover .rail-tooltip,
        .rail-btn:focus-visible .rail-tooltip { opacity: 1; }

        #context-menu {
            position: fixed;
            display: none;
            min-width: 160px;
            background: rgba(12, 9, 5, 0.96);
            border: 1px solid var(--gold-dark);
            box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6);
            z-index: var(--z-context);
            padding: 4px 0;
            border-radius: 0;
            font-family: Georgia, "Times New Roman", serif;
            backdrop-filter: blur(2px);
        }

        .context-item {
            display: block;
            width: 100%;
            border: none;
            background: transparent;
            color: var(--stone-text);
            text-align: left;
            padding: 6px 12px;
            cursor: pointer;
            font-size: var(--fs-body);
            transition: background 0.1s, color 0.1s;
        }

        .context-item:hover {
            background: rgba(200, 160, 80, 0.18);
            color: var(--gold-light);
        }
        .context-item + .context-item { border-top: 1px solid rgba(58, 48, 32, 0.4); }

        /* Page chrome — dark stone, gold accents. */
        body {
            font-family: Georgia, "Times New Roman", serif;
            background: linear-gradient(180deg, #2a2218 0%, #1a1410 100%);
            color: var(--stone-text);
        }

        h1 {
            font-family: Georgia, "Times New Roman", serif;
            color: var(--gold-light);
            text-shadow: 2px 2px 0 #0a0805;
            letter-spacing: 1px;
        }

        #status {
            position: absolute;
            top: 6px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(12, 9, 5, 0.78);
            border: 1px solid rgba(200, 160, 80, 0.35);
            color: var(--gold-light);
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
            border-radius: 0;
            padding: 3px 12px;
            margin: 0;
            font-size: var(--fs-fine);
            font-weight: normal;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            animation: none;
            z-index: var(--z-hud-overlay);
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s;
        }

        #status.disconnected {
            background: rgba(122, 63, 51, 0.85);
            border-color: rgba(231, 107, 107, 0.55);
            color: #fbe3e0;
            opacity: 1;
        }

        #game-canvas {
            border: 2px solid rgba(0, 0, 0, 0.55);
            box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
            background-color: #4e6830;
            cursor: default;
            touch-action: none;
        }

        /* Inner panel surfaces — let .game-panel chrome handle the outer frame;
           these target inputs/cards that previously got the sandstone override. */
        .stat-section {
            background: rgba(20, 17, 11, 0.85);
            border: 1px solid var(--stone-light);
            box-shadow: none;
        }

        .stat-section h3 {
            color: var(--gold-light);
            border-bottom: 1px solid var(--stone-light);
        }

        .stat-item span:first-child { color: var(--stone-muted); }
        .stat-item span:last-child  { color: var(--stone-text); }

        #chat-box {
            background: rgba(10, 8, 4, 0.55);
            border: 1px solid rgba(200, 160, 80, 0.18);
            color: var(--stone-text);
        }

        #chat-input-row {
            padding: 6px;
            border-top: 1px solid var(--stone-light);
            display: flex;
            gap: 6px;
            background: rgba(14, 12, 8, 0.7);
        }

        #chat-input {
            flex: 1;
            padding: 6px 8px;
            border: 1px solid var(--stone-light);
            border-radius: 0;
            background: rgba(8, 6, 4, 0.85);
            color: var(--stone-text);
            font-size: var(--fs-ui);
            font-family: Georgia, serif;
        }
        #chat-input:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold);
        }

        #chat-send-btn {
            padding: 6px 12px;
            border: 1px solid var(--gold-dark);
            border-radius: 0;
            cursor: pointer;
            color: var(--gold-light);
            background: var(--stone-mid);
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            min-width: 56px;
        }
        #chat-send-btn:hover {
            background: var(--stone-light);
            border-color: var(--gold);
            color: #fff;
        }

        .chat-message    {
            background: transparent;
            overflow-wrap: anywhere;
            word-break: break-word;
            min-width: 0;
            max-width: 100%;
        }
        .inline-icon {
            display: inline-block;
            width: 1em;
            height: 1em;
            vertical-align: -2px;
            image-rendering: pixelated;
            margin: 0 1px;
        }
        .rw-activity-icon .inline-icon {
            width: 1.2em;
            height: 1.2em;
            vertical-align: -3px;
        }

        #zone-notice {
            position: absolute;
            top: 24px;
            left: 50%;
            transform: translateX(-50%) translateY(-8px);
            padding: 8px 22px;
            background: rgba(14, 12, 8, 0.78);
            border: 1px solid rgba(200, 160, 80, 0.55);
            border-radius: 4px;
            color: #f0d68a;
            font-family: Georgia, serif;
            font-size: 18px;
            letter-spacing: 0.04em;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
            opacity: 0;
            pointer-events: none;
            z-index: var(--z-hud-overlay, 50);
            transition: opacity 700ms ease-out, transform 700ms ease-out;
            white-space: nowrap;
        }
        #zone-notice.visible {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
        #zone-notice.fading {
            opacity: 0;
            transform: translateX(-50%) translateY(-4px);
            transition: opacity 1000ms ease-in, transform 1000ms ease-in;
        }
        .system-message  {
            color: var(--gold);
            background: rgba(200, 160, 80, 0.08);
            font-style: italic;
        }

        /* Chat Window (overlay in bottom left of canvas) */
        #chat-window {
            background: var(--stone-dark);
            border-style: solid;
            border-width: 12px;
            border-image: url('/static/assets/sprites/ui/ui_panel_frame.png') 12 fill / 12px / 0px;
            border-image-width: 12px;
            display: flex;
            flex-direction: column;
            min-width: 0;
            max-width: 100%;
            width: 100%;
            box-sizing: border-box;
        }

        #chat-body.collapsed {
            display: none;
        }

        #chat-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 0 5px 0;
            border-bottom: 1px solid var(--stone-light);
            margin-bottom: 0;
        }

        #chat-header h3 {
            margin: 0;
            font-size: var(--fs-ui);
            color: var(--gold);
            font-weight: normal;
            font-family: Georgia, serif;
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }

        #chat-toggle-btn {
            background: transparent;
            border: none;
            color: var(--gold);
            cursor: pointer;
            font-size: var(--fs-ui);
            padding: 0 2px;
            line-height: 1;
        }

        #chat-toggle-btn:hover {
            color: var(--gold-light);
        }

        #chat-box {
            overflow-y: auto;
            overflow-x: hidden;
            padding: 8px;
            font-size: var(--fs-ui);
            height: 180px;
            min-width: 0;
            word-break: break-word;
            overflow-wrap: anywhere;
        }

        /* Chat tabs */
        #chat-tabs {
            display: flex;
            gap: 0;
            border-bottom: 1px solid var(--stone-light);
            background: var(--stone-mid);
            padding: 0;
            margin: 0;
        }

        .chat-tab-btn {
            flex: 1;
            padding: 6px 8px;
            border: none;
            background: transparent;
            color: var(--stone-muted);
            cursor: pointer;
            font-size: var(--fs-ui);
            font-family: Georgia, serif;
            font-weight: normal;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            border-bottom: 2px solid transparent;
            transition: color 0.15s, border-bottom-color 0.15s;
        }

        .chat-tab-btn:hover { color: var(--gold-light); }

        .chat-tab-btn.active {
            background: transparent;
            border-bottom-color: var(--gold);
            color: var(--gold-light);
        }

        /* Tab content */
        .chat-tab-content {
            display: none;
            flex: 1;
            overflow-y: auto;
            overflow-x: hidden;
            padding: 8px;
            font-size: var(--fs-ui);
            min-height: 200px;
            max-height: 250px;
            min-width: 0;
            word-break: break-word;
            overflow-wrap: anywhere;
        }

        /* Tier 2 Phase 4: per-channel filter strip inside the Chat tab. */
        #chat-channel-strip {
            display: flex;
            gap: 4px;
            padding: 4px 6px;
            background: rgba(14, 12, 8, 0.7);
            border-bottom: 1px solid var(--stone-light);
        }
        .chat-channel-btn {
            flex: 1;
            padding: 3px 6px;
            border: 1px solid var(--stone-light);
            background: rgba(20, 17, 11, 0.85);
            color: var(--stone-muted);
            cursor: pointer;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
        }
        .chat-channel-btn.active {
            background: var(--stone-light);
            color: var(--gold-light);
            border-color: var(--gold);
            font-weight: normal;
        }
        .chat-channel-btn:hover:not(.active) {
            color: var(--gold-light);
            border-color: var(--gold-dark);
        }
        /* Channel color theming for chat lines (dark-theme variants). */
        .chat-message.chan-global  { color: var(--chat-global); }
        .chat-message.chan-local   { color: var(--stone-text); }
        .chat-message.chan-party   { color: var(--chat-party); }
        .chat-message.chan-whisper { color: var(--chat-whisper); font-style: italic; }
        /* When a non-"all" channel filter is active, hide all messages
           that don't belong to the selected channel. */
        #chat-box[data-filter="local"]   .chat-message:not(.chan-local):not(.chan-system),
        #chat-box[data-filter="global"]  .chat-message:not(.chan-global):not(.chan-system),
        #chat-box[data-filter="party"]   .chat-message:not(.chan-party):not(.chan-system),
        #chat-box[data-filter="whisper"] .chat-message:not(.chan-whisper):not(.chan-system) {
            display: none;
        }

        .chat-tab-content.active {
            display: flex;
            flex-direction: column;
        }

        #chat-tab {
            display: none;
            flex-direction: column;
        }

        #chat-tab.active {
            display: flex;
        }

        #chat-box {
            flex: 1;
            overflow-y: auto;
            margin-bottom: 0;
        }

        #social-tab {
            display: none;
            flex-direction: column;
        }

        #social-tab.active {
            display: flex;
        }

        #social-players-list {
            flex: 1;
            overflow-y: auto;
            padding: 8px 0;
        }

        .player-list-item {
            background-color: rgba(200, 160, 80, 0.08);
            border-left: 3px solid var(--gold-dark);
            color: var(--stone-text);
        }

        .inventory-grid {
            display: grid;
            grid-template-columns: repeat(5, minmax(0, 1fr));
            gap: 6px;
            padding: 14px;
            flex: 1;
            align-content: start;
        }

        .inventory-slot {
            aspect-ratio: 1;
            padding: 4px;
            border: 1px solid var(--stone-light);
            background: rgba(8, 6, 4, 0.7);
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            user-select: none;
            transition: border-color 0.12s, background 0.12s;
            min-width: 0;
            min-height: 0;
        }

        .inventory-slot:not(.empty) {
            background: rgba(20, 17, 11, 0.85);
            cursor: pointer;
        }
        .inventory-slot:not(.empty):hover {
            border-color: var(--gold-dark);
            background: rgba(58, 48, 32, 0.7);
        }

        /* Rarity tint on the slot border (left edge a little brighter via inset). */
        .inventory-slot.rarity-uncommon { border-color: var(--rarity-uncommon); box-shadow: inset 2px 0 0 rgba(90, 200, 90, 0.35); }
        .inventory-slot.rarity-rare     { border-color: var(--rarity-rare); box-shadow: inset 2px 0 0 rgba(220, 160, 80, 0.4); }
        .inventory-slot.rarity-epic     { border-color: var(--rarity-epic); box-shadow: inset 2px 0 0 rgba(190, 130, 240, 0.45); }
        .inventory-slot.rarity-legendary{ border-color: var(--rarity-legendary); box-shadow: inset 2px 0 0 rgba(255, 220, 120, 0.55); }

        .inventory-slot.drag-over {
            outline: 2px solid var(--gold);
            outline-offset: -2px;
        }

        .inventory-slot.inv-selected {
            background: rgba(58, 44, 16, 0.85);
            border-color: var(--gold);
            box-shadow: 0 0 0 1px var(--gold), 0 0 8px rgba(200, 160, 80, 0.35);
        }

        .inventory-slot.equipped {
            border-color: var(--gold);
            box-shadow:
                inset 0 0 0 1px rgba(250, 227, 165, 0.25),
                0 0 6px rgba(200, 160, 80, 0.3);
        }
        .inventory-slot.equipped::after {
            content: 'E';
            position: absolute;
            top: 2px; left: 3px;
            font-size: 9px;
            font-weight: bold;
            color: var(--gold-light);
            text-shadow: 0 1px 1px rgba(0, 0, 0, 0.9);
            line-height: 1;
            letter-spacing: 0;
            pointer-events: none;
        }

        .inventory-slot.item-broken {
            border-color: var(--color-hp);
            box-shadow: 0 0 6px rgba(192, 80, 64, 0.35);
        }

        .inventory-sprite.sprite-broken {
            filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4)) sepia(0.7) hue-rotate(-20deg) brightness(0.7);
        }

        .inventory-broken-overlay {
            position: absolute;
            inset: 0;
            background: rgba(180, 30, 30, 0.15);
            pointer-events: none;
        }

        .inventory-sprite {
            width: 80%;
            height: 80%;
            image-rendering: pixelated;
            object-fit: contain;
        }

        /* Inventory quantity badge — bottom-right of the slot. */
        .inventory-qty {
            position: absolute;
            bottom: 2px;
            right: 4px;
            font-size: var(--fs-fine);
            color: var(--gold-light);
            font-weight: bold;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95);
            font-variant-numeric: tabular-nums;
            line-height: 1;
            pointer-events: none;
        }

        /* Equipped 'E' badge already styled via .equipment-slot.equipped::after; remove the older inventory-equipped-badge if rendered. */
        .inventory-equipped-badge { display: none; }

        /* ── Item tooltip — shared hover popup for inventory / bank / shop slots ── */
        #item-tooltip {
            position: fixed;
            top: 0;
            left: 0;
            min-width: 200px;
            max-width: 280px;
            background: rgba(12, 9, 5, 0.96);
            border: 1px solid var(--gold-dark);
            color: var(--stone-text);
            font-family: var(--font-serif);
            padding: 10px 12px;
            box-shadow: 0 4px 14px rgba(0, 0, 0, 0.65);
            z-index: var(--z-tooltip);
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.1s;
            backdrop-filter: blur(2px);
            line-height: 1.4;
        }
        #item-tooltip.visible { opacity: 1; }
        #item-tooltip .tt-name {
            font-size: var(--fs-ui);
            color: var(--gold-light);
            margin-bottom: 4px;
            letter-spacing: 0.02em;
        }
        #item-tooltip .tt-rarity {
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.14em;
            margin-bottom: 8px;
        }
        #item-tooltip .tt-rarity.rarity-common      { color: var(--stone-muted); }
        #item-tooltip .tt-rarity.rarity-uncommon    { color: var(--rarity-uncommon); }
        #item-tooltip .tt-rarity.rarity-rare        { color: var(--rarity-rare); }
        #item-tooltip .tt-rarity.rarity-epic        { color: var(--rarity-epic); }
        #item-tooltip .tt-rarity.rarity-legendary   { color: var(--rarity-legendary); }
        #item-tooltip .tt-category {
            font-size: var(--fs-fine);
            color: var(--stone-muted);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            margin-bottom: 6px;
        }
        #item-tooltip .tt-desc {
            font-size: var(--fs-body);
            color: var(--stone-text);
            font-style: italic;
            margin-bottom: 6px;
        }
        #item-tooltip .tt-stats {
            font-size: var(--fs-fine);
            color: var(--gold-light);
            display: flex;
            flex-direction: column;
            gap: 2px;
            padding-top: 6px;
            border-top: 1px solid var(--stone-light);
        }
        #item-tooltip .tt-stat {
            display: flex;
            justify-content: space-between;
            gap: 8px;
        }
        #item-tooltip .tt-stat-label { color: var(--stone-muted); text-transform: uppercase; letter-spacing: 0.06em; }
        #item-tooltip .tt-stat-value { color: var(--gold-light); font-variant-numeric: tabular-nums; }
        #item-tooltip .tt-flags {
            font-size: var(--fs-fine);
            color: var(--color-hp-low);
            margin-top: 6px;
            font-style: italic;
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }

        .inventory-icon-fallback {
            display: none;
            font-size: var(--fs-title);
            line-height: 1;
        }

        .inventory-qty {
            position: absolute;
            right: 2px;
            bottom: 1px;
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            color: var(--gold-light);
            text-shadow: 0 0 3px #000, 0 0 3px #000;
            pointer-events: none;
        }

        .inventory-equipped-badge {
            position: absolute;
            left: 2px;
            top: 2px;
            min-width: 10px;
            height: 10px;
            padding: 0 2px;
            font-size: var(--fs-fine);
            line-height: 10px;
            font-weight: bold;
            color: #2f2208;
            background: linear-gradient(180deg, #f6dc9b 0%, #d3ad58 100%);
            border: 1px solid rgba(52, 38, 13, 0.72);
            text-align: center;
            pointer-events: none;
        }

        .inv-detail {
            border-top: 1px solid var(--stone-light);
            padding: 10px 14px;
            background: #141008;
            min-height: 72px;
            flex-shrink: 0;
            display: flex;
            align-items: center;
        }

        .inv-detail-empty {
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            font-style: italic;
            color: var(--stone-muted);
            width: 100%;
            text-align: center;
        }

        .inv-detail-content {
            display: flex;
            gap: 12px;
            align-items: flex-start;
            width: 100%;
        }

        .inv-detail-thumb {
            width: 36px;
            height: 36px;
            flex-shrink: 0;
            background: #0a0804;
            padding: 2px;
            image-rendering: pixelated;
            object-fit: contain;
        }

        .inv-detail-info {
            flex: 1;
            min-width: 0;
        }

        .inv-detail-name {
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            color: var(--gold-light);
            margin-bottom: 4px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            letter-spacing: 0.02em;
        }

        .inv-detail-rarity {
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            margin-bottom: 4px;
        }

        .inv-detail-type {
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            color: var(--stone-muted);
            text-transform: capitalize;
        }

        .inv-detail-actions {
            display: flex;
            flex-direction: column;
            gap: 4px;
            flex-shrink: 0;
        }

        .inv-detail-use,
        .inv-detail-drop {
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            padding: 5px 10px;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            cursor: pointer;
            border-radius: 0;
        }

        .inv-detail-use {
            background: var(--stone-mid);
            border: 1px solid var(--gold);
            color: var(--gold-light);
        }

        .inv-detail-use:hover { filter: brightness(1.15); }

        .inv-detail-drop {
            background: var(--color-danger-bg);
            border: 1px solid var(--color-danger-dark);
            color: #d05040;
        }

        .inv-detail-drop:hover { filter: brightness(1.15); }

        #inventory-context-menu {
            position: fixed;
            display: none;
            min-width: 150px;
            background: linear-gradient(180deg, #3f3826 0%, #2b261a 100%);
            border: 1px solid #bfa574;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.45);
            z-index: var(--z-toast);
            padding: 4px 0;
            border-radius: 0;
            font-family: Georgia, "Times New Roman", serif;
        }

        #map-toggle-btn,
        #login-form button,
        #map-close-btn,
        #trade-close-btn,
        #leaderboard-close-btn,
        #economy-close-btn,
        #economy-refresh-btn,
        #economy-complete-btn {
            background: linear-gradient(180deg, #786945 0%, #5b4f31 100%);
            border: 1px solid #2f2a1c;
            box-shadow: inset 0 0 0 1px #9a8a5e;
            color: #f5eacb;
            font-family: Georgia, "Times New Roman", serif;
        }

        #map-toggle-btn:hover,
        #login-form button:hover,
        #map-close-btn:hover,
        #trade-close-btn:hover,
        #leaderboard-close-btn:hover,
        #economy-close-btn:hover,
        #economy-refresh-btn:hover,
        #economy-complete-btn:hover {
            background: linear-gradient(180deg, #86764e 0%, #675739 100%);
        }

        #ui-panel {
            position: absolute;
            right: 10px;
            bottom: 10px;
            width: 320px;
            /* Cap the inventory at the canvas height so it can never spill
               outside the play area. Leaves a small gutter so it doesn't
               hug the canvas edge. */
            max-height: calc(100% - 20px);
            z-index: var(--z-hud-overlay);
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }
        #ui-panel #inventory-panel-body {
            flex: 1;
            overflow: hidden auto;
            display: flex;
            flex-direction: column;
            min-height: 0;
        }
        #ui-panel .inventory-grid {
            flex: 0 0 auto;
            min-height: 0;
        }

        #osrs-tabs {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 4px;
            margin-bottom: 8px;
        }

        .hud-tab {
            border: 1px solid var(--stone-light);
            background: rgba(20, 17, 11, 0.78);
            color: var(--stone-muted);
            border-radius: 0;
            padding: 6px 0;
            font-size: var(--fs-fine);
            cursor: pointer;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            transition: background 0.12s, border-color 0.12s, color 0.12s;
        }
        .hud-tab:hover {
            background: rgba(58, 48, 32, 0.85);
            border-color: var(--gold-dark);
            color: var(--gold-light);
        }

        .hud-tab.active {
            background: rgba(58, 44, 16, 0.9);
            color: var(--gold-light);
            border-color: var(--gold);
        }

        .hud-section {
            display: none;
            max-height: none;
            overflow-y: visible;
            margin-bottom: 0;
        }

        .hud-section.active {
            display: block;
        }

@media (max-width: 1200px) {
            #game-container {
                flex-direction: column;
                align-items: center;
            }

            #canvas-wrap {
                width: min(100vw - 20px, 1024px);
                height: auto;
            }

            #game-canvas {
                width: 100%;
                height: auto;
            }

            #ui-panel {
                position: static;
                width: min(96vw, 640px);
                max-height: 560px;
            }

            #left-hud-panel {
                left: 56px;
                top: 0;
                bottom: 0;
                width: 210px;
            }
        }

        @media (max-width: 768px) {
            body {
                padding: 8px;
            }

            h1 {
                font-size: var(--fs-title);
                margin-bottom: 10px;
            }

            #status {
                margin-bottom: 10px;
                padding: 8px 10px;
            }

            #controls {
                width: 96vw;
                padding: 10px;
            }

            #controls p {
                font-size: var(--fs-ui);
            }

            #minimap-container {
                width: 80px;
                height: 80px;
                right: 6px;
                top: 6px;
                padding: 0;
            }

            #minimap-canvas {
                width: 80px;
                height: 80px;
            }

            #left-rail {
                left: 6px;
                top: 52px;
            }

            .rail-btn {
                width: 40px;
                font-size: var(--fs-title);
            }

#leaderboard-panel {
                width: 96vw;
                max-height: 72vh;
                padding: 10px;
            }

            #leaderboard-tabs {
                grid-template-columns: repeat(3, 1fr);
            }

            .economy-grid {
                grid-template-columns: 1fr;
            }

            #left-hud-panel {
                left: 48px;
                width: 190px;
            }
        }

        /* Unified Yondermarch UI skin */
        :root {
            --ui-frame-dark: #262117;
            --ui-frame-mid: #5f533d;
            --ui-surface-1: #4b4438;
            --ui-surface-2: #343026;
            --ui-text-main: #eadfc2;
            --ui-text-soft: #c5b792;
            --ui-shadow: rgba(0, 0, 0, 0.35);
        }

        #ui-panel,
        #controls,
        #map-panel,
        #trade-panel,
        #leaderboard-panel,
        #economy-panel,
        #login-form {
            border: 2px solid var(--ui-frame-dark);
            border-radius: 0;
            background:
                linear-gradient(160deg, rgba(255, 255, 255, 0.06), transparent 35%),
                linear-gradient(180deg, var(--ui-surface-1) 0%, var(--ui-surface-2) 100%);
            box-shadow:
                inset 0 0 0 1px rgba(215, 195, 144, 0.3),
                inset 0 12px 20px rgba(0, 0, 0, 0.18),
                0 10px 22px var(--ui-shadow);
            color: var(--ui-text-main);
        }

        #ui-panel {
            width: 320px;
            padding: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        #inventory-panel-body {
            display: flex;
            flex-direction: column;
            flex: 1;
            overflow: hidden;
        }

        #inventory-panel-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 8px 14px;
            background: linear-gradient(180deg, #1f1a12 0%, #14110b 100%);
            border-bottom: 1px solid var(--gold-dark);
            flex-shrink: 0;
            position: relative;
        }
        #inventory-panel-header::after {
            content: '';
            position: absolute;
            left: 14px; right: 14px; bottom: -1px;
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--gold), transparent);
            opacity: 0.5;
            pointer-events: none;
        }

        .inv-panel-title {
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            text-transform: uppercase;
            letter-spacing: 0.12em;
            color: var(--gold-light);
        }

        .inv-panel-header-right {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .inv-panel-gold {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            color: var(--gold-light);
            font-variant-numeric: tabular-nums;
        }
        .inv-panel-gold-icon {
            width: 18px;
            height: 18px;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
        }

        #inventory-panel-footer {
            display: flex;
            justify-content: flex-end;
            padding: 8px 14px;
            background: linear-gradient(180deg, #14110b 0%, #1f1a12 100%);
            border-top: 1px solid var(--gold-dark);
            flex-shrink: 0;
            position: relative;
        }
        #inventory-panel-footer::before {
            content: '';
            position: absolute;
            left: 14px; right: 14px; top: -1px;
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--gold), transparent);
            opacity: 0.5;
            pointer-events: none;
        }
        #ui-panel.collapsed #inventory-panel-footer {
            display: none;
        }

        .inv-panel-slots {
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            color: var(--stone-muted);
            text-transform: uppercase;
            letter-spacing: 0.06em;
            font-variant-numeric: tabular-nums;
        }

        #inventory-collapse-btn {
            position: absolute;
            top: 6px;
            right: 6px;
            width: 14px;
            height: 14px;
            padding: 0;
            font-size: var(--fs-fine);
            line-height: 1;
            cursor: pointer;
            background: transparent;
            border: none;
            color: var(--stone-muted);
            transition: color 0.12s;
            z-index: 2;
        }

        #inventory-collapse-btn:hover {
            color: var(--gold-light);
        }

        #inventory-panel-header {
            display: none;
        }

        #ui-panel.collapsed {
            width: 120px;
        }

        #ui-panel.collapsed #inventory-panel-body {
            display: none;
        }

        #left-hud-panel {
            position: absolute;
            left: 62px;
            top: 0;
            bottom: 0;
            width: 250px;
            z-index: var(--z-hud-overlay);
            display: none;
            flex-direction: column;
            border-right: 1px solid var(--gold-dark);
            background: linear-gradient(180deg, rgba(26, 22, 16, 0.96) 0%, rgba(20, 17, 11, 0.96) 100%);
            backdrop-filter: blur(4px);
            box-shadow: 4px 0 18px rgba(0, 0, 0, 0.55);
        }

        #left-hud-panel.visible {
            display: flex;
        }

        /* Skills panel renders 1–3 columns of "Lv N (cur/need XP)" rows;
           230px is too narrow and forces wraps/overlaps. */
        #left-hud-panel:has(.left-hud-section[data-section="skills"].active) {
            width: 560px;
        }

        #left-hud-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 14px 8px;
            border-bottom: 1px solid var(--gold-dark);
            border-radius: 0;
            background: linear-gradient(180deg, #1f1a12 0%, #14110b 100%);
            flex-shrink: 0;
            position: relative;
        }
        #left-hud-header::after {
            content: '';
            position: absolute;
            left: 14px; right: 14px; bottom: -1px;
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--gold), transparent);
            opacity: 0.5;
            pointer-events: none;
        }

        #left-hud-header h3 {
            margin: 0;
            font-family: Georgia, serif;
            font-size: var(--fs-ui);
            font-weight: normal;
            color: var(--gold-light);
            text-transform: uppercase;
            letter-spacing: 0.12em;
        }

        #left-hud-close-btn {
            width: 22px;
            height: 22px;
            padding: 0;
            font-size: var(--fs-ui);
            line-height: 1;
            cursor: pointer;
            background: transparent;
            border: none;
            color: var(--stone-muted);
            transition: color 0.12s, background 0.12s;
        }
        #left-hud-close-btn:hover {
            background: rgba(192, 48, 32, 0.18);
            color: var(--color-hp-low);
        }

        .left-hud-open-btn.active {
            background: rgba(58, 44, 16, 0.9);
            border-color: var(--gold);
            color: var(--gold-light);
        }

        .stat-section {
            border: 1px solid var(--stone-light);
            border-radius: 0;
            background: rgba(20, 17, 11, 0.8);
            box-shadow: none;
            padding: 10px 12px;
        }

        .stat-section h3 {
            color: var(--gold);
            border-bottom: 1px solid var(--stone-light);
            text-shadow: none;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.14em;
            font-weight: normal;
            margin: 0 0 8px;
            padding-bottom: 5px;
        }

        .stat-item {
            display: flex;
            justify-content: space-between;
            padding: 3px 0;
            font-size: var(--fs-body);
        }
        .stat-item span:first-child { color: var(--stone-muted); }
        .stat-item span:last-child { color: var(--stone-text); font-variant-numeric: tabular-nums; }

        .combat-stance-list {
            display: flex;
            flex-direction: column;
            gap: 6px;
            padding: 0 14px 14px;
        }

        .combat-stance-btn {
            border: 1px solid var(--stone-light);
            border-radius: 0;
            color: var(--stone-text);
            background: rgba(20, 17, 11, 0.6);
            padding: 8px 14px;
            font-family: Georgia, serif;
            font-size: var(--fs-body);
            text-align: left;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            cursor: pointer;
            transition: border-color 0.12s, background 0.12s, color 0.12s;
        }

        .combat-stance-btn:hover {
            background: rgba(58, 48, 32, 0.7);
            border-color: var(--gold-dark);
            color: var(--gold-light);
        }

        .combat-stance-btn.active {
            background: rgba(58, 44, 16, 0.9);
            border-color: var(--gold);
            color: var(--gold-light);
            position: relative;
            padding-left: 18px;
        }
        .combat-stance-btn.active::before {
            content: '';
            position: absolute;
            left: 0; top: 4px; bottom: 4px;
            width: 3px;
            background: var(--gold);
            box-shadow: 0 0 4px var(--gold);
        }

        #osrs-tabs {
            gap: 5px;
        }

        /* Duplicate .hud-tab and #left-rail .rail-btn rules from the OSRS-style
           override layer removed; lean dark-glass styles live earlier in this file
           (.hud-tab around L3545, .rail-btn around L2725). */

        #left-rail .rail-btn {
            position: relative;
        }
        /* Active "you are here" gold marker on the left edge. */
        #left-rail .rail-btn.active::before,
        #left-rail .rail-btn.active-tab::before {
            content: '';
            position: absolute;
            left: -1px;
            top: 4px;
            bottom: 4px;
            width: 3px;
            background: var(--gold);
            box-shadow: 0 0 4px var(--gold);
        }

        #left-rail .rail-btn.active,
        #left-rail .rail-btn.active-tab {
            background: rgba(58, 44, 16, 0.92);
            border-color: var(--gold);
            color: var(--gold-light);
        }

        .rail-btn-icon {
            display: flex;
            width: 24px;
            height: 24px;
            align-items: center;
            justify-content: center;
            user-select: none;
            filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
        }

        .rail-btn-icon img {
            width: 24px;
            height: 24px;
            display: block;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            pointer-events: none;
        }

        .rail-btn-label {
            font-family: Georgia, serif;
            font-size: var(--fs-fine);
            text-transform: uppercase;
            letter-spacing: 0.06em;
            color: var(--stone-muted);
            line-height: 1;
            pointer-events: none;
            opacity: 0.85;
            transition: color 0.12s, opacity 0.12s;
        }

        #left-rail .rail-btn:hover .rail-btn-label { color: var(--gold-light); opacity: 1; }
        #left-rail .rail-btn.active .rail-btn-label,
        #left-rail .rail-btn.active-tab .rail-btn-label {
            color: var(--gold-light);
            opacity: 1;
        }

        .header-icon {
            display: inline-block;
            width: 16px;
            height: 16px;
            background-image: url('/static/assets/sprites/ui/ui_buttons.png');
            background-size: 64px 48px;
            background-repeat: no-repeat;
            margin-right: 6px;
            vertical-align: middle;
        }

        /* Second OSRS-style override block removed: it duplicated and
           reverted the lean chrome of #minimap-container, #chat-box,
           #chat-input, the cross-modal button blob, table headers,
           .leaderboard-tab, #context-menu, and #status. Canonical lean
           styles live earlier in layout.css and modal.css. */

        /* Inventory context menu inherits #context-menu styles defined earlier. */
        #inventory-context-menu {
            position: fixed;
            display: none;
            min-width: 160px;
            background: rgba(12, 9, 5, 0.96);
            border: 1px solid var(--gold-dark);
            box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6);
            z-index: var(--z-context);
            padding: 4px 0;
            border-radius: 0;
            font-family: Georgia, "Times New Roman", serif;
            backdrop-filter: blur(2px);
        }

        #action-progress {
            visibility: hidden;
            opacity: 0;
            transition: opacity 0.15s;
            width: min(360px, 86vw);
            margin: 8px auto 10px;
            padding: 6px 12px;
            border: 1px solid var(--gold-dark);
            border-radius: 0;
            background: rgba(12, 9, 5, 0.78);
            backdrop-filter: blur(2px);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
        }

        #action-progress.active {
            visibility: visible;
            opacity: 1;
        }

        #action-progress-label {
            font-size: var(--fs-fine);
            color: var(--gold-light);
            margin-bottom: 4px;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 0.08em;
        }

        #action-progress-track {
            height: 6px;
            border-radius: 0;
            border: 1px solid rgba(0, 0, 0, 0.6);
            background: rgba(8, 6, 4, 0.85);
            overflow: hidden;
        }

        #action-progress-fill {
            height: 100%;
            width: 0%;
            border-radius: 0;
            background: linear-gradient(90deg, var(--gold-dark), var(--gold-light));
            transition: width 0.2s linear;
        }

        /* Equipment Panel Styles */
        .equipment-layout {
            display: flex;
            flex-direction: column;
            gap: 6px;
            padding: 12px;
            background: rgba(8, 6, 4, 0.45);
            border: 1px solid var(--stone-light);
            border-radius: 0;
            margin-bottom: 10px;
        }

        .equipment-row {
            display: flex;
            gap: 6px;
            justify-content: center;
        }

        .equipment-slot {
            position: relative;
            width: 60px;
            height: 60px;
            background: rgba(20, 17, 11, 0.85);
            border: 1px solid var(--stone-light);
            border-radius: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: border-color 0.12s, background 0.12s;
        }

        .equipment-slot.equipment-slot-large {
            width: 72px;
            height: 72px;
        }

        .equipment-slot:hover {
            border-color: var(--gold-dark);
            background: rgba(58, 48, 32, 0.6);
        }

        .equipment-slot.equipped {
            border-color: var(--gold);
            background: rgba(58, 44, 16, 0.55);
            box-shadow: 0 0 8px rgba(200, 160, 80, 0.3);
        }

        .equipment-slot.drag-over {
            border-color: var(--gold-light);
            background: rgba(232, 200, 120, 0.18);
        }

        .equipment-slot-icon {
            font-size: var(--fs-hero);
            margin-bottom: 2px;
            filter: grayscale(0.5) opacity(0.5);
            transition: filter 0.12s;
        }

        .equipment-slot.equipped .equipment-slot-icon {
            filter: grayscale(0) opacity(1);
        }

        .equipment-slot-name {
            font-size: 10px;
            color: var(--stone-muted);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            font-weight: normal;
            position: absolute;
            bottom: 2px;
            left: 0;
            right: 0;
            text-align: center;
            line-height: 1;
            opacity: 0.8;
        }
        .equipment-slot.equipped .equipment-slot-name {
            color: var(--gold-light);
        }

        .equipment-item-sprite {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -60%);
            width: 40px;
            height: 40px;
            object-fit: contain;
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
        }

        .equipment-slot.gear-broken .equipment-item-sprite {
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5)) sepia(0.6) hue-rotate(-20deg) brightness(0.6);
        }

        .equipment-durability-bar {
            position: absolute;
            bottom: 4px;
            left: 4px;
            right: 4px;
            height: 3px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 2px;
            overflow: hidden;
        }

        .equipment-durability-fill {
            height: 100%;
            border-radius: 2px;
            transition: width 0.3s ease;
        }

        .equipment-slot.equipment-slot-large .equipment-item-sprite {
            width: 48px;
            height: 48px;
        }

        .equipment-stats-summary {
            padding: 10px;
            background: rgba(20, 18, 15, 0.4);
            border-radius: 0;
            border: 1px solid rgba(229, 148, 67, 0.2);
        }

        .btn-unequip-all {
            display: block;
            width: calc(100% - 20px);
            margin: 8px 10px 10px;
            padding: 6px 0;
            background: rgba(60, 20, 20, 0.7);
            color: rgba(220, 120, 100, 0.9);
            border: 1px solid rgba(180, 60, 60, 0.4);
            border-radius: 3px;
            font-family: inherit;
            font-size: var(--fs-ui);
            letter-spacing: 1px;
            text-transform: uppercase;
            cursor: pointer;
        }

        .btn-unequip-all:hover {
            background: rgba(90, 30, 30, 0.8);
            border-color: rgba(220, 80, 80, 0.6);
            color: #e88;
        }

        .equipment-stats-summary h4 {
            margin: 0 0 8px 0;
            font-size: var(--fs-ui);
            color: rgba(229, 148, 67, 0.9);
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .equipment-stat-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 4px;
            font-size: var(--fs-ui);
        }

        .equipment-stat-item {
            display: flex;
            justify-content: space-between;
            padding: 3px 6px;
            background: rgba(48, 42, 31, 0.5);
            border-radius: 0;
            border: 1px solid rgba(229, 148, 67, 0.15);
        }

        .equipment-stat-label {
            color: rgba(243, 197, 111, 0.8);
            font-size: var(--fs-ui);
            text-transform: capitalize;
        }

        .equipment-stat-value {
            color: rgba(120, 240, 120, 0.9);
            font-weight: 600;
        }

        .equipment-stat-value.negative {
            color: rgba(240, 120, 120, 0.9);
        }

        /* Equipment Selection Modal */
        .equipment-modal-backdrop {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.7);
            z-index: var(--z-modal);
        }

        .equipment-modal-backdrop.active {
            display: block;
        }

        .equipment-select-modal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 90%;
            max-width: 500px;
            max-height: 80vh;
            background: linear-gradient(135deg, rgba(28, 24, 18, 0.98) 0%, rgba(20, 16, 12, 0.98) 100%);
            border: 3px solid rgba(229, 148, 67, 0.6);
            border-radius: 0;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8), inset 0 2px 8px rgba(229, 148, 67, 0.1);
            z-index: var(--z-modal-high);
            overflow: hidden;
        }

        .equipment-select-modal.active {
            display: flex;
            flex-direction: column;
        }

        .equipment-select-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 16px 20px;
            background: linear-gradient(90deg, rgba(48, 42, 31, 0.9) 0%, rgba(35, 30, 22, 0.9) 100%);
            border-bottom: 2px solid rgba(229, 148, 67, 0.3);
        }

        .equipment-select-header h3 {
            margin: 0;
            font-size: var(--fs-title);
            color: rgba(243, 197, 111, 0.95);
            text-transform: uppercase;
            letter-spacing: 1.5px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        }

        .equipment-select-close {
            background: rgba(240, 80, 80, 0.2);
            border: 1px solid rgba(240, 80, 80, 0.5);
            color: rgba(240, 120, 120, 0.9);
            font-size: var(--fs-title);
            width: 32px;
            height: 32px;
            border-radius: 0;
            cursor: pointer;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
        }

        .equipment-select-close:hover {
            background: rgba(240, 80, 80, 0.4);
            border-color: rgba(240, 80, 80, 0.8);
            transform: scale(1.1);
        }

        .equipment-select-items {
            padding: 16px;
            overflow-y: auto;
            flex: 1;
        }

        .equipment-select-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px;
            margin-bottom: 8px;
            background: linear-gradient(90deg, rgba(48, 42, 31, 0.6) 0%, rgba(35, 30, 22, 0.6) 100%);
            border: 2px solid rgba(229, 148, 67, 0.2);
            border-radius: 0;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .equipment-select-item:hover {
            border-color: rgba(229, 148, 67, 0.6);
            background: linear-gradient(90deg, rgba(58, 52, 41, 0.7) 0%, rgba(45, 40, 32, 0.7) 100%);
            transform: translateX(4px);
        }

        .equipment-select-item.equipped {
            border-color: rgba(229, 148, 67, 0.9);
            background: linear-gradient(90deg, rgba(58, 52, 41, 0.8) 0%, rgba(45, 40, 32, 0.8) 100%);
            box-shadow: 0 0 12px rgba(229, 148, 67, 0.3);
        }

        .equipment-select-item.cannot-equip {
            opacity: 0.5;
            cursor: not-allowed;
            border-color: rgba(240, 80, 80, 0.3);
        }

        .equipment-select-item.cannot-equip:hover {
            transform: none;
            border-color: rgba(240, 80, 80, 0.5);
        }

        .equipment-select-item-sprite {
            width: 48px;
            height: 48px;
            object-fit: contain;
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
        }

        .equipment-select-item-info {
            flex: 1;
        }

        .equipment-select-item-name {
            font-size: var(--fs-title);
            font-weight: 600;
            color: rgba(243, 197, 111, 0.95);
            margin-bottom: 4px;
            text-transform: capitalize;
        }

        .equipment-select-item-stats {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            font-size: var(--fs-ui);
        }

        .equipment-select-item-stat {
            padding: 2px 6px;
            background: rgba(20, 18, 15, 0.6);
            border-radius: 0;
            border: 1px solid rgba(229, 148, 67, 0.2);
        }

        .equipment-select-item-stat.positive {
            color: rgba(120, 240, 120, 0.9);
        }

        .equipment-select-item-stat.negative {
            color: rgba(240, 120, 120, 0.9);
        }

        .equipment-select-item-badge {
            padding: 4px 8px;
            background: rgba(229, 148, 67, 0.3);
            border: 1px solid rgba(229, 148, 67, 0.6);
            border-radius: 0;
            font-size: var(--fs-ui);
            color: rgba(243, 197, 111, 0.95);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 700;
        }

        .equipment-select-item-requirements {
            margin-top: 4px;
            font-size: var(--fs-ui);
            color: rgba(240, 120, 120, 0.9);
        }

        .equipment-select-empty {
            text-align: center;
            padding: 40px 20px;
            color: rgba(229, 148, 67, 0.6);
            font-size: var(--fs-title);
        }

        /* Responsive Design */
        @media (max-width: 1400px) {
            main {
                flex-direction: column;
                gap: 20px;
            }

            aside {
                width: 100%;
                flex-direction: row;
                gap: 20px;
            }

            .sidebar-panel {
                flex: 1;
            }
        }

        @media (max-width: 1100px) {
            aside {
                flex-direction: column;
                width: 100%;
            }

            .sidebar-panel {
                width: 100%;
            }

            header {
                flex-direction: column;
                gap: 15px;
                text-align: center;
            }

            nav a {
                margin: 0 10px;
                font-size: var(--fs-ui);
            }
        }

        @media (max-width: 768px) {
            main {
                padding: 15px;
            }

            header {
                padding: 10px 15px;
            }

            nav a {
                margin: 0 5px;
                font-size: var(--fs-ui);
            }

            .logo {
                font-size: var(--fs-title);
            }

            aside {
                gap: 15px;
            }

            .sidebar-panel {
                padding: 12px;
            }

            .sidebar-panel h3 {
                font-size: var(--fs-ui);
            }

            footer {
                padding: 15px;
                font-size: var(--fs-ui);
            }

            footer a {
                margin: 0 8px;
            }
        }

/* ── Quality hides section in inventory panel ── */
.quality-hides-section {
    margin: 8px 10px 4px;
}
.quality-hides-header {
    font-size: var(--fs-body);
    color: #a08060;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid #2d281d;
}
.quality-hides-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}
.quality-hide-card {
    background: var(--stone-dark);
    border: 1px solid var(--stone-light);
    border-radius: 0;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: default;
}
.quality-hide-card:hover {
    border-color: #6a5a40;
}
.qhide-sprite {
    width: 28px;
    height: 28px;
    object-fit: contain;
    image-rendering: pixelated;
}
.qhide-icon-fallback {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-title);
}
.qhide-name {
    font-size: var(--fs-fine);
    color: var(--stone-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.qhide-bar-wrap {
    width: 100%;
    height: 4px;
    background: #2d281d;
    border-radius: 2px;
    overflow: hidden;
}
.qhide-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.2s;
}
.qbar-low  { background: #8b3a3a; }
.qbar-mid  { background: #8b7a3a; }
.qbar-high { background: #3a8b5a; }
.qhide-label {
    font-size: var(--fs-fine);
    color: #7a6a50;
}

/* ── Panel message (loading / empty state text in sidebar panels) ── */
.panel-message {
    color: var(--stone-muted);
    font-size: var(--fs-ui);
    padding: 10px 0;
}

/* ── Below-viewport row: Latest Updates + Server Status ── */
#below-viewport-row {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    width: 100%;
    flex-wrap: wrap;
}
#below-viewport-row > .sidebar-panel {
    flex: 1 1 320px;
    min-width: 280px;
}

/* ── Right-side column (legacy — now unused) ── */
#right-widgets-col {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-self: flex-start;
}

/* Minimap panel */
#rw-map-canvas-wrap {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(14, 22, 8, 0.78);
    border: 1px solid var(--gold-dark);
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#rw-map-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#rw-map-compass {
    position: absolute;
    top: 6px;
    right: 8px;
    color: var(--gold-light);
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95);
    pointer-events: none;
}

#rw-map-region {
    position: absolute;
    bottom: 6px;
    left: 8px;
    right: 8px;
    color: var(--gold-light);
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    font-style: italic;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

#rw-map-legend {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    color: var(--stone-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Activity widget — vertical event feed under the minimap. */
.rw-activity-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 5px 8px;
    border-bottom: 1px solid rgba(58, 48, 32, 0.4);
}
.rw-activity-row:last-child { border-bottom: none; }

.rw-activity-icon {
    font-size: var(--fs-body);
    flex-shrink: 0;
    margin-top: 1px;
    opacity: 0.85;
}

.rw-activity-text {
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    color: var(--stone-text);
    line-height: 1.45;
    flex: 1;
}

/* Quest tracker (compact pinned-quest card under the activity feed). */
#rw-quest {
    display: none;
    background: rgba(20, 17, 11, 0.7);
    border-left: 3px solid var(--gold);
    padding: 10px 12px;
}

#rw-quest-name {
    font-family: Georgia, serif;
    font-size: var(--fs-body);
    color: var(--gold-light);
    margin-bottom: 6px;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

#rw-quest-step {
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    color: var(--stone-muted);
    font-style: italic;
    margin-bottom: 10px;
    line-height: 1.5;
}

#rw-quest-progress-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-family: Georgia, serif;
    font-size: var(--fs-fine);
    color: var(--stone-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-variant-numeric: tabular-nums;
}

#rw-quest-progress-label { color: var(--gold); }

#rw-quest-bar-track {
    height: 4px;
    background: rgba(8, 6, 4, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.6);
}

#rw-quest-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    opacity: 0.9;
    transition: width 0.3s ease;
}

@media (max-width: 900px) {
    #right-widgets-col { display: none; }
}

/* Tier 1 UI: dialogue + quest journal */
#dialogue-panel { width: 520px; max-width: 92vw; }
#dialogue-body { padding: 18px 22px 20px; }
#dialogue-text {
    color: var(--stone-text);
    font-size: var(--fs-ui);
    line-height: 1.6;
    margin: 0 0 18px;
    white-space: pre-wrap;
    font-style: italic;
    padding-left: 14px;
    border-left: 3px solid var(--gold-dark);
}
#dialogue-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.dialogue-choice {
    appearance: none;
    border: 1px solid var(--stone-light);
    background: rgba(20, 17, 11, 0.7);
    color: var(--stone-text);
    padding: 10px 14px 10px 32px;
    text-align: left;
    cursor: pointer;
    font: inherit;
    font-size: var(--fs-body);
    position: relative;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.dialogue-choice::before {
    content: '▸';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold-dark);
    font-size: var(--fs-body);
    transition: color 0.12s, transform 0.12s;
}
.dialogue-choice:hover {
    background: rgba(58, 44, 16, 0.6);
    border-color: var(--gold);
    color: var(--gold-light);
}
.dialogue-choice:hover::before {
    color: var(--gold-light);
    transform: translateY(-50%) translateX(2px);
}

#quest-journal-panel { width: 580px; max-width: 92vw; }
#quest-journal-body { padding: 14px 16px; overflow-y: auto; }
#quest-journal-empty {
    color: var(--stone-muted);
    font-style: italic;
    padding: 20px 4px;
    text-align: center;
}
.quest-entry {
    border-left: 3px solid var(--gold-dark);
    background: rgba(20, 17, 11, 0.7);
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: border-left-color 0.15s, background 0.15s;
}
.quest-entry:hover { background: rgba(58, 48, 32, 0.5); }
.quest-entry-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 6px;
}
.quest-name {
    color: var(--gold-light);
    font-weight: normal;
    font-size: var(--fs-ui);
    letter-spacing: 0.02em;
}
.quest-state {
    color: var(--stone-muted);
    font-size: var(--fs-fine);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 2px 8px;
    border: 1px solid var(--stone-light);
    flex-shrink: 0;
}
.quest-meta {
    color: var(--stone-muted);
    font-size: var(--fs-fine);
    margin-bottom: 8px;
    font-style: italic;
}
.quest-meta em { color: var(--stone-text); font-style: normal; }
.quest-objectives {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}
.quest-obj {
    color: var(--stone-text);
    padding: 3px 0 3px 18px;
    font-size: var(--fs-body);
    position: relative;
}
.quest-obj::before {
    content: '○';
    position: absolute;
    left: 0;
    top: 3px;
    color: var(--stone-muted);
    font-size: 12px;
    line-height: 1;
}
.quest-obj-done {
    color: var(--color-positive);
}
.quest-obj-done::before {
    content: '●';
    color: var(--color-positive);
}
.quest-obj-hidden {
    color: var(--stone-muted);
    font-style: italic;
    opacity: 0.65;
}
.quest-state-ready_turnin {
    border-left-color: var(--gold);
    background: rgba(58, 44, 16, 0.55);
}
.quest-state-ready_turnin .quest-name {
    color: var(--gold-light);
    text-shadow: 0 0 8px rgba(255, 200, 80, 0.35);
}
.quest-state-ready_turnin .quest-state {
    color: var(--gold-light);
    border-color: var(--gold);
    background: rgba(200, 160, 80, 0.15);
}
.quest-state-completed {
    opacity: 0.5;
    border-left-color: var(--color-positive);
}

/* Cutscene-active: fade out HUD so the scripted scene reads as cinematic.
   Toggled by game-cutscene.js on cutscene_start / cutscene_end. */
body.cutscene-active #left-rail,
body.cutscene-active #left-hud-panel,
body.cutscene-active #minimap-container,
body.cutscene-active #chat-window,
body.cutscene-active #party-hud,
body.cutscene-active #mail-hud-badge {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-out;
}
