/*
 * 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), opacity 0.3s;
    
    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%, -130%);
    opacity: 0;
}

/* 右側縦型モード（デフォルト） */
#ui-toolbar.pos-right {
    top: 50%;
    right: 15px;
    left: auto;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 14px 8px;
    border-radius: 25px;
    gap: 12px;
}
#ui-toolbar.pos-right.hidden {
    transform: translate(130%, -50%);
    opacity: 0;
}

/* ガイドスイッチ */
.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%);
}

/* ==========================================
   カラーピッカー（Gridレイアウトによる2列化）
   ========================================== */
.color-picker {
    display: grid;
    grid-template-rows: repeat(2, 1fr);
    grid-auto-flow: column; /* 上部バーの時は横4列×縦2行 */
    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; /* 右側バーの時は横2列×縦4行 */
    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-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; }