:root {
    --bg: #101216;
    --panel: #1b1d23;
    --panel-alt: #23262d;
    --border: #34383f;
    --text: #ece9e2;
    --text-dim: #99a0ab;
    --accent: #d4af5a;
    --accent-dim: #8a6f28;
    --danger: #b3402f;
    --success: #3f8a52;
    --radius: 10px;
    --font-display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
    background:
        radial-gradient(ellipse at top, rgba(212, 175, 90, 0.06), transparent 55%),
        linear-gradient(180deg, #0a0b0d, #101216 220px);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--accent); }

h1, h2, h3 {
    font-family: var(--font-display);
    letter-spacing: 0.3px;
}

.panel {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

.center-wrap {
    max-width: 380px;
    margin: 80px auto;
    padding: 0 16px;
}

header.topbar {
    padding: 14px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.topbar-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
}

header.topbar .brand {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--accent);
    font-size: 1.3rem;
    text-decoration: none;
    text-shadow: 0 0 18px rgba(212, 175, 90, 0.25);
}

nav.tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

nav.tabs a {
    padding: 8px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.92rem;
    white-space: nowrap;
}

nav.tabs a.active, nav.tabs a:hover {
    background: var(--panel-alt);
    color: var(--text);
}

.stats-bar {
    display: flex;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-dim);
    align-items: center;
}

.stats-bar b { color: var(--accent); }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

h1, h2, h3 { margin-top: 0; }

.form-group { margin-bottom: 14px; }

.color-swatch-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
}

.color-swatch.selected {
    border-color: #ffffff;
    box-shadow: 0 0 0 2px var(--panel);
}

label { display: block; margin-bottom: 5px; font-size: 0.88rem; color: var(--text-dim); }

input[type=text], input[type=password], input[type=email], input[type=number] {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
}

input:focus { outline: none; border-color: var(--accent-dim); }

button, .btn {
    display: inline-block;
    padding: 10px 18px;
    background: var(--accent);
    color: #1a1a1a;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}

button:hover, .btn:hover { background: #d9b350; }

button:disabled {
    background: var(--panel-alt);
    color: var(--text-dim);
    cursor: not-allowed;
}

button.secondary, .btn.secondary {
    background: var(--panel-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

button.secondary:hover { background: #30353c; }

.error-msg {
    background: rgba(179, 64, 47, 0.15);
    border: 1px solid var(--danger);
    color: #e79485;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 0.88rem;
}

.success-msg {
    background: rgba(63, 138, 82, 0.15);
    border: 1px solid var(--success);
    color: #8fd3a0;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-size: 0.88rem;
}

.xp-bar {
    height: 10px;
    background: var(--panel-alt);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.profile-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: #1a1a1a;
}

.chat-friend-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-friend-avatar-placeholder {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: #1a1a1a;
    flex-shrink: 0;
}

.chat-avatar-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.chat-online-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--panel);
}

.chat-conversation-status {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 400;
}

.chat-conversation-status.chat-status-online { color: var(--success); }

.mission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.mission-card {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.mission-card h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
}

.mission-card p {
    color: var(--text-dim);
    font-size: 0.85rem;
    min-height: 34px;
}

.mission-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.mission-meta .money { color: var(--accent); }

.locked {
    opacity: 0.5;
}

.active-mission-box {
    text-align: center;
    padding: 24px;
}

.timer {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--accent);
    margin: 10px 0;
    font-variant-numeric: tabular-nums;
}

table.inventory-table {
    width: 100%;
    border-collapse: collapse;
}

table.inventory-table th, table.inventory-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

table.inventory-table th { color: var(--text-dim); font-weight: 500; font-size: 0.8rem; }

.item-name { display: flex; align-items: center; gap: 8px; }

/* Equipment panel */
.equipment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.equipment-slot {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}

.equipment-slot-label {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.equipment-slot-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.88rem;
    margin-bottom: 4px;
}

.equipment-slot-bonus {
    font-size: 0.76rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.equipment-slot-empty {
    color: var(--text-dim);
    font-size: 0.8rem;
    padding: 10px 0;
}

.cat-tag {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--panel);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 0;
}

/* Info boxes (tutorial tips) */
.info-box {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: rgba(201, 161, 59, 0.08);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.88rem;
    color: var(--text-dim);
}

.info-box-icon { font-size: 1.3rem; line-height: 1; }

.info-box a { margin-left: 6px; white-space: nowrap; }

/* Tutorial page */
.tutorial-entry {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
}

.tutorial-entry summary {
    cursor: pointer;
    font-weight: 600;
}

.tutorial-entry p {
    color: var(--text-dim);
    margin-bottom: 0;
    margin-top: 10px;
    font-size: 0.92rem;
    line-height: 1.5;
}

/* Mission / car banner images */
.mission-banner {
    height: 110px;
    margin: -16px -16px 12px;
    border-radius: var(--radius) var(--radius) 0 0;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 8px;
}

.mission-banner-icon {
    font-size: 1.6rem;
    background: rgba(20, 22, 26, 0.75);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Garage: damage/condition bar */
.damage-bar {
    height: 8px;
    width: 90px;
    background: var(--panel);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
    display: inline-block;
    vertical-align: middle;
}

.damage-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger), var(--success));
}

.damage-label {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-left: 6px;
}

.garage-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.value-cell { color: var(--accent); }

.table-scroll {
    overflow-x: auto;
}

/* Empire */
.empire-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.empire-stat {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.empire-stat-label { font-size: 0.76rem; color: var(--text-dim); }
.empire-stat-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 2px;
}

.legend-swatch.tile-neutral-legend { background: var(--panel-alt); border: 1px solid var(--border); }

.empire-buy-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}

.empire-buy-card {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.88rem;
    height: 100%;
}

.empire-buy-stat {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.82rem;
}

.empire-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-auto-rows: 1fr;
    gap: 3px;
    max-width: 560px;
    margin: 16px auto 0;
    aspect-ratio: 1;
}

.empire-tile {
    aspect-ratio: 1;
    width: 100%;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: transform 0.1s;
    background: var(--panel-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-sizing: border-box;
}

.empire-tile:hover { transform: scale(1.12); z-index: 2; }
.empire-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* Owned tile colors are set inline per-player; this just marks which are yours. */
.empire-tile.tile-mine { border: 2px solid #ffffff; }
.empire-tile.tile-shielded { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6); }

.tile-detail {
    margin-top: 16px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.tile-detail-header {
    font-weight: 600;
    margin-bottom: 8px;
}

.tile-detail p {
    color: var(--text-dim);
    font-size: 0.88rem;
    margin: 6px 0;
}

/* Chat widget (bottom-right, site-wide) */
.chat-widget {
    position: fixed;
    left: 16px;
    bottom: 16px;
    width: 280px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    overflow: hidden;
}

.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--panel-alt);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.chat-widget-header.open { border-bottom: 1px solid var(--border); }

.chat-badge {
    background: var(--danger);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
}

.chat-widget-body {
    max-height: 380px;
    display: flex;
    flex-direction: column;
}

.chat-widget-list {
    max-height: 380px;
    overflow-y: auto;
}

.chat-friend-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    font-size: 0.86rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.chat-friend-row:hover { background: var(--panel-alt); }

.chat-friend-row-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-friend-name { white-space: nowrap; }

.chat-friend-preview {
    color: var(--text-dim);
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-widget-conversation {
    display: flex;
    flex-direction: column;
    height: 380px;
}

.chat-conversation-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.88rem;
}

.chat-conversation-header button { padding: 4px 10px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-message {
    max-width: 80%;
    padding: 7px 11px;
    border-radius: 14px;
    font-size: 0.85rem;
    word-wrap: break-word;
}

.chat-message-mine {
    align-self: flex-end;
    background: var(--accent-dim);
    color: #ffffff;
}

.chat-message-theirs {
    align-self: flex-start;
    background: var(--panel-alt);
}

.chat-message-time {
    font-size: 0.68rem;
    opacity: 0.7;
    margin-top: 3px;
    text-align: right;
}

.chat-typing-indicator {
    padding: 2px 14px 6px;
    font-size: 0.78rem;
    color: var(--text-dim);
    font-style: italic;
}

#chat-send-form {
    display: flex;
    gap: 6px;
    padding: 10px;
    border-top: 1px solid var(--border);
}

#chat-send-form input {
    flex: 1;
    padding: 8px 10px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
}

#chat-send-form button { padding: 8px 14px; }

/* ---------------------------------------------------------------------- */
/* Mobile responsiveness */
/* ---------------------------------------------------------------------- */
@media (max-width: 640px) {
    header.topbar { padding: 10px 14px; }

    .topbar-row { gap: 8px; }

    header.topbar .brand { font-size: 1.05rem; }

    .stats-bar { gap: 8px; font-size: 0.8rem; }

    nav.tabs { gap: 2px; }

    nav.tabs a { padding: 7px 10px; font-size: 0.82rem; }

    .wrap { padding: 16px 10px 40px; }

    .panel { padding: 14px; }

    .center-wrap { margin: 40px auto; }

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

    .timer { font-size: 1.9rem; }

    table.inventory-table th, table.inventory-table td {
        padding: 8px 6px;
        font-size: 0.82rem;
    }

    .garage-actions { flex-direction: column; }

    .garage-actions button { width: 100%; }

    .chat-widget { left: 8px; bottom: 8px; width: calc(100vw - 16px); max-width: 320px; }

    .empire-grid { max-width: 100%; gap: 2px; }

    .empire-tile { font-size: 0.7rem; }
}
