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

.text-reader-object-icon {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50%) rotate(var(--stone-rot, 0deg));
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    z-index: 10;
    pointer-events: auto;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.text-reader-object-icon:empty {
    display: none;
}
.text-reader-object-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background-color: #1a1a1a;
    color: white;
    overflow: hidden;
}

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

#bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(circle at 20% 20%, rgba(0,255,255,0.05), transparent 40%),
                radial-gradient(circle at 80% 70%, rgba(0,255,200,0.04), transparent 45%),
                #0e0e12;
}

canvas#gameCanvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    background-color: #0e0e12;
    display: block;
    margin: 0 auto;
    border: 2px solid #222;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6) inset, 0 0 30px rgba(0,0,0,0.5);
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    touch-action: none;
}

#torusCanvas {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
    width: 180px;
    height: 180px;
    z-index: 100;
    pointer-events: none;
    background: transparent;
}

.hud {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top, 0px));
    left: calc(16px + env(safe-area-inset-left, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 2;
}

.hud-item {
    pointer-events: none;
    font-size: 13px;
    font-weight: 400;
    opacity: 0.95;
}
.hud-item.hud-meta {
    font-size: 11px;
    opacity: 0.7;
}

.hud-left { 
    display: flex; 
    gap: 12px; 
    font-weight: 400; 
    text-shadow: 0 0 6px rgba(0,255,180,0.45);
}

.hud-bottom {
    position: absolute;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    pointer-events: none;
    z-index: 2;
    font-size: 12px;
    opacity: 0.8;
    text-shadow: 0 0 6px rgba(0,255,180,0.35);
}

.waypoint-toggle {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    z-index: 20;
    pointer-events: auto;
    display: none;
}

.controls-hud {
    position: absolute;
    left: calc(16px + env(safe-area-inset-left, 0px));
    top: calc(56px + env(safe-area-inset-top, 0px));
    z-index: 2;
    pointer-events: none;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(0,255,255,0.18);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 10px 30px rgba(0,255,255,0.08);
    max-width: 320px;
}

.controls-hud-title {
    font-size: 11px;
    opacity: 0.85;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.controls-hud-row {
    font-size: 11px;
    line-height: 1.25;
    opacity: 0.9;
    margin: 4px 0;
    white-space: nowrap;
}

.controls-hud-row .key {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.92);
}

.controls-hud-row .sep {
    opacity: 0.6;
    margin: 0 4px;
}

#layerHud {
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.92);
}

.hud-right { 
    display: flex; 
    gap: 12px; 
}

.energy-bar {
    width: 220px;
    height: 12px;
    border: 1px solid #0ff;
    border-radius: 6px;
    background: rgba(0, 255, 255, 0.08);
    box-shadow: 0 0 10px rgba(0,255,255,0.2), inset 0 0 10px rgba(0,255,255,0.1);
}

.energy-bar #energyFill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #19f, #0ff);
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.7);
}

.displacement-overlay {
    position: fixed;
    left: calc(50% - 370px);
    top: 46%;
    transform: translate(-24px, 0px);
    z-index: 9999;
    pointer-events: none;
    width: 420px;
    max-width: calc(100vw - 40px);
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.62);
    box-shadow: 0 10px 40px rgba(0,255,255,0.18), inset 0 2px 0 rgba(255,255,255,0.04), inset 0 -2px 0 rgba(0,0,0,0.25);
}

.stats-overlay {
    position: fixed;
    left: calc(50% - 760px);
    top: 34%;
    transform: translate(-24px, 0px);
    z-index: 9998;
    pointer-events: auto;
    width: 420px;
    max-width: calc(100vw - 40px);
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.68);
    border: 1px solid rgba(0,255,255,0.18);
    box-shadow: 0 10px 40px rgba(0,255,255,0.14), inset 0 2px 0 rgba(255,255,255,0.04), inset 0 -2px 0 rgba(0,0,0,0.25);
}

.stats-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    cursor: grab;
    user-select: none;
}

.stats-overlay-header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stats-overlay-name {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.05;
    color: rgba(255,255,255,0.94);
    text-shadow: 0 0 10px rgba(0,255,230,0.25);
}

.stats-overlay-title {
    font-size: 11px;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stats-overlay-close {
    pointer-events: auto;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.14);
    color: rgba(255,255,255,0.9);
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 14px;
    padding: 0;
}

.stats-overlay-text {
    font-size: 11px;
    line-height: 1.25;
    opacity: 0.92;
    white-space: pre;
    margin: 0;
}

.stats-overlay-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-start;
    gap: 10px;
}

.stats-overlay-actions button {
    pointer-events: auto;
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 8px;
}

.overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.86), rgba(0,0,0,0.72));
    padding: 28px 36px 32px;
    border-radius: 12px;
    border: 1px solid rgba(0,255,255,0.2);
    box-shadow: 0 10px 40px rgba(0,255,255,0.18), inset 0 2px 0 rgba(255,255,255,0.04), inset 0 -2px 0 rgba(0,0,0,0.25);
    z-index: 3;
}

.overlay .main-title {
    font-family: 'Papyrus', 'Copperplate', fantasy;
    font-size: 48px;
    color: #ee88ff;
    text-shadow: 
        0 0 10px rgba(255, 100, 200, 0.8),
        0 0 20px rgba(200, 80, 255, 0.6),
        0 0 40px rgba(180, 60, 220, 0.5),
        0 0 60px rgba(255, 100, 180, 0.4);
    margin-bottom: 8px;
    letter-spacing: 4px;
}
.overlay .subtitle {
    font-size: 12px;
    font-weight: 300;
    opacity: 0.85;
    margin-top: -4px;
    margin-bottom: 12px;
}
.overlay p { font-size: 14px; margin: 6px 0; opacity: 0.95; }

.settings {
    display: grid;
    gap: 12px;
    margin: 12px 0 8px;
    text-align: left;
}

.settings-row {
    display: grid;
    grid-template-columns: 160px 1fr auto;
    gap: 10px;
    align-items: center;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 10px 14px;
}

label {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.9;
}

input[type="text"] {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: #eaffff;
    padding: 8px 10px;
    border-radius: 8px;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #00ffe7;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(0,255,230,0.6);
}

.value { font-size: 12px; opacity: 0.8; }

.theme-options {
    display: flex;
    gap: 10px;
}
.theme-card {
    position: relative;
    width: 120px;
    height: 70px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.14);
    overflow: hidden;
    display: grid;
    place-items: end center;
    font-size: 11px;
    color: #eaffff;
    padding-bottom: 6px;
    cursor: pointer;
}
.theme-card input { display: none; }
.theme-card span { text-shadow: 0 2px 6px rgba(0,0,0,0.8); }
.theme-card:has(input:checked) { outline: 2px solid #00ffe7; box-shadow: 0 0 12px rgba(0,255,230,0.5); }

.theme-card.neon { background: repeating-linear-gradient(90deg, rgba(0,255,255,0.05) 0 2px, transparent 2px 64px), repeating-linear-gradient(0deg, rgba(0,255,255,0.05) 0 2px, transparent 2px 64px), radial-gradient(circle at 30% 20%, rgba(0,255,255,0.1), transparent 40%), #0e0e12; }
.theme-card.dotted { background: radial-gradient(circle at 2px 2px, rgba(255,255,255,0.15) 1px, transparent 1px) 0 0/12px 12px, #1a1f24; }
.theme-card.cosmic { background: radial-gradient(1200px 600px at 50% 80%, rgba(255,240,150,0.35), transparent 40%), radial-gradient(800px 400px at 20% 20%, rgba(150,120,255,0.25), transparent 40%), radial-gradient(800px 400px at 80% 30%, rgba(120,230,255,0.25), transparent 40%), #0a0f1a; }

/* Background presets applied via body classes */
body.theme-dotted #bg { background: radial-gradient(circle at 2px 2px, rgba(255,255,255,0.12) 1px, transparent 1px) 0 0/12px 12px, #111418; }
body.theme-cosmic #bg { background: radial-gradient(1600px 700px at 50% 90%, rgba(255,240,150,0.28), transparent 38%), radial-gradient(1000px 500px at 20% 25%, rgba(170,120,255,0.22), transparent 40%), radial-gradient(1000px 500px at 80% 35%, rgba(120,230,255,0.22), transparent 40%), #0a0f1a; }
body.theme-neon #bg { background: radial-gradient(circle at 20% 20%, rgba(0,255,255,0.05), transparent 40%), radial-gradient(circle at 80% 70%, rgba(0,255,200,0.04), transparent 45%), #0e0e12; }

.hidden {
    display: none !important;
}

.tuning-toggle {
    pointer-events: auto;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(0,255,255,0.3);
    background: rgba(0,0,0,0.35);
    color: #eaffff;
}

.tuning-panel {
    position: absolute;
    right: 16px;
    top: 56px;
    width: 280px;
    z-index: 3;
    background: rgba(0,0,0,0.7);
    border: 1px solid rgba(0,255,255,0.2);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,255,255,0.15);
    padding: 12px;
}
.tuning-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 600;
}
.tuning-header button {
    background: transparent;
    border: none;
    color: #eaffff;
    font-size: 14px;
    cursor: pointer;
}
.tuning-row {
    display: grid;
    grid-template-columns: 130px 1fr auto;
    gap: 8px;
    align-items: center;
    margin: 8px 0;
}
.tuning-row label { font-size: 12px; opacity: 0.9; }
.tuning-hint { font-size: 11px; opacity: 0.7; margin-top: 6px; }
.tuning-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(0,255,200,0.5);
    border-top: 1px solid rgba(0,255,200,0.15);
    margin-top: 10px;
    padding-top: 8px;
}

.friends-panel {
    position: absolute;
    right: 16px;
    top: 56px;
    min-width: 220px;
    max-width: 280px;
    background: rgba(14,14,18,0.96);
    border: 1px solid rgba(100,150,255,0.3);
    border-radius: 8px;
    z-index: 20;
    box-shadow: 0 8px 30px rgba(100,150,255,0.15);
    padding: 12px;
    pointer-events: auto;
}

.waypoints-panel {
    position: absolute;
    right: 16px;
    top: 56px;
    width: 360px;
    max-height: 520px;
    background: rgba(14,14,18,0.96);
    border: 1px solid rgba(100,150,255,0.3);
    border-radius: 10px;
    z-index: 21;
    box-shadow: 0 8px 30px rgba(100,150,255,0.15);
    padding: 12px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.waypoints-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
    font-weight: 600;
    color: #aaddff;
}

.waypoints-header button {
    background: transparent;
    border: none;
    color: #eaffff;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    margin: 0;
}

.waypoints-controls {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 8px;
    align-items: center;
    font-size: 12px;
}

.waypoints-controls select {
    pointer-events: auto;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(80,160,255,0.25);
    color: rgba(255,255,255,0.9);
    border-radius: 8px;
    padding: 6px 8px;
    outline: none;
}

.waypoints-list {
    flex: 1;
    overflow: auto;
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.03);
    border-radius: 10px;
    padding: 6px;
}

.waypoints-row {
    display: grid;
    grid-template-columns: 14px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
}

.waypoints-row:hover {
    background: rgba(255,255,255,0.05);
}

.waypoints-row.selected {
    background: rgba(0,255,231,0.10);
    outline: 1px solid rgba(0,255,231,0.25);
}

.waypoints-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.25);
}

.waypoints-meta {
    font-size: 10px;
    opacity: 0.75;
    text-align: right;
}

.waypoints-editor {
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.03);
    border-radius: 10px;
    padding: 8px;
    display: grid;
    gap: 8px;
}

.waypoints-editor-row {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 8px;
    align-items: center;
    font-size: 12px;
}

.waypoints-editor input[type="text"],
.waypoints-editor input[type="url"],
.waypoints-editor textarea {
    pointer-events: auto;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(80,160,255,0.25);
    border-radius: 8px;
    padding: 6px 8px;
    color: rgba(255,255,255,0.92);
    outline: none;
    font-family: inherit;
    font-size: 12px;
}

.waypoints-editor textarea {
    resize: vertical;
}

.waypoints-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.waypoints-actions button {
    pointer-events: auto;
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    margin: 0;
}
.friends-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 600;
    color: #aaddff;
}
.friends-header button {
    background: transparent;
    border: none;
    color: #eaffff;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    margin: 0;
}
.friends-list {
    max-height: 300px;
    overflow-y: auto;
}
.friends-empty {
    font-size: 11px;
    opacity: 0.6;
    padding: 8px 0;
}
.friends-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
    cursor: pointer;
    transition: background 0.15s;
}
.friends-item:hover {
    background: rgba(100,150,255,0.15);
}
.friends-item-name {
    font-size: 12px;
    font-weight: 500;
}
.friends-item-type {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
}
.friends-item-type.affinity {
    background: rgba(150,150,150,0.3);
    color: #aaa;
}
.friends-item-type.friend {
    background: rgba(100,255,150,0.2);
    color: #8f8;
}
.friends-item-type.love {
    background: rgba(255,100,180,0.2);
    color: #f9c;
}
.friends-item-online {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}
.friends-item-online.online {
    background: #0f0;
    box-shadow: 0 0 4px #0f0;
}
.friends-item-online.offline {
    background: #666;
}

.seed-display {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 6px;
    background: rgba(20,20,30,0.85);
    border: 1px solid rgba(100,150,255,0.4);
    transition: all 0.2s;
    font-size: 12px;
    z-index: 10;
    pointer-events: auto !important;
}
.seed-display:hover {
    background: rgba(40,40,60,0.95);
    border-color: rgba(100,150,255,0.7);
    transform: translateX(-50%) scale(1.03);
}
.seed-display::after {
    content: ' ✎';
    opacity: 0.6;
}

.radio-display {
    position: fixed;
    top: calc(88px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20,40,60,0.85);
    border: 1px solid rgba(80,160,255,0.4);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    color: rgba(150,200,255,0.9);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
}
.radio-input {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(80,160,255,0.3);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 11px;
    color: #fff;
    width: 80px;
    outline: none;
    font-family: inherit;
}
.radio-input:focus {
    border-color: rgba(100,180,255,0.7);
    background: rgba(0,0,0,0.5);
}

.seed-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.seed-modal.hidden {
    display: none;
}
.seed-modal-content {
    background: rgba(14,14,18,0.98);
    border: 1px solid rgba(100,150,255,0.4);
    border-radius: 12px;
    padding: 20px;
    min-width: 320px;
    max-width: 400px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.seed-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 600;
    color: #aaddff;
}
.seed-modal-header button {
    background: transparent;
    border: none;
    color: #eaffff;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    margin: 0;
}
.seed-modal-desc {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 16px;
    line-height: 1.5;
}
.seed-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(100,150,255,0.3);
    border-radius: 6px;
    color: #eaffff;
    margin-bottom: 16px;
    box-sizing: border-box;
}
.seed-input:focus {
    outline: none;
    border-color: rgba(100,150,255,0.6);
    background: rgba(255,255,255,0.15);
}
.seed-modal-actions {
    display: flex;
    gap: 10px;
}
.seed-modal-actions button {
    flex: 1;
    padding: 10px 16px;
    font-size: 13px;
    margin: 0;
}

/* Synth XY Pad Panel */
.synth-panel {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: rgba(10, 10, 15, 0.95);
    border: 1px solid rgba(200, 100, 255, 0.4);
    border-radius: 12px;
    padding: 16px;
    width: 240px;
    z-index: 50;
    box-shadow: 0 8px 32px rgba(150, 50, 200, 0.3);
}
.synth-panel.hidden { display: none; }
.synth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #dd99ff;
}
.synth-header button {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 16px;
    padding: 2px 6px;
    margin: 0;
    cursor: pointer;
}
.synth-labels {
    position: relative;
    height: 0;
}
.synth-label-y {
    position: absolute;
    left: -24px;
    top: 90px;
    transform: rotate(-90deg);
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.synth-label-x {
    position: absolute;
    bottom: -185px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.synth-xy {
    position: relative;
    width: 200px;
    height: 200px;
    background: linear-gradient(135deg, rgba(100, 50, 150, 0.3), rgba(50, 100, 150, 0.3));
    border: 1px solid rgba(200, 100, 255, 0.3);
    border-radius: 8px;
    margin: 8px auto;
    cursor: crosshair;
    overflow: hidden;
}
.synth-grid {
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 25% 25%;
}
.synth-cursor {
    position: absolute;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(255,150,255,0.9), rgba(150,100,255,0.6));
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    left: 50%;
    top: 50%;
    pointer-events: none;
    box-shadow: 0 0 15px rgba(255, 150, 255, 0.6);
    transition: left 0.05s, top 0.05s;
}
.synth-values {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #aaa;
    margin: 8px 4px;
}
.synth-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.synth-preset {
    flex: 1;
    min-width: 45%;
    padding: 6px 8px;
    font-size: 11px;
    margin: 0;
    background: linear-gradient(to bottom, rgba(150, 80, 200, 0.6), rgba(100, 50, 150, 0.6));
    border: 1px solid rgba(200, 100, 255, 0.3);
}
.synth-preset:hover {
    background: linear-gradient(to bottom, rgba(180, 100, 230, 0.8), rgba(130, 70, 180, 0.8));
}

.synth-divider {
    height: 1px;
    background: rgba(200, 100, 255, 0.3);
    margin: 12px 0;
}
.cruise-hum-section {
    padding: 4px 0;
}
.cruise-hum-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 8px;
}
.cruise-hum-toggle input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.cruise-osc-sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cruise-osc {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
}
.cruise-osc label {
    width: 40px;
    color: rgba(255,255,255,0.7);
}
.cruise-osc input[type="range"] {
    flex: 1;
    height: 4px;
    cursor: pointer;
}
.cruise-osc span {
    width: 55px;
    text-align: right;
    color: rgba(200,150,255,0.9);
    font-size: 10px;
}

/* Chat input */
.chat-input {
    position: fixed;
    width: 160px;
    padding: 10px 12px;
    background: rgba(20, 60, 120, 0.75);
    border: 1px solid rgba(80, 160, 255, 0.5);
    border-radius: 4px;
    color: #fff;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0, 100, 200, 0.3);
}
.chat-input.active {
    opacity: 1;
    pointer-events: auto;
}
.chat-input:focus {
    border-color: rgba(100, 180, 255, 0.8);
    background: rgba(30, 80, 150, 0.85);
}
.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

button {
    background: linear-gradient(to bottom, #00ffc3, #00bcd4);
    border: none;
    color: white;
    padding: 12px 24px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 10px 2px;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s ease;
}

button:hover {
    background: linear-gradient(to bottom, #00c1a1, #0097a7);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.relinquish-soul {
    background: linear-gradient(to bottom, #ff5577, #b1003a);
}

.relinquish-soul:hover {
    background: linear-gradient(to bottom, #e64266, #8f002e);
}

.boost-hud {
    position: absolute;
    left: 16px;
    bottom: 16px;
    display: grid;
    grid-template-columns: 260px 280px 340px;
    gap: 12px;
    z-index: 2;
    pointer-events: none;
}

.boost-meter,
.boost-debug,
.boost-graph {
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(0,255,255,0.18);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 10px 30px rgba(0,255,255,0.08);
}

.boost-meter-label,
.boost-debug-label,
.boost-graph-label {
    font-size: 11px;
    opacity: 0.85;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.boost-graph canvas {
    display: block;
    width: 100%;
    height: 120px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.10);
}

.boost-meter-bar {
    position: relative;
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
}

.boost-meter-zone {
    position: absolute;
    top: 0;
    bottom: 0;
}

.boost-zone-optimal {
    left: calc(((1.25 - 0.03) / 1.5) * 100%);
    width: calc((0.06 / 1.5) * 100%);
    background: rgba(255, 240, 150, 0.95);
    box-shadow: 0 0 12px rgba(255, 240, 150, 0.55);
}

.boost-meter-needle {
    position: absolute;
    top: -4px;
    width: 2px;
    height: 22px;
    left: 0%;
    background: rgba(0,255,231,0.95);
    box-shadow: 0 0 12px rgba(0,255,231,0.55);
}

.boost-meter-needle.optimal {
    width: 3px;
    background: rgba(255, 240, 150, 0.98);
    box-shadow: 0 0 16px rgba(255, 240, 150, 0.75);
}

.boost-meter-bar.optimal {
    border-color: rgba(255, 240, 150, 0.45);
    box-shadow: 0 0 18px rgba(255, 240, 150, 0.22);
}

.boost-meter-scale {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    opacity: 0.7;
    margin-top: 6px;
}

.boost-debug-text {
    font-size: 11px;
    line-height: 1.25;
    opacity: 0.9;
    white-space: pre;
    margin: 0;
}

h1 {
    color: #00ffe7;
    margin-bottom: 20px;
    text-shadow: 0 0 18px rgba(0,255,255,0.7);
    font-family: 'Papyrus', 'Papyrus MT', fantasy, 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

h2 {
    color: #ff5577;
    margin-bottom: 15px;
    text-shadow: 0 0 14px rgba(255,85,119,0.35);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .hud {
        top: 8px;
        left: 8px;
        right: 8px;
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .hud-left {
        font-size: 11px;
        gap: 6px;
    }
    
    .hud-right {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: flex-end;
    }
    
    .tuning-toggle {
        font-size: 10px;
        padding: 4px 6px;
        border-radius: 4px;
    }
    
    .energy-bar {
        width: 60px;
        height: 6px;
    }
    
    .seed-display {
        top: calc(64px + env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        font-size: 10px;
        padding: 4px 8px;
    }
    
    .radio-display {
        top: calc(88px + env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        font-size: 10px;
    }
    
    .radio-input {
        width: 70px;
        font-size: 10px;
        padding: 2px 4px;
    }
    
    #torusCanvas {
        width: 100px;
        height: 100px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        right: calc(10px + env(safe-area-inset-right, 0px));
    }
    
    .hud-bottom {
        bottom: calc(92px + env(safe-area-inset-bottom, 0px));
        max-width: calc(100vw - 16px);
        flex-wrap: wrap;
        justify-content: center;
        font-size: 10px;
        line-height: 1.2;
        gap: 6px 10px;
    }

    #layerHud {
        order: 1;
        width: 100%;
        text-align: center;
    }

    #ageHud {
        order: 2;
        width: 100%;
        text-align: center;
        white-space: nowrap;
    }

    .waypoint-toggle {
        display: inline-flex;
        bottom: calc(140px + env(safe-area-inset-bottom, 0px));
        padding: 10px 12px;
        font-size: 12px;
        border-radius: 10px;
    }
    
    .tuning-panel {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
        top: 50px;
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .tuning-row {
        grid-template-columns: 100px 1fr auto;
        gap: 4px;
        font-size: 11px;
    }
    
    .controls-hud {
        top: 50px;
        left: 8px;
        max-width: calc(100vw - 20px);
        padding: 8px;
    }
    
    .synth-panel, .friends-panel {
        width: calc(100vw - 20px);
        left: 10px;
        right: 10px;
    }

    .waypoints-panel {
        width: calc(100vw - 20px);
        left: 10px;
        right: 10px;
        top: 50px;
        max-height: 70vh;
    }
}

/* ============ TEXT FRAGMENT SYSTEM ============ */
.text-drop-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 255, 230, 0.06);
    border: 2px dashed rgba(0, 255, 230, 0.4);
    pointer-events: none;
}

.text-drop-overlay.hidden {
    display: none;
}

.text-drop-message {
    font-size: 18px;
    font-weight: 600;
    color: rgba(0, 255, 230, 0.8);
    text-shadow: 0 0 20px rgba(0, 255, 230, 0.4);
    letter-spacing: 0.5px;
}

.text-reader-modal {
    position: absolute;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.text-reader-stage {
    width: min(980px, calc(100vw - 64px));
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-reader-modal.hidden {
    display: none;
}

.text-reader-orbit {
    position: relative;
    width: min(980px, calc(100vw - 64px));
    height: min(74vh, 640px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-reader-orbit-previews {
    position: absolute;
    inset: 0;
    pointer-events: auto;
}

.text-reader-content {
background: rgba(10, 12, 18, 0.95);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
width: min(520px, calc(100vw - 48px));
max-height: min(70vh, 520px);
display: flex;
flex-direction: column;
overflow: visible;
box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 1px rgba(255, 255, 255, 0.1);
position: relative;
z-index: 5;
}

.text-reader-preview {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) translate(var(--ox, 0px), var(--oy, 0px)) scale(var(--os, 0.95));
opacity: var(--oo, 0.75);
pointer-events: auto;
background: rgba(10, 12, 18, 0.72);
border: 1px solid var(--preview-border, rgba(255, 255, 255, 0.10));
border-radius: 8px;
padding: 10px 10px;
cursor: pointer;
transition: transform 0.12s, border-color 0.12s, background 0.12s, opacity 0.12s;
z-index: 2;
width: 180px;
max-width: min(220px, calc(100vw - 64px));
}


 .stone-reader-trash-btn {
     width: 28px;
     height: 28px;
     padding: 0;
     display: inline-flex;
     align-items: center;
     justify-content: center;
     border: 1px solid rgba(255, 255, 255, 0.12);
     border-radius: 6px;
     background: rgba(255, 255, 255, 0.04);
     color: rgba(255, 255, 255, 0.7);
     cursor: pointer;
 }

 .stone-reader-trash-btn:hover {
     background: rgba(255, 90, 90, 0.14);
     border-color: rgba(255, 90, 90, 0.35);
     color: rgba(255, 200, 200, 0.95);
 }

 .stone-confirm-modal {
     position: fixed;
     inset: 0;
     z-index: 1400;
     display: flex;
     align-items: center;
     justify-content: center;
     background: rgba(0,0,0,0.55);
 }

 .stone-confirm-box {
     width: min(420px, calc(100vw - 40px));
     background: rgba(10, 12, 18, 0.96);
     border: 1px solid rgba(255,255,255,0.14);
     border-radius: 10px;
     box-shadow: 0 10px 50px rgba(0,0,0,0.7);
     padding: 14px 14px;
 }

 .stone-confirm-msg {
     font-size: 13px;
     line-height: 1.45;
     color: rgba(255,255,255,0.85);
     margin-bottom: 12px;
 }

 .stone-confirm-actions {
     display: flex;
     justify-content: flex-end;
     gap: 8px;
 }

 .stone-confirm-danger {
     border-color: rgba(255, 90, 90, 0.45) !important;
     background: rgba(255, 90, 90, 0.14) !important;
     color: rgba(255, 220, 220, 0.95) !important;
 }

.text-reader-preview-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--preview-dot, rgba(255, 255, 255, 0.55));
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.text-reader-preview:hover {
    border-color: rgba(0, 255, 230, 0.28);
    background: rgba(0, 255, 230, 0.04);
    transform: translate(-50%, -50%) translate(var(--ox, 0px), var(--oy, 0px)) scale(calc(var(--os, 0.95) * 1.02));
}

.text-reader-preview.active {
    border-color: rgba(0, 255, 230, 0.42);
    background: rgba(0, 255, 230, 0.06);
}

.text-reader-preview-title {
font-size: 11px;
color: rgba(255, 255, 255, 0.55);
margin-bottom: 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.text-reader-preview-snippet {
font-size: 12px;
line-height: 1.4;
color: rgba(255, 255, 255, 0.78);
max-height: 48px;
overflow: hidden;
}

.text-reader-header {
display: flex;
align-items: center;
justify-content: center;
padding: 22px 16px 12px 16px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
position: relative;
}

.text-reader-story-badge {
    position: absolute;
    left: 12px;
    top: 10px;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(170, 120, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.55);
    cursor: pointer;
}

.text-reader-story-badge.hidden {
    display: none;
}

.text-reader-author {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 400;
    text-align: center;
    width: 100%;
}

.text-reader-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    position: absolute;
    top: 8px;
    right: 8px;
}

.text-reader-close:hover {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}

.text-reader-body {
    padding: 20px 16px;
    font-size: 14px;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.85);
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Inter', system-ui, sans-serif;
}

.text-reader-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.text-reader-vote {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

.text-reader-vote:hover {
    color: rgba(0, 255, 230, 0.9);
    border-color: rgba(0, 255, 230, 0.4);
    background: rgba(0, 255, 230, 0.06);
}

.text-reader-votes {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    min-width: 20px;
    text-align: center;
}

.text-composer-modal {
    position: absolute;
    inset: 0;
    z-index: 320;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
}

.text-composer-modal.hidden {
    display: none;
}

.text-composer-content {
    background: rgba(10, 12, 18, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    max-width: 520px;
    width: 92%;
    box-shadow: 0 10px 44px rgba(0, 0, 0, 0.65), 0 0 1px rgba(255, 255, 255, 0.1);
    padding: 12px 12px 10px;
}

.text-composer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px 10px;
}

.text-composer-title {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 600;
    letter-spacing: 0.2px;
}

.text-composer-input {
    width: 100%;
    resize: none;
    outline: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.22);
    color: rgba(255, 255, 255, 0.88);
    padding: 12px;
    font-size: 14px;
    line-height: 1.55;
    min-height: 86px;
    max-height: 56vh;
    overflow-y: auto;
}

.text-composer-input:focus {
    border-color: rgba(0, 255, 230, 0.35);
    box-shadow: 0 0 0 3px rgba(0, 255, 230, 0.06);
}

.text-composer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 4px 0;
}

@media (max-width: 480px) {
    .tuning-toggle {
        font-size: 9px;
        padding: 3px 5px;
    }
    
    .hud-left {
        font-size: 10px;
    }
    
    .energy-bar {
        width: 50px;
    }
}

/* ── Inventory Panel ── */
.inventory-panel {
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 200;
    width: 180px;
    background: rgba(10, 10, 16, 0.88);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 10px;
    backdrop-filter: blur(8px);
    font-family: 'Inter', system-ui, sans-serif;
    user-select: none;
    transition: opacity 0.2s;
}
.inventory-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.inventory-title {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.inventory-count {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    margin-left: auto;
}
.inventory-collapse-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 12px;
    cursor: pointer;
    padding: 0 2px;
    transition: transform 0.2s;
}
.inventory-panel.collapsed .inventory-collapse-btn {
    transform: rotate(-90deg);
}
.inventory-body {
    max-height: 45vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 6px 8px 8px;
}
.inventory-panel.collapsed .inventory-body {
    max-height: 0;
    padding: 0 8px;
    overflow: hidden;
}

.notes-panel {
    left: 204px;
    width: 180px;
}

.notes-hide-attached {
    background: rgba(160, 120, 255, 0.10);
    border: 1px solid rgba(160, 120, 255, 0.25);
    color: rgba(200, 180, 255, 0.90);
    width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
}
.notes-hide-attached:hover {
    border-color: rgba(160, 120, 255, 0.40);
    background: rgba(160, 120, 255, 0.16);
}
.notes-hide-attached.active {
    background: rgba(160, 120, 255, 0.22);
    border-color: rgba(160, 120, 255, 0.60);
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 28px;
}

.notes-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.06);
    background: rgba(255,255,255,0.03);
    cursor: grab;
    font-size: 11px;
    color: rgba(255,255,255,0.78);
    overflow: hidden;
}

.notes-item-main {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.notes-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-item-time {
    font-size: 9px;
    color: rgba(255,255,255,0.42);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notes-item:hover {
    background: rgba(100,150,255,0.10);
    border-color: rgba(100,150,255,0.20);
}

.notes-item:active {
    cursor: grabbing;
}

.notes-item.active {
    background: rgba(0,255,231,0.08);
    border-color: rgba(0,255,231,0.22);
}

.notes-item-handle {
    width: 10px;
    flex: 0 0 10px;
    opacity: 0.45;
}

.notes-attached-badge {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: rgba(170, 120, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(40, 20, 60, 0.9);
    flex: 0 0 8px;
}

.stone-story-badge {
    position: absolute;
    left: -2px;
    bottom: -2px;
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: rgba(170, 120, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.55);
    pointer-events: none;
}

.write-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.write-modal-edit {
    border: 1px solid rgba(255,255,255,0.16);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.78);
    border-radius: 10px;
    padding: 6px 10px;
    font: 700 12px Inter, Arial, sans-serif;
    cursor: pointer;
}
.write-modal-edit:hover {
    color: rgba(255,255,255,0.94);
    border-color: rgba(0,255,231,0.24);
    background: rgba(255,255,255,0.08);
}
.write-modal-edit.hidden { display: none; }

.write-modal-save.hidden { display: none; }

.write-modal-save-close {
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.70);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
}
.write-modal-save-close:hover {
    color: rgba(255,255,255,0.92);
    border-color: rgba(0,255,231,0.24);
    background: rgba(255,255,255,0.07);
}
.write-modal-save-close.hidden { display: none; }

.write-modal-save {
    border: 1px solid rgba(0,255,231,0.35);
    background: rgba(0,255,231,0.10);
    color: rgba(230,255,255,0.92);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
}

.write-modal-save:hover {
    background: rgba(0,255,231,0.16);
}
.inventory-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    align-content: flex-start;
    min-height: 28px;
}
.inventory-empty {
    font-size: 10px;
    color: rgba(255,255,255,0.25);
    padding: 4px 0;
    text-align: center;
    width: 100%;
}

/* ── Stone (inventory item) ── */
.stone-item {
    position: relative;
    cursor: grab;
    transition: transform 0.15s, filter 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stone-item:hover {
    transform: scale(1.18);
    filter: brightness(1.3);
    z-index: 10;
}
.stone-item:active {
    cursor: grabbing;
}

.stone-placed-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    line-height: 1;
    background: rgba(0, 255, 230, 0.12);
    border: 1px solid rgba(0, 255, 230, 0.25);
    color: rgba(0, 255, 230, 0.95);
    pointer-events: none;
}

.stone-global-tooltip {
    position: fixed;
    z-index: 1000;
    background: rgba(0,0,0,0.88);
    color: rgba(255,255,255,0.88);
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 8px));
    border: 1px solid rgba(255,255,255,0.10);
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.stone-global-tooltip.hidden {
    display: none;
}

.stone-drag-ghost {
    position: fixed;
    z-index: 1100;
    pointer-events: none;
    transform: translate(-50%, -50%);
    opacity: 0.9;
    filter: drop-shadow(0 6px 12px rgba(0,0,0,0.45));
}
.stone-drag-ghost.hidden {
    display: none;
}

/* ── Feel Button ── */
.feel-button {
    position: fixed;
    z-index: 300;
    background: rgba(255, 138, 61, 0.15);
    border: 1px solid rgba(255, 138, 61, 0.5);
    color: #ff8a3d;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 5px 16px;
    border-radius: 14px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    pointer-events: auto;
    transition: background 0.2s, border-color 0.2s, opacity 0.3s;
    animation: feel-pulse 2s ease-in-out infinite;
}
.feel-button:hover {
    background: rgba(255, 138, 61, 0.3);
    border-color: rgba(255, 138, 61, 0.8);
}
.feel-button.hidden {
    display: none;
}
@keyframes feel-pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(255,138,61,0.2); }
    50% { box-shadow: 0 0 14px rgba(255,138,61,0.4); }
}

/* ── Stone naming ── */
.stone-item-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-width: 0;
}
.stone-name-label {
    font-size: 7px;
    color: rgba(255,255,255,0.45);
    max-width: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    line-height: 1.1;
}
.stone-name-label.unnamed {
    color: rgba(255,160,60,0.4);
    font-style: italic;
}
/* ── Tarnished stone ── */
.stone-item.tarnished {
    filter: saturate(0.55);
}
.stone-item.tarnished:hover {
    filter: saturate(0.55) brightness(1.3);
}
.stone-tarnish-badge {
    position: absolute;
    bottom: 0;
    right: 0;
    font-size: 7px;
    font-weight: 700;
    font-style: italic;
    color: rgba(180,180,180,0.6);
    line-height: 1;
    pointer-events: none;
    text-shadow: 0 0 2px rgba(0,0,0,0.6);
}

/* ── Stone context menu ── */
.stone-context-menu {
    position: fixed;
    z-index: 1300;
    background: rgba(10,10,18,0.95);
    border: 1px solid rgba(255,200,100,0.3);
    border-radius: 4px;
    padding: 2px 0;
    min-width: 72px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}
.stone-context-menu button {
    background: none;
    border: none;
    color: #ffe0a0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    padding: 4px 10px;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
}
.stone-context-menu button:hover {
    background: rgba(255,200,100,0.15);
}
.stone-context-menu-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-top: 1px solid rgba(255,200,100,0.12);
    margin-top: 2px;
    padding-top: 2px;
}
.stone-context-menu-row button {
    padding: 4px 8px;
    text-align: center;
}
.stone-context-menu-row button + button {
    border-left: 1px solid rgba(255,200,100,0.10);
}
.stone-context-menu button:disabled {
    opacity: 0.35;
    cursor: default;
}
.stone-context-menu button:disabled:hover {
    background: none;
}
/* Safety triangle: invisible hover bridge from cursor origin to menu */
.stone-context-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    z-index: -1;
}

.stone-name-input {
    position: fixed;
    z-index: 1200;
    background: rgba(10,10,18,0.95);
    border: 1px solid rgba(255,200,100,0.4);
    color: #ffe0a0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    outline: none;
    width: 140px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.stone-name-input::placeholder {
    color: rgba(255,200,100,0.3);
}
.stone-lost-toast {
    position: fixed;
    z-index: 1000;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(180,80,20,0.85);
    color: #ffe0a0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s;
    white-space: nowrap;
}
.stone-lost-toast.visible {
    opacity: 1;
}

/* ── Realm Outliner ─────────────────────────────────────────── */
.realm-outliner-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(77,166,255,0.5);
    background: rgba(10,18,40,0.82);
    color: rgba(77,166,255,0.9);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    pointer-events: all;
}
.realm-outliner-toggle:hover {
    background: rgba(20,40,80,0.95);
    border-color: rgba(77,166,255,0.9);
    transform: translateY(-50%) !important;
}

.realm-outliner {
    position: absolute;
    right: 56px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 240px;
    max-height: 70vh;
    background: rgba(8,14,32,0.88);
    border: 1px solid rgba(77,166,255,0.3);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: all;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.realm-outliner.hidden { display: none; }

.realm-outliner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
    border-bottom: 1px solid rgba(77,166,255,0.15);
    flex-shrink: 0;
}
.realm-outliner-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: rgba(77,166,255,0.9);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.realm-outliner-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 13px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}
.realm-outliner-close:hover { color: rgba(255,255,255,0.85); }

.realm-outliner-tree {
    overflow-y: auto;
    flex: 1;
    padding: 6px 0;
}
.realm-outliner-tree::-webkit-scrollbar { width: 4px; }
.realm-outliner-tree::-webkit-scrollbar-thumb { background: rgba(77,166,255,0.25); border-radius: 2px; }

.realm-node {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 14px 5px 0;
    cursor: pointer;
    border-radius: 6px;
    margin: 1px 6px;
    transition: background 0.1s;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    color: rgba(255,255,255,0.75);
    user-select: none;
    position: relative;
}
.realm-node:hover { background: rgba(77,166,255,0.1); color: #fff; }
.realm-node.active {
    background: rgba(77,166,255,0.18);
    color: #4da6ff;
}
.realm-node.previewing {
    background: rgba(77,166,255,0.08);
    color: rgba(255,255,255,0.9);
    outline: 1px solid rgba(77,166,255,0.35);
}
.realm-node-indent {
    display: inline-block;
    flex-shrink: 0;
}
.realm-node-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid currentColor;
}
.realm-node-dot.filled { background: currentColor; }
.realm-node-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.realm-node-badge {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    flex-shrink: 0;
}
.realm-node-actions {
    display: none;
    gap: 4px;
    flex-shrink: 0;
}
.realm-node:hover .realm-node-actions { display: flex; }
.realm-node-btn {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid rgba(77,166,255,0.35);
    background: rgba(10,18,40,0.7);
    color: rgba(77,166,255,0.85);
    cursor: pointer;
    white-space: nowrap;
}
.realm-node-btn:hover { background: rgba(77,166,255,0.2); color: #fff; }
.realm-node-btn.teleport {
    border-color: rgba(100,255,180,0.4);
    color: rgba(100,255,180,0.85);
}
.realm-node-btn.teleport:hover { background: rgba(100,255,180,0.15); color: #fff; }

/* Override global button:hover translateY(-2px) for Realm Outliner controls */
.realm-outliner button:hover {
    transform: none !important;
}

/* ── Map Explorer Modal ─────────────────────────────────────── */
.map-explorer-modal {
    position: absolute;
    inset: 0;
    z-index: 15000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
}
.map-explorer-modal.hidden { display: none; }

.map-explorer-content {
    width: 75vw;
    height: 75vh;
    background: rgba(8, 12, 22, 0.92);
    border: 1px solid rgba(77,166,255,0.28);
    border-radius: 14px;
    box-shadow: 0 20px 70px rgba(0,0,0,0.65);
    backdrop-filter: blur(14px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.map-explorer-header {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.map-explorer-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(77,166,255,0.9);
}
.map-explorer-subtitle {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
}
.map-explorer-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.55);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
}
.map-explorer-close:hover { color: rgba(255,255,255,0.95); transform: none !important; }

 .write-modal {
     position: fixed;
     left: 50vw;
     top: 50vh;
     transform: translate(-50%, -50%);
     width: min(520px, 82vw);
     height: min(360px, 70vh);
     background: rgba(8, 12, 22, 0.94);
     border: 1px solid rgba(77,166,255,0.28);
     border-radius: 12px;
     box-shadow: 0 18px 60px rgba(0,0,0,0.6);
     backdrop-filter: blur(12px);
     z-index: 16000;
     display: flex;
     flex-direction: column;
     overflow: hidden;
 }
 .write-modal.hidden { display: none; }

 .write-modal.reader {
     background: rgba(6, 9, 16, 0.90);
     border: 1px solid rgba(255,255,255,0.12);
     box-shadow: 0 12px 42px rgba(0,0,0,0.55);
 }

 .write-modal-header {
     display: flex;
     align-items: center;
     justify-content: space-between;
     padding: 10px 12px;
     border-bottom: 1px solid rgba(255,255,255,0.08);
     cursor: grab;
     user-select: none;
 }
 .write-modal-title-card {
     display: flex;
     flex-direction: column;
     gap: 2px;
     min-width: 0;
 }
 .write-modal-title {
     font-family: 'Inter', system-ui, sans-serif;
     font-size: 12px;
     font-weight: 700;
     letter-spacing: 0.08em;
     text-transform: uppercase;
     color: rgba(77,166,255,0.9);
 }

 .write-modal-card-title {
     font: 700 12px Inter, Arial, sans-serif;
     color: rgba(255,255,255,0.92);
     max-width: 360px;
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
     cursor: pointer;
 }
 .write-modal-card-title:hover {
     color: rgba(255,255,255,0.98);
     text-decoration: underline;
 }
 .write-modal-card-meta {
     font: 600 10px Inter, Arial, sans-serif;
     color: rgba(255,255,255,0.45);
     max-width: 360px;
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
 }
 .write-modal-close {
     background: none;
     border: none;
     color: rgba(255,255,255,0.55);
     font-size: 18px;
     cursor: pointer;
     padding: 2px 6px;
 }
 .write-modal-close:hover { color: rgba(255,255,255,0.95); transform: none !important; }

 .write-modal-input {
     flex: 1;
     width: 100%;
     resize: none;
     border: none;
     outline: none;
     padding: 12px;
     background: rgba(0,0,0,0.18);
     color: rgba(255,255,255,0.9);
     font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
     font-size: 12px;
     line-height: 1.4;
 }

 .write-modal.reader .write-modal-input {
     background: rgba(0,0,0,0.10);
     color: rgba(255,255,255,0.86);
 }

 .write-modal.readonly .write-modal-input {
     opacity: 0.92;
 }

.map-explorer-toggle {
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.14);
    color: rgba(255,255,255,0.75);
    font: 600 12px Inter, Arial, sans-serif;
    padding: 5px 10px;
    border-radius: 10px;
    cursor: pointer;
}
.map-explorer-toggle:hover {
    color: rgba(255,255,255,0.95);
    border-color: rgba(0,255,231,0.38);
    transform: none !important;
}
.map-explorer-toggle.active {
    color: rgba(0,255,231,0.95);
    border-color: rgba(0,255,231,0.55);
    box-shadow: 0 0 0 2px rgba(0,255,231,0.08) inset;
}

.map-explorer-body {
    flex: 1;
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 0;
}

.map-explorer-outliner {
    border-right: 1px solid rgba(77,166,255,0.14);
    background: rgba(10,16,30,0.55);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.map-explorer-outliner-header {
    padding: 10px 12px;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.55);
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.map-explorer-outliner-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.map-explorer-outliner-tree::-webkit-scrollbar { width: 4px; }
.map-explorer-outliner-tree::-webkit-scrollbar-thumb { background: rgba(77,166,255,0.22); border-radius: 2px; }

.map-explorer-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: rgba(2, 6, 16, 0.35);
}

.map-explorer-canvas-wrap {
    position: relative;
    min-height: 0;
}

.map-explorer-waypoint-editor {
    position: absolute;
    right: 14px;
    top: 14px;
    width: 220px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(77,166,255,0.22);
    background: rgba(8, 14, 32, 0.92);
    box-shadow: 0 18px 55px rgba(0,0,0,0.55);
    backdrop-filter: blur(12px);
}
.map-explorer-waypoint-editor.hidden { display: none; }

.map-explorer-waypoint-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.65);
    margin-bottom: 8px;
}

.map-explorer-waypoint-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.88);
    outline: none;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    margin-bottom: 10px;
}
.map-explorer-waypoint-input:focus {
    border-color: rgba(77,166,255,0.55);
    box-shadow: 0 0 0 2px rgba(77,166,255,0.12);
}

.map-explorer-waypoint-btn {
    width: 100%;
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(77,166,255,0.24);
    background: rgba(77,166,255,0.10);
    color: rgba(255,255,255,0.82);
    cursor: pointer;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 12px;
    transform: none !important;
}
.map-explorer-waypoint-btn:hover {
    background: rgba(77,166,255,0.16);
    border-color: rgba(77,166,255,0.40);
    transform: none !important;
}
.map-explorer-waypoint-btn.danger {
    border-color: rgba(255,90,120,0.35);
    background: rgba(255,90,120,0.10);
}
.map-explorer-waypoint-btn.danger:hover {
    background: rgba(255,90,120,0.16);
    border-color: rgba(255,90,120,0.55);
}
