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

html,
body{

    width:100%;
    height:100%;

    overflow:hidden;

    background:#255b3d;

    font-family:Arial,sans-serif;
}

#game{
    
    touch-action: none;
    display:block;

    width:100vw;
    height:100vh;

    background:#2f7b52;

}

/* ObjectCard hidden state must always win */
.object-card .hidden {
    display: none !important;
}
/* ==========================
   UI ROOT
========================== */

#ui-root{
    position:fixed;
    inset:0;
    pointer-events:none;
    z-index:100;
}

/* ==========================
   EDITOR BUTTON
========================== */

.editor-toggle{

    position:absolute;

    top:14px;
    right:14px;

    width:52px;
    height:52px;

    border:none;
    border-radius:16px;

    font-size:24px;

    background:rgba(0,0,0,.55);
    color:white;

    cursor:pointer;

    pointer-events:auto;

    backdrop-filter:blur(12px);

    transition:.20s;
}

.editor-toggle:hover{

    transform:scale(1.05);

}

/* ==========================
   ALLIANCE BUTTON
========================== */

.alliance-change-button {
    position: absolute;

    top: 14px;
    left: 14px;

    width: 52px;
    height: 52px;

    padding: 0 4px;

    border: none;
    border-radius: 16px;

    background: rgba(0, 0, 0, .55);
    color: #56c8ff;

    font-size: 11px;
    font-weight: 800;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    cursor: pointer;
    pointer-events: auto;

    backdrop-filter: blur(12px);

    transition: .20s;
}

.alliance-change-button:hover {
    transform: scale(1.05);
}


/* ==========================
   SWORDLAND GUIDE
========================== */

.swordland-guide-link {
    position: fixed;
    top: 138px;
    left: 14px;
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 16px;
    background: rgba(72, 45, 24, .88);
    color: white;
    font-size: 23px;
    text-decoration: none;
    cursor: pointer;
    backdrop-filter: blur(12px);
    z-index: 1200;
}

.swordland-guide-link:hover {
    transform: scale(1.05);
}


/* ==========================
   LAYOUT PLANNING
========================== */

.layout-plan-button {
    position: absolute;
    top: 76px;
    left: 14px;
    width: 52px;
    height: 52px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 16px;
    background: rgba(24, 27, 25, .82);
    color: white;
    font-size: 23px;
    cursor: pointer;
    pointer-events: auto;
    backdrop-filter: blur(12px);
    z-index: 1200;
}

.layout-plan-button.hidden,
.layout-session-bar.hidden,
.layout-suggestions-overlay.hidden,
.layout-session-btn.hidden {
    display: none !important;
}

.layout-session-bar {
    position: fixed;
    top: 12px;
    left: 50%;
    width: min(680px, calc(100vw - 24px));
    min-height: 64px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px 10px 16px;
    border: 1px solid rgba(255, 210, 70, .34);
    border-radius: 17px;
    background: rgba(24, 27, 25, .96);
    color: white;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .36);
    pointer-events: auto;
    z-index: 5000;
}

.layout-session-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.layout-session-copy strong {
    color: #ffd252;
    font-size: 15px;
}

.layout-session-copy span {
    max-width: 330px;
    color: rgba(255, 255, 255, .64);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-session-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 7px;
}

.layout-session-btn,
.layout-suggestions-button,
.layout-card-btn {
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px;
    background: rgba(255, 255, 255, .09);
    color: white;
    font-weight: 750;
    cursor: pointer;
}

.layout-session-btn {
    min-height: 38px;
    padding: 7px 11px;
}

.layout-session-btn.primary,
.layout-card-btn.primary {
    background: #e7b82d;
    color: #171717;
}

.layout-session-btn.danger {
    background: rgba(180, 55, 55, .27);
    color: #ffc2c2;
}

.layout-session-btn.success,
.layout-card-btn.success {
    background: rgba(58, 170, 98, .28);
    color: #bfffd2;
}

.layout-session-btn:disabled {
    opacity: .45;
    cursor: wait;
}

.layout-suggestions-button {
    width: 94px;
    min-height: 46px;
    padding: 6px;
    font-size: 12px;
}

body.layout-planning .editor-toggle,
body.layout-planning .alliance-change-button,
body.layout-planning .viewer-search,
body.layout-planning .layout-suggestions-button,
body.layout-planning .swordland-guide-link,
body.layout-preview .editor-toggle,
body.layout-preview .alliance-change-button,
body.layout-preview .viewer-search,
body.layout-preview .swordland-guide-link {
    display: none !important;
}

body.layout-planning .building-bar [data-tool="farm"] {
    display: none;
}

.layout-suggestions-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, .66);
    pointer-events: auto;
    z-index: 10500;
}

.layout-suggestions-panel {
    width: min(620px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 20px;
    background: rgba(24, 27, 25, .98);
    color: white;
    box-shadow: 0 20px 70px rgba(0, 0, 0, .52);
    overflow: hidden;
}

.layout-suggestions-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.layout-suggestions-header h2 {
    font-size: 20px;
}

.layout-suggestions-header p {
    margin-top: 4px;
    color: rgba(255, 255, 255, .55);
    font-size: 12px;
}

.layout-suggestions-header button {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .08);
    color: white;
    cursor: pointer;
}

.layout-suggestions-list {
    display: grid;
    gap: 10px;
    padding: 14px;
    overflow-y: auto;
}

.layout-suggestion-card {
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 14px;
    background: rgba(255, 255, 255, .045);
}

.layout-suggestion-card strong {
    display: block;
    color: #ffd252;
    font-size: 16px;
}

.layout-suggestion-date {
    display: block;
    margin-top: 3px;
    color: rgba(255, 255, 255, .42);
    font-size: 10px;
}

.layout-suggestion-card p {
    margin-top: 8px;
    color: rgba(255, 255, 255, .72);
    font-size: 12px;
    line-height: 1.4;
}

.layout-suggestion-comment {
    padding: 9px 10px;
    border-radius: 9px;
    background: rgba(0, 0, 0, .18);
}

.layout-suggestion-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 7px;
    margin-top: 12px;
}

.layout-card-btn {
    min-height: 38px;
    padding: 7px;
    font-size: 12px;
}

.layout-card-btn.danger {
    background: rgba(180, 55, 55, .26);
    color: #ffb4b4;
}

.layout-suggestions-empty {
    padding: 40px 20px;
    color: rgba(255, 255, 255, .55);
    text-align: center;
}

@media (max-width: 560px) {
    .layout-session-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .layout-session-actions {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    }

    .layout-session-btn {
        min-width: 0;
        padding: 7px 5px;
        font-size: 12px;
    }

    .layout-suggestion-actions {
        grid-template-columns: repeat(2, 1fr);
    }
}


/* ==========================
   ACTIONS BAR
========================== */

.actions-bar {
    position: fixed;
    right: 14px;
    top: 100px;

    display: flex;
    flex-direction: column;
    gap: 10px;

    z-index: 1000;
    pointer-events: auto;
    transition:

        transform .22s ease,

        opacity .22s ease;

    transform: translateX(0);

    opacity: 1;
}

.actions-bar .tool-btn {
    width: 94px;
    height: 46px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    font-size: 16px;
    border-radius: 14px;
}

.building-bar .tool-btn {
    width: 54px;
    height: 54px;
    font-size: 24px;
}

.actions-bar.hidden {
    transform: translateX(120px);
    opacity: 0;
    pointer-events: none;
}

/* ==========================
   BUILDING BAR
========================== */

.building-bar {
    position: fixed;
    left: 50%;
    bottom: 15px;

    transform: translateX(-50%);

    display: flex;
    gap: 10px;

    z-index: 1000;
    pointer-events: auto;
    transition:

        transform .22s ease,

        opacity .22s ease;

    transform: translateX(-50%) translateY(0);

    opacity:1;
}

.building-bar.hidden{

    transform:
        translateX(-50%)
        translateY(100px);

    opacity:0;

    pointer-events:none;

}

/* ==========================
   TOOL BUTTON
========================== */

.tool-btn{

    width:48px;
    height:48px;

    border:none;

    border-radius:14px;

    background:rgba(255,255,255,.10);

    color:white;

    font-size:22px;

    cursor:pointer;

    transition:.18s;

}

.tool-btn:hover{

    transform:scale(1.06);

}

.tool-btn.active{

    background:#e7b82d;

    color:black;

}

html,
body,
canvas,
#ui-root {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#game {
    touch-action: none;
}


#toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);

    background: rgba(35, 35, 35, 0.92);
    color: white;

    padding: 12px 20px;
    border-radius: 10px;

    font-family: Arial, sans-serif;
    font-size: 15px;

    opacity: 0;
    pointer-events: none;

    transition: opacity 0.25s ease;

    z-index: 9999;
}

#toast.visible {
    opacity: 1;
}

.tool-btn.disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* ==========================
   DIALOG
========================== */

.dialog-overlay {
    position: fixed;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(0,0,0,.45);

    z-index: 12000;

    pointer-events: auto;
}

.dialog-overlay.hidden {
    display: none;
}

.dialog-box {

    width: 320px;

    background: #2d2d2d;

    color: white;

    border-radius: 16px;

    padding: 20px;

    box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

.dialog-title{

    font-size:20px;
    font-weight:bold;

    margin-bottom:12px;

}

.dialog-message{

    color:#d9d9d9;

    margin-bottom:22px;

    line-height:1.5;

}

.dialog-actions{

    display:flex;

    justify-content:flex-end;

    gap:10px;

}

.dialog-btn{

    border:none;

    border-radius:10px;

    padding:10px 18px;

    cursor:pointer;

}

.dialog-btn.primary{

    background:#e7b82d;

    color:black;

}

.dialog-input {
    width: 100%;
    margin-bottom: 22px;
    padding: 12px 14px;

    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    outline: none;

    background: rgba(255, 255, 255, 0.08);
    color: white;

    font-size: 16px;
}

.dialog-input:focus {
    border-color: #e7b82d;
}

.dialog-input.hidden {
    display: none;
}


/*===================
SEARCH
===================*/

.viewer-search{

    position:absolute;

    top:16px;

    left:50%;

    transform:translateX(-50%);

    width: min(320px, calc(100vw - 140px));

    z-index:2000;
    
    pointer-events: auto;

}

.viewer-search input{

    width:100%;

    padding:10px 14px;

    border:none;

    border-radius:12px;

    background:rgba(35,35,35,.92);

    color:white;

    font-size:16px;

    outline:none;
    
    pointer-events: auto;

}

.viewer-search-results {
    display: flex;
    flex-direction: column;
    gap: 6px;

    margin-top: 8px;
    padding: 6px;

    border-radius: 14px;

    background: rgba(20, 20, 20, 0.92);

    backdrop-filter: blur(12px);

    max-height: 300px;
    overflow-y: auto;
}

.viewer-search-results.hidden {
    display: none;
}

.viewer-search-result {
    width: 100%;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 10px 12px;

    border: none;
    border-radius: 10px;

    background: rgba(255, 255, 255, 0.08);
    color: white;

    text-align: left;
    cursor: pointer;

    transition:
        background 0.15s ease,
        transform 0.15s ease;
}

.viewer-search-result:active {
    background: rgba(231, 184, 45, 0.22);
    transform: scale(0.98);
}

.viewer-search-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.viewer-search-text {
    display: flex;
    flex-direction: column;

    min-width: 0;
}

.viewer-search-name {
    font-size: 14px;
    font-weight: 700;

    white-space: normal;
    overflow: visible;
    text-overflow: clip;

    line-height: 1.2;
    overflow-wrap: anywhere;
}

.viewer-search-coordinates {
    margin-top: 2px;

    font-size: 11px;
    color: rgba(255, 255, 255, 0.58);
}

/* ====================
   ALLIANCE SELECTOR
==================== */

.alliance-select-overlay {
    position: fixed;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background:
        rgba(8, 12, 10, 0.72);

    backdrop-filter: blur(8px);

    z-index: 10000;
}


.alliance-select-card {
    width: min(
        360px,
        calc(100vw - 40px)
    );

    padding: 26px;

    border-radius: 22px;

    background:
        rgba(28, 31, 29, 0.97);

    box-shadow:
        0 18px 60px
        rgba(0, 0, 0, 0.45);

    color: white;

    text-align: center;
}


.alliance-select-icon {
    font-size: 42px;
    margin-bottom: 8px;
}


.alliance-select-title {
    font-size: 22px;
    font-weight: 800;
}


.alliance-select-kingdom {
    margin-top: 5px;

    font-size: 13px;

    color:
        rgba(255, 255, 255, 0.55);
}


.alliance-select-text {
    margin-top: 22px;
    margin-bottom: 14px;

    font-size: 15px;
    font-weight: 600;
}


.alliance-select-grid {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 10px;
}


.alliance-select-btn {
    padding: 14px 10px;

    border: 1px solid
        rgba(255, 255, 255, 0.10);

    border-radius: 12px;

    background:
        rgba(255, 255, 255, 0.08);

    color: white;

    font-size: 15px;
    font-weight: 800;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        background 0.15s ease;
}


.alliance-select-btn:hover {
    background:
        rgba(255, 210, 70, 0.16);
}


.alliance-select-btn:active {
    transform: scale(0.96);

    background:
        rgba(255, 210, 70, 0.24);
}


.alliance-select-note {
    margin-top: 18px;

    font-size: 11px;

    color:
        rgba(255, 255, 255, 0.42);
}

/* =========================
   OBJECT CARD - COMPACT
========================= */

.object-card {
    position: fixed;

    left: 50%;
    bottom: 105px;

    width: min(
        235px,
        calc(100vw - 28px)
    );

    transform: translateX(-50%);

    z-index: 9000;

    border-radius: 15px;

    background:
        rgba(24, 27, 25, 0.97);

    color: white;

    box-shadow:
        0 12px 35px
        rgba(0, 0, 0, 0.42);

    backdrop-filter: blur(12px);

    overflow: hidden;
}


.object-card.hidden {
    opacity: 0;
    pointer-events: none;
}


/*
 * Svarbu:
 * ObjectCard viduje .hidden VISADA turi laimėti.
 */

.object-card .hidden {
    display: none !important;
}


/* -------------------------
   Small top handle
------------------------- */

.object-card-handle {
    width: 34px;
    height: 4px;

    touch-action: none;
    cursor: grab;
    margin: 7px auto 0;

    border-radius: 999px;

    background:
        rgba(255, 255, 255, 0.16);
}


/* -------------------------
   Content
------------------------- */

.object-card-content {
    padding:
        7px 12px 10px;
}


/* -------------------------
   Header
------------------------- */

.object-card-header {
    display: flex;

    align-items: flex-start;

    justify-content: space-between;

    gap: 10px;
}


.object-card-title {
    font-size: 17px;

    font-weight: 800;

    line-height: 1.2;
}


.object-card-subtitle {
    margin-top: 2px;

    font-size: 11px;

    color:
        rgba(255, 255, 255, 0.52);
}


.object-card-close {
    flex-shrink: 0;

    width: 29px;
    height: 29px;

    border: none;

    border-radius: 50%;

    background:
        rgba(255, 255, 255, 0.08);

    color: white;

    font-size: 12px;

    cursor: pointer;
}


/* -------------------------
   Info
------------------------- */

.object-card-meta {
    margin-top: 5px;

    padding-bottom: 6px;

    border-bottom:
        1px solid
        rgba(255, 255, 255, 0.08);

    color:
        rgba(255, 255, 255, 0.68);

    font-size: 11px;

    font-weight: 600;
}

/* -------------------------
   Viewer
------------------------- */

.object-card-viewer-actions {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 6px;

    margin-top: 9px;
}


.object-card-question {
    margin-bottom: 6px;

    font-size: 11px;

    color:
        rgba(255, 255, 255, 0.64);
}


/* -------------------------
   Editor buttons
------------------------- */

.object-card-editor-actions {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 6px;

    margin-top: 9px;
}


.object-card-btn {
    width: 100%;

    padding:
        9px 10px;

    border: none;

    border-radius: 9px;

    background:
        rgba(255, 255, 255, 0.09);

    color: white;

    font-size: 12px;

    font-weight: 700;

    cursor: pointer;
}


.object-card-btn.primary {
    background:
        rgba(236, 190, 55, 0.94);

    color:
        #191919;
}


.object-card-btn.danger {
    background:
        rgba(180, 55, 55, 0.30);

    color:
        #ffb4b4;
}

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

.object-card-header:active {
    cursor: grabbing;
}


/* Dialogai VISADA virš kortelės */

.dialog-overlay {
    z-index: 12000;
}

.alliance-create-btn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;

    border: 1px dashed
        rgba(255,255,255,0.25);

    border-radius: 12px;

    background:
        rgba(255,255,255,0.04);

    color: white;

    font-weight: 700;
    cursor: pointer;
}
