/*
 * LightPen Web
 * Copyright (c) 2026 Sketlab LLC.
 * Released under the MIT license
 * https://opensource.org/licenses/mit-license.php
 */

* {
    box-sizing: border-box;
    user-select: none;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000000;
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000000;
}

#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000000;
}

#video-element {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    z-index: 1;
    pointer-events: none;
}

#paint-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    touch-action: none;
    cursor: crosshair;
}

/* ==========================================
   ライセンス用ウォーターマーク（透かし）
   ========================================== */
.watermark-logo {
    position: absolute;
    top: 25px;
    left: 25px;
    z-index: 5;
    pointer-events: none;
    display: none;
}

.watermark-logo img {
    width: 80px;
    height: auto;
    opacity: 0.6;
    filter: drop-shadow(0px 2px 4px rgba(0,0,0,0.5));
}

.watermark-text {
    position: absolute;
    bottom: 20px;
    right: 25px;
    z-index: 5;
    pointer-events: none;
    display: none;
    color: rgba(255, 255, 255, 0.45);
    font-size: 24px;
    font-family: Arial, sans-serif;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

/* ==========================================
   メニューバー
   ========================================== */
#ui-toolbar {
    position: absolute;
    z-index: 10;
    background: rgba(25, 25, 25, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transition: transform 0.35s cubic-bezier(0.1, 0.9, 0.2, 1);
    
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 16px;
    border-radius: 30px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* 上部バー非表示時（ツマミを残して画面外へスライド） */
#ui-toolbar.hidden {
    transform: translate(-50%, calc(-100% - 15px));
}

/* 右側縦型モード（デフォルト） */
#ui-toolbar.pos-right {
    top: 50%;
    right: 15px;
    left: auto;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 14px 8px;
    border-radius: 25px;
    gap: 12px;
}
/* 右側バー非表示時（浮いている15px分も合わせて完全に画面外へ隠す） */
#ui-toolbar.pos-right.hidden {
    transform: translate(calc(100% + 15px), -50%);
}

#ui-toolbar.pos-right #toolbar-trigger {
    top: 50%;
    left: -40px; 
    transform: translateY(-50%);
    width: 40px;
    height: 80px;
    border-radius: 12px 0 0 12px;
    border-right: none;
    font-size: 16px;

    /* 👇【追加】スマホ特有の「0.3秒のタップ遅延」を強制的に解除する */
    touch-action: manipulation; 
}

/* 👇【追加】擬似要素を使って、見た目はそのままに「透明なタップ判定領域」を上下左右に広げる */
#ui-toolbar #toolbar-trigger::before {
    content: "";
    position: absolute;
    top: -20px;    /* 上に20px判定を広げる */
    left: -20px;   /* 左に20px判定を広げる */
    right: -20px;  /* 右に20px判定を広げる */
    bottom: -20px; /* 下に20px判定を広げる */
}

/* ==========================================
   スマホ用 メニュー引き出しツマミ（サイズを押しやすく拡大）
   ========================================== */
#toolbar-trigger {
    position: absolute;
    background: rgba(25, 25, 25, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    z-index: 11;
    box-shadow: -2px 0 10px rgba(0,0,0,0.3);
}
#toolbar-trigger:hover {
    color: #ffffff;
    background: rgba(40, 40, 40, 0.95);
}

/* 右側配置のときのツマミ（横幅を22px → 40px、高さも大きくして超タップしやすく） */
#ui-toolbar.pos-right #toolbar-trigger {
    top: 50%;
    left: -40px; 
    transform: translateY(-50%);
    width: 40px;
    height: 80px;
    border-radius: 12px 0 0 12px;
    border-right: none;
    font-size: 16px;
}
#ui-toolbar.pos-right.hidden #toolbar-trigger::after { content: "◀"; }
#ui-toolbar.pos-right:not(.hidden) #toolbar-trigger::after { content: "▶"; }

/* 上部配置のときのツマミ（こちらも同様に拡大） */
#ui-toolbar:not(.pos-right) #toolbar-trigger {
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 40px;
    border-radius: 0 0 12px 12px;
    border-top: none;
    font-size: 16px;
}
#ui-toolbar:not(.pos-right).hidden #toolbar-trigger::after { content: "▼"; }
#ui-toolbar:not(.pos-right):not(.hidden) #toolbar-trigger::after { content: "▲"; }


/* ガイドスイッチ */
.guide-container {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
    border-right: 1px solid rgba(255,255,255,0.2);
    padding-right: 12px;
    margin-right: 4px;
    height: 28px;
}
.guide-container input { cursor: pointer; margin: 0; }

#ui-toolbar.pos-right .guide-container {
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-right: 0;
    padding-bottom: 8px;
    margin-right: 0;
    margin-bottom: 4px;
    width: 100%;
    height: auto;
}

/* ボタン基本 */
.btn {
    position: relative;
    background: none;
    border: none;
    padding: 0;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, filter 0.2s;
}
.btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    transition: box-shadow 0.2s;
}
.btn:hover { filter: brightness(1.2); }
.btn:active { transform: scale(0.92); }
.btn.active img {
    box-shadow: 0 0 12px #007bff, 0 0 4px #007bff;
    outline: 2px solid rgba(0, 123, 255, 0.6);
}

/* ツールチップ（上部用） */
.btn::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.88);
    color: #ffffff;
    padding: 5px 9px;
    border-radius: 5px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
}
#ui-toolbar.guide-mode .btn:hover::after { opacity: 1; }

/* ツールチップ（右側用） */
#ui-toolbar.pos-right .btn::after {
    top: 50%;
    right: 52px;
    left: auto;
    transform: translateY(-50%);
}

/* カラーピッカー */
.color-picker {
    display: grid;
    grid-template-rows: repeat(2, 1fr);
    grid-auto-flow: column;
    gap: 6px;
    border-left: 1px solid rgba(255,255,255,0.15);
    border-right: 1px solid rgba(255,255,255,0.15);
    padding: 0 12px;
    align-items: center;
}
#ui-toolbar.pos-right .color-picker {
    grid-template-rows: none;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-flow: row;
    border-left: none;
    border-right: none;
    border-top: 1px solid rgba(255,255,255,0.15);
    border-bottom: 1px solid rgba(255,255,255,0.15);
    padding: 10px 0;
}
.color-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}
.color-dot.active {
    border-color: #ffffff;
    transform: scale(1.25);
    box-shadow: 0 0 8px rgba(255,255,255,0.8);
}

/* 線幅選択 */
.width-container {
    display: flex;
    flex-direction: row;
    gap: 4px;
    border-right: 1px solid rgba(255,255,255,0.15);
    padding-right: 10px;
}
#ui-toolbar.pos-right .width-container {
    flex-direction: column;
    border-right: none;
    padding-right: 0;
    gap: 6px;
}
.btn-text {
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.btn-text.active {
    background: #007bff;
    color: white;
    font-weight: bold;
}

/* モーダル */
#source-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}
#source-modal.hidden { display: none; }
.modal-content {
    background: #1e1e1e;
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    border: 1px solid #333;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}
.modal-content h3 { color: white; margin-top: 0; margin-bottom: 20px; }
.modal-grid { display: flex; flex-direction: column; gap: 10px; }
.modal-select {
    background: #222;
    color: #ffffff;
    border: 1px solid #444;
    padding: 11px;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
}
.modal-btn {
    background: #2d2d2d;
    color: white;
    border: 1px solid #444;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.2s;
}
.modal-btn:hover { background: #3d3d3d; }

#video-file-input { display: none; }

/* ==========================================
   URL背景（iframe）用のスタイル
   ========================================== */
#url-bg-element {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    z-index: 1;
    background: #000;
    display: none; /* 👈 初期状態は非表示にしておく */
}

/* 物体追従ボタンが利用できない背景ソースでのロック表示 */
#btn-mode-tracking:disabled,
#btn-mode-tracking.disabled {
    opacity: 0.25 !important;           /* 強制的にしっかりと半透明にする */
    pointer-events: none !important;    /* タップやクリック操作をシステムレベルで完全拒否 */
    cursor: not-allowed !important;     /* 禁止マークのカーソルにする（PC用） */
    filter: grayscale(100%) !important; /* アイコンの色味を完全に白黒にして無効感を出す */
}

#btn-mode-tracking:disabled img,
#btn-mode-tracking.disabled img {
    box-shadow: none !important;
    outline: none !important;
}
