:root {
    --court-border-width: 2px;
    --court-line-color: #555;
    --net-color: #333;
    --toolbar-height: 60px;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: #f0f0f0;
    font-family: sans-serif;
    overscroll-behavior: none;
    touch-action: none; /* Disable pinch-zoom, etc. */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#app-container {
    width: 100vw;
    height: 100svh; /* Use small viewport height */
}

#main-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

#court-container {
    flex-grow: 1; /* Take remaining horizontal space */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    height: 100%;
    box-sizing: border-box;
}

#court {
    height: 100%; 
    aspect-ratio: 1 / 2; /* Enforce 9m x 18m court ratio */
    background-color: #fdf8e1;
    border: var(--court-border-width) solid var(--court-line-color);
    box-sizing: border-box;
    position: relative;
}

#court.placement-mode {
    cursor: crosshair;
}

.net {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: var(--net-color);
    transform: translateY(-50%);
    z-index: 1;
}

.line {
    position: absolute;
    background-color: var(--court-line-color);
}

.top-line { top: 0; left: 0; width: 100%; height: var(--court-border-width); }
.bottom-line { bottom: 0; left: 0; width: 100%; height: var(--court-border-width); }
.left-line { top: 0; left: 0; width: var(--court-border-width); height: 100%; }
.right-line { top: 0; right: 0; width: var(--court-border-width); height: 100%; }

.middle-line {
    top: 50%;
    left: 0;
    width: 100%;
    height: var(--court-border-width);
    transform: translateY(-50%);
}

.attack-line-top {
    top: calc(50% - (100% / 6));
    left: 0;
    width: 100%;
    height: var(--court-border-width);
}

.attack-line-bottom {
    top: calc(50% + (100% / 6));
    left: 0;
    width: 100%;
    height: var(--court-border-width);
}

#toolbar {
    width: var(--toolbar-height);
    height: 100%;
    display: flex;
    align-items: center;
    background-color: #2c3e50;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    box-sizing: border-box;
    overflow-y: auto;
    flex-direction: column;
}

#toolbar-buttons {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    padding: 10px 0;
    height: 100%;
    flex-direction: column;
}

#toolbar button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background-color: #34495e;
    color: #ecf0f1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease-in-out;
    font-size: 18px;
}

#toolbar button:hover {
    background-color: #4a627a;
}

#toolbar button:disabled, #toolbar button:disabled:hover {
    background-color: #34495e;
    opacity: 0.5;
    cursor: default;
}

#toolbar button.active {
    background-color: #007bff;
    color: #fff;
}

#toggle-toolbar-btn {
    position: absolute;
    top: 50%;
    right: var(--toolbar-height);
    transform: translateY(-50%);
    width: 25px;
    height: 60px;
    background: #2c3e50;
    border: none;
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #ecf0f1;
    box-shadow: -2px 3px 5px -2px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: right 0.3s ease;
}

#toolbar.collapsed + #toggle-toolbar-btn {
    right: 0;
}



#toolbar.collapsed {
    width: 0 !important;
    padding: 0;
    border: none;
    box-shadow: none;
}

#toolbar.collapsed #toolbar-buttons {
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s 0.3s, opacity 0.3s ease;
}


#toolbar input[type="color"] {
    width: 40px;
    height: 40px;
    border: none;
    padding: 0;
    cursor: pointer;
    background-color: transparent;
}

.court-object {
    position: absolute;
    box-sizing: border-box;
    cursor: grab;
    z-index: 10; /* Create stacking context */
}

.court-object::before {
    content: '';
    position: absolute;
    top: -15px;
    left: -15px;
    right: -15px;
    bottom: -15px;
    background-color: transparent; /* For debugging */
    z-index: -1;
}


.court-object:active {
    cursor: grabbing;
    z-index: 10;
}

.player {
    /* Oval shape representing a person viewed from above (shoulders) */
    border-radius: 40%;
}

.ball {
    border-radius: 50%;
}

.court-object.selected {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.delete-handle, .rotate-handle {
    position: absolute;
    width: 25px;
    height: 25px;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    cursor: pointer;
    z-index: 20;
}

.delete-handle:hover, .rotate-handle:hover {
    background-color: #f0f0f0;
}

.delete-handle {
    top: -13px;
    left: -13px;
    color: red;
}

.rotate-handle {
    bottom: -13px;
    right: -13px;
    cursor: move; /* Indicates it can be moved/dragged */
}

.line-object {
    stroke-width: 6;
    cursor: pointer;
}

.line-handle {
    fill: #007bff;
    stroke: white;
    stroke-width: 2;
    cursor: move;
}

#color-palette {
    display: none;
    flex-wrap: wrap;
    gap: 5px;
    padding: 10px 5px;
    justify-content: center;
}

#color-palette.palette-open {
    display: flex;
}

.color-swatch {
    width: 25px;
    height: 25px;
    border: 2px solid #fff;
    outline: 1px solid #ccc;
    cursor: pointer;
    box-sizing: border-box;
    display: none;
}

#color-palette.palette-open .color-swatch {
    display: block;
}

.color-swatch.selected {
    outline: 2px solid #007bff;
    outline-offset: 1px;
}

#color-picker {
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.color-picker-preview {
    width: 25px;
    height: 25px;
    border: 2px solid #fff;
    outline: 1px solid #ccc;
    cursor: pointer;
    box-sizing: border-box;
    display: block;
}
