:root {
    --bg-color: #ffffff;
    --text-color: #121212;
    --header-bg: #f8f8f8;
    --border-color: #e0e0e0;
    --input-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #121212;
        --text-color: #ffffff;
        --header-bg: #1f1f1f;
        --border-color: #333333;
        --input-bg: #2a2a2a;
    }
}

body { font-family: sans-serif; background: var(--bg-color); color: var(--text-color); margin: 0; overflow-x: hidden; }

header { 
    padding: 10px 15px; 
    background: var(--header-bg); 
    border-bottom: 1px solid var(--border-color); 
    position: sticky; 
    top: 0; 
    z-index: 10; 
}

.header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
h1 { margin: 0; font-size: 20px; color: #ff0000; }

.menu-container { position: relative; }
.icon-btn { background: none; border: none; font-size: 24px; color: var(--text-color); cursor: pointer; padding: 5px; }

#side-menu {
    position: absolute; right: 0; top: 40px; background: var(--header-bg);
    border: 1px solid var(--border-color); border-radius: 8px; padding: 12px;
    width: 220px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); display: flex; flex-direction: column; gap: 8px;
    z-index: 20;
}
.hidden { display: none !important; }
.menu-divider { border-top: 1px solid var(--border-color); margin: 5px 0; }
#side-menu button { 
    background: none; border: 1px solid var(--border-color); color: var(--text-color); 
    padding: 8px; text-align: left; border-radius: 4px; font-size: 14px; cursor: pointer;
}

.usage-info { font-size: 12px; color: var(--text-color); opacity: 0.9; line-height: 1.4; }
.usage-title { font-weight: bold; margin: 0 0 5px 0; font-size: 13px; color: #ff0000; }
.usage-info ul { margin: 0; padding-left: 18px; }
.usage-info li { margin-bottom: 4px; }

.toggle-item { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; padding: 4px 0; }

.input-area { display: flex; gap: 8px; }
input[type="text"] { 
    flex: 1; padding: 8px 12px; border-radius: 4px; border: 1px solid var(--border-color); 
    background: var(--input-bg); color: var(--text-color); font-size: 14px; 
}
#add-btn { background: #ff0000; color: #fff; border: none; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-weight: bold; }

#thumbnail-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
    gap: 10px; 
    padding: 10px; 
}
.thumb-item { position: relative; border-radius: 6px; overflow: hidden; background: #000; cursor: pointer; }
.thumb-item img { width: 100%; display: block; transition: opacity 0.2s; }

.delete-btn {
    position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.5);
    color: #fff; border: none; border-radius: 2px; width: 20px; height: 20px;
    font-size: 14px; line-height: 1; cursor: pointer; padding: 0; z-index: 5;
}

.modal { display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100vw; height: 100vh; background: #000; }
.modal-content { 
    width: 100vw; height: 100vh; display: flex; flex-direction: column; 
    justify-content: center; align-items: center; position: relative;
}

.hide-cursor { cursor: none !important; }

#player-container {
    position: relative;
    width: 100vw;
    height: calc(100vw * 9 / 16);
    max-height: 100vh;
    max-width: calc(100vh * 16 / 9);
}

@media (min-aspect-ratio: 16/9) {
    #player-container { height: 100vh; width: calc(100vh * 16 / 9); }
}

#player { width: 100%; height: 100%; border: none; }

#status-indicator {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 18px;
    font-weight: bold;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 120;
}
#status-indicator.show { opacity: 1; }

#touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100% - 60px); 
    z-index: 2147483647;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 24px;
    display: none;
    z-index: 2147483647;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* スマホ（幅480px以下）のときだけ閉じるボタンを表示 */
@media (max-width: 480px) {
    .close-btn { display: flex; }
    h1 { font-size: 18px; }
    #thumbnail-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
    #side-menu { width: 200px; }
}

/* 全画面時のレイアウト調整 */
:fullscreen #player-container,
:-webkit-full-screen #player-container {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
}

@media (max-width: 480px) {
    h1 { font-size: 18px; }
    #thumbnail-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
    #side-menu { width: 200px; }
}