/* RimTown - AI Town Simulation Styles */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Prevent horizontal scroll on all devices */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --accent: #e94560;
    --accent-light: #ff6b6b;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --text-muted: #666;
    --border: #333;
    --positive: #4ade80;
    --negative: #f87171;
    --warning: #fbbf24;
    --info: #60a5fa;
}

.rimtown-container *,
.rimtown-container *::before,
.rimtown-container *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.rimtown-container {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden !important;
    height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    line-height: 1.5;
    font-size: 14px;
}

/* WordPress full-width page support */
body.rimtown-page .site-content,
body.rimtown-page .entry-content,
body.rimtown-page .post-content,
body.rimtown-page main,
body.rimtown-page article {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}
body.rimtown-page #page,
body.rimtown-page .site {
    overflow: hidden;
}
body.rimtown-page header.site-header,
body.rimtown-page .site-footer,
body.rimtown-page footer,
body.rimtown-page .wp-block-post-title {
    display: none;
}

/* Header removed — town name now in mobile-header */
.town-info-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.78rem;
    flex-wrap: wrap;
}
.town-info-name { color: var(--accent); font-weight: bold; letter-spacing: 1px; }
.town-info-pop { color: var(--text-secondary); }
.town-info-clock { color: var(--warning); font-family: monospace; margin-left: auto;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8rem;
    flex-wrap: wrap;
}

.clock-display {
    color: var(--warning);
    font-family: monospace;
    font-size: 0.85rem;
}

.controls {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.controls button {
    padding: 4px 12px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.controls button:hover {
    background: var(--accent);
}

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

.speed-controls {
    display: inline-flex;
    gap: 1px;
    background: var(--bg-primary);
    border-radius: 4px;
    padding: 2px;
    border: 1px solid var(--accent);
    margin-left: 2px;
}

.speed-controls .btn-speed {
    padding: 3px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: bold;
    transition: all 0.15s;
    white-space: nowrap;
}

.speed-controls .btn-speed:hover {
    background: rgba(233,69,96,0.25);
    color: var(--text-primary);
}

.speed-controls .btn-speed.active {
    background: var(--accent);
    color: #fff;
}

.llm-status {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
}
.llm-status.connected {
    color: var(--positive);
    border-color: var(--positive);
}
.llm-status.disconnected {
    color: var(--negative);
    border-color: var(--negative);
}

/* Main Layout — use absolute positioning to be immune to theme overrides */
.rimtown-container .main-layout {
    position: relative !important;
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    align-self: stretch !important;
}

/* Town Map — absolute position, leave 360px for sidebar */
.rimtown-container .map-panel {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 360px !important;
    bottom: 0 !important;
    overflow: hidden !important;
    background: #1a1a2e !important;
    display: block !important;
    visibility: visible !important;
    z-index: 1 !important;
}

.rimtown-container #town-map-canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: grab;
    touch-action: none;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}
.rimtown-container #town-map-canvas:active {
    cursor: grabbing;
}

.town-map {
    width: 100%;
    height: 100%;
    position: relative;
}

.location {
    position: absolute;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    text-align: center;
    min-width: 80px;
}

.location:hover {
    transform: scale(1.1);
    z-index: 10;
    border-color: var(--accent);
}

.location.cat-work {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.4);
}

.location.cat-social {
    background: rgba(168, 85, 247, 0.3);
    border-color: rgba(168, 85, 247, 0.4);
}

.location.cat-residential {
    background: rgba(34, 197, 94, 0.3);
    border-color: rgba(34, 197, 94, 0.4);
}

.location.cat-nature {
    background: rgba(16, 185, 129, 0.3);
    border-color: rgba(16, 185, 129, 0.4);
}

.location-name {
    font-weight: bold;
    color: var(--text-primary);
}

.location-count {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Agent dots on the map */
.agent-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.5s ease;
    z-index: 5;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.agent-dot:hover {
    transform: scale(1.8);
    z-index: 20;
}

.agent-dot .tooltip {
    display: none;
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    pointer-events: none;
}

.agent-dot:hover .tooltip {
    display: block;
}

/* Sidebar — absolute position on right */
.rimtown-container .rt-sidebar {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 360px !important;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Sidebar Tabs — grid layout */
.rt-sidebar-tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    flex-shrink: 0;
    position: relative;
}

/* Desktop: hide mobile-only elements */
.mobile-group-tabs {
    display: none;
}

/* Sub-tab bar inside panels */
.sub-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin: -10px -10px 10px -10px;
    padding: 0;
    background: var(--bg-primary);
}
.sub-tab-bar button {
    flex: 1;
    padding: 8px 6px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
}
.sub-tab-bar button:hover {
    background: rgba(233, 69, 96, 0.1);
    color: var(--text-primary);
}
.sub-tab-bar button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}

.rt-sidebar-tabs button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    transition: all 0.15s ease;
    position: relative;
}

.rt-sidebar-tabs button:hover {
    background: rgba(233, 69, 96, 0.1);
    color: var(--text-primary);
}

.rt-sidebar-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}

.rt-sidebar-tabs .tab-icon {
    font-size: 1rem;
    line-height: 1;
}

.rt-sidebar-tabs .tab-label {
    font-size: 0.65rem;
    line-height: 1;
    white-space: nowrap;
}

.rt-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* Resident List */
.resident-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.resident-card:hover {
    border-color: var(--accent);
}

.resident-card.selected {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.resident-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.resident-name {
    font-weight: bold;
    font-size: 0.95rem;
}

.resident-job {
    font-size: 0.75rem;
    color: var(--info);
}

.resident-status {
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.mood-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.mood-ecstatic, .mood-happy { background: var(--positive); }
.mood-content { background: var(--warning); }
.mood-unhappy, .mood-stressed { background: #f97316; }
.mood-miserable { background: var(--negative); }

/* Needs Bars */
.needs-bar {
    display: flex;
    align-items: center;
    margin: 3px 0;
    font-size: 0.65rem;
}

.needs-bar label {
    width: 70px;
    color: var(--text-secondary);
}

.needs-bar .bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.needs-bar .bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.bar-fill.high { background: var(--positive); }
.bar-fill.medium { background: var(--warning); }
.bar-fill.low { background: var(--negative); }

/* Agent Detail Panel */
.detail-panel {
    display: none;
}

.detail-panel.visible {
    display: block;
}

.detail-section {
    margin-bottom: 12px;
}

.detail-section h3 {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.trait-tag {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(233, 69, 96, 0.2);
    border-radius: 10px;
    font-size: 0.7rem;
    margin: 2px;
    color: var(--accent-light);
}

.relationship-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.memory-item {
    padding: 4px 0;
    font-size: 0.7rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.memory-time {
    color: var(--text-muted);
    font-size: 0.65rem;
}

/* Message Log */
.log-panel {
    display: none;
}

.log-panel.visible {
    display: block;
}

.log-entry {
    padding: 4px 0;
    font-size: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-entry .log-time {
    color: var(--text-muted);
    font-size: 0.65rem;
    margin-right: 6px;
}

.log-entry.type-conversation { border-left: 2px solid var(--info); padding-left: 6px; }
.log-entry.type-gossip { border-left: 2px solid var(--warning); padding-left: 6px; }
.log-entry.type-event { border-left: 2px solid var(--accent); padding-left: 6px; }

/* Events Panel */
.event-card {
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 6px;
    font-size: 0.8rem;
}

.event-card.severity-minor { border-color: var(--info); background: rgba(96, 165, 250, 0.1); }
.event-card.severity-moderate { border-color: var(--warning); background: rgba(251, 191, 36, 0.1); }
.event-card.severity-major { border-color: var(--negative); background: rgba(248, 113, 113, 0.1); }

.event-type-badge {
    display: inline-block;
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    font-weight: bold;
    text-transform: uppercase;
}
.event-type-badge.type-raid { background: var(--negative); color: #fff; }
.event-type-badge.type-chain { background: var(--warning); color: #000; }
.event-type-badge.type-departure { background: var(--info); color: #fff; }
.event-type-badge.type-arrival { background: var(--positive); color: #000; }
.event-type-badge.type-random { background: var(--text-muted); color: #fff; }

.travelling-section {
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}
.travelling-section h4 {
    color: var(--info);
    font-size: 0.75rem;
    margin-bottom: 4px;
}
.travelling-item {
    padding: 3px 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.chain-section {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}
.chain-section h4 {
    color: var(--warning);
    font-size: 0.75rem;
    margin-bottom: 4px;
}

.resident-card.travelling {
    opacity: 0.5;
    border-left: 3px solid var(--info);
}

/* Scrollbar */
.rimtown-container ::-webkit-scrollbar {
    width: 6px;
}

.rimtown-container ::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.rimtown-container ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.rimtown-container ::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Thought bubble */
.thought-bubble {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.6rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 15;
}

.thought-bubble.visible {
    opacity: 1;
}

/* ===== Player & Chat Styles ===== */

/* Player dot on map */
.player-dot {
    z-index: 8 !important;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
    animation: player-pulse 2s ease-in-out infinite;
}

@keyframes player-pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 255, 255, 0.4); }
    50% { box-shadow: 0 0 14px rgba(255, 255, 255, 0.8); }
}

/* Highlight location where player is */
.location.player-here {
    border-color: #fff !important;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Nearby badge on resident cards */
.nearby-badge {
    display: inline-block;
    background: var(--positive);
    color: #000;
    font-size: 0.55rem;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    font-weight: bold;
    vertical-align: middle;
}

/* Chat-with button on cards */
.chat-with-btn {
    margin-top: 6px;
    padding: 4px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
}
.chat-with-btn:hover {
    background: var(--accent-light);
}

/* Chat panel - Messaging App Style */

/* Contact list */
.chat-contacts {
    border-bottom: 1px solid var(--border);
}
.chat-contacts-header {
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.5px;
}
.chat-contacts-count {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: bold;
}
.chat-contacts-list {
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
}
.chat-contact {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background 0.2s, transform 0.1s;
    font-size: 0.8rem;
}
.chat-contact:hover {
    background: rgba(233,69,96,0.08);
}
.chat-contact:active {
    transform: scale(0.98);
}
.chat-contact.active {
    background: linear-gradient(135deg, rgba(233,69,96,0.18), rgba(233,69,96,0.08));
    border-left: 3px solid var(--accent);
}
.chat-contact-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #1a3a6e, #0f3460);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(233,69,96,0.3);
    position: relative;
}
.chat-contact-avatar-pixel {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    overflow: hidden;
}
.avatar-pixel-art {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.chat-contact-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.chat-contact-name {
    font-weight: bold;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(233,69,96,0.6);
    animation: unread-pulse 2s infinite;
}
@keyframes unread-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.avatar-initial {
    font-size: 1rem;
    line-height: 1;
}
.chat-contact-job {
    font-size: 0.68rem;
    color: var(--accent-light);
    opacity: 0.8;
}
.chat-contact-thought {
    font-size: 0.62rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.3;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-contact-preview {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.chat-contact-time {
    font-size: 0.6rem;
    color: var(--text-muted);
    flex-shrink: 0;
    white-space: nowrap;
}

/* Conversation header */
.chat-conv-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--bg-card), var(--bg-secondary));
}
.chat-conv-name {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--text-primary);
}
.chat-conv-detail {
    font-size: 0.7rem;
    color: var(--accent-light);
    opacity: 0.8;
    margin-top: 2px;
}

/* Chat messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    min-height: 180px;
    max-height: calc(100vh - 420px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-hint {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    animation: bubble-in 0.25s ease-out;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
@keyframes bubble-in {
    from { opacity: 0; transform: translateY(8px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-player {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent), #d63051);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-npc {
    align-self: flex-start;
    background: linear-gradient(135deg, #1a3a6e, var(--bg-card));
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.06);
}

.chat-system {
    align-self: center;
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
    font-size: 0.75rem;
    text-align: center;
}

.chat-speaker {
    font-size: 0.65rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 2px;
}
.chat-player .chat-speaker {
    color: rgba(255, 255, 255, 0.8);
}

.chat-time {
    font-size: 0.58rem;
    color: rgba(255, 255, 255, 0.35);
    margin-top: 3px;
    text-align: right;
}
.chat-npc .chat-time {
    color: var(--text-muted);
    text-align: left;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 10px 16px;
    background: linear-gradient(135deg, #1a3a6e, var(--bg-card));
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.06);
    display: flex;
    gap: 4px;
    align-items: center;
    animation: bubble-in 0.25s ease-out;
}
.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input area */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 22px;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(233,69,96,0.15);
}
.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    padding: 10px 18px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: bold;
    min-width: 64px;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 2px 6px rgba(233,69,96,0.3);
}
.chat-send-btn:hover {
    background: var(--accent-light);
    box-shadow: 0 3px 10px rgba(233,69,96,0.4);
}
.chat-send-btn:active {
    transform: scale(0.95);
}
.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* Chat badge for unread messages */
.chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--accent);
    color: white;
    font-size: 0.55rem;
    font-weight: bold;
    min-width: 14px;
    height: 14px;
    line-height: 14px;
    border-radius: 7px;
    text-align: center;
    padding: 0 3px;
    box-sizing: border-box;
}

/* Chat Archive */
.chat-archive-bar {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    border-top: 1px solid var(--border);
}
.btn-archive-view, .btn-archive-save {
    flex: 1;
    padding: 5px 8px;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-archive-view:hover, .btn-archive-save:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}
.archive-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.archive-header h3 {
    margin: 4px 0 2px;
    font-size: 0.85rem;
}
.archive-header .archive-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
}
.btn-back {
    padding: 3px 8px;
    font-size: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.btn-back:hover { color: var(--accent); border-color: var(--accent); }
.archive-list {
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}
.archive-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}
.archive-item:hover { background: rgba(255,255,255,0.03); }
.archive-info { flex: 1; }
.archive-title { font-size: 0.8rem; font-weight: 600; }
.archive-meta { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }
.archive-npcs { font-size: 0.65rem; color: var(--text-secondary); margin-top: 2px; }
.archive-actions { display: flex; gap: 4px; }
.archive-actions button {
    padding: 3px 8px;
    font-size: 0.65rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}
.archive-actions button:hover { border-color: var(--accent); }
.archive-actions .btn-danger:hover { border-color: var(--negative); color: var(--negative); }

.muted-text {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ===== Skills Display ===== */
.skills-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.skill-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 2px 0;
}

.skill-name {
    width: 80px;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.skill-passion {
    width: 30px;
    text-align: center;
    font-size: 0.6rem;
}

.passion-burning .skill-passion { color: #f59e0b; }
.passion-major .skill-passion { color: #f97316; }
.passion-minor .skill-passion { color: #60a5fa; }
.passion-incapable .skill-name { color: var(--text-muted); text-decoration: line-through; }
.passion-incapable .skill-passion { color: var(--negative); }

.skill-bar {
    flex: 1;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.skill-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--info);
    transition: width 0.5s ease;
}

.passion-burning .skill-bar-fill { background: #f59e0b; }
.passion-major .skill-bar-fill { background: #f97316; }
.passion-minor .skill-bar-fill { background: #60a5fa; }

.skill-level {
    width: 18px;
    text-align: right;
    font-weight: bold;
    font-size: 0.7rem;
}

.passion-incapable .skill-level { color: var(--text-muted); }

/* Skill up log entries */
.log-entry.type-skill_up { border-left: 2px solid #f59e0b; padding-left: 6px; }

/* Player chat log entries */
.log-entry.type-player_chat { border-left: 2px solid var(--positive); padding-left: 6px; }
.log-entry.type-player_move { border-left: 2px solid #fff; padding-left: 6px; }

/* New game / terrain */
.btn-new-game {
    background: var(--bg-card) !important;
    border-color: var(--warning) !important;
    color: var(--warning) !important;
}
.btn-new-game:hover {
    background: var(--warning) !important;
    color: #000 !important;
}

.terrain-display {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: monospace;
}

/* =====================================================
   TUTORIAL OVERLAY — New player intro & guide
   ===================================================== */
/* Quest Guidance Banner */
.quest-guidance {
    position: fixed;
    top: 44px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150000;
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, rgba(20,30,50,0.95), rgba(30,45,70,0.95));
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 8px 16px;
    max-width: min(500px, calc(100vw - 32px));
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 10px rgba(0,229,255,0.15);
    animation: guidanceSlideIn 0.5s ease;
    backdrop-filter: blur(8px);
}
.quest-guidance.hidden { display: none !important; }
.quest-guidance-icon { font-size: 1.3rem; flex-shrink: 0; }
.quest-guidance-text { flex: 1; min-width: 0; }
.quest-guidance-title {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--accent-light, #80dfff);
    margin-bottom: 2px;
}
.quest-guidance-hint {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.quest-guidance-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 4px;
    flex-shrink: 0;
    opacity: 0.6;
}
.quest-guidance-dismiss:hover { opacity: 1; color: var(--text-primary); }
@keyframes guidanceSlideIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.tutorial-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 190000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}
.tutorial-overlay.hidden { display: none !important; }
.tutorial-overlay.fade-out { opacity: 0; pointer-events: none; }
.tutorial-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(10, 10, 30, 0.65);
}
.tutorial-card {
    position: relative; z-index: 1;
    background: rgba(22, 33, 62, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 32px 28px 20px;
    width: 440px; max-width: 92vw; max-height: 80vh; overflow-y: auto;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}
.tutorial-step.hidden { display: none; }
.tutorial-story-icon { text-align: center; font-size: 3rem; margin-bottom: 8px; }
.tutorial-story-title { text-align: center; font-size: 1.5rem; color: var(--text-primary); margin: 0 0 4px; font-weight: 700; letter-spacing: 2px; }
.tutorial-story-subtitle { text-align: center; font-size: 0.72rem; color: var(--text-muted); margin: 0 0 20px; letter-spacing: 1px; }
.tutorial-story-text p { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.7; margin: 0 0 10px; }
.tutorial-step-icon { text-align: center; font-size: 2.2rem; margin-bottom: 6px; }
.tutorial-step h3 { text-align: center; font-size: 1.1rem; color: var(--accent-light); margin: 0 0 14px; font-weight: 600; }
.tutorial-step-text p { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.6; margin: 0 0 8px; }
.tutorial-step-text ul { list-style: none; padding: 0; margin: 8px 0; }
.tutorial-step-text li { font-size: 0.78rem; color: var(--text-secondary); padding: 4px 0 4px 4px; line-height: 1.5; }
.tutorial-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; gap: 12px; }
.tutorial-dots { display: flex; gap: 6px; justify-content: center; flex: 1; }
.tutorial-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: background 0.2s; }
.tutorial-dot.active { background: var(--accent); }
.tutorial-btn { padding: 8px 18px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-primary); border-radius: 8px; cursor: pointer; font-size: 0.8rem; white-space: nowrap; transition: all 0.2s; }
.tutorial-btn:hover { border-color: var(--accent); }
.tutorial-btn-primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.tutorial-btn-primary:hover { background: var(--accent-light); }
.tutorial-btn.hidden { display: none; }
.tutorial-skip { display: block; margin: 14px auto 0; background: none; border: none; color: var(--text-muted); font-size: 0.7rem; cursor: pointer; padding: 4px 8px; }
.tutorial-skip:hover { color: var(--text-secondary); }
@media (max-width: 768px) {
    .tutorial-overlay { overflow: hidden; }
    .tutorial-card { padding: 24px 20px 16px; width: calc(100vw - 32px); max-width: calc(100vw - 32px); overflow-x: hidden; }
    .tutorial-story-title { font-size: 1.3rem; }
    .tutorial-story-text p { font-size: 0.78rem; word-break: break-word; }
}

/* ===== Settings Modal ===== */
.rimtown-container .modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
}
.rimtown-container #auth-modal {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }
.hidden { display: none !important; }

/* ===== Guest Banner ===== */
#guest-banner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-secondary);
}
#guest-banner.hidden { display: none !important; }
#guest-register-btn {
    padding: 2px 10px;
    border: 1px solid var(--accent);
    border-radius: 3px;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.7rem;
}
#guest-banner-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 4px;
}

/* Mobile-only elements: hidden on desktop, shown only at ≤768px */
.mobile-header {
    display: none !important;
}
.mobile-population {
    display: none;
}
.mobile-drag-handle {
    display: none !important;
}
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 360px;
    max-width: 90vw;
}
.modal-content h2 {
    color: var(--accent);
    margin-bottom: 16px;
    font-size: 1.1rem;
}
.setting-group {
    margin-bottom: 12px;
}
.setting-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.setting-group select,
.setting-group input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
}
.setting-group select:focus,
.setting-group input:focus {
    border-color: var(--accent);
}
.modal-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}
.modal-buttons button {
    padding: 8px 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}
.modal-buttons button:hover { background: var(--accent); }

/* Game Dialog (custom alert/confirm) */
.game-dialog-content {
    text-align: center;
    padding: 28px 24px 20px;
    max-width: 320px;
    animation: gameDialogIn 0.2s ease-out;
}
@keyframes gameDialogIn {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.game-dialog-icon {
    font-size: 2.2rem;
    margin-bottom: 12px;
}
.game-dialog-msg {
    font-size: 0.88rem;
    color: var(--text-primary);
    line-height: 1.5;
    margin-bottom: 20px;
    white-space: pre-line;
}
.game-dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.game-dialog-buttons button {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
}
.game-dialog-buttons button:active {
    transform: scale(0.96);
}
.game-dialog-buttons .game-dialog-ok {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.game-dialog-buttons .game-dialog-ok:hover {
    filter: brightness(1.15);
}
.game-dialog-buttons .game-dialog-cancel:hover {
    background: var(--bg-secondary);
}

.btn-accent {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}
.btn-settings {
    background: var(--bg-card) !important;
    border-color: var(--text-muted) !important;
    color: var(--text-secondary) !important;
}
.btn-settings:hover {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}
.version-display { font-size: 0.65rem; color: rgba(255,255,255,0.4); padding: 2px 6px; user-select: none; }

/* Raid/departure log entry styles */
.log-entry.type-raid { border-left: 2px solid var(--negative); padding-left: 6px; }
.log-entry.type-departure { border-left: 2px solid var(--info); padding-left: 6px; }
.log-entry.type-arrival { border-left: 2px solid var(--positive); padding-left: 6px; }
.log-entry.type-immigration { border-left: 2px solid var(--positive); padding-left: 6px; }
.log-entry.type-chain_event { border-left: 2px solid var(--warning); padding-left: 6px; }
.log-entry.type-economy { border-left: 2px solid var(--warning); padding-left: 6px; }
.log-entry.type-building { border-left: 2px solid #a78bfa; padding-left: 6px; }
.log-entry.type-trade { border-left: 2px solid #fbbf24; padding-left: 6px; }
.log-entry.type-research { border-left: 2px solid #60a5fa; padding-left: 6px; }

/* Economy Tab */
.economy-panel { padding: 8px; }
.econ-section { margin-bottom: 12px; }
.econ-section h3 { font-size: 0.9rem; margin-bottom: 6px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 3px; }

.resource-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.resource-item { display: flex; flex-direction: column; align-items: center; padding: 4px; background: var(--bg-secondary); border-radius: 4px; font-size: 0.7rem; }
.resource-item.res-low { background: rgba(248,113,113,0.15); }
.resource-item.res-high { background: rgba(74,222,128,0.1); }
.res-icon { font-size: 1rem; }
.res-label { color: var(--text-secondary); font-size: 0.65rem; }
.res-amount { font-weight: bold; font-size: 0.85rem; }

.merchant-card { background: var(--bg-secondary); border-radius: 6px; padding: 8px; border: 1px solid var(--warning); }
.merchant-name { font-weight: bold; color: var(--warning); }
.merchant-info { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 6px; }
.trade-offers { display: flex; flex-direction: column; gap: 4px; }
.trade-offer { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 3px 6px; background: var(--bg-primary); border-radius: 3px; font-size: 0.7rem; }
.trade-offer.trade-sell { border-left: 2px solid var(--positive); }
.trade-offer.trade-buy { border-left: 2px solid var(--info); }
.trade-btn { padding: 4px 10px; font-size: 0.7rem; background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.trade-btn:hover { background: var(--accent); border-color: var(--accent); }

.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.shop-card { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; background: var(--bg-secondary); border-radius: 4px; gap: 2px; }
.shop-card-icon { font-size: 1.1rem; }
.shop-card-name { font-size: 0.75rem; font-weight: bold; }
.shop-card-stock { font-size: 0.6rem; color: var(--text-muted); }
.shop-card-btn { width: 90%; padding: 3px 0; font-size: 0.65rem; background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; text-align: center; }
.shop-card-btn:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.shop-card-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.shop-card-btn.shop-buy { border-color: var(--info); color: var(--info); }
.shop-card-btn.shop-sell { border-color: var(--positive); color: var(--positive); }

.building-progress { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.building-item { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; }
.progress-bar { flex: 1; height: 8px; background: var(--bg-primary); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.research-fill { background: var(--info); }
.progress-text { font-size: 0.65rem; color: var(--text-secondary); min-width: 30px; text-align: right; }

.completed-buildings { font-size: 0.7rem; color: var(--positive); margin: 4px 0; padding: 4px; background: rgba(74,222,128,0.1); border-radius: 3px; display: flex; flex-direction: column; gap: 2px; }
.completed-building-item { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px; }
.building-level { font-size: 0.65rem; color: var(--accent-gold, #f59e0b); font-weight: bold; }
.build-effects { font-size: 0.65rem; color: var(--accent-gold, #f59e0b); width: 100%; }

.build-label { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; }
.available-buildings, .research-available { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.build-option, .research-option { background: var(--bg-secondary); border-radius: 4px; padding: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.build-option.cant-afford { opacity: 0.5; }
.build-name { font-weight: bold; font-size: 0.75rem; flex: 1; min-width: 80px; }
.build-desc { font-size: 0.65rem; color: var(--text-secondary); width: 100%; }
.build-cost { font-size: 0.65rem; color: var(--warning); }
.build-btn { padding: 2px 8px; font-size: 0.65rem; background: var(--accent); color: white; border: none; border-radius: 3px; cursor: pointer; }
.build-btn:hover { background: var(--accent-light); }
.build-btn:disabled { background: var(--text-muted); cursor: not-allowed; }

.research-current { padding: 6px; background: var(--bg-secondary); border-radius: 4px; border-left: 3px solid var(--info); margin-bottom: 6px; font-size: 0.75rem; }
.research-option.active { border: 1px solid var(--info); }

/* News Bulletins */
.news-section { margin-bottom: 12px; }
.news-section h4 { color: var(--warning); font-size: 0.85rem; margin-bottom: 6px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.news-ticker { display: flex; flex-direction: column; gap: 6px; }
.news-bulletin { background: var(--bg-secondary); border-radius: 6px; padding: 8px; font-size: 0.75rem; position: relative; overflow: hidden; }
.news-bulletin::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.news-bulletin.severity-good::before { background: var(--positive); }
.news-bulletin.severity-info::before { background: var(--info); }
.news-bulletin.severity-warning::before { background: var(--warning); }
.news-bulletin.severity-danger::before { background: var(--negative); }
.news-header { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.news-severity { font-size: 0.7rem; }
.news-category { font-size: 0.6rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.news-duration { font-size: 0.6rem; color: var(--text-muted); margin-left: auto; background: var(--bg-primary); padding: 1px 5px; border-radius: 3px; }
.news-headline { font-weight: bold; font-size: 0.8rem; color: var(--text-primary); margin-bottom: 2px; }
.news-headline-en { font-size: 0.65rem; color: var(--text-secondary); font-style: italic; margin-bottom: 3px; }
.news-flavor { font-size: 0.7rem; color: var(--text-secondary); line-height: 1.3; }
.news-time { font-size: 0.6rem; color: var(--text-muted); margin-top: 3px; }
.news-effects { font-size: 0.7rem; padding: 6px 8px; background: var(--bg-secondary); border-radius: 4px; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.news-effects-label { font-weight: bold; color: var(--text-secondary); font-size: 0.65rem; }
.news-effect { padding: 1px 5px; border-radius: 3px; font-size: 0.6rem; }
.news-effect.effect-positive { background: rgba(74,222,128,0.15); color: var(--positive); }
.news-effect.effect-negative { background: rgba(248,113,113,0.15); color: var(--negative); }
.news-effect.effect-neutral { background: rgba(96,165,250,0.15); color: var(--info); }
.log-entry.type-news { border-left: 2px solid var(--warning); padding-left: 6px; font-weight: bold; }
.log-entry.type-system { border-left: 2px solid var(--positive); padding-left: 6px; font-style: italic; }

/* Save/Load buttons */
.btn-save, .btn-export, .btn-import {
    background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
    padding: 2px 8px; font-size: 0.7rem; border-radius: 3px; cursor: pointer;
}
.btn-save { border-color: var(--positive); color: var(--positive); }
.btn-save:hover { background: var(--positive); color: var(--bg-primary); }
.btn-export:hover, .btn-import:hover { border-color: var(--info); color: var(--info); }

/* ===== Relationship Status Badges ===== */
.rel-status-badge {
    display: inline-block; font-size: 0.55rem; padding: 1px 5px; border-radius: 8px;
    margin-left: 4px; vertical-align: middle; font-weight: bold;
}
.rel-status-badge.rel-dating { background: #e91e8c33; color: #f472b6; border: 1px solid #f472b644; }
.rel-status-badge.rel-married { background: #fbbf2433; color: #fbbf24; border: 1px solid #fbbf2444; }
.rel-status-badge.rel-ex { background: #6b728033; color: #9ca3af; border: 1px solid #6b728044; }
.rel-status-badge.rel-cheating { background: #dc262633; color: #f87171; border: 1px solid #dc262644; }
.relationship-item.rel-has-status { background: rgba(255,255,255,0.03); padding: 4px 6px; border-radius: 4px; margin-bottom: 2px; border-left: 2px solid #f472b6; }
.log-entry.type-relationship { border-left: 2px solid #f472b6; padding-left: 6px; }
.log-entry.type-mischief { border-left: 2px solid #fbbf24; padding-left: 6px; }
.log-entry.type-discovery { border-left: 2px solid #a78bfa; padding-left: 6px; }

/* ===== NPC Conversation Display ===== */
.npc-convo-section { margin-bottom: 8px; }
.npc-convo-entry {
    padding: 8px 10px;
    margin: 6px 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.npc-convo-entry:hover { background: rgba(255,255,255,0.05); border-color: var(--accent); }
.npc-convo-header {
    font-size: 0.78rem;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.npc-convo-toggle {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-right: 2px;
    transition: transform 0.2s;
    display: inline-block;
}
.npc-convo-entry.expanded .npc-convo-toggle { transform: rotate(90deg); }
.npc-convo-summary {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 2px;
}
.npc-convo-entry.expanded .npc-convo-summary { color: var(--accent-light); }
.npc-convo-dialogue {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.25);
    border-radius: 6px;
    border-left: 2px solid var(--accent);
}
.npc-convo-entry.expanded .npc-convo-dialogue { display: block; }
.npc-convo-line {
    font-size: 0.72rem;
    color: var(--text-primary);
    margin: 6px 0;
    line-height: 1.5;
    padding-left: 4px;
}
.npc-convo-line + .npc-convo-line { border-top: 1px solid rgba(255,255,255,0.04); padding-top: 6px; }
.npc-convo-speaker { color: var(--accent-light); font-weight: bold; }

/* ===== Login Modal ===== */
.login-content { max-width: 360px; text-align: center; position: relative; }
.login-content h2 { font-size: 1.5rem; margin-bottom: 4px; }
.login-subtitle { color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 16px; }
.login-error { color: var(--negative); font-size: 0.75rem; min-height: 18px; margin: 4px 0; }
.login-note { color: var(--text-muted); font-size: 0.65rem; margin-top: 12px; }
/* Prevent iOS auto-zoom on input focus (requires font-size >= 16px) */
.login-content input[type="text"],
.login-content input[type="password"],
.login-content input[type="email"] { font-size: 16px !important; }

/* ===== User Display ===== */
.user-display { display: flex; align-items: center; gap: 6px; }
.user-name { color: var(--accent-light); font-size: 0.75rem; font-weight: bold; }
.btn-towns, .btn-logout { background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
    padding: 1px 6px; font-size: 0.65rem; border-radius: 3px; cursor: pointer; }
.btn-towns:hover { border-color: var(--info); color: var(--info); }
.btn-logout:hover { border-color: var(--negative); color: var(--negative); }

/* ===== Town Manager ===== */
.town-content { max-width: 500px; }
.town-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; }
.town-item:hover { background: rgba(255,255,255,0.03); }
.town-item.active { border-left: 3px solid var(--accent); }
.town-info { flex: 1; }
.town-name { font-size: 0.85rem; font-weight: bold; color: var(--text-primary); }
.town-meta { font-size: 0.65rem; color: var(--text-secondary); margin-top: 2px; }
.current-badge { background: var(--accent); color: #fff; font-size: 0.55rem; padding: 1px 5px;
    border-radius: 8px; margin-left: 6px; vertical-align: middle; }
.town-actions { display: flex; gap: 4px; }
.town-actions button { background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
    padding: 2px 6px; font-size: 0.7rem; border-radius: 3px; cursor: pointer; }
.town-modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.town-btn {
    flex: 1; padding: 10px 16px; border: none; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s ease; text-align: center;
}
.town-btn-primary {
    background: var(--accent); color: #fff;
    box-shadow: 0 2px 8px rgba(233, 69, 96, 0.3);
}
.town-btn-primary:hover {
    background: #d43d5e; transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}
.town-btn-secondary {
    background: var(--bg-card); color: var(--text-secondary);
    border: 1px solid var(--border);
}
.town-btn-secondary:hover {
    background: var(--border); color: var(--text-primary);
}

/* ===== Election System ===== */
.election-section {
    background: rgba(233, 69, 96, 0.08);
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
.election-section h4 {
    color: var(--accent);
    font-size: 0.85rem;
    margin-bottom: 8px;
}
.election-info {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.election-candidate {
    background: var(--bg-card);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
    border: 1px solid transparent;
}
.election-candidate:hover {
    border-color: var(--accent);
}
.election-winner-card {
    border-color: var(--warning) !important;
    background: rgba(251, 191, 36, 0.1);
}
.candidate-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.candidate-name {
    font-weight: bold;
    font-size: 0.8rem;
    color: var(--text-primary);
}
.candidate-policy {
    font-size: 0.7rem;
    color: var(--info);
    background: rgba(96, 165, 250, 0.15);
    padding: 1px 6px;
    border-radius: 8px;
}
.candidate-votes {
    font-size: 0.7rem;
    color: var(--warning);
    margin-left: auto;
    font-weight: bold;
}
.candidate-speech {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-style: italic;
    line-height: 1.3;
}
.election-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}
.election-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease;
}
.election-bar-fill.winner {
    background: var(--warning);
}
.btn-vote {
    width: 100%;
    padding: 4px 8px;
    margin-top: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}
.btn-vote:hover {
    opacity: 0.85;
}
.election-total {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
}
.election-winner {
    text-align: center;
    padding: 8px;
    margin-bottom: 8px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 6px;
}
.winner-name {
    font-size: 1rem;
    font-weight: bold;
    color: var(--warning);
}
.winner-policy {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}
.election-history-brief {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    margin-bottom: 8px;
}
.log-entry.type-election { border-left: 2px solid var(--warning); padding-left: 6px; }

/* ===== Festival Section ===== */
.festival-section {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
.festival-section h4 {
    color: var(--warning);
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.quest-section {
    background: rgba(96, 165, 250, 0.08);
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
.quest-section h4 {
    color: var(--info);
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.quest-progress {
    height: 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 5px;
    overflow: hidden;
    margin-top: 6px;
    position: relative;
}
.quest-bar {
    height: 100%;
    background: var(--info);
    border-radius: 5px;
    transition: width 0.5s ease;
}
.quest-progress span {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    color: var(--text-primary);
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ===== Faction Section ===== */
.faction-section {
    margin-bottom: 10px;
}
.faction-section h4 {
    color: var(--info);
    font-size: 0.85rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.faction-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}
.faction-card:hover {
    border-color: var(--accent);
}
.faction-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.faction-cohesion {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 6px;
    border-radius: 8px;
}
.faction-cohesion.cohesion-high {
    color: var(--positive);
    background: rgba(74, 222, 128, 0.12);
}
.faction-cohesion.cohesion-low {
    color: var(--negative);
    background: rgba(248, 113, 113, 0.12);
}
.faction-members {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.4;
}
.faction-relations {
    font-size: 0.68rem;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.faction-rival {
    color: var(--negative);
    background: rgba(248, 113, 113, 0.1);
    padding: 1px 5px;
    border-radius: 4px;
}
.faction-ally {
    color: var(--positive);
    background: rgba(74, 222, 128, 0.1);
    padding: 1px 5px;
    border-radius: 4px;
}

/* ===== Exploration Section ===== */
.explore-section {
    margin-bottom: 10px;
}
.explore-section h4 {
    color: var(--accent-light);
    font-size: 0.85rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.expedition-active {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.25);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    font-size: 0.75rem;
}
.expedition-active strong {
    font-size: 0.72rem;
    color: var(--warning);
    display: block;
    margin-bottom: 4px;
}
.expedition-item {
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding: 2px 0;
}
.explore-zone {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}
.explore-zone:hover {
    border-color: var(--accent);
}
.zone-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.zone-diff {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--warning);
}
.zone-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 4px;
}
.zone-stats {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.zone-send {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}
.explore-select {
    flex: 1;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.7rem;
    padding: 2px;
}
.explore-select option {
    padding: 2px 4px;
}
.explore-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.7rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}
.explore-btn:hover {
    background: var(--accent-light);
}
.zone-busy {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Lifecycle Section (Births & Graveyard) ===== */
.lifecycle-section {
    margin-bottom: 10px;
}
.lifecycle-section h4 {
    font-size: 0.85rem;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}
.birth-item {
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding: 4px 8px;
    background: rgba(74, 222, 128, 0.06);
    border-left: 2px solid var(--positive);
    border-radius: 0 4px 4px 0;
    margin-bottom: 4px;
    line-height: 1.4;
}
.birth-time {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-left: 6px;
}
.grave-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 6px;
}
.grave-name {
    font-weight: bold;
    font-size: 0.78rem;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.grave-info {
    font-size: 0.7rem;
    color: var(--text-secondary);
}
.grave-epitaph {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 3px;
    line-height: 1.3;
}
.grave-time {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Quest System ===== */
.quest-card {
    background: var(--bg-card);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    border-left: 3px solid var(--border);
    transition: all 0.2s;
}
.quest-card.quest-active {
    border-left-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}
.quest-card.quest-completed {
    border-left-color: var(--positive);
    opacity: 0.75;
}
.quest-card.quest-locked {
    opacity: 0.4;
    border-left-color: var(--text-muted);
}
.quest-title {
    font-weight: bold;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}
.quest-desc {
    font-size: 0.73rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 6px;
}
.quest-objectives {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 6px;
}
.quest-objective {
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}
.quest-objective.done {
    color: var(--positive);
}
.quest-objective.done span:first-child {
    text-decoration: line-through;
    text-decoration-color: var(--positive);
}
.quest-obj-progress {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: monospace;
}
.quest-rewards {
    font-size: 0.7rem;
    color: var(--warning);
    padding: 3px 6px;
    background: rgba(251, 191, 36, 0.1);
    border-radius: 4px;
    margin-top: 4px;
}
.quest-complete-msg {
    font-size: 0.7rem;
    color: var(--positive);
    font-style: italic;
    margin-top: 4px;
}
.log-entry.type-quest { border-left: 2px solid var(--accent); padding-left: 6px; font-weight: bold; }

/* ===== Job Panel ===== */
.job-current-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(233,69,96,0.12), rgba(233,69,96,0.04));
    border: 1px solid rgba(233,69,96,0.3);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
}
.job-current-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.job-current-name {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--accent);
}
.btn-quit-job {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(239,68,68,0.12);
    color: #ef4444;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.75rem;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.2s;
}
.btn-quit-job:hover {
    background: rgba(239,68,68,0.25);
    border-color: rgba(239,68,68,0.5);
}
.job-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.job-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    padding: 8px 4px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    font-size: 0.7rem;
}
.job-btn:hover:not(:disabled) {
    background: rgba(233,69,96,0.1);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.job-btn.active {
    background: rgba(233,69,96,0.15);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 8px rgba(233,69,96,0.2);
}
.job-btn:disabled {
    cursor: default;
    opacity: 0.8;
}
.job-btn-icon {
    font-size: 1.2rem;
    line-height: 1;
}
.job-btn-title {
    font-size: 0.7rem;
    font-weight: 500;
}

/* ===== Newspaper Cards ===== */
.news-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.news-card:hover {
    border-color: rgba(233,69,96,0.4);
    background: rgba(255,255,255,0.03);
}
.news-card.news-latest {
    border-color: var(--accent);
    background: rgba(233,69,96,0.06);
}
.news-card.news-expanded {
    border-color: var(--accent);
}
.news-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.news-card-issue {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--accent);
    min-width: 32px;
}
.news-card-meta {
    flex: 1;
    min-width: 0;
}
.news-card-date {
    font-size: 0.8rem;
    color: var(--text-primary);
    font-weight: 500;
}
.news-card-reporter {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 1px;
}
.news-card-toggle {
    font-size: 0.6rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.news-card-preview {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed rgba(255,255,255,0.06);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.news-card-content {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    white-space: pre-wrap;
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ===== Center Notification Overlay ===== */
.center-notification-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: centerNotifFadeIn 0.3s ease;
}
.center-notification-overlay.hidden { display: none !important; }
.center-notification-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(10, 10, 30, 0.65);
}
.center-notification-card {
    position: relative; z-index: 1;
    background: rgba(22, 33, 62, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    padding: 28px 24px 20px;
    width: 420px; max-width: 90vw; max-height: 75vh; overflow-y: auto;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5), 0 0 30px rgba(201, 160, 51, 0.15);
    text-align: center;
}
.center-notif-icon { font-size: 3rem; margin-bottom: 8px; filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.4)); }
.center-notif-title { font-size: 1.2rem; font-weight: 700; color: #c9a033; letter-spacing: 2px; margin-bottom: 4px; }
.center-notif-name { font-size: 1.1rem; font-weight: 700; color: #fff; text-shadow: 0 0 8px rgba(255, 215, 0, 0.3); margin-bottom: 8px; }
.center-notif-desc { font-size: 0.82rem; color: rgba(255, 255, 255, 0.7); line-height: 1.6; margin-bottom: 16px; }
.center-notif-content { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.7; text-align: left; margin-bottom: 16px; white-space: pre-wrap; }
.center-notif-dismiss {
    display: inline-block;
    padding: 8px 24px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.center-notif-dismiss:hover { background: var(--accent-light); transform: scale(1.05); }
@keyframes centerNotifFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@media (max-width: 768px) {
    .center-notification-card { padding: 20px 16px 16px; width: calc(100vw - 24px); }
    .center-notif-icon { font-size: 2.5rem; }
    .center-notif-title { font-size: 1rem; }
    .center-notif-name { font-size: 0.95rem; }
}

/* ===== Achievement Toast ===== */
.achievement-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    z-index: 200000;
    display: flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, #2a1f0a 0%, #1a1a2e 40%, #1a1a2e 100%);
    border: 2px solid #c9a033;
    border-radius: 12px;
    padding: 14px 20px;
    min-width: 280px;
    max-width: 420px;
    box-shadow: 0 0 20px rgba(201, 160, 51, 0.35), 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,215,0,0.1);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
    pointer-events: none;
}
.achievement-toast.show {
    display: flex !important;
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
    animation: ach-toast-glow 2s ease-in-out infinite alternate;
}
@keyframes ach-toast-glow {
    0% { box-shadow: 0 0 20px rgba(201, 160, 51, 0.35), 0 8px 32px rgba(0,0,0,0.5); }
    100% { box-shadow: 0 0 30px rgba(201, 160, 51, 0.55), 0 8px 32px rgba(0,0,0,0.5); }
}
.ach-toast-icon {
    font-size: 2.2rem;
    line-height: 1;
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5));
    flex-shrink: 0;
}
.ach-toast-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.ach-toast-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #c9a033;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.ach-toast-name {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}
.ach-toast-desc {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.3;
}

/* ===== Achievements Panel ===== */
.achievements-panel {
    padding: 8px;
}
.achievements-panel h3 {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ach-count {
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(233, 69, 96, 0.12);
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: bold;
}
.ach-category {
    margin-bottom: 14px;
}
.ach-category h4 {
    font-size: 0.82rem;
    color: var(--accent-light);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.5px;
}
.ach-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.ach-card {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}
.ach-card.unlocked {
    border-color: rgba(251, 191, 36, 0.4);
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.08) 0%, rgba(233, 69, 96, 0.05) 100%);
}
.ach-card.unlocked::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--warning), var(--accent));
}
.ach-card.unlocked:hover {
    border-color: var(--warning);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.15);
}
.ach-card.locked {
    opacity: 0.45;
    border-color: transparent;
    background: rgba(255, 255, 255, 0.02);
}
.ach-card.locked:hover {
    opacity: 0.6;
}
.ach-icon {
    font-size: 1.4rem;
    line-height: 1;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ach-card.locked .ach-icon {
    filter: grayscale(1);
    font-size: 1.1rem;
}
.ach-info {
    flex: 1;
    min-width: 0;
}
.ach-name {
    font-weight: bold;
    font-size: 0.75rem;
    color: var(--text-primary);
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ach-card.unlocked .ach-name {
    color: var(--warning);
}
.ach-card.locked .ach-name {
    color: var(--text-muted);
}
.ach-desc {
    font-size: 0.65rem;
    color: var(--text-secondary);
    line-height: 1.3;
}
.ach-card.locked .ach-desc {
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Mobile Sidebar Toggle (removed - was non-functional) ===== */
.mobile-sidebar-toggle {
    display: none !important;
}

/* ===== Mobile Back to Map Button ===== */
.mobile-back-to-map {
    display: none !important;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 0;
    width: 100%;
    text-align: center;
}
.mobile-back-to-map:hover {
    background: var(--accent);
    color: #fff;
}

/* ===== Responsive: Tablet (≤1024px) ===== */
@media (max-width: 1024px) {
    .rimtown-container {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    .rimtown-container .rt-sidebar {
        width: 300px !important;
    }
    .rimtown-container .map-panel {
        right: 300px !important;
    }
    .controls button {
        padding: 3px 8px;
        font-size: 0.75rem;
    }
    /* Tablet: tab icons and labels */
    .rt-sidebar-tabs button {
        padding: 5px 2px;
    }
    .rt-sidebar-tabs .tab-icon {
        font-size: 1rem;
    }
    .rt-sidebar-tabs .tab-label {
        font-size: 0.6rem;
    }
    /* Tablet: achievement toast */
    .achievement-toast {
        max-width: 360px;
        min-width: 240px;
        padding: 12px 16px;
    }
}

/* ===== Responsive: Mobile (≤768px) ===== */
@media (max-width: 768px) {
    /* Force container to viewport, prevent page scroll & horizontal shift */
    .rimtown-container {
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        overflow: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }
    /* Prevent WordPress wrappers from scrolling */
    body.rimtown-page {
        overflow: hidden !important;
        height: 100vh !important;
        height: 100dvh !important;
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    /* Show mobile header on mobile */
    .mobile-header {
        display: block !important;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
    }
    .mobile-header-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 4px 10px;
        min-height: 36px;
    }
    .mobile-title {
        font-size: 0.9rem;
        font-weight: bold;
        color: var(--accent);
    }
    .mobile-clock {
        font-size: 0.75rem;
        color: var(--warning);
        font-family: monospace;
    }
    .mobile-header-actions {
        display: flex;
        gap: 4px;
    }
    .mobile-ctrl-btn {
        background: var(--bg-card);
        border: 1px solid var(--border);
        color: var(--text-primary);
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 0.8rem;
        cursor: pointer;
        min-width: 40px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .mobile-menu-dropdown {
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        padding: 6px 10px;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
    }
    .mobile-menu-dropdown.hidden {
        display: none !important;
    }
    .mobile-menu-dropdown button {
        background: var(--bg-card);
        border: 1px solid var(--border);
        color: var(--text-primary);
        padding: 6px 12px;
        border-radius: 4px;
        font-size: 0.75rem;
        cursor: pointer;
        min-height: 36px;
    }
    .mobile-menu-speed {
        display: flex;
        align-items: center;
        gap: 1px;
        font-size: 0.7rem;
        color: var(--text-secondary);
        background: var(--bg-primary);
        border-radius: 4px;
        padding: 1px;
        border: 1px solid var(--border);
    }
    .mobile-menu-speed .btn-speed {
        padding: 4px 6px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        border-radius: 3px;
        cursor: pointer;
        font-size: 0.65rem;
        font-weight: bold;
        min-height: 28px;
    }
    .mobile-menu-speed .btn-speed.active {
        background: var(--accent);
        color: #fff;
    }
    .mobile-menu-ai {
        font-size: 0.7rem;
    }
    /* Hide desktop header elements on mobile */
    #population-count,
    .clock-display,
    .terrain-display {
        display: none;
    }
    .btn-export, .btn-import, .btn-towns, .btn-new-game {
        display: none;
    }
    .speed-controls {
        display: none;
    }
    .llm-status {
        display: none;
    }

    /* Main layout on mobile: flex column to stack map + sidebar */
    .rimtown-container .main-layout {
        position: relative !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Map: fill available space above the bottom bar */
    .rimtown-container .map-panel {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        overflow: hidden !important;
    }
    #town-map-canvas {
        touch-action: none; /* allow JS to handle pinch/pan */
    }

    /* ===== Bottom Sheet Sidebar ===== */
    .rimtown-container .rt-sidebar {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: auto !important;
        max-height: 55vh !important;
        border-left: none !important;
        border-top: 2px solid var(--accent);
        z-index: 50;
        display: flex !important;
        flex-direction: column !important;
        background: var(--bg-primary) !important;
        transition: max-height 0.3s ease;
        padding-bottom: env(safe-area-inset-bottom, 0);
        overflow: hidden !important;
    }

    /* Collapsed state: only show tab bar */
    .rt-sidebar.mobile-collapsed {
        max-height: 52px !important;
    }
    .rt-sidebar.mobile-collapsed .rt-sidebar-content {
        display: none !important;
    }
    .rt-sidebar.mobile-collapsed .mobile-back-to-map {
        display: none !important;
    }
    .rt-sidebar.mobile-collapsed .mobile-drag-handle {
        display: none !important;
    }

    /* Hide the old back-to-map button, use collapse handle instead */
    .mobile-back-to-map {
        display: none !important;
    }

    /* Drag handle for bottom sheet */
    .mobile-drag-handle {
        display: block !important;
        width: 100%;
        padding: 4px 0;
        cursor: grab;
        text-align: center;
        flex-shrink: 0;
    }
    .mobile-drag-handle::after {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--text-muted);
        border-radius: 2px;
        margin: 0 auto;
    }

    /* Tab bar: fixed 5 tabs, no scroll */
    .rt-sidebar-tabs {
        display: flex !important;
        grid-template-columns: none !important;
        flex-direction: row !important;
        overflow: hidden !important;
        gap: 0;
        flex-shrink: 0;
        border-bottom: 1px solid var(--border);
        max-width: 100%;
        width: 100%;
    }

    /* Guest banner: move to bottom, above tab bar */
    #guest-banner {
        position: fixed;
        top: auto;
        bottom: 52px;
        left: 0;
        right: 0;
        z-index: 51;
        padding: 3px 8px;
        font-size: 0.65rem;
        gap: 4px;
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
    }
    #guest-banner span { white-space: nowrap; }
    #guest-register-btn { font-size: 0.6rem; padding: 1px 8px; }
    /* Hide overflow tabs on mobile (accessed via mobile group sub-tabs) */
    .rt-sidebar-tabs button.mobile-hidden {
        display: none !important;
    }
    .rt-sidebar-tabs button {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 4px;
        min-height: 48px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        white-space: nowrap;
        border-bottom: 2px solid transparent;
    }
    .rt-sidebar-tabs button.active {
        border-bottom-color: var(--accent);
        background: rgba(233, 69, 96, 0.12);
    }
    .rt-sidebar-tabs .tab-icon {
        font-size: 1.35rem;
    }
    .rt-sidebar-tabs .tab-label {
        font-size: 0.6rem;
        display: block;
    }

    /* Mobile group sub-tab bar — visible on mobile */
    .mobile-group-tabs {
        display: flex !important;
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-secondary);
    }

    /* Sub-tab bar: prevent negative margin overflow on mobile */
    .sub-tab-bar {
        margin-left: 0;
        margin-right: 0;
    }

    /* Sidebar content: scrollable area when expanded */
    .rt-sidebar-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 6px;
        min-height: 0;
        max-width: 100%;
    }

    /* Chat messages */
    .chat-messages {
        max-height: calc(45vh - 160px);
        min-height: 100px;
    }

    /* Settings inputs: prevent iOS auto-zoom on focus */
    .setting-group input,
    .setting-group select {
        font-size: 16px !important; /* prevents iOS zoom */
    }

    /* When virtual keyboard is open, expand sidebar so input stays visible */
    .rt-sidebar.keyboard-open {
        max-height: 70vh !important;
    }

    /* Chat input bigger touch targets */
    .chat-input {
        padding: 10px 14px;
        font-size: 16px; /* prevents iOS zoom */
    }
    .chat-send-btn {
        padding: 10px 18px;
        font-size: 0.85rem;
    }

    /* Modals */
    .modal-content {
        width: 95vw;
        padding: 16px;
        max-height: 85vh;
        overflow-y: auto;
    }

    /* Resource grid: 2 columns */
    .resource-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Archive list */
    .archive-list {
        max-height: calc(45vh - 140px);
    }
    .archive-item {
        flex-wrap: wrap;
    }
    .archive-actions {
        width: 100%;
        margin-top: 4px;
    }

    /* Mobile population display */
    .mobile-population {
        display: inline !important;
        font-size: 0.7rem;
        color: var(--accent-light);
        font-weight: bold;
        white-space: nowrap;
    }

    /* Hide hamburger FAB (removed) */
    .mobile-sidebar-toggle {
        display: none !important;
    }

    /* Festival / Quest / Faction sections responsive */
    .festival-section,
    .quest-section {
        padding: 8px;
        margin-bottom: 8px;
    }
    .faction-card {
        padding: 8px;
        margin-bottom: 6px;
    }
    .faction-header {
        font-size: 0.75rem;
    }
    .faction-members {
        font-size: 0.68rem;
    }

    /* Quest cards responsive */
    .quest-card {
        padding: 8px;
        margin-bottom: 6px;
    }
    .quest-title {
        font-size: 0.78rem;
    }
    .quest-desc {
        font-size: 0.68rem;
    }
    .quest-objectives {
        font-size: 0.68rem;
    }

    /* Achievement cards responsive */
    .achievement-card {
        padding: 8px;
        margin-bottom: 6px;
    }
    .achievement-filters {
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 8px;
    }
    .achievement-filters button {
        padding: 4px 8px;
        font-size: 0.65rem;
        min-height: 30px;
    }

    /* Prosperity dashboard responsive */
    .prosperity-dashboard {
        padding: 8px;
    }
    .prosperity-bar-label {
        font-size: 0.65rem;
    }

    /* Safe area insets for iPhone notch & home indicator */
    .mobile-header {
        padding-top: env(safe-area-inset-top, 0);
    }

    /* Mobile: achievement toast */
    .achievement-toast {
        top: 12px;
        min-width: 0;
        max-width: calc(100vw - 32px);
        padding: 10px 14px;
        gap: 10px;
        border-radius: 10px;
    }
    .ach-toast-icon {
        font-size: 1.8rem;
    }
    .ach-toast-name {
        font-size: 0.85rem;
    }
    .ach-toast-desc {
        font-size: 0.7rem;
    }

    /* Nearby buttons */
    .nearby-btn {
        padding: 3px 8px;
        font-size: 0.7rem;
    }

    /* Resident cards: tighter */
    .resident-card {
        padding: 8px 10px;
        margin-bottom: 6px;
    }

    /* ── Mobile: enlarge sidebar content text & buttons ── */
    .econ-section h3 {
        font-size: 1.05rem;
        padding-bottom: 5px;
        margin-bottom: 8px;
    }
    .trade-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
        border-radius: 6px;
        min-height: 36px;
    }
    .btn-speed {
        font-size: 0.8rem !important;
        padding: 6px 10px !important;
    }
    .setting-group label {
        font-size: 0.88rem !important;
    }
    .resident-name {
        font-size: 1.05rem;
    }
    .resident-job {
        font-size: 0.85rem;
    }
    .resident-status {
        font-size: 0.82rem;
    }
    .needs-bar {
        font-size: 0.78rem;
    }
    .needs-bar label {
        width: 80px;
    }
    .needs-bar .bar {
        height: 8px;
    }
    .resource-item {
        font-size: 0.82rem;
        padding: 6px;
    }
    .res-icon {
        font-size: 1.2rem;
    }
    .res-label {
        font-size: 0.72rem;
    }
    .res-amount {
        font-size: 0.92rem;
    }
    .building-item {
        font-size: 0.85rem;
    }
    .build-name {
        font-size: 0.88rem;
    }
    .build-desc {
        font-size: 0.78rem;
    }
    .build-cost {
        font-size: 0.78rem;
    }
    .build-btn {
        padding: 4px 12px;
        font-size: 0.78rem;
    }
    .research-current {
        font-size: 0.85rem;
    }
    .progress-text {
        font-size: 0.78rem;
    }
    .news-section h4 {
        font-size: 0.95rem;
    }
    .news-bulletin {
        font-size: 0.85rem;
    }
    .merchant-info {
        font-size: 0.82rem;
    }
    .trade-offer {
        font-size: 0.82rem;
    }
    .completed-buildings {
        font-size: 0.82rem;
    }
    .sub-tab-bar button {
        font-size: 0.85rem;
        padding: 10px 6px;
    }
    .log-entry {
        font-size: 0.82rem;
    }
    .chat-message {
        font-size: 0.85rem;
    }
    .version-display {
        font-size: 0.75rem;
    }
    .faction-header {
        font-size: 0.85rem;
    }
    .faction-members {
        font-size: 0.78rem;
    }
    .quest-title {
        font-size: 0.88rem;
    }
    .quest-desc {
        font-size: 0.78rem;
    }
    .quest-objectives {
        font-size: 0.78rem;
    }
    .achievement-filters button {
        padding: 6px 10px;
        font-size: 0.75rem;
        min-height: 34px;
    }
    .prosperity-bar-label {
        font-size: 0.78rem;
    }
}

/* ===== Responsive: Small Phone (≤480px) ===== */
@media (max-width: 480px) {
    /* Hide save button on very small screens */
    .btn-save {
        display: none;
    }

    /* Small phone: tab bar */
    .rt-sidebar-tabs button {
        padding: 6px 2px;
        min-height: 44px;
    }
    .rt-sidebar-tabs .tab-icon {
        font-size: 1.2rem;
    }
    .rt-sidebar-tabs .tab-label {
        font-size: 0.55rem;
    }
    .rt-sidebar.mobile-collapsed {
        max-height: 46px !important;
    }

    /* Town manager modal */
    .town-content {
        max-width: 100%;
    }
    .town-item {
        flex-wrap: wrap;
    }
    .town-actions {
        width: 100%;
        margin-top: 4px;
    }

    /* Mobile population: slightly smaller */
    .mobile-population {
        font-size: 0.65rem;
    }

    /* Small phone: achievement toast */
    .achievement-toast {
        top: 8px;
        padding: 8px 12px;
        gap: 8px;
    }
    .ach-toast-icon {
        font-size: 1.5rem;
    }
    .ach-toast-title {
        font-size: 0.6rem;
        letter-spacing: 1px;
    }
    .ach-toast-name {
        font-size: 0.8rem;
    }
    .ach-toast-desc {
        font-size: 0.65rem;
    }
}

/* ===== Responsive: iPad Portrait (768px-1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .rimtown-container {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    .rimtown-container .main-layout {
        overflow-x: hidden !important;
    }
    /* iPad: slightly larger tab icons */
    .rt-sidebar-tabs .tab-icon {
        font-size: 1.1rem;
    }
    .rt-sidebar-tabs .tab-label {
        font-size: 0.65rem;
    }

    /* iPad: enlarge sidebar content */
    .econ-section h3 {
        font-size: 0.95rem;
    }
    .trade-btn {
        padding: 5px 12px;
        font-size: 0.78rem;
    }
    .resident-name {
        font-size: 1rem;
    }
    .resident-job {
        font-size: 0.8rem;
    }
    .resident-status {
        font-size: 0.78rem;
    }
    .needs-bar {
        font-size: 0.72rem;
    }
    .sub-tab-bar button {
        font-size: 0.8rem;
        padding: 9px 6px;
    }
    .resource-item {
        font-size: 0.78rem;
    }
    .res-icon {
        font-size: 1.1rem;
    }
    .res-label {
        font-size: 0.68rem;
    }
    .res-amount {
        font-size: 0.88rem;
    }
    .building-item {
        font-size: 0.82rem;
    }
    .news-bulletin {
        font-size: 0.82rem;
    }
    .setting-group label {
        font-size: 0.85rem;
    }
}

/* === PWA Install Banner === */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: linear-gradient(135deg, #0f3460, #1a1a2e);
    border-top: 2px solid var(--accent);
    padding: 12px 16px;
    animation: pwa-slide-up 0.4s ease;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
}
.pwa-install-banner.hidden { display: none; }
@keyframes pwa-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}
.pwa-install-icon { font-size: 32px; }
.pwa-install-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pwa-install-text strong { color: var(--text-primary); font-size: 0.95rem; }
.pwa-install-text small { color: var(--text-secondary); font-size: 0.75rem; }
.pwa-install-accept {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}
.pwa-install-accept:hover { background: var(--accent-light); }
.pwa-install-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* PWA standalone mode adjustments */
@media (display-mode: standalone) {
    .rimtown-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}
