html,
body {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
    overflow: hidden;
    /* Disable double-tap zoom on iOS */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

video {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
    overflow: hidden;
    object-fit: contain;
    background-color: #000;
}

#video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

body {
    background-color: #455;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#connection {
    text-align: center; /* Center contents horizontally */
    display: flex;
    flex-direction: column; /* Stack title and buttons vertically */
    align-items: center; /* Center contents vertically */
}

#title {
    font-size: 5em;
    color: white;
    display: block;
    text-align: center;
    margin-top: -100px;
    margin-bottom: 100px;
}

#connection button,
#connection input {
    font-size: 1em;
    padding: 0.5em 1em;
    margin-bottom: 40px;
    display: block;
    width: 200px;
}

.notice {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 8px;
    padding: 15px;
    margin: 20px 0;
    font-size: 0.9em;
    color: #e0e0e0;
    text-align: left;
    max-width: 400px;
}

.notice strong {
    color: #ffc107;
}

#drawing {
    position: absolute;
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 2;
    /* Disable double-tap zoom on drawing area */
    touch-action: manipulation;
}

#canvasContainer {
    position: absolute;
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas {
    position: relative;
    touch-action: none;
    /* Ensure proper pointer event handling */
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
    /* Apple Pencil optimizations */
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    /* Disable iOS momentum scrolling */
    -webkit-overflow-scrolling: auto;
    /* Ensure immediate response */
    will-change: transform;
}
#canvas.cover {
    background-color: #AAAAFFAA;
}

#tools {
    top: 0;
    position: absolute;
    display: flex;
    /* safe: when the controls overflow, start at the left so all can be scrolled to */
    justify-content: safe center;
    align-items: center;
    width: 100%;
    max-width: 100%;
    pointer-events: none;
    background: rgba(30, 30, 40, 0.95);
    backdrop-filter: blur(10px);
    padding: 5px 20px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 15px;
    font-size: 18px;
    color: #e0e0e0;
    box-sizing: border-box;
    overflow-x: auto;
    z-index: 100;
}

#tools > * {
    pointer-events: all;
    /* Scroll the toolbar on narrow screens rather than squashing the controls */
    flex-shrink: 0;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.tool-item label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #b0b0b0;
    white-space: nowrap;
}

.tool-separator {
    width: 1px;
    height: 30px;
    background: rgba(255, 255, 255, 0.2);
}

.tool-spacer {
    flex: 1;
}

.tool-label {
    font-size: 13px;
    color: #b0b0b0;
    display: flex;
    align-items: center;
    gap: 5px;
}

.tool-value {
    font-size: 12px;
    color: #7373e8;
    min-width: 20px;
    text-align: center;
}

.tool-button,
#tools button {
    background: rgba(255, 255, 255, 0.652);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
    margin: 0;
    /* Disable double-tap zoom on buttons */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tool-button:hover,
#tools button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.tool-button:active,
#tools button:active {
    transform: translateY(0);
}

#tools button.active {
    background: rgb(115, 115, 232);
    border-color: #7373e8;
    box-shadow: 0 0 8px rgba(115, 115, 232, 0.4);
    transform: scale(1.1);
}

.tool-button svg,
#tools button svg {
    width: 26px;
    height: 26px;
}

.color-group {
    align-items: center;
}

#tools .colorOption {
    width: 44px;
    height: 44px;
    display: inline-block;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-sizing: border-box;
    cursor: pointer;
    transition: all 0.2s ease;
}

#tools .colorOption:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

#tools .colorOption.selected {
    border-color: #7373e8;
    border-width: 3px;
    box-shadow: 0 0 10px rgba(115, 115, 232, 0.5);
    transform: scale(1.1);
}

#tools #colorPicker {
    width: 44px;
    height: 44px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
}

#tools #colorPicker:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

#tools #colorPicker.selected {
    border-color: #7373e8;
    border-width: 3px;
    box-shadow: 0 0 10px rgba(115, 115, 232, 0.5);
    transform: scale(1.1);
}

#tools input[type="number"] {
    width: 60px;
    height: 44px;
    font-size: 18px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #e0e0e0;
    padding: 0 4px;
    transition: all 0.2s ease;
}

#tools input[type="number"]:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

#tools input[type="number"]:focus {
    outline: none;
    border-color: #7373e8;
    background: rgba(255, 255, 255, 0.15);
}

#tools #canvas {
    width: 100%;
    height: 100%;
}

#tools button#toggleTools svg {
    transition: transform 0.3s ease;
}

#tools button#toggleTools.flip svg {
    transform: rotate(180deg);
}

#tools input#lineWidth {
    width: 120px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    transition: all 0.2s ease;
}

#tools input#lineWidth:hover {
    background: rgba(255, 255, 255, 0.15);
}

#tools input#lineWidth::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #7373e8;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#tools input#lineWidth::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 10px rgba(115, 115, 232, 0.5);
}

#tools input#lineWidth::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #7373e8;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#tools input#lineWidth::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 10px rgba(115, 115, 232, 0.5);
}

/* Disable double-tap zoom on all interactive elements */
button, input, select, textarea, .colorOption {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.hide {
    display: none !important;
}

.show-tools-button {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 40, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.show-tools-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateX(-50%) translateY(-1px);
}

.show-tools-button svg {
    width: 20px;
    height: 20px;
}

#pencil-cursor {
    position: fixed;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    pointer-events: none;
    z-index: 1000;
    transition: all 0.05s ease;
    transform: translate(-50%, -50%);
}