/* style.css */

/* Game-specific styles */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background-color: #f4f4f4;
}

/* Player UI */
.player-ui {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 10px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Opponent UI */
.opponent-ui {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Controls */
.controls {
    display: flex;
    gap: 10px;
    padding: 10px;
}

.unit-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 10px;
    padding: 10px;
}

.control-button {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-button:hover {
    background-color: #f0f0f0;
}

.control-button:active {
    background-color: #e0e0e0;
}

/* Editor-specific body styles to prevent scrolling */
body.editor-page {
    position: fixed;
    /* Prevent bounce on iOS */
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: none;
    /* Disable iOS momentum scrolling */
    display: block;
    /* Override flex display */
    background: #f4f4f4;
    /* Match the UI background color, not the canvas */
}

/* Regular pages can scroll normally */
body.scrollable-page {
    position: static;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

#boardContainer {
    width: 100%;
    height: 100%;
    background: white;
    /* White background for the game board */
}

/* General styles for .player-ui */
.player-ui {
    position: fixed;
    width: 100%;
    height: 120px;
    background-color: #f4f4f4;
    z-index: 100;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    gap: 10px;
    /* Add spacing between flex items */
}

/* Specific styles for opponent UI */
#opponentUI {
    top: 0;
    justify-content: space-between;
    flex-direction: row;
}

/* Add a container div for the time-box to control its size */
.time-box-container {
    height: 100%;
    display: flex;
    align-items: stretch;
    justify-content: flex-end;
    width: 140px;
    /* Fixed width instead of max-width */
    flex: 0 0 140px;
    /* Don't grow or shrink, maintain 140px width */
    margin-right: 0;
}

/* Specific styles for player UI */
#playerUI {
    bottom: 0;
    justify-content: space-between;
    flex-direction: row;
}

/* Controls container styles */
.player-controls,
.opponent-controls {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    height: 100%;
    flex: 1 1 auto;
    /* Allow growing and shrinking */
    min-width: 0;
    /* Allow container to shrink below content size */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 5px;
    gap: 10px;
    /* Add spacing between controls */
}

/* Scrollbar styling for Webkit browsers */
.player-controls::-webkit-scrollbar,
.opponent-controls::-webkit-scrollbar {
    height: 6px;
    background-color: #f4f4f4;
}

.player-controls::-webkit-scrollbar-thumb,
.opponent-controls::-webkit-scrollbar-thumb {
    background-color: #888;
    border-radius: 3px;
}

.player-controls::-webkit-scrollbar-track,
.opponent-controls::-webkit-scrollbar-track {
    background-color: #f4f4f4;
}

/* Unit Controls Styling */
.unit-controls {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    min-width: min-content;
    /* Ensure it doesn't shrink below content width */
}

.unit-controls .controls-wrapper {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    max-height: 120px;
    margin-right: 20px;
    min-width: min-content;
    /* Ensure it doesn't shrink below content width */
}

.unit-controls button,
.unit-controls input {
    margin: 5px;
    min-height: 30px;
    /* Minimum touch target size */
    font-size: 16px;
    /* Readable font size on mobile */
}

.unit-controls .delete-button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    align-self: flex-start;
}

.general-controls {
    display: flex;
    flex-direction: column;
    width: auto;
    /* Allow content to determine width */
    min-width: 100px;
}

.general-controls input,
.general-controls button {
    width: 100%;
    min-height: 36px;
    /* Better touch targets */
    margin-bottom: 5px;
}

/* Existing controls styling */
.existing-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    justify-content: center;
    min-width: min-content;
    /* Ensure it doesn't shrink below content width */
}

.existing-controls select,
.existing-controls button {
    margin: 5px;
    min-height: 36px;
    /* Better touch targets */
    font-size: 16px;
    /* Readable font size */
}

.reinforcement-controls {
    display: grid;
    grid-template-columns: repeat(2, auto);
    /* Two narrow columns */
    gap: 5px 15px;
    /* Small spacing between items */
    max-height: 100%;
    /* Prevents overflowing */
    overflow-y: auto;
    /* Enables scrolling if necessary */
    align-items: start;
    /* Aligns items to the top */
    width: fit-content;
    /* Prevents full-width stretching */
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
    min-width: min-content;
    /* Ensure it doesn't shrink below content width */
}

/* Ensure each form-group (label + input) stays together */
.reinforcement-controls .form-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 200px;
    white-space: nowrap;
    /* Prevents wrapping inside the form-group */
}

/* Adjust the main menu button */
#mainMenuButton {
    margin-left: 10px;
    font-size: 24px;
    width: 44px;
    /* Minimum touch target size */
    height: 44px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
}

.reserve-area-container {
    position: relative;
    height: 100%;
    flex: 0 1 auto;
    /* Don't grow, but allow shrinking */
    min-width: 200px;
    /* Minimum width before shrinking */
    overflow: visible;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

#opponent-reserve-container {
    padding: 0 20px;
    margin-left: 75px;
}

#player-reserve-container {
    padding: 0 20px;
    margin-left: 20px;
}

.arrow-container {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: visible;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 102;
    /* Above the player-ui z-index */
}

.arrow-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 103;
    /* Above the reserve area */
}

.arrow-svg path {
    pointer-events: auto;
    cursor: pointer;
}

#playerReserveArea,
#opponentReserveArea {
    position: relative;
    pointer-events: auto;
    cursor: default;
    flex: 1 1 auto;
    height: 100%;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    z-index: 101;
}

#mainActionButton {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #ddd;
    /* Default button background */
    border: 1px solid #ccc;
    /* Subtle border for the button */
    transition: background-color 0.3s, border-color 0.3s;
    color: #000;
    min-height: 44px;
    /* Minimum touch target size */
    min-width: 80px;
}

#mainActionButton:hover {
    background-color: #ccc;
    /* Lighter when hovered */
    border-color: #888;
    /* Darker border on hover */
}

#mainActionButton.disabled {
    cursor: not-allowed;
    background-color: #f4f4f4;
    /* Disabled background */
    border-color: #aaa;
    /* Lighter border for disabled state */
    color: #888;
}

#mainActionButton.disabled:hover {
    background-color: #f4f4f4;
    /* Remain the same on hover */
    border-color: #aaa;
    /* Remain the same on hover */
}

#gameContainer {
    margin-top: 120px;
    /* Same as the height of the opponentUI */
    margin-bottom: 120px;
    /* Same as the height of the playerUI */
    height: calc(100vh - 240px);
    /* Adjust based on the UI heights */
    overflow: hidden;
}

#editorContainer {
    width: 100vw;
    height: calc(100vh - 240px);
    /* Account for top and bottom UI */
    margin-top: 120px;
    /* Same as the height of the opponentUI */
    position: fixed;
    overflow: hidden;
    touch-action: none;
    /* Prevent browser handling of touch gestures */
    top: 0;
    /* Ensure it's aligned with the top edge */
    left: 0;
    /* Ensure it's aligned with the left edge */
}

/* Ensure the editor canvas has a blue background for water */
#editorCanvas {
    width: 100%;
    height: 100%;
    background: transparent;
    /* Allow background to be set by JS */
    display: block;
    /* Ensure no gaps between block elements */
}

#svgContent {
    background: transparent;
    /* Allow background to be set by JS */
}

/* Show horizontal scroll indicators with fading edges */
.scroll-indicator-container {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.scroll-indicator-left,
.scroll-indicator-right {
    display: none;
    /* Hidden by default, shown via JS when scrollable */
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    pointer-events: none;
    /* Allow clicking through */
    z-index: 101;
}

.scroll-indicator-left {
    left: 0;
    background: linear-gradient(to right, rgba(244, 244, 244, 0.8), rgba(244, 244, 244, 0));
}

.scroll-indicator-right {
    right: 0;
    background: linear-gradient(to left, rgba(244, 244, 244, 0.8), rgba(244, 244, 244, 0));
}

@keyframes pulseEffect {
    0% {
        fill-opacity: 0.3;
    }

    50% {
        fill-opacity: 0.7;
    }

    100% {
        fill-opacity: 0.3;
    }
}

.pulsate {
    animation: pulseEffect 1.5s infinite;
}

.selected {
    fill-opacity: 0.4;
    fill: white;
}

#feedbackMessage {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Fixed at a position */
    bottom: 140px;
    /* Distance from bottom */
    left: 50%;
    transform: translateX(-50%);
    /* Center horizontally */
    padding: 15px;
    background-color: #f8f9fa;
    border: 1px solid #ccc;
    border-radius: 5px;
    z-index: 1000;
    /* Make sure it's on top */
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    /* Add shadow for better visibility */
    max-width: 90%;
    /* Limit width on mobile */
    font-size: 16px;
    /* Readable text */
}

.layer-selector {
    margin-right: 10px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #fff;
    font-size: 16px;
    cursor: pointer;
    height: 44px;
    /* Larger for better touch targets */
}

/* Style for the hamburger menu button */
#mainMenuButton {
    position: fixed;
    top: 10px;
    left: 10px;
    background-color: #333;
    color: white;
    border: none;
    padding: 10px 15px;
    font-size: 24px;
    cursor: pointer;
    z-index: 110;
    /* Ensure it's above other UI elements */
    border-radius: 5px;
}

#mainMenuButton:hover {
    background-color: #555;
}

/* Main menu overlay */
.main-menu {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    /* Semi-transparent black background */
    z-index: 200;
    /* Higher than other UI elements */
    color: white;
    font-size: 24px;
    text-align: center;
    padding-top: 100px;
    overflow-y: auto;
    /* Allow scrolling if needed */
}

/* Close button inside the menu */
#closeMenuButton {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 10px 15px;
    font-size: 24px;
    cursor: pointer;
    border-radius: 5px;
    width: 44px;
    /* Minimum touch target size */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#closeMenuButton:hover {
    background-color: #c0392b;
}

/* Menu item styles */
.main-menu ul {
    list-style-type: none;
    padding: 0;
}

.main-menu li {
    padding: 15px 0;
}

.main-menu a {
    color: white;
    text-decoration: none;
    font-size: 24px;
    transition: color 0.3s;
    padding: 10px;
    display: inline-block;
}

.main-menu a:hover {
    color: #ddd;
}

.time-box {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* Distribute content to fill space */
    align-items: center;
    font-size: 14px;
    /* Larger font size */
    padding: 10px;
    /* More padding */
    background-color: #000;
    color: #fff;
    margin: 0;
    width: 100%;
    /* Fill full width of container */
    height: 100%;
    /* Fill full height of container */
    box-sizing: border-box;
    min-width: 120px;
    line-height: 1.2;
    overflow: hidden;
    flex-shrink: 0;
    border: none;
    /* Remove any border */
}

/* Style each element in the time box */
.time-box p,
.time-box h1 {
    margin: 4px 0;
    /* More spacing between elements */
    width: 100%;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.time-box #displayDate {
    font-size: 14px;
    /* Larger date font */
}

.time-box #displayTime {
    font-size: 24px;
    /* Larger time font */
    font-weight: bold;
    margin: 4px 0;
}

.time-box #displayPhase {
    font-size: 14px;
    /* Larger phase font */
}

/* Adjust the Edit Time Settings button */
.time-box button {
    margin-top: 4px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
    height: auto !important;
    min-height: 26px !important;
}

/* Form Group styling */
.form-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    min-width: 100px;
    margin-left: 10px;
    margin-bottom: 5px;
}

/* Label styling */
.form-group label {
    margin-right: 10px;
    white-space: nowrap;
    font-size: 16px;
    /* More readable on mobile */
}

/* Input and Select styling */
.form-group input,
.form-group select {
    flex: 1;
    min-width: 0;
    height: 36px;
    /* Better touch targets */
    font-size: 16px;
    /* More readable on mobile */
    padding: 5px;
}

/* Add swipe indicator for scrollable containers */
.swipe-indicator {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 5px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    z-index: 102;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.swipe-indicator.visible {
    opacity: 1;
    animation: swipeHint 1.5s infinite;
}

@keyframes swipeHint {

    0%,
    100% {
        transform: translateX(-50%);
    }

    50% {
        transform: translateX(-30%);
    }
}

/* Media Queries for Responsive Design */
@media screen and (max-width: 768px) {

    /* Adjust UI height for mobile */
    .player-ui {
        height: 140px;
        padding: 5px;
        /* Reduce padding on mobile */
        gap: 5px;
        /* Reduce gap on mobile */
    }

    #gameContainer {
        margin-top: 140px;
        margin-bottom: 140px;
        height: calc(100vh - 280px);
    }

    #editorContainer {
        height: calc(100vh - 280px);
        margin-top: 140px;
    }

    /* Stack control items when needed */
    .player-controls,
    .opponent-controls {
        gap: 5px;
        /* Reduce gap on mobile */
        padding: 5px;
    }

    /* Make the layer selector full width on small screens */
    .existing-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .layer-selector,
    #mainActionButton {
        width: 100%;
        margin: 5px 0;
    }

    /* Ensure feedback message is properly positioned */
    #feedbackMessage {
        bottom: 160px;
    }

    /* Time box container styling for tablets */
    .time-box-container {
        width: 120px;
        flex: 0 0 120px;
    }

    /* Time box styling for tablets */
    .time-box {
        font-size: 12px;
        padding: 8px;
    }

    .time-box #displayTime {
        font-size: 20px;
    }

    .time-box #displayDate,
    .time-box #displayPhase {
        font-size: 12px;
    }

    .reserve-area-container {
        min-width: 150px;
        /* Smaller minimum width on mobile */
    }
}

/* For very small screens */
@media screen and (max-width: 480px) {
    .player-ui {
        height: 160px;
        padding: 3px;
        gap: 3px;
    }

    #gameContainer {
        margin-top: 160px;
        margin-bottom: 160px;
        height: calc(100vh - 320px);
    }

    #editorContainer {
        height: calc(100vh - 320px);
        margin-top: 160px;
    }

    /* Further adjust spacing and sizing */
    .form-group {
        margin-left: 5px;
        min-width: 80px;
    }

    .unit-controls .controls-wrapper {
        max-height: 150px;
    }

    /* Make text more readable */
    .form-group label {
        font-size: 14px;
    }

    /* Ensure feedback message is properly positioned */
    #feedbackMessage {
        bottom: 180px;
    }

    /* Time box container styling for phones */
    .time-box-container {
        width: 100px;
        flex: 0 0 100px;
    }

    /* Time box styling for phones */
    .time-box {
        font-size: 11px;
        padding: 6px;
        min-width: 90px;
    }

    .time-box #displayTime {
        font-size: 16px;
    }

    .time-box #displayDate,
    .time-box #displayPhase {
        font-size: 11px;
    }

    .reserve-area-container {
        min-width: 120px;
    }
}