@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

:root {
    --ui-scale: 1;
}

#loading-screen {
    position: fixed;
    inset: 0;
    background: #66bb46;
    z-index: 6000;
    display: flex;
    align-items: center;
    justify-content: center;
}
#loading-screen.hidden { display: none; }
.loading-text {
    font-size: 32px;
    color: #fff;
    -webkit-text-stroke: 4px #000;
    paint-order: stroke fill;
}

#chatbox {
    position: fixed;
    bottom: 28px;
    left: 130px;
    width: 320px;
    height: 220px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    border-radius: 8px;
    padding: 10px 12px 10px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    transform-origin: bottom left;
    transform: scale(var(--ui-scale));
    user-select: none;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    margin-bottom: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.25); border-radius: 3px; }
.chat-line {
    font-size: 13px;
    color: #fff;
    margin-bottom: 3px;
    line-height: 1.25;
    word-wrap: break-word;
}
.chat-line .chat-user { color: #fff; }
.chat-line .chat-colon { color: #fff; }
.chat-line .chat-owner-tag { color: #ff2a2a; margin-right: 2px; }
.chat-line .outlined { -webkit-text-stroke: 1.625px #000; }
#chat-input {
    flex-shrink: 0;
    height: 30px;
    background: #fff;
    border: 3px solid #000;
    border-radius: 4px;
    padding: 0 8px;
    font-size: 13px;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
    color: #000;
    -webkit-text-stroke: 0;
    pointer-events: auto;
}

#username-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.username-card {
    background: #5a9fdb;
    border: 5px solid #4881b1;
    border-radius: 10px;
    padding: 28px 32px;
    text-align: center;
    min-width: 280px;
}

.username-title {
    font-size: 32px;
    color: #fff;
    margin-bottom: 6px;
}

.username-subtitle {
    font-size: 12px;
    color: #fff;
    opacity: 0.85;
    margin-bottom: 16px;
    font-weight: 700;
}

#username-input {
    width: 100%;
    height: 38px;
    background: #fff;
    border: 3px solid #000;
    border-radius: 4px;
    padding: 0 10px;
    font-size: 16px;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
    color: #000;
    margin-bottom: 12px;
    -webkit-text-stroke: 0;
}

#username-submit {
    width: 100%;
    height: 38px;
    background: #66d63c;
    border: 3px solid #4ea82a;
    border-radius: 4px;
    color: #fff;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    -webkit-text-stroke: 2px #000;
    paint-order: stroke fill;
}

.username-err {
    margin-top: 8px;
    color: #ffdc4a;
    font-size: 12px;
    -webkit-text-stroke: 1.5px #000;
    paint-order: stroke fill;
}

.username-err.hidden { display: none; }

#game {
    display: block;
    width: 100vw;
    height: 100vh;
}

#status-bar {
    position: fixed;
    top: 24px;
    left: 24px;
    width: 360px;
    height: 110px;
    pointer-events: none;
    transform: scale(calc(var(--ui-scale) * 0.7));
    transform-origin: top left;
    z-index: 50;
}

#status-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100px;
    height: 100px;
    z-index: 2;
}

.hp-bar {
    position: absolute;
    left: 75px;
    top: 32px;
    width: 280px;
    height: 36px;
    background: #66d63c;
    border: 4px solid #000;
    border-radius: 18px;
    overflow: hidden;
    padding-left: 30px;
    z-index: 1;
}

.hp-fill {
    display: none;
}

.player-name {
    position: absolute;
    inset: 0 0 0 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    z-index: 1;
}

.lvl-bar {
    position: absolute;
    left: 115px;
    top: 78px;
    width: 220px;
    height: 26px;
    background: #d7f265;
    border: 4px solid #000;
    border-radius: 13px;
    overflow: hidden;
    z-index: 1;
}

.player-lvl {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14.4px;
    color: #fff;
}

#tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 12px 14px;
    pointer-events: none;
    z-index: 200;
    min-width: 180px;
    max-width: 320px;
    color: #fff;
}

#tooltip.hidden { display: none; }

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.tooltip-title {
    font-size: 22px;
    color: #fff;
}

.tooltip-respawn {
    font-size: 14px;
    color: #fff;
}

.tooltip-rarity {
    font-size: 14px;
    margin-bottom: 8px;
}

.tooltip-desc {
    font-size: 12px;
    color: #fff;
    margin-bottom: 8px;
    line-height: 1.3;
}

.tooltip-stats {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.stat-line {
    font-size: 13px;
    color: #fff;
}

.stat-label-hp     { color: #4ade80; }
.stat-label-dmg    { color: #f87171; }
.stat-label-poison { color: #c084fc; }

#joystick {
    display: none;
    position: fixed;
    bottom: 40px;
    left: 40px;
    width: 130px;
    height: 130px;
    z-index: 90;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transform: scale(var(--ui-scale));
    transform-origin: bottom left;
}

body.mobile #joystick {
    display: block;
}

#mobile-buttons {
    display: none;
    position: fixed;
    right: 30px;
    bottom: 40px;
    flex-direction: column;
    gap: 14px;
    z-index: 80;
    pointer-events: auto;
    transform: scale(var(--ui-scale));
    transform-origin: bottom right;
}

body.mobile #mobile-buttons {
    display: flex;
}

.mb-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 4px solid #000;
    color: #fff;
    font-size: 30px;
    font-weight: 700;
    font-family: 'Ubuntu', sans-serif;
    cursor: pointer;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.mb-attack { background: #e34646; }
.mb-defense { background: #3a8de8; }
.mb-swap { background: #66d63c; }

.joystick-base {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.joystick-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.5);
    border: 3px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

body.mobile #inventory {
    bottom: 200px;
}

body.mobile #game {
    cursor: default;
}

#inventory {
    position: fixed;
    bottom: 28px;
    left: 28px;
    width: 64px;
    height: 64px;
    background: #5a9fdb;
    border: 4px solid #4881b1;
    border-radius: 5px;
    transform: scale(calc(var(--ui-scale) * 0.8));
    transform-origin: bottom left;
    pointer-events: none;
    user-select: none;
    z-index: 2500;
}

.inventory-icon {
    position: absolute;
    top: 8%;
    left: 8%;
    width: 84%;
    height: 84%;
}

.inventory-key {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 12px;
    line-height: 1;
}

#inventory-popup {
    position: fixed;
    bottom: 28px;
    left: 130px;
    width: 320px;
    max-height: 38vh;
    background: #5a9fdb;
    border: 5.6px solid #4881b1;
    border-radius: 10px;
    padding: 20px 22px 16px;
    overflow: hidden;
    z-index: 100;
    user-select: none;
    display: flex;
    flex-direction: column;
    transform-origin: bottom left;
    transform: scale(var(--ui-scale)) translateY(0);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

#inventory-popup.hidden {
    transform: scale(var(--ui-scale)) translateY(calc(100% + 100px));
    pointer-events: none;
}

.popup-header {
    flex-shrink: 0;
    margin-bottom: 8px;
}

.popup-rarities {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    padding-right: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.popup-rarities::-webkit-scrollbar {
    width: 8px;
}

.popup-rarities::-webkit-scrollbar-track {
    background: transparent;
    margin: 6px 0;
}

.popup-rarities::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.popup-rarities::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: #d04a4a;
    border: 3px solid #a83a3a;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

.popup-close::before,
.popup-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60%;
    height: 5px;
    background: #fff;
    border-radius: 3px;
}

.popup-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.popup-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.popup-title {
    text-align: center;
    font-size: 17.6px;
    margin-bottom: 3px;
    color: #fff;
}

.popup-subtitle {
    text-align: center;
    font-size: 10.4px;
    margin-bottom: 12px;
    color: #fff;
}

.popup-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.stack-toggle {
    width: 38px;
    height: 38px;
    background: #c0bbb8;
    border: 3px solid #8a8581;
    border-radius: 5px;
    flex-shrink: 0;
}

.stack-label {
    font-size: 14.4px;
    color: #fff;
}

.search-input {
    flex: 1;
    height: 38px;
    background: #fff;
    border: 3px solid #000;
    border-radius: 4px;
    padding: 0 10px;
    font-size: 12.8px;
    font-family: 'Ubuntu', sans-serif;
    font-weight: 700;
    color: #000;
    -webkit-text-stroke: 0;
}

.rarity-section {
    margin-bottom: 16px;
}

.rarity-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.rarity-header hr {
    flex: 1;
    border: none;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    margin: 0;
}

.rarity-name {
    font-size: 11.52px;
    paint-order: stroke fill;
    line-height: 1;
}

.petal-grid {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

.petal-card {
    position: relative;
    width: 40.04px;
    height: 40.04px;
    border: 2.504px solid;
    border-radius: 5px;
    box-sizing: border-box;
}

.petal-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 65%;
    height: 65%;
    object-fit: contain;
    transform: translate(-50%, -55%);
    pointer-events: none;
    z-index: 1;
}

.petal-icon.iris-icon {
    width: 52%;
    height: 52%;
}

.petal-count {
    position: absolute;
    top: 1px;
    right: 3px;
    font-size: 8.8px;
    color: #fff;
    transform: rotate(-12deg);
    transform-origin: center;
    line-height: 1;
    z-index: 2;
}

.petal-name {
    position: absolute;
    bottom: 3.76px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 6.88px;
    color: #fff;
    line-height: 1;
    z-index: 2;
}

#loadout {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) scale(calc(var(--ui-scale) * 0.73));
    transform-origin: bottom center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
    user-select: none;
}

.loadout-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slot {
    --slot-border: 4px;
    background: #ffffff;
    border: var(--slot-border) solid #c0bbb8;
    border-radius: 5px;
    position: relative;
}

.petal-overlay {
    position: absolute;
    inset: calc(-1 * var(--slot-border));
    border: var(--slot-border) solid;
    border-radius: 5px;
    box-sizing: border-box;
    overflow: hidden;
    pointer-events: none;
}

.slot.slot-swap-empty .petal-overlay {
    display: none;
}

.slot-equipped {
    pointer-events: auto;
    cursor: pointer;
}

.reload-overlay {
    position: absolute;
    inset: -3px;
    pointer-events: none;
    border-radius: inherit;
    background: rgba(80, 80, 80, 0.65);
    clip-path: polygon(
        0% 0%,
        100% 0%,
        100% calc((1 - var(--reload, 0)) * 100%),
        0% calc((1 - var(--reload, 0)) * 100%)
    );
}

.slot-large {
    width: 64px;
    height: 64px;
}

.slot-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 65%;
    height: 65%;
    object-fit: contain;
    transform: translate(-50%, -55%);
    pointer-events: none;
}

.slot-name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    text-align: center;
    font-size: 11px;
    line-height: 1;
    color: #fff;
    pointer-events: none;
}

.petal-card {
    cursor: grab;
    touch-action: none;
}

.slot-small {
    --slot-border: 2.752px;
    width: 44px;
    height: 44px;
}

.slot-small .slot-icon {
    width: 65%;
    height: 65%;
    transform: translate(-50%, -55%);
}

.slot-small .slot-name {
    font-size: 7.56px;
}

.outlined {
    color: #fff;
    -webkit-text-stroke: 2.5px #000;
    paint-order: stroke fill;
}

/* per-class outline scaling: font-size / 8 (HP-bar reference: 20px / 2.5px) */
.player-lvl       { -webkit-text-stroke: 1.8px #000; }
.popup-title      { -webkit-text-stroke: 2.2px #000; }
.popup-subtitle   { -webkit-text-stroke: 1.3px #000; }
.stack-label      { -webkit-text-stroke: 1.8px #000; }
.rarity-name      { -webkit-text-stroke: 1.44px #000; }
.petal-count      { -webkit-text-stroke: 1.1px #000; }
.petal-name       { -webkit-text-stroke: 0.86px #000; }
.slot-name        { -webkit-text-stroke: 1.375px #000; }
.slot-small .slot-name { -webkit-text-stroke: 0.945px #000; }
.slot-key         { -webkit-text-stroke: 1.625px #000; }
.key-label        { -webkit-text-stroke: 1.875px #000; }
.speed-text       { -webkit-text-stroke: 1.125px #000; }
.inventory-key    { -webkit-text-stroke: 1.5px #000; }
.tooltip-title    { -webkit-text-stroke: 2.75px #000; }
.tooltip-respawn  { -webkit-text-stroke: 1.75px #000; }
.tooltip-rarity   { -webkit-text-stroke: 1.75px #000; }
.tooltip-desc     { -webkit-text-stroke: 1.5px #000; }
.stat-line        { -webkit-text-stroke: 1.625px #000; }
.username-title   { -webkit-text-stroke: 4px #000; }
.mb-btn           { -webkit-text-stroke: 3.75px #000; }
.loading-text     { -webkit-text-stroke: 4px #000; }

.slot-key {
    position: absolute;
    bottom: -22px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 13px;
}

.bottom-slots {
    display: flex;
    gap: 6px;
}

.key-label {
    font-size: 15px;
}

.speed-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: conic-gradient(
        from 0deg,
        rgba(255, 255, 255, 0.2) 0deg calc(var(--speed-fill, 0) * 360deg),
        rgba(0, 0, 0, 0.2) calc(var(--speed-fill, 0) * 360deg) 360deg
    );
}

.speed-dots {
    position: absolute;
    inset: 0;
}

.speed-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    margin: -4px 0 0 -4px;
    background: #fff;
    border-radius: 50%;
}

.speed-dot:nth-child(1) { transform: rotate(0deg)   translateY(-19px); }
.speed-dot:nth-child(2) { transform: rotate(72deg)  translateY(-19px); }
.speed-dot:nth-child(3) { transform: rotate(144deg) translateY(-19px); }
.speed-dot:nth-child(4) { transform: rotate(216deg) translateY(-19px); }
.speed-dot:nth-child(5) { transform: rotate(288deg) translateY(-19px); }

.speed-text {
    color: #fff;
    font-size: 9px;
    letter-spacing: 0.2px;
    z-index: 1;
}

