:root {
    --bg-dark: #f8f9fa;
    /* 白に近い爽やかなグレー */
    --bg-panel: rgba(255, 255, 255, 0.9);
    /* 白ベースの半透明 */
    --accent: #ff4757;
    --text: #2d3436;
    /* 濃いグレー。完全な黒より柔らかい */
    --text-dim: #636e72;
    --border: rgba(0, 0, 0, 0.08);
    /* ライトテーマ用の薄い線 */
    --glass: rgba(0, 0, 0, 0.03);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    min-height: 50px;
    height: auto;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 20px;
    z-index: 100;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    justify-content: flex-end;
}

.menu-toggle {
    display: none;
    padding: 8px 15px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.logo-area {
    display: none;
    /* 要素が空なので非表示に */
}

/* --- Rest of the file cleanup --- */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        min-height: 50px;
        padding: 5px 15px;
    }

    .sidebar {
        padding-top: 10px;
    }

    .d-pad-container {
        transform: scale(0.8);
        transform-origin: bottom right;
        bottom: 10px;
        right: 10px;
    }
}

/* Chat UI (Moved outside small landscape media query) */
.chat-toggle-btn {
    position: fixed;
    bottom: 30px;
    right: 170px;
    /* Moved further left to clear D-pad */
    padding: 0 20px;
    height: 50px;
    border-radius: 25px;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: transform 0.2s;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
}

.chat-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ff0000;
    border-radius: 50%;
    border: 2px solid var(--bg-dark);
}

.chat-container {
    position: fixed;
    bottom: 90px;
    right: 30px;
    width: 320px;
    height: 400px;
    background: var(--bg-panel);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    /* transition via JS class instead of entrance animation */
    transition: transform 0.3s cubic-bezier(0.1, 0.9, 0.2, 1), opacity 0.3s ease;
}

.chat-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-header {
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text);
}

#chat-close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 5px;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    /* Allow shrinking */
}

.chat-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    word-break: break-word;
    position: relative;
    animation: fade-in 0.2s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.self {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-message.other {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border-bottom-left-radius: 2px;
}

.chat-message.system {
    align-self: center;
    background: none;
    color: var(--text-dim);
    font-size: 0.7rem;
    text-align: center;
    padding: 5px;
    border: 1px dashed var(--border);
    width: 100%;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    /* Prevent from disappearing */
}

#chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 12px;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
}

#chat-send-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.8rem;
}

@media (max-width: 768px) {
    .chat-container {
        right: 0;
        left: 0;
        bottom: 100px;
        width: 100%;
        height: 35vh;
        /* About 2-3 lines + input */
        min-height: 250px;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        border-left: none;
        border-right: none;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.8);
        z-index: 9999;
        position: fixed;
    }

    .chat-container.hidden {
        transform: translateY(100%);
        opacity: 1;
        /* Keep opacity solid for mobile slide, rely on transform */
    }

    /* Redundant definition removed */


    body.chat-open .canvas-wrapper {
        /* Shrink the wrapper height so we can scroll/pan above the chat drawer */
        height: calc(100% - (35vh + 100px));
    }
}

.d-pad-container.dimmed,
.chat-toggle-btn.dimmed {
    opacity: 0.2;
    pointer-events: none;
    transition: opacity 0.3s;
}

.tagline {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-weight: 300;
}

.ad-banner {
    display: none;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
    width: 100%;
}

.ad-banner.top-ad-pc {
    min-height: 110px;
}

.ad-banner.top-ad-mobile {
    min-height: 70px;
}

/* Ensure ad content isn't squashed */
.ad-banner>* {
    flex-shrink: 0;
}

.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #e0e0e0;
    touch-action: none;
    overscroll-behavior: none;
}

.menu-toggle {
    display: none;
}

.sidebar {
    width: 340px;
    /* Widened for 300px ad */
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    overflow-y: auto;
}

/* PC Layout Override */
#app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

@media (min-width: 769px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        background-color: #1a1a1b;
        overflow: hidden;
    }

    #app-shell {
        max-width: 800px;
        background: #f8f9fa;
        box-shadow: 0 0 80px rgba(0, 0, 0, 0.9);
        border: 1px solid var(--border);
        margin: 0 auto;
    }

    .main-container {
        display: flex;
        flex: 1;
        width: 100%;
        overflow: hidden;
    }

    .canvas-wrapper {
        display: block !important;
        position: relative;
        overflow: hidden;
    }
}

.tools-wrapper .action-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    flex: 1;
    margin-top: 0;
}

.tools-wrapper .action-btn {
    margin: 0 !important;
    height: 100%;
    /* forces button to stretch inside grid */
}

/* Range Input Custom Styling for dark theme */
.tools-wrapper input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
    height: 24px;
    /* Explicit height for hit area */
    display: block;
}

.tools-wrapper input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    /* Slightly thicker track */
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.tools-wrapper input[type="range"]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -6px;
    /* Centers thumb on 8px track: (8/2) - (18/2) = 4 - 9 = -5 */
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
    border: 2px solid #fff;
    border-radius: 50% !important;
}

/* Global Circular Slider Thumbs */
input[type="range"]::-webkit-slider-thumb {
    border-radius: 50% !important;
}

input[type="range"]::-moz-range-thumb {
    border-radius: 50% !important;
}

/* Global Overrides and Resets */
.sidebar,
.tools-wrapper-container,
.pc-ad-container,
.mobile-close-container {
    display: none !important;
}

#pc-board-section {
    display: none !important;
}

.sidebar {
    display: none !important;
}

.tools-wrapper-container {
    display: none !important;
}

@media (max-width: 768px) {
    .canvas-wrapper {
        padding: 10px;
        padding-bottom: 150px;
    }

    .pc-ad-container {
        position: absolute;
        visibility: hidden;
        width: 0;
        height: 0;
        overflow: visible;
    }

    .ad-wrapper {
        display: none;
    }

    .chat-container {
        visibility: visible;
    }

    .ad-banner.top-ad {
        display: flex;
        height: 50px;
        margin: 0 auto;
    }
}


.share-btn {
    font-size: 0.65rem;
}

.tool-section {
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.presented-by {
    font-size: 0.65rem;
    opacity: 0.7;
}

.board-count {
    font-size: 0.65rem;
    opacity: 0.9;
}

.total-count {
    opacity: 0.6;
    margin-left: 2px;
}

.presented-by a {
    color: inherit;
    text-decoration: underline;
}

.presented-by a:hover {
    opacity: 1;
}

.participant-count {
    font-size: 0.9rem;
    font-weight: 700;
    background: #2ed573;
    color: #000;
    padding: 4px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 0 15px rgba(46, 213, 115, 0.4);
    animation: live-pulse 2s infinite;
}

@keyframes live-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(46, 213, 115, 0.4);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 25px rgba(46, 213, 115, 0.6);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 15px rgba(46, 213, 115, 0.4);
    }
}

.tool-section h3 {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 5px;
}

/* Horizontal Grid for Tools */
.tool-group.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.tool-group.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.tool-btn,
.action-btn {
    width: 100%;
    padding: 8px 4px;
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.65rem;
    text-align: center;
    margin-bottom: 4px;
}

.tool-btn.active,
.tool-btn:hover,
.action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.tool-btn,
.action-btn,
.board-tab,
.color-swatch,
.logo,
.zoom-btn,
.mobile-zoom-btn,
.d-pad-btn {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.color-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#color-picker {
    width: 100%;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
}

.preset-colors {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin-top: 10px;
}

.color-swatch {
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
}

#width-slider {
    width: 100%;
    margin-bottom: 5px;
}

#width-value {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.board-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.board-tab {
    padding: 8px 4px;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    text-align: center;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 60px;
    justify-content: center;
}

.board-name {
    font-weight: 700;
}

.board-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.55rem;
    opacity: 0.7;
    width: 100%;
}

.board-count {
    color: #2ed573;
}

.board-last-active {
    font-size: 0.5rem;
    white-space: nowrap;
}

.board-tab.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--text);
}

.zoom-controls-row,
.zoom-controls-grid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 4px;
    width: 100%;
}

.zoom-btn {
    padding: 2px 6px;
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

#zoom-level {
    font-size: 0.7rem;
    color: var(--text-dim);
    min-width: 35px;
    text-align: center;
}

.zoom-level-box {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 35px;
}

.small-btn {
    font-size: 0.6rem !important;
    padding: 4px 6px !important;
    width: auto !important;
    margin: 0 !important;
}

.canvas-container {
    background-color: #fff;
    /* box-shadow removed per user request */
    position: absolute;
    top: 0;
    left: 0;
    width: 2000px;
    height: 2000px;
    transform-origin: 0 0;
    overflow: hidden;
    will-change: transform;
}

.canvas-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    background-size: cover;
    background-position: center;
    z-index: 0;
    pointer-events: none;
}

#main-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    cursor: crosshair;
    touch-action: none;
    background-color: transparent;
}

.replay-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border);
    padding: 15px 25px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#replay-close {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: var(--accent);
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    z-index: 1001;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}

/* Ad Overlay */
.ad-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 40px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.ad-modal h3 {
    margin-bottom: 20px;
}

.ad-modal-content {
    background: var(--glass);
    min-height: 250px;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    border-radius: 8px;
}

#close-ad {
    padding: 10px 30px;
    background: var(--accent);
    border: none;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
}

.mobile-zoom-controls {
    display: none;
}

#thickness-indicator-container {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    min-width: 150px;
    height: auto;
    padding: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    pointer-events: none;
    z-index: 10000;
}

/* D-Pad Controls */
.d-pad-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    z-index: 2000;
}



.d-pad-row {
    display: flex;
    gap: 5px;
}

.d-pad-btn {
    width: 60px;
    height: 60px;
    background: var(--accent);
    color: white;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    user-select: none;
    transition: transform 0.1s, background 0.1s;
}

.d-pad-btn:active {
    background: #00d2ff;
    transform: scale(0.95);
}

/* Startup Modal */
.startup-modal {
    max-width: 500px;
    padding: 30px 40px !important;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 249, 250, 0.98) 100%) !important;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.15) !important;
    animation: modal-appear 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-appear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.startup-logo-container {
    margin-bottom: 15px;
    text-align: center;
}

.startup-logo {
    max-width: 220px;
    height: auto;
    filter: drop-shadow(0 0 15px rgba(255, 71, 87, 0.1));
}

.language-selection {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.lang-select-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 24px 20px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text);
}

.lang-select-btn:hover {
    background: white;
    border-color: var(--accent);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(255, 71, 87, 0.15);
}

.lang-icon {
    font-size: 2rem;
}

.lang-text {
    font-size: 0.9rem;
    font-weight: 600;
}

.welcome-text-container {
    margin: 15px 0;
    line-height: 1.4;
}

.welcome-text.ja {
    font-size: 0.95rem;
    color: #333;
    margin-bottom: 8px;
}

.welcome-text.en {
    font-size: 0.85rem;
    color: #666;
}


/* Mobile Responsive Overhaul */
@media (max-width: 768px) {
    body {
        height: 100vh;
        width: 100vw;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        height: -webkit-fill-available;
    }

    html {
        width: 100vw;
        overflow: hidden;
    }

    .header {
        height: auto;
        /* Allow growth for new header */
        min-height: auto;
        padding: 5px 10px;
        flex-direction: column;
        gap: 5px;
        background: var(--bg-panel);
    }

    .pc-only {
        display: none !important;
    }

    .ad-banner.top-ad-mobile {
        display: flex;
    }

    /* Header V3 styles moved to global section */
    .mobile-header-v3 {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    /* Floating Chat FAB */
    .mobile-chat-fab {
        position: fixed;
        bottom: 110px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--accent);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        z-index: 10050;
        border: none;
    }

    .mobile-chat-fab::after {
        content: '💬';
        font-size: 1.5rem;
    }


    /* Relocate Footer to permanent bottom */
    .page-footer {
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        width: 100%;
        height: 40px;
        background: #fff;
        color: #333;
        padding: 5px 10px !important;
        text-align: center;
        z-index: 10101;
        display: flex;
        flex-direction: column;
        justify-content: center;
        border-top: 1px solid var(--border);
    }

    .mobile-footer-controls {
        display: flex !important;
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: 95%;
        max-width: 450px;
        height: 55px;
        background: var(--bg-panel);
        border: 2px solid var(--text-dim);
        border-radius: 8px;
        z-index: 1000;
        pointer-events: none;
        transition: opacity 0.3s ease;
        /* Removing overflow: hidden so floating badge can escape */
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    body.is-drawing .mobile-footer-controls,
    body.is-drawing .pan-horizontal-bar {
        opacity: 0;
        pointer-events: none;
    }

    .mobile-footer-controls.dimmed {
        display: none !important;
    }

    .mobile-footer-controls>* {
        pointer-events: auto;
    }

    .mobile-footer-controls button {
        background: transparent !important;
        border: none !important;
        color: var(--text) !important;
        font-size: 1.3rem !important;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        height: 100% !important;
        width: auto !important;
        transform: none !important;
        touch-action: none;
    }

    .mobile-footer-controls button:active {
        background: rgba(255, 255, 255, 0.2) !important;
    }

    .mobile-footer-controls .chat-toggle-btn {
        flex: 2;
        border-right: 2px solid var(--text-dim) !important;
        position: relative;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        border-radius: 0 !important;
    }

    .mobile-active-users-badge {
        position: absolute;
        top: -32px;
        left: 10px;
        background: rgba(0, 0, 0, 0.7);
        color: #2ed573;
        padding: 4px 10px;
        border-radius: 12px;
        font-size: 0.8rem;
        font-weight: bold;
        pointer-events: none;
        backdrop-filter: blur(5px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
        border: 1px solid rgba(46, 213, 115, 0.5);
        z-index: 1010;
        white-space: nowrap;
    }

    .mobile-active-users-badge.hidden {
        display: none !important;
    }

    .mobile-footer-controls .chat-icon {
        display: none !important;
    }

    .mobile-footer-controls .chat-label {
        font-size: 0.9rem;
        font-weight: bold;
    }

    .mobile-footer-controls .chat-unread-badge {
        top: 5px;
        right: 8px;
        border: 1px solid var(--bg-dark);
        width: 10px;
        height: 10px;
    }

    .mobile-footer-controls .mobile-zoom-btn,
    .mobile-footer-controls .d-pad-btn.left,
    .mobile-footer-controls .d-pad-btn.right {
        flex: 1;
        border-right: 2px solid var(--text-dim) !important;
    }

    .mobile-footer-controls .d-pad-vertical {
        flex: 1;
        display: flex;
        flex-direction: column;
        height: 100%;
        pointer-events: auto;
    }

    .mobile-footer-controls .d-pad-vertical .d-pad-btn {
        flex: 1;
        height: 50% !important;
        width: 100% !important;
    }

    .mobile-footer-controls .d-pad-vertical .d-pad-btn.up {
        border-bottom: 2px solid var(--text-dim) !important;
    }

    /* Canvas container for transform-based pan/zoom */
    .canvas-container {
        margin: 0;
        /* transform is set by JavaScript for pan/zoom - DO NOT override! */
        width: 2000px;
        height: 2000px;
        display: block;
        overflow: hidden;
        position: absolute;
        top: 0;
        left: 0;
        transform-origin: 0 0;
    }

    #main-canvas,
    .canvas-bg {
        width: 100%;
        height: 100%;
        display: block;
    }

    #thickness-indicator-circle {
        border: 2px solid #fff !important;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.5) !important;
    }

    .replay-controls {
        width: 90%;
        bottom: 20px;
        padding: 12px 20px;
        gap: 10px;
    }
}

/* Landscape Mode Optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        height: 40px;
        padding: 5px 15px;
    }

    .sidebar {
        padding-top: 10px;
    }

    .d-pad-container {
        transform: scale(0.8);
        transform-origin: bottom right;
        bottom: 10px;
        right: 10px;
    }
}

.tool-btn,
.action-btn {
    padding: 8px 10px;
    min-height: 36px;
}

/* Active Board Highlighting */
.board-tab.has-participants {
    border-color: #2ed573;
    background: rgba(46, 213, 115, 0.1);
    box-shadow: 0 0 10px rgba(46, 213, 115, 0.2);
    animation: pulse-border 2s infinite;
}

.popup-close-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 34px;
    height: 34px;
    background: #fff;
    border: 1px solid var(--border);
    color: #333;
    font-size: 1.4rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    z-index: 1010;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.popup-close-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.online-count-highlight {
    color: #2ed573;
    font-weight: bold;
    font-size: 0.8rem;
    /* Larger than normal */
    text-shadow: 0 0 5px rgba(46, 213, 115, 0.5);
}

/* Board List Redesign */
.board-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.board-card {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}

.board-card:hover {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
}

.board-card.active {
    border-color: var(--text);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
}

.board-card.has-participants {
    border-color: #2ed573;
    box-shadow: 0 0 10px rgba(46, 213, 115, 0.15);
}

.board-card.has-participants .board-card-header {
    background: rgba(46, 213, 115, 0.1);
    color: #2ed573;
}

/* Board Cards Horizontal Design */
.board-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    min-width: 280px;
    height: 140px;
    /* matched to horizontal design */
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.board-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.board-card.active {
    border-color: var(--accent);
    background: rgba(255, 71, 87, 0.05);
}

.board-card-content {
    display: flex;
    flex: 1;
    padding: 12px;
}

.board-card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.board-card-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.board-name-label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.board-time-label {
    font-size: 0.65rem;
    color: var(--text-dim);
}

.board-card-stats {
    display: flex;
    gap: 10px;
}

.total-stat {
    display: flex;
    flex-direction: column;
}

.total-label {
    font-size: 0.55rem;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.total-count-val {
    font-size: 0.75rem;
    font-weight: 600;
}

.board-card-online {
    width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-left: 1px solid var(--border);
    margin-left: 10px;
}

.online-box {
    text-align: center;
}

.participation-count {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.participation-label {
    font-size: 0.55rem;
    color: var(--text-dim);
    display: block;
    margin-top: 2px;
}

.board-card.has-participants .participation-count {
    color: #2ed573;
    text-shadow: 0 0 10px rgba(46, 213, 115, 0.3);
}

.decor-bar {
    position: absolute;
    right: 0;
    top: 20%;
    bottom: 20%;
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    opacity: 0.5;
}

.board-card-footer {
    display: flex;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.card-action-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 4px;
    color: var(--text);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
    border-right: 1px solid var(--border);
}

.card-action-btn:last-child {
    border-right: none;
}

.card-action-btn:hover {
    background: var(--glass);
}

.card-action-btn.sign-btn:hover {
    background: rgba(255, 71, 87, 0.2);
    color: #ff4757;
}

.board-card.active .board-card-footer {
    background: rgba(255, 71, 87, 0.1);
}


/* Modal Adjustments */
#unsigned-alert-modal .action-btn {
    width: 100%;
    margin: 0;
}

.replaying {
    background: #ff4757 !important;
    color: white !important;
    animation: replay-pulse 1.5s infinite ease-in-out;
}

@keyframes replay-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Page Footer (Contact) */
#startup-modal:not(.hidden)~.page-footer {
    display: none;
}

.page-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 10000;
    text-align: center;
    width: 100%;
    background: #fff;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}

.footer-link {
    font-size: 0.75rem;
    color: #000;
    text-decoration: none;
    opacity: 1;
    transition: opacity 0.2s;
    font-weight: 600;
}

.footer-link:hover {
    opacity: 0.7;
    color: var(--accent);
}

/* Unified Layout Styles (Global - Mobile V3) */

/* Hide old mobile controls */
.mobile-footer-controls {
    display: none !important;
}

#app-shell {
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

@media (min-width: 769px) {
    #app-shell {
        max-width: 800px;
        /* Widened to 800px for 728px ad and better canvas view */
        margin: 0 auto;
        position: relative;
    }

    .ad-banner.top-ad-pc {
        display: flex;
    }
}

.mobile-nav-v3 {
    position: fixed;
    bottom: 40px;
    left: 0;
    width: 100%;
    height: 60px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 10px;
    z-index: 10100;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.05);
}

@media (min-width: 769px) {
    .mobile-nav-v3 {
        width: 800px;
        left: 50%;
        transform: translateX(-50%);
    }
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.4rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: transform 0.1s, background 0.2s;
    cursor: pointer;
}

.nav-item:active {
    transform: scale(0.9);
    background: rgba(0, 0, 0, 0.05);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(255, 71, 87, 0.15);
}

.mobile-popup {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 400px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    padding: 15px;
    z-index: 10200;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    transition: opacity 0.2s, transform 0.2s;
}

.mobile-popup.hidden {
    display: none;
    opacity: 0;
    transform: translate(-50%, 10px);
}

/* Horizontal Panning Bar Area */
.pan-horizontal-bar {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0;
    z-index: 10050;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100vw;
    touch-action: none;
    height: 24px;
}

@media (min-width: 769px) {
    .pan-horizontal-bar {
        width: 800px;
    }
}

.pan-bar-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: #333;
    font-size: 1rem;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s;
    font-weight: bold;
    border-radius: 0 !important;
    touch-action: none;
}

.pan-bar-btn:last-child {
    border-right: none;
    font-size: 1rem;
}

.pan-bar-btn:hover {
    background: #f0f0f0;
}

.pan-bar-btn:active {
    background: #e0e0e0;
}

/* Specific styling for the embedded chat button to override bubble look */
.chat-toggle-btn.pan-bar-btn {
    position: static !important;
    bottom: auto !important;
    right: auto !important;
    height: 24px !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #333 !important;
    font-size: 0.85rem !important;
    font-weight: bold !important;
    box-shadow: none !important;
    width: 100% !important;
    margin: 0 !important;
    transform: none !important;
}

.chat-toggle-btn.pan-bar-btn:hover {
    background: #f0f0f0 !important;
    transform: none !important;
}


.page-footer {
    position: fixed !important;
    bottom: 0 !important;
    left: 0;
    width: 100%;
    height: 40px;
    background: #fff;
    color: #333;
    padding: 5px 10px !important;
    text-align: center;
    z-index: 10101;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-top: 1px solid var(--border);
}

@media (min-width: 769px) {
    .page-footer {
        width: 800px;
        left: 50%;
        transform: translateX(-50%);
    }
}

.header-board-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto 10px auto;
    /* 広告との間に余白を追加 */
}

/* PC Header Board Buttons */
.header-board-grid .board-select-btn {
    padding: 2px 4px;
    /* 上下パディングを極小に */
    height: 24px;
    /* 高さを従来の約半分（24px程度）に固定 */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    aspect-ratio: auto;
    /* 正方形の強制を解除して高さを自然に */
}

/* Hover effect */
.header-board-grid .board-select-btn:hover {
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* State: Active Board (Currently viewing) - Dark/Solid Red */
.header-board-grid .board-select-btn.btn-danger {
    background: #ff4d4d;
    color: white;
    border-color: #ff4d4d;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.2);
}

/* State: Has Participants (but not active) - Light/Glowing Red */
.header-board-grid .board-select-btn.btn-outline-danger {
    background: rgba(255, 77, 77, 0.1);
    color: #ff4d4d;
    border-color: rgba(255, 77, 77, 0.5);
    box-shadow: 0 0 8px rgba(255, 77, 77, 0.3);
}

/* State: Empty (and not active) - Default Light */
.header-board-grid .board-select-btn.btn-light {
    background: var(--bg-secondary);
    color: var(--text-dim);
    border-color: var(--border);
}

.board-select-btn {
    aspect-ratio: 1;
    min-width: 32px;
    /* Prevent squashing on PC */
    min-height: 32px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.board-select-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.board-select-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* reCAPTCHA Attribution */
.grecaptcha-badge {
    visibility: hidden;
}

.recaptcha-attribution {
    font-size: 0.7rem;
    color: #666;
    margin-top: 5px;
    opacity: 0.8;
}

.recaptcha-attribution a {
    color: #000;
    text-decoration: underline;
}

.recaptcha-attribution a:hover {
    color: var(--accent);
}

/* Unified Header V3 */
.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 5px;
    font-weight: bold;
    color: var(--text);
    font-size: 1rem;
    border-bottom: 2px solid var(--border);
    margin-bottom: 5px;
}

.header-top-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-aux-actions {
    display: flex;
    gap: 6px;
}

.header-mini-btn {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: all 0.2s;
    white-space: nowrap;
}

.header-mini-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

#header-board-name {
    font-size: 1.1rem;
    white-space: nowrap;
}

#header-participation {
    font-size: 0.85rem;
    opacity: 0.8;
    white-space: nowrap;
}

/* Unified Popups V3 */
.mobile-popup {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 400px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    z-index: 10200;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
    overflow: visible;
    /* Allow close button to overlap on corner */
}

.mobile-popup:not(.hidden) {
    display: block;
}

.popup-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.popup-grid-colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    justify-items: center;
    width: 100%;
}

.mobile-color-picker-wrapper {
    grid-column: span 4;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: 5px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.mobile-color-picker-wrapper #mobile-color-picker {
    width: 44px;
    height: 44px;
    border: none;
    background: none;
    cursor: pointer;
}

.color-picker-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.popup-grid-colors .color-swatch {
    width: 100% !important;
    max-width: 60px;
    height: auto !important;
    aspect-ratio: 1;
}

.mobile-opt {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.9rem;
    width: 100%;
    cursor: pointer;
}

.popup-slider-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0;
}

.slider-val {
    text-align: center;
    font-weight: bold;
    color: var(--accent);
    font-size: 1.1rem;
}

#mobile-width-slider {
    width: 100%;
    accent-color: var(--accent);
}

.thickness-preview-wrap {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 5px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 50%;
    border: 1px solid var(--border);
    width: 80px;
    margin: 5px auto;
}

#mobile-thickness-preview-circle {
    border-radius: 50% !important;
}

.popup-zoom-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.zoom-act {
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    color: var(--text);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.share-opt {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    color: var(--text);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
}

/* Replay Controls Refinement */
.replay-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 700px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    padding: 15px 25px;
    border-radius: 16px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    z-index: 10200;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}

.replay-seek {
    flex: 1;
    min-width: 220px;
    display: flex;
    flex-direction: column;
}

.replay-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

.replay-btns button {
    padding: 8px 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--glass);
    cursor: pointer;
    font-weight: bold;
}

.replay-seek input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* Color Hex/RGB Input */
.color-hex-input {
    flex: 1;
    min-width: 0;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
    color: var(--text);
    font-family: 'Inter', monospace;
    font-size: 0.75rem;
    outline: none;
    transition: border-color 0.2s;
}

.color-hex-input::placeholder {
    color: var(--text-dim);
    opacity: 0.5;
    font-size: 0.65rem;
}

.color-hex-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 71, 87, 0.15);
}

.color-hex-preview {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background-color: #000000;
    flex-shrink: 0;
}

.mobile-color-hex-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    grid-column: 1 / -1;
    padding: 4px 0;
}