body {
margin: 0;
background: #111;
color: white;
font-family: sans-serif;
overflow: hidden;

padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
box-sizing: border-box;
}

#header {
height: 44px;
background: #222;
display: flex;
align-items: center;
gap: 8px;
padding: 0 10px;
box-sizing: border-box;
user-select: none;
overflow-x: auto;
}

button {
padding: 6px 10px;
cursor: pointer;
}

#imageSelector {
min-width: 70px;
max-width: 90px;
padding: 5px;
background: #333;
color: #fff;
border: 2px solid #fff;
border-radius: 4px;
}

#folderScopeSelector {
min-width: 140px;
max-width: 180px;
padding: 5px;
background: #333;
color: #fff;
border: 2px solid #fff;
border-radius: 4px;
}

#folderOpenHeaderButton {
min-width: 34px;
width: 34px;
height: 32px;
padding: 0;
display: inline-flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
text-align: center;
background: #eee;
border: 1px solid #888;
border-radius: 4px;
}


#pageReloadHeaderButton {
min-width: 34px;
width: 34px;
height: 32px;
padding: 0;
display: inline-flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
text-align: center;
font-size: 20px;
font-weight: bold;
color: #111;
background: #eee;
border: 1px solid #888;
border-radius: 4px;
}

.folderIcon {
position: relative;
display: inline-block;
width: 20px;
height: 15px;
box-sizing: border-box;
border: 2px solid #111;
border-radius: 2px;
background: rgba(0, 0, 0, 0.06);
}

.folderIcon::before {
content: '';
position: absolute;
left: -2px;
top: -7px;
width: 9px;
height: 6px;
box-sizing: border-box;
border: 2px solid #111;
border-bottom: 0;
border-radius: 2px 2px 0 0;
background: #eee;
}

#sortOrderSelector,
#fileTypeFilterSelector,
.menuSelect {
min-width: 110px;
max-width: 180px;
padding: 5px;
background: #333;
color: #fff;
border: 2px solid #fff;
border-radius: 4px;
}

#folderSelector {
min-width: 90px;
max-width: 180px;
padding: 5px;
background: #333;
color: #fff;
border: 1px solid #666;
border-radius: 4px;
}

#zoomLabel {
min-width: auto;
width: auto;
text-align: left;
color: #ccc;
font-size: 13px;
white-space: nowrap;
}

#zoomResetButton {
white-space: nowrap;
}

#zoomControls {
margin-left: auto;
display: inline-flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
}

#headerHideButton {
margin-left: 0;
min-width: 26px;
width: 26px;
padding: 6px 4px;
display: flex;
justify-content: center;
align-items: center;
}

.hideIcon {
display: inline-block;
width: 4px;
height: 24px;
border-radius: 999px;
background: #ccc;
}

#headerShowButton {
position: fixed;
top: calc(env(safe-area-inset-top) + 8px);
right: 8px;
z-index: 9000;
min-width: 24px;
width: 24px;
height: 48px;
padding: 4px;
background: rgba(34, 34, 34, 0.85);
color: #fff;
border: 1px solid #666;
border-radius: 999px;
display: flex;
justify-content: center;
align-items: center;
}

.showIcon {
display: inline-block;
width: 4px;
height: 28px;
border-radius: 999px;
background: #ccc;
}

#viewer {
height: calc(100vh - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
display: flex;
overflow-x: auto;
overflow-y: hidden;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
}

.page {
min-width: 100vw;
height: 100%;
scroll-snap-align: center;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.imageWrap,
.videoWrap {
width: 100vw;
height: calc(100vh - 90px);
overflow: auto;
}

.imageStage {
min-width: 100%;
min-height: 100%;
display: flex;
justify-content: center;
align-items: center;
}

img {
max-width: none;
max-height: none;
width: auto;
height: auto;
object-fit: contain;
transform: none;
transition: width 0.12s ease, height 0.12s ease;
}

.videoWrap {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 8px;
overflow: hidden;
}

.videoFrame {
width: 100vw;
height: calc(100% - 36px);
max-width: none;
border: 0;
background: #000;
}

.videoPlaceholder {
width: 100vw;
height: calc(100% - 36px);
max-width: none;
background: #000;
color: #ccc;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
border: 1px solid #333;
box-sizing: border-box;
}

.videoPage .videoWrap {
height: calc(100vh - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.videoPage .caption {
display: none;
}

.videoControls {
width: min(96vw, 720px);
display: flex;
justify-content: center;
align-items: center;
gap: 12px;
flex-wrap: wrap;
color: #ccc;
font-size: 13px;
}

.videoControls label {
display: inline-flex;
align-items: center;
gap: 4px;
}

.videoControls select {
background: #333;
color: #fff;
border: 1px solid #666;
border-radius: 4px;
padding: 4px 6px;
}

.videoControls a {
color: #9cf;
text-decoration: none;
}

.videoControls button {
padding: 4px 8px;
}

.caption {
margin-top: 8px;
font-size: 13px;
color: #ccc;
text-align: center;
max-width: 90vw;
word-break: break-all;
height: 38px;
}

body.headerHidden {
padding-top: 0;
}

body.headerHidden #header {
display: none;
}

body.headerHidden .caption {
display: none;
}

body.headerHidden #viewer {
height: calc(100vh - env(safe-area-inset-bottom));
}

body.headerHidden .imageWrap,
body.headerHidden .videoWrap {
height: calc(100vh - env(safe-area-inset-bottom));
}

body.headerHidden .videoPage .videoWrap {
height: calc(100vh - env(safe-area-inset-bottom));
}



.menuBackdrop {
position: fixed;
inset: 0;
z-index: 20000;
background: transparent;
}

.menuPanel {
position: fixed;
top: calc(env(safe-area-inset-top) + 52px);
left: 10px;
z-index: 20001;
width: min(320px, 88vw);
background: #222;
color: #fff;
border: 1px solid #555;
border-radius: 10px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
overflow: hidden;
}

.menuHeader {
padding: 10px 12px;
background: #333;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}

.menuTitle {
font-size: 16px;
font-weight: bold;
}

.menuSection {
padding: 12px;
}

.menuLabel {
display: flex;
flex-direction: column;
gap: 6px;
color: #ccc;
font-size: 13px;
}

.menuLabel select {
width: 100%;
}

.menuInlineRow {
display: flex;
align-items: flex-end;
justify-content: flex-start;
gap: 10px;
}

.menuLabelGrow {
flex: 0 0 160px;
min-width: 0;
}

.menuRadioGroup {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
color: #ccc;
font-size: 13px;
white-space: nowrap;
padding-bottom: 10px;
}

.menuRadioGroup label,
.filterCheckboxItem,
.menuCheckItem {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
}

.menuCheckItem {
color: #ccc;
font-size: 13px;
}

.filterCheckboxList {
margin-top: 8px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
color: #ccc;
font-size: 13px;
}

.filterCheckboxItem input,
.menuRadioGroup input,
.menuCheckItem input {
accent-color: #1976d2;
}


.dialogBackdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.72);
z-index: 9999;
display: flex;
justify-content: center;
align-items: flex-start;
padding-top: 24px;
box-sizing: border-box;
}

.dialogPanel {
width: min(92vw, 720px);
min-height: 420px;
max-height: 86vh;
background: #222;
color: #fff;
border: 1px solid #555;
border-radius: 10px;
display: flex;
flex-direction: column;
overflow: hidden;
}

.dialogHeader {
padding: 12px;
background: #333;
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
}

.dialogTitle {
font-size: 18px;
font-weight: bold;
}

.dialogSubTitle {
margin-top: 4px;
font-size: 13px;
color: #ccc;
word-break: break-all;
}

.dialogGroupTabs,
.dialogModeTabs {
padding: 10px;
display: flex;
gap: 8px;
border-bottom: 1px solid #444;
background: #262626;
}

.dialogGroupTabs {
background: #202020;
}

.dialogGroupTabs button,
.dialogModeTabs button {
background: #333;
color: #fff;
border: 1px solid #555;
border-radius: 6px;
}

.dialogGroupTabs button.activeMode,
.dialogModeTabs button.activeMode {
background: #666;
border-color: #aaa;
}

.dialogActions {
padding: 10px;
display: flex;
gap: 8px;
border-bottom: 1px solid #444;
}

#normalFolderSection,
#workCharacterSection,
#historySection {
flex: 1;
min-height: 0;
flex-direction: column;
}

#normalFolderSection {
display: flex;
}

#workCharacterSection,
#historySection {
display: none;
}

.folderList {
padding: 10px;
overflow-y: auto;
flex: 1;
min-height: 0;
-webkit-overflow-scrolling: touch;
}

.folderRow {
display: flex;
gap: 8px;
margin-bottom: 8px;
align-items: stretch;
}

.folderOpenButton {
flex: 1;
text-align: left;
padding: 12px;
background: #333;
color: #fff;
border: 1px solid #555;
border-radius: 6px;
cursor: pointer;
}

.folderOpenButton:hover {
background: #444;
}

.folderDisplayButton {
flex: 0 0 auto;
padding: 12px 16px;
background: #444;
color: #fff;
border: 1px solid #666;
border-radius: 6px;
cursor: pointer;
white-space: nowrap;
}

.folderDisplayButton:hover {
background: #555;
}

.historyMeta {
font-size: 0.85em;
color: #bbb;
}

.folderItem {
width: 100%;
text-align: left;
margin-bottom: 8px;
padding: 12px;
background: #333;
color: #fff;
border: 1px solid #555;
border-radius: 6px;
cursor: pointer;
}

.folderItem:hover {
background: #444;
}

.folderEmpty {
color: #ccc;
padding: 12px;
}

.workCharacterControls {
padding: 10px;
display: flex;
flex-direction: column;
gap: 10px;
border-bottom: 1px solid #444;
flex: 0 0 auto;
}

.workCharacterControls label {
display: flex;
flex-direction: column;
gap: 4px;
color: #ccc;
font-size: 13px;
}

.workCharacterControls select {
padding: 8px;
background: #333;
color: #fff;
border: 1px solid #666;
border-radius: 4px;
}

.authorItem {
width: 100%;
text-align: left;
margin-bottom: 8px;
padding: 12px;
background: #333;
color: #fff;
border: 1px solid #555;
border-radius: 6px;
cursor: pointer;
}

.authorItem:hover {
background: #444;
}



.lastFolderConfirmBackdrop {
position: fixed;
inset: 0;
z-index: 12000;
background: rgba(0, 0, 0, 0.72);
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
box-sizing: border-box;
}

.lastFolderConfirmPanel {
width: min(92vw, 520px);
background: #222;
color: #fff;
border: 1px solid #555;
border-radius: 10px;
padding: 18px;
box-sizing: border-box;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.lastFolderConfirmTitle {
font-size: 18px;
font-weight: bold;
margin-bottom: 14px;
}

.lastFolderConfirmBody {
margin-bottom: 14px;
word-break: break-all;
}

.lastFolderConfirmTrail {
color: #aaa;
font-size: 13px;
line-height: 1.5;
margin-bottom: 4px;
}

.lastFolderConfirmFolderName {
color: #fff;
font-size: 20px;
line-height: 1.45;
font-weight: bold;
}

.lastFolderConfirmNote {
color: #ccc;
font-size: 13px;
margin-bottom: 16px;
}

.lastFolderConfirmActions {
display: flex;
justify-content: flex-end;
gap: 10px;
}

.lastFolderConfirmActions .primaryButton {
background: #555;
color: #fff;
border: 1px solid #888;
}

@media screen and (orientation: portrait) and (max-width: 1000px) {
#header {
    height: 96px !important;
    gap: 14px !important;
    padding: 0 14px !important;
    overflow-x: auto !important;
}

#header button {
    font-size: 32px !important;
    padding: 14px 20px !important;
    min-width: 72px !important;
    min-height: 64px !important;
    line-height: 1.2 !important;
}

#folderOpenHeaderButton {
    min-width: 56px !important;
    width: 56px !important;
    height: 64px !important;
    padding: 0 !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    background: #eee !important;
    border: 1px solid #888 !important;
    border-radius: 6px !important;
}


#pageReloadHeaderButton {
    min-width: 56px !important;
    width: 56px !important;
    height: 64px !important;
    padding: 0 !important;
    display: inline-flex !important;
    justify-content: center !important;
    align-items: center !important;
    font-size: 34px !important;
    color: #111 !important;
    background: #eee !important;
    border: 1px solid #888 !important;
    border-radius: 6px !important;
}

.folderIcon {
    width: 30px !important;
    height: 22px !important;
    border-width: 3px !important;
    border-radius: 3px !important;
    border-color: #111 !important;
    background: rgba(0, 0, 0, 0.06) !important;
}

.folderIcon::before {
    left: -3px !important;
    top: -10px !important;
    width: 14px !important;
    height: 9px !important;
    border-width: 3px !important;
    border-bottom: 0 !important;
    background: #222 !important;
}

#folderScopeSelector {
    font-size: 30px !important;
    min-width: 200px !important;
    max-width: 260px !important;
    height: 64px !important;
    padding: 10px !important;
    border: 2px solid #fff !important;
}

#imageSelector {
    font-size: 30px !important;
    min-width: 150px !important;
    max-width: 195px !important;
    height: 64px !important;
    padding: 10px !important;
    border: 2px solid #fff !important;
}

#filterSelector,
#sortOrderSelector,
#fileTypeFilterSelector {
    font-size: 30px !important;
    min-width: 180px !important;
    max-width: 240px !important;
    height: 64px !important;
    padding: 10px !important;
}

#folderSelector {
    font-size: 30px !important;
    min-width: 170px !important;
    max-width: 260px !important;
    height: 64px !important;
    padding: 10px !important;
}

.zoomButton {
    display: none !important;
}

#zoomLabel {
    font-size: 30px !important;
    min-width: auto !important;
    width: auto !important;
    text-align: left !important;
    white-space: nowrap !important;
}

#zoomResetButton {
    display: none !important;
}

#zoomControls {
    margin-left: auto !important;
    gap: 12px !important;
}

#headerHideButton {
    margin-left: 0 !important;
    min-width: 42px !important;
    width: 42px !important;
    height: 64px !important;
    padding: 8px !important;
}

.hideIcon {
    width: 6px !important;
    height: 42px !important;
}

#headerShowButton {
    top: calc(env(safe-area-inset-top) + 12px) !important;
    right: 12px !important;
    width: 42px !important;
    height: 72px !important;
}

.showIcon {
    width: 6px !important;
    height: 48px !important;
}

#viewer {
    height: calc(100vh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
}

.imageWrap,
.videoWrap {
    height: calc(100vh - 150px) !important;
}

.videoFrame,
.videoPlaceholder {
    width: 100vw !important;
    height: calc(100% - 54px) !important;
    max-width: none !important;
}

.videoPage .videoWrap {
    height: calc(100vh - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
}

.videoControls {
    font-size: 22px !important;
    gap: 14px !important;
}

.videoControls select {
    font-size: 22px !important;
    padding: 10px !important;
}

.caption {
    font-size: 20px !important;
    height: 54px !important;
}

body.headerHidden #viewer {
    height: calc(100vh - env(safe-area-inset-bottom)) !important;
}

body.headerHidden .imageWrap,
body.headerHidden .videoWrap {
    height: calc(100vh - env(safe-area-inset-bottom)) !important;
}

body.headerHidden .videoPage .videoWrap {
    height: calc(100vh - env(safe-area-inset-bottom)) !important;
}

body.headerHidden .caption {
    display: none !important;
}

.menuPanel {
    top: calc(env(safe-area-inset-top) + 108px) !important;
    left: 14px !important;
    width: min(560px, 92vw) !important;
}

.menuTitle {
    font-size: 28px !important;
}

.menuHeader button {
    font-size: 26px !important;
    padding: 8px 14px !important;
    min-width: 56px !important;
    min-height: 48px !important;
}

.menuInlineRow {
    gap: 14px !important;
    align-items: flex-end !important;
}

.menuLabel {
    font-size: 24px !important;
    gap: 10px !important;
}

.menuLabelGrow {
    flex: 0 0 260px !important;
    min-width: 0 !important;
}

.menuLabel select {
    font-size: 28px !important;
    height: 64px !important;
    padding: 10px !important;
}

.menuRadioGroup {
    flex-direction: row !important;
    align-items: center !important;
    gap: 16px !important;
    padding-bottom: 14px !important;
}



.dialogBackdrop {
    align-items: flex-start !important;
    padding-top: calc(env(safe-area-inset-top) + 12px) !important;
}

.dialogPanel {
    width: 96vw !important;
    min-height: 70vh !important;
    max-height: 88vh !important;
}

.dialogTitle {
    font-size: 28px !important;
}

.dialogSubTitle {
    font-size: 20px !important;
}

.dialogGroupTabs button,
.dialogModeTabs button {
    font-size: 22px !important;
    padding: 12px 16px !important;
}

.dialogActions button {
    font-size: 24px !important;
    padding: 12px 16px !important;
}

.folderOpenButton,
.folderDisplayButton {
    font-size: 24px !important;
    padding: 18px !important;
}

.folderDisplayButton {
    min-width: 120px !important;
}

.folderItem,
.authorItem {
    font-size: 24px !important;
    padding: 18px !important;
}

.workCharacterControls label {
    font-size: 22px !important;
}

.workCharacterControls select {
    font-size: 24px !important;
    padding: 14px !important;
}

.workCharacterControls button {
    font-size: 24px !important;
    padding: 14px 18px !important;
}


#sortOrderSelector,
#fileTypeFilterSelector,
.menuSelect {
    font-size: 22px !important;
    padding: 10px !important;
    min-height: 52px !important;
}

.menuRadioGroup,
.filterCheckboxList,
.menuLabel,
.menuCheckItem {
    font-size: 20px !important;
}

.menuRadioGroup input,
.filterCheckboxItem input,
.menuCheckItem input {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    transform: scale(1.35);
    transform-origin: center;
    margin: 8px !important;
}

.filterCheckboxList {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px 18px !important;
}

.lastFolderConfirmPanel {
    width: 94vw !important;
    padding: 22px !important;
}

.lastFolderConfirmTitle {
    font-size: 26px !important;
}

.lastFolderConfirmTrail,
.lastFolderConfirmNote {
    font-size: 20px !important;
}

.lastFolderConfirmFolderName {
    font-size: 28px !important;
}

.lastFolderConfirmActions button {
    font-size: 24px !important;
    padding: 12px 18px !important;
}

}