
* {
    box-sizing: border-box;
}

:root {
    --purple-dark: #573b70;
    --purple: #9b6dcc;
    --purple-hover: #8052b1;
    --border: #e2d9eb;
    --background: #f4f1f7;
    --text: #30283a;
}

body {
    margin: 0;
    padding: 16px;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--background);
    color: var(--text);
}

header {
    width: 100%;
    margin: 0 auto 16px;
    padding: 20px 24px;
    background: var(--purple-dark);
    color: white;
    border-radius: 12px;
}

header h1 {
    margin-top: 0;
}

header p {
    margin-bottom: 0;
}

main {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(320px, 1fr);
    grid-template-areas:
        "map players"
        "status players"
        "log log";
    gap: 16px;
    align-items: start;
}

section {
    min-width: 0;
    padding: 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
}

h2 {
    margin-top: 0;
    font-size: 1.2rem;
}

h3 {
    margin-top: 0;
}

#game-map {
    grid-area: map;
}

#players {
    grid-area: players;
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

#game-status {
    grid-area: status;
}

#game-log {
    grid-area: log;
    max-height: 300px;
    overflow-y: auto;
}

button {
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: var(--purple);
    color: white;
    font-size: 0.95rem;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--purple-hover);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* Map canvas */

#map-canvas {
    position: relative;
    width: 100%;
    aspect-ratio: 743 / 450;
    min-height: 0;
    overflow: hidden;
    background-image: url("images/map.webp");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 10px;
}

#map-routes {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

#map-locations {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}



/* Location markers */

.location-card {
    position: absolute;
    width: 76px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 2;
}

.location-card:hover {
    z-index: 4;
    background: transparent;
    box-shadow: none;
}

.location-card h3 {
    order: 2;
    margin: 0;
    padding: 2px 5px;
    max-width: 110px;
    border-radius: 5px;
    background: rgb(255 255 255 / 90%);
    color: var(--text);
    font-size: 0.72rem;
    line-height: 1.15;
    text-align: center;
    overflow-wrap: anywhere;
}

.location-card > p,
.location-card h4,
.location-card > ul {
    display: none;
}

.location-card::before {
    content: "";
    order: 1;
    display: block;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: 3px solid white;
    border-radius: 50%;
    background: #8a9c76;
    box-shadow: 0 2px 6px rgb(0 0 0 / 35%);
}

.location-card:hover::before {
    transform: scale(1.12);
}

.location-card.current-player-location::before {
    background: var(--purple);
    box-shadow:
        0 0 0 4px rgb(155 109 204 / 30%),
        0 2px 6px rgb(0 0 0 / 35%);
}

.location-card.reachable-location::before {
    background: #d1891e;
}

.location-card.special-reachable-location::before {
    background: #3186b8;
}

.location-card.secret-unavailable-location::before {
    background: #999999;
}

.location-card.unreachable-location {
    opacity: 0.85;
}

/* Keep the existing action buttons usable until actions move
   into the player panel. */
.location-card button {
    order: 3;
    width: 110px;
    padding: 5px;
    font-size: 0.68rem;
}

.player-card {
    padding: 12px;
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #faf8fc;
}

.player-card h3 {
    margin-top: 0;
}

.active-player {
    border: 2px solid var(--purple);
    padding: 15px;
    background: #f5edfa;
}

.compact-player {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: white;
}

.player-summary {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: none;
    background: #eee3f7;
    color: var(--purple-dark);
    cursor: pointer;
    text-align: left;
}

.player-summary:hover {
    background: #e2d0f1;
}

.compact-player .player-details {
    padding: 12px;
    background: #faf8fc;
}

.player-details[hidden] {
    display: none;
}

/* Smaller screens */

@media (max-width: 900px) {
    body {
        padding: 10px;
    }

    main {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "players"
            "map"
            "status"
            "log";
    }

    #players {
        position: static;
        max-height: none;
    }

    #map-canvas {
        min-height: 400px;
    }

    #map-locations {
        min-height: 400px;
    }
}

.farm-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.farm-field {
    padding: 8px;
    border: 1px solid #9b6dcc;
    border-radius: 8px;
    background: #f5edfa;
}

.farm-field p {
    margin: 5px 0 0;
    font-size: 0.9rem;
}
/* Active player panel */
.active-player {
    border: 3px solid #9b6dcc;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 12px;
    background: #f5edfa;
}

#turn-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

#turn-controls[hidden] {
    display: none;
}

#turn-status,
#location-actions,
#movement-controls,
#turn-options {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
}

#turn-status h3,
#location-actions h3,
#movement-controls h3 {
    margin-bottom: 8px;
}

#location-actions button,
#turn-options button {
    margin: 4px;
}

/* Card Draw Popup */

.popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;

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

    padding: 20px;
    background: rgb(0 0 0 / 65%);
}

.popup-overlay[hidden] {
    display: none;
}

.card-popup {
    width: 100%;
    max-width: 420px;
    padding: 24px;

    border: 3px solid var(--purple);
    border-radius: 14px;

    background: white;
    box-shadow: 0 8px 30px rgb(0 0 0 / 30%);

    text-align: center;
}

.card-popup h2 {
    margin-top: 0;
    color: var(--purple-dark);
}

#card-popup-content {
    margin: 24px 0;
    padding: 20px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: #f5edfa;
}

#card-popup-content h3 {
    margin-top: 0;
    font-size: 1.4rem;
}

#card-popup-content p {
    margin-bottom: 0;
}

#card-popup-close {
    min-width: 120px;
}

/* Community Center Popup */

.community-center-popup {
    max-width: 750px;
    max-height: 90vh;
    overflow-y: auto;
}

#community-center-description {
    margin-bottom: 20px;
}

#community-center-slots {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.donation-slot {
    min-height: 100px;
    padding: 12px 8px;

    border: 2px solid var(--border);
    border-radius: 10px;

    background: #eeeeee;
    color: #777;

    text-align: center;
}

.donation-slot.available {
    border-color: var(--purple);
    background: #f5edfa;
    color: var(--purple-dark);
    cursor: pointer;
}

.donation-slot.available:hover {
    background: #eadcf5;
}

.donation-slot.completed {
    border-color: #6a9b70;
    background: #e8f3e9;
    color: #35643b;
}

.donation-slot:disabled {
    cursor: default;
    opacity: 1;
}

.donation-slot strong,
.donation-slot span {
    display: block;
}

.donation-slot strong {
    margin-bottom: 8px;
}

.donation-slot span {
    font-size: 0.9rem;
}

#community-center-progress {
    font-weight: bold;
    color: var(--purple-dark);
}

@media (max-width: 500px) {
    #community-center-slots {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

#player-progress-popup {
    width: 90%;
    max-width: 850px;
    max-height: 85vh;
    overflow-y: auto;
}

#progress-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin: 15px 0;
}

.progress-section {
    min-width: 0;
}

.progress-section h3 {
    margin-bottom: 10px;
}

#progress-friendship,
#progress-monsters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

#progress-friendship p,
#progress-monsters p {
    margin: 2px 0;
}

#progress-monsters strong {
    margin-top: 8px;
}

@media (max-width: 600px) {
    #progress-columns {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* Player Progress Tabs */

#progress-tabs {
    display: flex;
    gap: 8px;
    margin: 20px 0;
    border-bottom: 2px solid var(--border);
}

.progress-tab {
    padding: 10px 18px;
    border: 2px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: #f5edfa;
    color: var(--purple-dark);
    font-weight: bold;
    cursor: pointer;
}

.progress-tab:hover {
    background: #eadcf5;
}

.progress-tab.active {
    background: var(--purple);
    color: white;
    border-color: var(--purple);
}

.progress-tab-panel {
    padding: 12px 0;
}

.progress-tab-panel[hidden] {
    display: none;
}

#progress-missions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

@media (max-width: 600px) {
    #progress-missions {
        grid-template-columns: 1fr;
    }
}

/* =====================================
   MISSION SELECTION POPUP
===================================== */

#mission-selection-popup {
    max-width: 750px;
    max-height: 90vh;
    overflow-y: auto;
}

#mission-selection-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.mission-selection-card {
    padding: 16px;

    border: 2px solid var(--border);
    border-radius: 10px;

    background: #f5edfa;
    text-align: left;
    cursor: pointer;
}

.mission-selection-card.selected {
    border-color: var(--purple);
    background: #eadcf5;
}

.mission-selection-card h3 {
    margin-top: 0;
    color: var(--purple-dark);
}

.mission-selection-card p {
    margin-bottom: 8px;
}

.mission-selection-card input {
    margin-right: 6px;
}

#mission-selection-count {
    font-weight: bold;
}

#mission-selection-confirm {
    min-width: 160px;
}

.mission-selection-card {
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.mission-selection-card:hover {
    border-color: var(--purple);
}

/* Mission requirement progress */

.progress-mission-card ul,
.progress-mission-card div {
    padding-left: 0;
    list-style: none;
}

.progress-mission-card li,
.progress-mission-card p {
    margin: 6px 0;
}

.progress-mission-card .requirement-completed {
    color: #54834f;
    font-weight: bold;
}

.progress-mission-card .mission-completed {
    color: #54834f;
}

.progress-mission-card .mission-incomplete {
    color: #a65b5b;
}

/* Player Info tab */
.player-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 12px 0 20px;
}

.player-info-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #faf8fc;
    overflow-wrap: anywhere;
}

.player-info-inventory {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.player-info-item {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #faf8fc;
}

.player-quick-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.player-quick-stats span {
    flex: 1;
    min-width: 70px;
    padding: 8px;
    border-radius: 6px;
    background: white;
    text-align: center;
    font-weight: bold;
}

/* ===== SELL ITEMS POPUP ===== */

.sell-popup {
    max-width: 850px;
    max-height: 85vh;
    overflow-y: auto;
}

.sell-item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin: 20px 0;
}

.sell-item-card {
    display: flex;
    flex-direction: column;
    gap: 8px;

    padding: 14px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: #f5edfa;
    text-align: left;
}

.sell-item-card h3 {
    margin: 0;
    color: var(--purple-dark);
    text-align: center;
}

.sell-item-card p {
    margin: 0;
}

.sell-item-card input[type="range"] {
    width: 100%;
    accent-color: var(--purple);
    cursor: pointer;
}

.sell-item-card p:last-child {
    font-weight: bold;
}

.sell-popup > button {
    min-width: 130px;
    margin: 6px;
}

.sell-popup > h3 {
    color: var(--purple-dark);
    margin: 20px 0;
}

/* Smaller screens */
@media (max-width: 600px) {
    .sell-popup {
        max-height: 90vh;
        padding: 16px;
    }

    .sell-item-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .sell-item-card {
        padding: 10px;
    }
}