:root {
    --bg-dark: #f0f0f5;
    --text-light: #111111;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(0, 0, 0, 0.1);
    --accent: #111111;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden; /* Hide scrollbars, we pan manually */
    user-select: none;
    -webkit-user-select: none;
}

/* Board */
#board-container {
    width: 100vw;
    height: 100vh;
    cursor: grab;
    position: relative;
    overflow: hidden;
}

#board-container:active {
    cursor: grabbing;
}

#board {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--board-width);
    height: var(--board-height);
    background-color: #ffffff;
    background-image: 
        radial-gradient(#e0e0e0 1px, transparent 1px),
        radial-gradient(#d0d0d0 1px, transparent 1px);
    background-size: 50px 50px, 250px 250px;
    background-position: 0 0, 25px 25px;
    box-shadow: 0 0 50px rgba(0,0,0,0.1);
    transform-origin: 0 0;
}

#board.animating {
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

/* 4-Sided Frame wrapper */
.board-frame {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 10;
    /* We draw the actual solid borders natively */
    border: var(--frame-size) solid var(--frame-color);
}

.frame-edge {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    white-space: nowrap;
    gap: 40px;
}

/* Top Edge */
.frame-edge-top {
    top: calc(var(--frame-size) * -1); left: 0; right: 0; height: var(--frame-size);
}
/* Bottom Edge */
.frame-edge-bottom {
    bottom: calc(var(--frame-size) * -1); left: 0; right: 0; height: var(--frame-size);
}
/* Right Edge */
.frame-edge-right {
    top: 0; right: calc(var(--frame-size) * -1); bottom: 0; width: var(--frame-size);
    writing-mode: vertical-rl;
}
/* Left Edge (Rotated 180 so it reads upward) */
.frame-edge-left {
    top: 0; left: calc(var(--frame-size) * -1); bottom: 0; width: var(--frame-size);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

/* Text Elements */
.frame-text-element { font-family: "Arial", "Helvetica", sans-serif; font-weight: bold; font-size: calc(var(--frame-size) * 0.4); color: white; display: inline-flex; align-items: center; justify-content: center; }
.frame-text-element.separator { font-size: calc(var(--frame-size) * 0.4); color: #cc0000; }

.frame-text-element.strikethrough { position: relative; }
.frame-text-element.strikethrough::after {
    content: '';
    position: absolute;
    left: -5%;
    top: 50%;
    width: 110%;
    height: calc(var(--frame-size) * 0.08);
    background: #cc0000;
    transform: translateY(-50%);
}

#signatures-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none; /* Let clicks pass to #board-container */
}

/* Re-enable pointer events on signatures so hover tooltips work */
.signature-item {
    pointer-events: auto;
}

/* Pending Spots */
.pending-spot {
    position: absolute;
    width: calc(30px / var(--board-scale, 1));
    height: calc(30px / var(--board-scale, 1));
    background-color: #e67e22; /* Orange */
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto; /* So the tooltip/title can be hovered */
    z-index: 15;
}

.pending-spot::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #e67e22;
    border-radius: 50%;
    animation: pending-pulse 1.5s infinite;
}

@keyframes pending-pulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(3); opacity: 0; }
}

/* Zoom Controls */
.zoom-controls {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem;
    z-index: 10;
}

.zoom-controls button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.9);
    color: #111;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-controls button:hover {
    transform: scale(1.1);
    background: #fff;
}

.live-indicator {
    width: 10px;
    height: 10px;
    background-color: #2ecc71;
    border-radius: 50%;
    margin: 15px auto 5px auto;
    animation: pulse 2s infinite;
    box-shadow: 0 0 5px #2ecc71;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
    70% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 10px rgba(46, 204, 113, 0); }
    100% { transform: scale(0.95); opacity: 0.5; box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

/* Glassmorphism */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Modal */
#signature-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255,255,255,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#signature-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    padding: 2rem;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#signature-modal.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-weight: 600;
    text-align: center;
}

.input-group {
    margin-bottom: 1rem;
}

input[type="text"], textarea {
    width: 100%;
    background: rgba(255,255,255,0.9);
    border: 2px solid var(--glass-border);
    color: #111;
    padding: 12px 16px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease;
}

input[type="text"]:focus, textarea:focus {
    border-color: var(--accent);
}

textarea {
    resize: none;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #111;
    padding: 8px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.5;
    transition: all 0.3s ease;
}

.tab-btn.active {
    opacity: 1;
    border-bottom-color: var(--accent);
}

.tab-content {
    display: block;
}

.tab-content.hidden {
    display: none;
}

/* Canvas */
.canvas-container {
    position: relative;
    background: #ffffff;
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
}

canvas {
    display: block;
    width: 100%;
    height: 150px;
    touch-action: none; /* Prevent scrolling while drawing */
}

#clear-pad {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.1);
    color: #111;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

#clear-pad:hover {
    background: rgba(0,0,0,0.1);
}

/* Type Tab */
.font-selector {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

.font-btn {
    flex: 1;
    background: rgba(255,255,255,0.9);
    border: 2px solid var(--glass-border);
    color: #111;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
}

.font-btn.active {
    border-color: var(--accent);
    background: rgba(0, 0, 0, 0.05);
}

#type-signature {
    font-size: 2rem;
    text-align: center;
}

/* Colors */
.color-picker {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
    box-shadow: 0 0 10px currentColor;
}

.color-swatch:hover {
    transform: scale(1.2);
}

.color-swatch.active {
    border-color: #111;
    transform: scale(1.2);
}

/* Buttons */
.modal-actions {
    display: flex;
    gap: 1rem;
}

.primary-btn, .secondary-btn {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid transparent;
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
    transition: opacity 0.2s;
}

.primary-btn {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.secondary-btn {
    background: transparent;
    border-color: var(--glass-border);
    color: #111;
}

.primary-btn:hover, .secondary-btn:hover {
    opacity: 0.8;
}

/* Placed Signatures */
.signature-item {
    position: absolute;
    transform: translate(-50%, -50%);
    cursor: pointer;
    /* Subtle float animation */
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0% { transform: translate(-50%, -50%) translateY(0px) rotate(0deg); }
    50% { transform: translate(-50%, -50%) translateY(-10px) rotate(2deg); }
    100% { transform: translate(-50%, -50%) translateY(0px) rotate(0deg); }
}

.sig-image {
    width: 225px;
    height: auto;
    pointer-events: none;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.sig-text {
    font-size: 37.5px;
    white-space: nowrap;
    pointer-events: none;
}

/* Congratulatory Overlay */
#congratulatory-overlay {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: transparent;
    padding: 10px;
    max-width: min(400px, 80vw);
    text-align: center;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#congratulatory-overlay.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#congrat-text {
    font-size: 14px;
    font-weight: normal;
    font-style: italic;
    font-family: 'Georgia', serif;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 0 10px rgba(255,255,255,0.8);
    white-space: pre-wrap;
    line-height: 1.5;
}

/* Loading */
#loading {
    position: fixed;
    top:0; left:0; width:100vw; height:100vh;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }
