:root {
    --sand: #fff8ef;
    --ink: #1f2d2a;
    --teal: #12876a;
    --teal-soft: #d9fff2;
    --amber: #f6b74e;
    --rose: #f16e7f;
    --card: rgba(255, 255, 255, 0.86);
    --border: rgba(31, 45, 42, 0.12);
    --note: #fffdf7;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
}

body {
    margin: 0;
    min-height: 100%;
    font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at 10% 10%, #fff7d3 0%, transparent 38%),
        radial-gradient(circle at 88% 12%, #ddf9ff 0%, transparent 34%),
        linear-gradient(140deg, #f7fafc 0%, #eef9ff 48%, #f9f8ff 100%);
}

.app-shell {
    position: relative;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
}

.floating-panel {
    position: absolute;
    left: 14px;
    top: 14px;
    z-index: 30;
    width: min(258px, calc(100vw - 28px));
    padding: 0.7rem 0.72rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 16px 40px rgba(25, 45, 40, 0.14);
    backdrop-filter: blur(20px);
    transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

.floating-panel.is-collapsed {
    transform: translateX(calc(-100% + 36px));
    opacity: 0.76;
}

.floating-panel.is-collapsed .panel-content {
    opacity: 0;
    max-height: 0;
    pointer-events: none;
    margin-top: 0;
    overflow: hidden;
}

.panel-content {
    max-height: 84vh;
    transition: opacity 140ms ease, max-height 160ms ease;
}

.panel-toggle {
    position: absolute;
    top: 10px;
    right: -9px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.96);
    color: rgba(31, 45, 42, 0.7);
    font-size: 0.8rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(25, 45, 40, 0.1);
}

.floating-panel.is-collapsed .panel-toggle {
    transform: rotate(180deg);
}

.tool-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.55rem;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 0.55rem;
    border-radius: 10px;
    border: 1px solid rgba(31, 45, 42, 0.12);
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    font-weight: 600;
    font-size: 0.78rem;
    transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

.tool-btn span {
    pointer-events: none;
}

.tool-btn.active {
    background: rgba(18, 135, 106, 0.12);
    border-color: rgba(18, 135, 106, 0.28);
    color: #124e3d;
}

.tool-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(18, 135, 106, 0.2);
}

.tool-icon {
    display: inline-flex;
    width: 1rem;
    height: 1rem;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(18, 135, 106, 0.1);
    font-size: 0.7rem;
}

.panel-row {
    margin-top: 0.6rem;
}

.panel-row .form-label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.74rem;
    color: rgba(31, 45, 42, 0.68);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.9rem;
}

.panel-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
}

.panel-subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.72rem;
    color: rgba(31, 45, 42, 0.68);
}

.panel-badge {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #1fba7d;
    box-shadow: 0 0 0 8px rgba(31, 186, 125, 0.16);
    margin-top: 4px;
}

.panel-row {
    margin-top: 1rem;
}

.panel-inline {
    display: flex;
    gap: 0.56rem;
    align-items: flex-end;
}

.panel-inline > div {
    flex: 1;
}

.panel-actions {
    margin-top: 0.8rem;
}

.panel-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.32rem;
    align-items: center;
    margin-top: 0.55rem;
}

.toolbar-pill {
    font-size: 0.64rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.2rem 0.44rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 45, 42, 0.06);
}

.lobby-board {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(246, 252, 254, 0.9), rgba(255, 255, 255, 0.88));
}

.board-card {
    padding: 0;
    border-radius: 0;
    min-height: 100vh;
    border: none;
}

.board-toolbar {
    display: none;
}

#draw-canvas,
.note-layer {
    position: absolute;
    inset: 0;
}

#draw-canvas {
    touch-action: none;
    height: 100vh;
}

.hero-glow {
    position: fixed;
    z-index: -1;
    border-radius: 999px;
    filter: blur(24px);
    opacity: 0.45;
}

.hero-glow-a {
    top: 6%;
    left: 4%;
    width: 280px;
    height: 280px;
    background: #ffcf8b;
}

.hero-glow-b {
    right: 8%;
    bottom: 9%;
    width: 320px;
    height: 320px;
    background: #8deacc;
}

.lobby-shell {
    width: min(1200px, 100%);
}

.control-card,
.board-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    backdrop-filter: blur(6px);
    box-shadow: 0 14px 36px rgba(23, 48, 42, 0.09);
}

.control-card {
    padding: 1.25rem;
}

.board-card {
    padding: 1rem;
}

.display-title {
    font-family: "Fraunces", Georgia, serif;
    font-size: clamp(2rem, 5vw, 2.4rem);
    line-height: 1.05;
}

.subtitle {
    color: rgba(31, 45, 42, 0.75);
}

.status-line {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.65rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 0.9rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #c64d4d;
    box-shadow: 0 0 0 4px rgba(198, 77, 77, 0.2);
}

.dot.connected {
    background: #1fba7d;
    box-shadow: 0 0 0 4px rgba(31, 186, 125, 0.2);
}

.board-toolbar {
    margin-bottom: 0.75rem;
}

.toolbar-pill {
    font-size: 0.82rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--border);
}

.lobby-board {
    position: relative;
    width: 100%;
    min-height: 560px;
    height: 100vh;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(22, 45, 42, 0.12);
    background: linear-gradient(145deg, #fefffb 0%, #f6fff9 100%);
}

#lobby-board,
#draw-canvas,
.note-layer {
    position: absolute;
    inset: 0;
}

#grid-canvas,
#draw-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#grid-canvas {
    z-index: 0;
}

#draw-canvas {
    z-index: 1;
    touch-action: none;
    display: block;
}

#lobby-board {
    touch-action: auto;
}

.note-layer {
    pointer-events: none;
}

.canvas-note {
    position: absolute;
    min-width: 100px;
    max-width: 220px;
    padding: 0.5rem 0.6rem;
    border-radius: 13px;
    background: var(--note);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 10px 22px rgba(24, 45, 40, 0.16);
    transform: translate(-50%, -50%);
    transform-origin: center;
    animation: note-in 0.2s ease;
}

.canvas-note .nick {
    display: block;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(24, 45, 40, 0.65);
    margin-bottom: 0.1rem;
}

.canvas-note .message {
    font-size: 0.9rem;
    line-height: 1.22;
    color: rgba(0, 0, 0, 0.78);
    white-space: pre-wrap;
    word-break: break-word;
}

.tool-toggle .btn {
    font-weight: 600;
}

.tool-toggle .btn.active {
    background: #1f2d2a;
    border-color: #1f2d2a;
    color: #fff;
}

.board-hint {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 4;
    font-size: 0.77rem;
    letter-spacing: 0.01em;
    padding: 0.35rem 0.55rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

@media (max-width: 820px) {
    .floating-panel {
        position: fixed;
        left: 8px;
        right: 8px;
        top: auto;
        bottom: max(14px, env(safe-area-inset-bottom, 14px));
        width: auto;
        padding: 0.95rem 1rem;
        border-radius: 20px;
    }

    .floating-panel.is-collapsed {
        transform: translateY(calc(100% - 64px));
    }

    .panel-toggle {
        top: -14px;
        right: 18px;
        width: 30px;
        height: 30px;
    }

    .tool-btn {
        padding: 0.85rem 0.85rem;
        font-size: 0.92rem;
        min-height: 52px;
    }

    .panel-row {
        margin-top: 0.85rem;
    }

    .panel-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .panel-inline > div {
        width: 100%;
    }

    .toolbar-pill {
        font-size: 0.72rem;
        padding: 0.28rem 0.55rem;
    }

    .board-hint {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(92vw, 380px);
        padding: 0.75rem 0.9rem;
        font-size: 0.8rem;
    }
}

.lobby-board.tool-pen {
    cursor: crosshair;
}

.lobby-board.tool-eraser {
    cursor: cell;
}

.lobby-board.tool-text {
    cursor: text;
}

.lobby-board.tool-pan {
    cursor: grab;
}

.lobby-board.tool-pan.is-panning {
    cursor: grabbing;
}

@keyframes note-in {
    from {
        opacity: 0;
        transform: translate(-50%, -55%) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@media (max-width: 992px) {
    .lobby-board {
        min-height: 460px;
    }
}

@media (max-width: 576px) {
    .control-card,
    .board-card {
        border-radius: 14px;
    }

    .lobby-board {
        min-height: 360px;
    }

    .canvas-note {
        max-width: 150px;
    }
}