/* ============================================================
   リセット・基本
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
	--accent     : #81c31f;
	--ctrl-bg    : rgba(0, 0, 0, 0.0);
	--grad-top   : linear-gradient(to bottom, rgba(0,0,0,0.75) 0%, transparent 100%);
	--grad-bottom: linear-gradient(to top,   rgba(0,0,0,0.85) 0%, transparent 100%);
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

html, body {
	width: 100%; height: 100%;
	background: #000;
	overflow: hidden;
	font-family: "Hiragino Kaku Gothic ProN","Hiragino Sans","Helvetica Neue",Helvetica,Arial,メイリオ,"Meiryo UI",sans-serif;
	color: #fff;
	-webkit-user-select: none;
	user-select: none;
}

/* ============================================================
   プレイヤーラッパー
   ============================================================ */
#player-wrap {
	position: relative;
	width: 100%;
	height: 100%;
	background: #000;
	overflow: hidden;
}

#video {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
	cursor: pointer;
}

/* ============================================================
   コントロールオーバーレイ全体
   ============================================================ */
#controls {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	opacity: 0;
	transition: opacity 0.3s ease;
	pointer-events: none;
	z-index: 1;
}
/* iOS Safari は再生中/メタ取得後の <video> を独自の合成レイヤーにして
   z-index 順を無視して前面に描画する。コントロール表示時も translateZ(0) で
   自前の合成レイヤーに昇格させ、動画レイヤーより前面に出す。 */
#controls.visible {
	opacity: 1;
	z-index: 3;
	transform: translateZ(0);
	-webkit-transform: translateZ(0);
}
#controls.visible .ctrl-interactive { pointer-events: auto; }

/* SPでは背景全体フェード */
@media (hover: none), (pointer: coarse) {
	#controls{
		position: absolute;
		inset: 0;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		opacity: 0;
		transition: opacity 0.3s ease;
		pointer-events: none;
		background-color: rgba(0,0,0,0.65);
	}
}

/* ============================================================
   上部バー (戻るボタン + タイトル)
   ============================================================ */
#ctrl-top {
	background: var(--grad-top);
	padding: 12px 16px 32px;
	display: flex;
	align-items: center;
	gap: 10px;
	z-index: 4;
}

#btn-back {
	background: none; border: none; color: #fff;
	cursor: pointer; padding: 4px; flex-shrink: 0;
	display: flex; align-items: center;
}
#btn-back:hover { opacity: 0.75; }

#ctrl-title {
	font-size: 14px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	flex: 1;
}

/* ============================================================
   SP タップゾーン（左右スキップ）
   ============================================================ */
.tap-zone {
	position: absolute;
	top: 0; bottom: 0;
	width: 35%;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: auto;  /* 常に有効 */
}
#tap-left  { left: 0;  border-radius: 0 50% 50% 0; }
#tap-right { right: 0; border-radius: 50% 0 0 50%; }

.skip-ripple {
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 72px; height: 72px;
	background: rgba(255,255,255,0.18);
	border-radius: 50%;
	font-size: 11px;
	gap: 2px;
	animation: ripple-fade 0.7s ease forwards;
}
.skip-ripple.show { display: flex; }

@keyframes ripple-fade {
	0%   { opacity: 1; transform: scale(0.8); }
	60%  { opacity: 1; transform: scale(1.0); }
	100% { opacity: 0; transform: scale(1.1); }
}

/* PCではタップゾーン非表示 */
@media (hover: hover) and (pointer: fine) {
	.tap-zone { display: none; }
}

/* ============================================================
   中央の大きな再生ボタン
   ============================================================ */
#center-play {
	position: absolute;
	top: 50%; left: 50%;
	transform: translate(-50%, -50%);
	background: rgba(0,0,0,0.45);
	border: 2px solid rgba(255,255,255,0.8);
	border-radius: 50%;
	width: 68px; height: 68px;
	display: flex; align-items: center; justify-content: center;
	cursor: pointer;
	transition: opacity 0.25s, transform 0.15s;
	pointer-events: auto;
	z-index: 1;
}
#center-play:hover { transform: translate(-50%, -50%) scale(1.08); }
#center-play.hide  { opacity: 0; pointer-events: none; }

/* ============================================================
   カウントダウン（次の動画へ）
   ============================================================ */
#countdown-wrap {
	position: absolute;
	bottom: 110px;
	left: 50%;
	transform: translateX(-50%);
	display: none;
	align-items: center;
	gap: 8px;
	font-size: 14px;
	background: rgba(0,0,0,0.55);
	border-radius: 20px;
	padding: 6px 14px 6px 8px;
	pointer-events: none;
	white-space: nowrap;
}
#countdown-wrap.show { display: flex; }

#countdown-svg { width: 22px; height: 22px; }
#countdown-circle {
	fill: none; stroke: var(--accent);
	stroke-width: 4;
	stroke-linecap: round;
	stroke-dasharray: 100 100;
	transform-origin: 50% 50%;
	transform: rotate(-90deg);
	transition: stroke-dasharray 0.9s linear;
}
#countdown-circle-bg { fill: none; stroke: #555; stroke-width: 4; }

/* ============================================================
   下部コントロール
   ============================================================ */
#ctrl-bottom {
	background: var(--grad-bottom);
	padding: 32px 12px 12px;
	z-index: 4;
}

/* --- チャプター行 --- */
#chapter-row {
	position: relative;
	margin-bottom: 20px;
}
#chapter-btn {
	display: none;
	align-items: center;
	gap: 6px;
	cursor: pointer;
	font-size: 13px;
	max-width: calc(100% - 140px);
	padding: 2px 0;
}
#chapter-btn.visible { display: flex; }
#chapter-disp {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

#chapter-menu {
	position: absolute;
	bottom: calc(100% + 4px);
	left: 0;
	background: rgba(28,28,28,0.97);
	border-radius: 10px;
	overflow-y: auto;
	max-height: 220px;
	min-width: 200px;
	max-width: min(340px, calc(100vw - 24px));
	display: none;
	z-index: 20;
}
#chapter-menu.open { display: block; }
#chapter-menu table { width: 100%; border-collapse: collapse; }
#chapter-menu td {
	padding: 10px 16px;
	cursor: pointer;
	font-size: 13px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	border-bottom: 1px solid rgba(255,255,255,0.06);
}
#chapter-menu td:hover { background: rgba(255,255,255,0.1); }
#chapter-menu tr.active td { color: var(--accent); font-weight: bold; }
#chapter-menu tr:last-child td { border-bottom: none; }

/* --- プログレスバー行 --- */
#progress-row {
	position: relative;
	display: flex;
	align-items: center;
	gap: 10px;
	bottom: 10px;
}

#progress-bar {
	-webkit-appearance: none;
	appearance: none;
	flex: 1;
	height: 4px;
	border-radius: 2px;
	background: rgba(255,255,255,0.3);
	cursor: pointer;
	outline: none;
}
#progress-bar::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 14px; height: 14px;
	border-radius: 50%;
	background: var(--accent);
	cursor: pointer;
}
#progress-bar::-moz-range-thumb {
	width: 14px; height: 14px;
	border-radius: 50%;
	background: var(--accent);
	border: none;
	cursor: pointer;
}

/* プログレスバーの塗り（--progress-pct はJSで更新） */
#progress-bar {
	background: linear-gradient(
		to right,
		var(--accent) 0%,
		var(--accent) var(--progress-pct, 0%),
		rgba(255,255,255,0.3) var(--progress-pct, 0%),
		rgba(255,255,255,0.3) 100%
	);
}

#time-display {
	position: relative;
	display: flex;
	font-size: 12px;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

/* --- ボタン行 --- */
#btn-row {
	display: flex;
	align-items: center;
	gap: 4px;
}

.ctrl-btn {
	background: none; border: none; color: #fff;
	cursor: pointer; padding: 6px;
	display: flex; align-items: center; justify-content: center;
	flex-shrink: 0;
	border-radius: 4px;
	transition: opacity 0.2s, background 0.15s;
}
.ctrl-btn:hover   { background: rgba(255,255,255,0.1); }
.ctrl-btn:active  { background: rgba(255,255,255,0.2); }
.ctrl-btn.dim     { opacity: 0.35; pointer-events: none; }
.ctrl-btn svg     { display: block; }

.flex-spacer { flex: 1; min-width: 0; }

.ctrl-select {
	background: rgba(0,0,0,0.55);
	border: 1px solid rgba(255,255,255,0.35);
	border-radius: 5px;
	color: #fff;
	font-size: 12px;
	padding: 4px 6px;
	cursor: pointer;
	flex-shrink: 0;
}
.ctrl-select option { background: #1c1c1c; color: #fff; }

/* ============================================================
   PC / SP 表示切替
   ・デフォルト（SP基準）: .pc-only を非表示
   ・PCマウス環境:        .sp-only を非表示
   ============================================================ */
@media (hover: none), (pointer: coarse) {
	/* SP: PCのみ要素を隠す */
	.pc-only { display: none !important; }
}
@media (hover: hover) and (pointer: fine) {
	/* PC: SPのみ要素を隠す */
	.sp-only { display: none !important; }
}




/* ============================================================
   SP専用 中央コントロール（タイトル＋前話/再生/次話）
   ============================================================ */
@media (hover: none), (pointer: coarse) {
	/* PC用中央再生ボタンはSPで非表示 */
	#center-play { display: none; }
}

#ctrl-center-sp {
	position: relative;
    top: auto;
    left: auto;
    transform: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0 24px;
}

#title-sp {
	font-size: 15px;
	font-weight: bold;
	text-align: center;
	line-height: 1.55;
	text-shadow: 0 1px 5px rgba(0,0,0,0.85);
	word-break: break-all;
	max-width: 90%;
	margin-bottom: 100px;
}

#play-row-sp {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 36px;
	margin-bottom: 100px;
}

.btn-ep-sp {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 5px;
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	font-size: 12px;
	opacity: 1;
	transition: opacity 0.2s;
	padding: 0;
}
.btn-ep-sp.dim    { opacity: 0.35; pointer-events: none; }
.btn-ep-sp:active { opacity: 0.6; }

#btn-play-sp {
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	width: 62px; height: 62px;
	display: flex; align-items: center; justify-content: center;
	border-radius: 50%;
	padding: 0;
	margin-left: 30px;
	margin-right: 30px;
}
#btn-play-sp:active { opacity: 0.7; }

/* SP用 時間表示（#btn-row 内） */
#time-sp {
	font-size: 12px;
	white-space: nowrap;
	flex-shrink: 0;
	font-variant-numeric: tabular-nums;
}

/* ============================================================
   SP 横向き（landscape）レイアウト調整
   ============================================================ */
@media (hover: none) and (orientation: landscape),
       (pointer: coarse) and (orientation: landscape) {

    /* 下部コントロールの上パディングを縮小 */
    #ctrl-bottom {
        padding: 8px 12px 8px;
    }

    /* タイトルの下マージンを縮小 */
    #title-sp {
        margin-bottom: 16px;
        font-size: 13px;
    }

    /* 再生ボタン行の下マージンを縮小 */
    #play-row-sp {
        margin-bottom: 16px;
        gap: 20px;
    }

    /* 再生ボタンを小さく */
    #btn-play-sp {
        width: 44px;
        height: 44px;
    }
    #btn-play-sp svg {
        width: 40px;
        height: 40px;
    }

    /* 前話/次話ボタンの SVG を小さく */
    .btn-ep-sp svg {
        width: 24px;
        height: 28px;
    }

    /* chapter行の下マージンも縮小 */
    #chapter-row {
        margin-bottom: 20px;
    }
}


/* ============================================================
   PC専用 音量ホバーバー
   ============================================================ */
#volume-wrap {
	position: relative;
	display: flex;
	align-items: center;
	flex-shrink: 0;
}

#volume-popup {
	position: absolute;
	bottom: calc(100% + 8px);
	left: 50%;
	transform: translateX(-50%);
	background: rgba(28,28,28,0.96);
	border-radius: 8px;
	padding: 8px 5px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	opacity: 0;
	visibility: hidden;
	/* ホバー離脱後 1.2秒待ってからフェードアウト */
	transition: opacity 0.35s 1.2s, visibility 0s 1.55s;
	z-index: 25;
	pointer-events: none;
}

#volume-wrap.show-volume #volume-popup,
#volume-popup.active {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition: opacity 0.15s, visibility 0s;
}

#volume-popup.pinned {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

#volume-label {
	font-size: 11px;
	color: rgba(255,255,255,0.7);
	font-variant-numeric: tabular-nums;
	min-width: 28px;
	text-align: center;
}

/* 音量スライダー */
#volume-slider {
    position: relative;
    -webkit-appearance: none;
    appearance: none;
    writing-mode: vertical-lr;
    direction: rtl;
    width: 5px;
    height: 80px;
    cursor: pointer;
    outline: none;
    border-radius: 2px;
    /* トラックの塗りは JS で --volume-pct を更新して反映する */
    background: linear-gradient(
        to top,
        var(--accent) var(--volume-pct, 100%),
        rgba(255,255,255,0.25) var(--volume-pct, 100%)
    );
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

#volume-slider::-moz-range-track {
    width: 5px;
    background: rgba(255,255,255,0.25);
    border-radius: 2px;
}

#volume-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* Firefox: トラック塗り */
#volume-slider::-moz-range-progress {
    background: var(--accent);
    border-radius: 2px;
}

/* 透明な当たり判定レイヤー */
#volume-slider::before {
	content: "";
	position: absolute;
	left: -15px;
	right: -15px;
	top: -15px;
	bottom: -15px;
}

/* --- 字幕パネル --- */
#subtitle-panel {
	position: absolute;
	bottom: calc(100% + 4px);
	left: -70px;
	background: rgba(28,28,28,0.97);
	border-radius: 10px;
	min-width: 140px;
	display: none;
	z-index: 20;
}
#subtitle-panel.open { display: block; }
#subtitle-panel table { width: 100%; border-collapse: collapse; }
#subtitle-panel td {
	padding: 10px 12px;
	cursor: pointer;
	font-size: 13px;
	border-bottom: 1px solid rgba(255,255,255,0.06);
}
#subtitle-panel td:hover { background: rgba(255,255,255,0.1); }
#subtitle-panel tr.active td { color: var(--accent); }
#subtitle-panel tr:last-child td { border-bottom: none; }
.sub-check { width: 22px; text-align: center; font-size: 11px; }

#btn-subtitle { display: none; }
#btn-subtitle.visible { display: flex; }

/* ============================================================
   字幕スタイル
   ============================================================ */
video::cue {
    position: relative;
    font-size: 16px !important;
	background: rgba(0, 0, 0, 0.8);
	color: white;
	border-radius: 4px !important;
	white-space: pre-line !important;
    padding: 0px 10px;
    bottom: 15%;
}

/* .text-track {
    font-size: 16px !important;
	line-height: 1.3 !important;
	color: white;
	background: rgba(0, 0, 0, 0.8);
	border-radius: 4px !important;
} */

/* ============================================================
   エラーオーバーレイ
   ============================================================ */
#error-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.82);
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 50;
	pointer-events: auto;
}
#error-overlay.show { display: flex; }

#error-box {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 14px;
	padding: 32px 28px;
	max-width: 320px;
	text-align: center;
}
#error-msg {
	font-size: 14px;
	line-height: 1.7;
	color: rgba(255, 255, 255, 0.9);
	white-space: pre-line;
}
#error-box button {
	background: var(--accent);
	border: none;
	border-radius: 6px;
	color: #fff;
	cursor: pointer;
	font-size: 14px;
	padding: 10px 28px;
	margin-top: 4px;
}
#error-box button:active { opacity: 0.78; }

/* ============================================================
   ローディングオーバーレイ
   ============================================================ */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    align-items: center;
    justify-content: center;
    z-index: 49;
    pointer-events: auto;
    display: none;
}
#loading-overlay.show { display: flex; }

#loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

#loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: loading-spin 0.9s linear infinite;
}

@keyframes loading-spin {
    to { transform: rotate(360deg); }
}

#loading-msg {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.04em;
}

/* エラーサブメッセージ（DRMエラー時の補足説明） */
#error-sub {
    font-size: 12px;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.55);
    white-space: pre-line;
    margin-top: -6px;
}

/* ============================================================
   モーダルシート
   ============================================================ */
#backscreen {
	position: fixed; inset: 0;
	background: rgba(0,0,0,0.6);
	-webkit-backdrop-filter: blur(3px);
	backdrop-filter: blur(3px);
	visibility: hidden; opacity: 0;
	transition: visibility 0s 0.2s, opacity 0.2s;
	z-index: 99;
	cursor: pointer;
}
#backscreen.on {
	visibility: visible; opacity: 1;
	transition: visibility 0s, opacity 0.2s;
}

#sheet-itemnavi {
	position: fixed;
	bottom: 0; left: 0; right: 0;
	background: #fff;
	border-radius: 16px 16px 0 0;
	max-height: 0;
	overflow: hidden;
	transition: max-height 0.3s ease;
	z-index: 100;
	visibility: hidden;
}
#sheet-itemnavi.on { max-height: 80vh; visibility: visible;}

.sheet-inner {
	display: flex;
	flex-direction: column;
	max-height: 80vh;
}
.sheet-header {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	padding: 12px 16px;
	border-bottom: 1px solid #eee;
	flex-shrink: 0;
}
.sheet-close {
	background: none; border: none;
	font-size: 20px; color: #555;
	cursor: pointer; padding: 4px 8px;
	line-height: 1;
}
.sheet-content { flex: 1; overflow-y: auto; }
#item-navi { width: 100%; border: none; display: block; }

@media screen and (min-width: 600px) {
	#sheet-itemnavi {
		bottom: auto; top: 50%; left: 50%;
		width: 86%; max-width: 700px;
		transform: translate(-50%, -50%);
		border-radius: 24px;
		height: 80%;
		max-height: 560px;
		transition: opacity 0.2s;
		opacity: 0;
		visibility: hidden;
	}
	#sheet-itemnavi.on { max-height: 560px; opacity: 1; visibility: visible;}
	.sheet-inner { max-height: 560px; }
}

/* ============================================================
   オーディオブックモード
   ============================================================ */
body.audio-mode #video { visibility: hidden; }
body.audio-mode #player-wrap {
	background-size: contain;
	background-position: center;
	background-repeat: no-repeat;
}

/* ============================================================
   設定パネル
   ============================================================ */
#settings-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

#settings-panel {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background: rgba(22, 22, 22, 0.98);
    border-radius: 10px;
    width: 240px;
    overflow: hidden;
    display: none;
    z-index: 20;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}
#settings-panel.open { display: block; }

#setting-page {
	z-index: 22;
}

/* スライドコンテナ */
#settings-pages-container {
    /* 各ページは display:none / block で切り替え */
}

/* メインメニュー行 */
.settings-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 14px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    transition: background 0.15s;
    color: #fff;
	z-index: 21;
}
.settings-menu-item:hover  { background: rgba(255,255,255,0.08); }
.settings-menu-item:active { background: rgba(255,255,255,0.14); }
.settings-menu-item:last-child { border-bottom: none; }

.settings-menu-label-title {
    font-size: 13px;
    color: #fff;
}

.settings-menu-value {
    display: flex;
    align-items: center;
    gap: 2px;
    color: rgba(255,255,255,0.55);
    font-size: 12px;
}

/* サブページヘッダー（戻るボタン） */
.settings-subpage-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 11px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    transition: background 0.15s;
}
.settings-subpage-header:hover  { background: rgba(255,255,255,0.08); }
.settings-subpage-header:active { background: rgba(255,255,255,0.14); }

/* 選択肢行 */
.settings-option {
    display: flex;
    align-items: center;
    padding: 11px 14px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 10px;
    color: #fff;
    transition: background 0.15s;
}
.settings-option:hover  { background: rgba(255,255,255,0.08); }
.settings-option:active { background: rgba(255,255,255,0.14); }
.settings-option:last-child { border-bottom: none; }
.settings-option.active { color: var(--accent); }

.settings-option-check {
    width: 16px;
    flex-shrink: 0;
    font-size: 13px;
    text-align: center;
	color: #8fc31f;
}

/* 字幕パネルは settings-panel に統合したため非表示化 */
#subtitle-panel { display: none !important; }

#settings-quality-menu-row{ display: none;}
